44#ifndef ROL_TYPEP_QUASINEWTONALGORITHM_DEF_HPP
45#define ROL_TYPEP_QUASINEWTONALGORITHM_DEF_HPP
55template<
typename Real>
64 ParameterList &lslist = list.sublist(
"Step").sublist(
"Line Search");
65 t0_ = list.sublist(
"Status Test").get(
"Gradient Scale" , 1.0);
66 initProx_ = lslist.get(
"Apply Prox to Initial Guess",
false);
67 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
68 c1_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
69 rhodec_ = lslist.sublist(
"Line-Search Method").get(
"Backtracking Rate", 0.5);
70 sigma1_ = lslist.sublist(
"PQN").get(
"Lower Step Size Safeguard", 0.1);
71 sigma2_ = lslist.sublist(
"PQN").get(
"Upper Step Size Safeguard", 0.9);
72 algoName_ = lslist.sublist(
"PQN").get(
"Subproblem Solver",
"Spectral Gradient");
73 int sp_maxit = lslist.sublist(
"PQN").get(
"Subproblem Iteration Limit", 1000);
74 sp_tol1_ = lslist.sublist(
"PQN").get(
"Subproblem Absolute Tolerance", 1e-4);
75 sp_tol2_ = lslist.sublist(
"PQN").get(
"Subproblem Relative Tolerance", 1e-2);
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);
85 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
90 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"User Defined Secant Name",
91 "Unspecified User Defined Secant Method");
96template<
typename Real>
102 std::ostream &outStream) {
110 state_->iterateVec->set(x);
125template<
typename Real>
130 std::ostream &outStream ) {
131 const Real half(0.5), one(1);
135 Real strial(0), ntrial(0), ftrial(0), gs(0), Qk(0), rhoTmp(0);
138 Ptr<TypeP::Algorithm<Real>> algo;
139 Ptr<PQNObjective<Real>> qobj = makePtr<PQNObjective<Real>>(
secant_,x,g);
146 xs->set(*
state_->iterateVec);
147 state_->iterateVec->set(x);
150 qobj->setAnchor(x,*
state_->gradientVec);
152 list_.sublist(
"Status Test").set(
"Gradient Tolerance",gtol);
153 if (
algoName_ ==
"Line Search") algo = makePtr<TypeP::ProxGradientAlgorithm<Real>>(
list_);
154 else if (
algoName_ ==
"iPiano") algo = makePtr<TypeP::iPianoAlgorithm<Real>>(
list_);
155 else algo = makePtr<TypeP::SpectralGradientAlgorithm<Real>>(
list_);
156 algo->run(*xs,*qobj,nobj,outStream);
157 s->set(*xs); s->axpy(-one,x);
159 state_->nprox += staticPtrCast<const TypeP::AlgorithmState<Real>>(algo->getState())->nprox;
167 strial = sobj.
value(x,tol);
168 ntrial = nobj.
value(x,tol);
169 ftrial = strial + ntrial;
171 gs =
state_->gradientVec->apply(*s);
172 Qk = gs + ntrial -
state_->nvalue;
174 outStream <<
" In TypeP::QuasiNewtonAlgorithm: Line Search" << std::endl;
175 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
176 outStream <<
" Trial objective value: " << ftrial << std::endl;
177 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
178 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
179 outStream <<
" Sufficient decrease bound: " << -Qk*
c1_ << std::endl;
180 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
183 rhoTmp = -half * Qk / (strial-
state_->svalue-
state_->searchSize*gs);
189 strial = sobj.
value(x,tol);
190 ntrial = nobj.
value(x,tol);
191 ftrial = strial + ntrial;
195 outStream << std::endl;
196 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
197 outStream <<
" Trial objective value: " << ftrial << std::endl;
198 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
199 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
200 outStream <<
" Sufficient decrease bound: " << -Qk*
c1_ << std::endl;
201 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
213 state_->iterateVec->set(x);
222 gold->set(*
state_->gradientVec);
224 gp->set(
state_->gradientVec->dual());
239template<
typename Real>
241 std::stringstream hist;
243 hist << std::string(114,
'-') << std::endl;
244 hist <<
"Line-Search Proximal Quasi-Newton with " <<
secantName_ <<
" Hessian approximation";
245 hist <<
" status output definitions" << std::endl << std::endl;
246 hist <<
" iter - Number of iterates (steps taken)" << std::endl;
247 hist <<
" value - Objective function value" << std::endl;
248 hist <<
" gnorm - Norm of the gradient" << std::endl;
249 hist <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
250 hist <<
" alpha - Line search step length" << std::endl;
251 hist <<
" #sval - Cumulative number of times the smooth objective function was evaluated" << std::endl;
252 hist <<
" #nval - Cumulative number of times the nonsmooth objective function was evaluated" << std::endl;
253 hist <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
254 hist <<
" #prox - Cumulative number of times the projection was computed" << std::endl;
255 hist <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
256 hist <<
" sp_iter - Number iterations to compute quasi-Newton step" << std::endl;
257 hist << std::string(114,
'-') << std::endl;
261 hist << std::setw(6) << std::left <<
"iter";
262 hist << std::setw(15) << std::left <<
"value";
263 hist << std::setw(15) << std::left <<
"gnorm";
264 hist << std::setw(15) << std::left <<
"snorm";
265 hist << std::setw(15) << std::left <<
"alpha";
266 hist << std::setw(10) << std::left <<
"#sval";
267 hist << std::setw(10) << std::left <<
"#nval";
268 hist << std::setw(10) << std::left <<
"#grad";
269 hist << std::setw(10) << std::left <<
"#prox";
270 hist << std::setw(10) << std::left <<
"#ls_fval";
271 hist << std::setw(10) << std::left <<
"sp_iter";
276template<
typename Real>
278 std::stringstream hist;
279 hist << std::endl <<
"Line-Search Proximal Quasi-Newton (Type P)" << std::endl;
283template<
typename Real>
285 std::stringstream hist;
286 hist << std::scientific << std::setprecision(6);
289 if (
state_->iter == 0 ) {
291 hist << std::setw(6) << std::left <<
state_->iter;
292 hist << std::setw(15) << std::left <<
state_->value;
293 hist << std::setw(15) << std::left <<
state_->gnorm;
294 hist << std::setw(15) << std::left <<
"---";
295 hist << std::setw(15) << std::left <<
"---";
296 hist << std::setw(10) << std::left <<
state_->nsval;
297 hist << std::setw(10) << std::left <<
state_->nnval;
298 hist << std::setw(10) << std::left <<
state_->ngrad;
299 hist << std::setw(10) << std::left <<
state_->nprox;
300 hist << std::setw(10) << std::left <<
"---";
301 hist << std::setw(10) << std::left <<
"---";
306 hist << std::setw(6) << std::left <<
state_->iter;
307 hist << std::setw(15) << std::left <<
state_->value;
308 hist << std::setw(15) << std::left <<
state_->gnorm;
309 hist << std::setw(15) << std::left <<
state_->snorm;
310 hist << std::setw(15) << std::left <<
state_->searchSize;
311 hist << std::setw(10) << std::left <<
state_->nsval;
312 hist << std::setw(10) << std::left <<
state_->nnval;
313 hist << std::setw(10) << std::left <<
state_->ngrad;
314 hist << std::setw(10) << std::left <<
state_->nprox;
315 hist << std::setw(10) << std::left <<
ls_nfval_;
316 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 interface for and implements limited-memory secant operators.
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 rhodec_
Backtracking rate (default: 0.5).
Real sigma2_
Upper safeguard for quadratic line search (default: 0.9).
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
QuasiNewtonAlgorithm(ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
Real sigma1_
Lower safeguard for quadratic line search (default: 0.1).
Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton).
int maxit_
Maximum number of line search steps (default: 20).
Real c1_
Sufficient Decrease Parameter (default: 1e-4).
void writeHeader(std::ostream &os) const override
Print iterate header.
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, Vector< Real > &dg, std::ostream &outStream=std::cout)
ESecant esec_
Secant type.
std::string secantName_
Secant name.
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...
void writeName(std::ostream &os) const override
Print step name.
Defines the linear algebra or vector space interface.
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.
ESecant StringToESecant(std::string s)
ROL::Ptr< Secant< Real > > SecantFactory(ROL::ParameterList &parlist, ESecantMode mode=SECANTMODE_BOTH)