44#ifndef ROL_TYPEP_QUASINEWTONALGORITHM_DEF_HPP
45#define ROL_TYPEP_QUASINEWTONALGORITHM_DEF_HPP
55template<
typename Real>
63 ParameterList &lslist = list.sublist(
"Step").sublist(
"Line Search");
64 t0_ = list.sublist(
"Status Test").get(
"Gradient Scale" , 1.0);
65 initProx_ = lslist.get(
"Apply Prox to Initial Guess",
false);
66 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
67 c1_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
68 rhodec_ = lslist.sublist(
"Line-Search Method").get(
"Backtracking Rate", 0.5);
69 sigma1_ = lslist.sublist(
"Inexact Newton").get(
"Lower Step Size Safeguard", 0.1);
70 sigma2_ = lslist.sublist(
"Inexact Newton").get(
"Upper Step Size Safeguard", 0.9);
71 algoName_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Solver",
"Spectral Gradient");
72 int sp_maxit = lslist.sublist(
"Inexact Newton").get(
"Subproblem Iteration Limit", 1000);
73 sp_tol1_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Absolute Tolerance", 1e-4);
74 sp_tol2_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Relative Tolerance", 1e-2);
75 sp_exp_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Tolerance Exponent", 1.0);
76 Real opt_tol = lslist.sublist(
"Status Test").get(
"Gradient Tolerance", 1e-8);
78 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
81 list_.sublist(
"Status Test").set(
"Iteration Limit", sp_maxit);
86template<
typename Real>
93 std::ostream &outStream) {
101 state_->iterateVec->set(x);
117template<
typename Real>
122 std::ostream &outStream ) {
127 Real strial(0), ntrial(0), ftrial(0), gs(0), Qk(0), rhoTmp(0);
130 Ptr<TypeP::Algorithm<Real>> algo;
131 Ptr<NewtonObj> qobj = makePtr<NewtonObj>(makePtrFromRef(sobj),x,g);
137 xs->set(*
state_->iterateVec);
138 state_->iterateVec->set(x);
140 qobj->setData(x,*
state_->gradientVec);
143 list_.sublist(
"Status Test").set(
"Gradient Tolerance",gtol);
144 if (
algoName_ ==
"Line Search") algo = makePtr<TypeP::ProxGradientAlgorithm<Real>>(
list_);
145 else if (
algoName_ ==
"iPiano") algo = makePtr<TypeP::iPianoAlgorithm<Real>>(
list_);
146 else if (
algoName_ ==
"Trust Region") algo = makePtr<TypeP::TrustRegionAlgorithm<Real>>(
list_);
147 else algo = makePtr<TypeP::SpectralGradientAlgorithm<Real>>(
list_);
148 algo->run(*xs,*qobj,nobj,outStream);
149 s->set(*xs); s->axpy(-one,x);
151 nhess_ += qobj->numHessVec();
152 state_->nprox += staticPtrCast<const TypeP::AlgorithmState<Real>>(algo->getState())->nprox;
160 strial = sobj.
value(x,tol);
161 ntrial = nobj.
value(x,tol);
162 ftrial = strial + ntrial;
164 gs =
state_->gradientVec->apply(*s);
165 Qk = gs + ntrial -
state_->nvalue;
167 outStream <<
" In TypeP::InexactNewtonAlgorithm: Line Search" << std::endl;
168 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
169 outStream <<
" Trial objective value: " << ftrial << std::endl;
170 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
171 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
172 outStream <<
" Sufficient decrease bound: " << -Qk*
c1_ << std::endl;
173 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
181 strial = sobj.
value(x,tol);
182 ntrial = nobj.
value(x,tol);
183 ftrial = strial + ntrial;
185 gs =
state_->gradientVec->apply(*s);
186 Qk = gs + ntrial -
state_->nvalue;
189 rhoTmp = -half * Qk / (strial-
state_->svalue-
state_->searchSize*gs);
195 strial = sobj.
value(x,tol);
196 ntrial = nobj.
value(x,tol);
197 ftrial = strial + ntrial;
201 outStream << std::endl;
202 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
203 outStream <<
" Trial objective value: " << ftrial << std::endl;
204 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
205 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
206 outStream <<
" Sufficient decrease bound: " << -Qk*
c1_ << std::endl;
207 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
219 state_->iterateVec->set(x);
229 gp->set(
state_->gradientVec->dual());
241template<
typename Real>
243 std::stringstream hist;
245 hist << std::string(114,
'-') << std::endl;
246 hist <<
"Line-Search Inexact Proximal Newton";
247 hist <<
" status output definitions" << std::endl << std::endl;
248 hist <<
" iter - Number of iterates (steps taken)" << std::endl;
249 hist <<
" value - Objective function value" << std::endl;
250 hist <<
" gnorm - Norm of the gradient" << std::endl;
251 hist <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
252 hist <<
" alpha - Line search step length" << std::endl;
253 hist <<
" #sval - Cumulative number of times the smooth objective function was evaluated" << std::endl;
254 hist <<
" #nval - Cumulative number of times the nonsmooth objective function was evaluated" << std::endl;
255 hist <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
256 hist <<
" #hess - Cumulative number of times the Hessian was applied" << std::endl;
257 hist <<
" #prox - Cumulative number of times the projection was computed" << std::endl;
258 hist <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
259 hist <<
" sp_iter - Number iterations to compute quasi-Newton step" << std::endl;
260 hist << std::string(114,
'-') << std::endl;
264 hist << std::setw(6) << std::left <<
"iter";
265 hist << std::setw(15) << std::left <<
"value";
266 hist << std::setw(15) << std::left <<
"gnorm";
267 hist << std::setw(15) << std::left <<
"snorm";
268 hist << std::setw(15) << std::left <<
"alpha";
269 hist << std::setw(10) << std::left <<
"#sval";
270 hist << std::setw(10) << std::left <<
"#nval";
271 hist << std::setw(10) << std::left <<
"#grad";
272 hist << std::setw(10) << std::left <<
"#hess";
273 hist << std::setw(10) << std::left <<
"#prox";
274 hist << std::setw(10) << std::left <<
"#ls_fval";
275 hist << std::setw(10) << std::left <<
"sp_iter";
280template<
typename Real>
282 std::stringstream hist;
283 hist << std::endl <<
"Line-Search Inexact Proximal Newton (Type P)" << std::endl;
287template<
typename Real>
289 std::stringstream hist;
290 hist << std::scientific << std::setprecision(6);
293 if (
state_->iter == 0 ) {
295 hist << std::setw(6) << std::left <<
state_->iter;
296 hist << std::setw(15) << std::left <<
state_->value;
297 hist << std::setw(15) << std::left <<
state_->gnorm;
298 hist << std::setw(15) << std::left <<
"---";
299 hist << std::setw(15) << std::left <<
"---";
300 hist << std::setw(10) << std::left <<
state_->nsval;
301 hist << std::setw(10) << std::left <<
state_->nnval;
302 hist << std::setw(10) << std::left <<
state_->ngrad;
303 hist << std::setw(10) << std::left <<
nhess_;
304 hist << std::setw(10) << std::left <<
state_->nprox;
305 hist << std::setw(10) << std::left <<
"---";
306 hist << std::setw(10) << std::left <<
"---";
311 hist << std::setw(6) << std::left <<
state_->iter;
312 hist << std::setw(15) << std::left <<
state_->value;
313 hist << std::setw(15) << std::left <<
state_->gnorm;
314 hist << std::setw(15) << std::left <<
state_->snorm;
315 hist << std::setw(15) << std::left <<
state_->searchSize;
316 hist << std::setw(10) << std::left <<
state_->nsval;
317 hist << std::setw(10) << std::left <<
state_->nnval;
318 hist << std::setw(10) << std::left <<
state_->ngrad;
319 hist << std::setw(10) << std::left <<
nhess_;
320 hist << std::setw(10) << std::left <<
state_->nprox;
321 hist << std::setw(10) << std::left <<
ls_nfval_;
322 hist << std::setw(10) << std::left <<
spgIter_;
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Provides the interface to evaluate objective functions.
virtual void prox(Vector< Real > &Pv, const Vector< Real > &v, Real t, Real &tol)
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
Provides an interface to check status of optimization algorithms.
void pgstep(Vector< Real > &pgiter, Vector< Real > &pgstep, Objective< Real > &nobj, const Vector< Real > &x, const Vector< Real > &dg, Real t, Real &tol) const
const Ptr< AlgorithmState< Real > > state_
virtual void writeExitStatus(std::ostream &os) const
const Ptr< CombinedStatusTest< Real > > status_
void initialize(const Vector< Real > &x, const Vector< Real > &g)
Real c1_
Sufficient Decrease Parameter (default: 1e-4).
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, std::ostream &outStream=std::cout) override
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
InexactNewtonAlgorithm(ParameterList &list)
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, Vector< Real > &dg, Vector< Real > &px, std::ostream &outStream=std::cout)
Real sigma2_
Upper safeguard for quadratic line search (default: 0.9).
Real sigma1_
Lower safeguard for quadratic line search (default: 0.1).
void writeName(std::ostream &os) const override
Print step name.
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
int maxit_
Maximum number of line search steps (default: 20).
Real rhodec_
Backtracking rate (default: 0.5).
void writeHeader(std::ostream &os) const override
Print iterate header.
Defines the linear algebra or vector space interface.
virtual Real norm() const =0
Returns where .
virtual void set(const Vector &x)
Set where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.