10#ifndef ROL_TYPEP_QUASINEWTONALGORITHM_DEF_HPP
11#define ROL_TYPEP_QUASINEWTONALGORITHM_DEF_HPP
21template<
typename Real>
30 ParameterList &lslist = list.sublist(
"Step").sublist(
"Line Search");
31 t0_ = list.sublist(
"Status Test").get(
"Gradient Scale" , 1.0);
32 initProx_ = lslist.get(
"Apply Prox to Initial Guess",
false);
33 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
34 c1_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
35 rhodec_ = lslist.sublist(
"Line-Search Method").get(
"Backtracking Rate", 0.5);
36 sigma1_ = lslist.sublist(
"PQN").get(
"Lower Step Size Safeguard", 0.1);
37 sigma2_ = lslist.sublist(
"PQN").get(
"Upper Step Size Safeguard", 0.9);
38 algoName_ = lslist.sublist(
"PQN").get(
"Subproblem Solver",
"Spectral Gradient");
39 int sp_maxit = lslist.sublist(
"PQN").get(
"Subproblem Iteration Limit", 1000);
40 sp_tol1_ = lslist.sublist(
"PQN").get(
"Subproblem Absolute Tolerance", 1e-4);
41 sp_tol2_ = lslist.sublist(
"PQN").get(
"Subproblem Relative Tolerance", 1e-2);
42 Real opt_tol = lslist.sublist(
"Status Test").get(
"Gradient Tolerance", 1e-8);
44 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
47 list_.sublist(
"Status Test").set(
"Iteration Limit", sp_maxit);
51 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
56 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"User Defined Secant Name",
57 "Unspecified User Defined Secant Method");
62template<
typename Real>
68 std::ostream &outStream) {
76 state_->iterateVec->set(x);
91template<
typename Real>
96 std::ostream &outStream ) {
97 const Real half(0.5), one(1);
101 Real strial(0), ntrial(0), ftrial(0), gs(0), Qk(0), rhoTmp(0);
104 Ptr<TypeP::Algorithm<Real>> algo;
105 Ptr<PQNObjective<Real>> qobj = makePtr<PQNObjective<Real>>(
secant_,x,g);
112 xs->set(*
state_->iterateVec);
113 state_->iterateVec->set(x);
116 qobj->setAnchor(x,*
state_->gradientVec);
118 list_.sublist(
"Status Test").set(
"Gradient Tolerance",gtol);
119 if (
algoName_ ==
"Line Search") algo = makePtr<TypeP::ProxGradientAlgorithm<Real>>(
list_);
120 else if (
algoName_ ==
"iPiano") algo = makePtr<TypeP::iPianoAlgorithm<Real>>(
list_);
121 else algo = makePtr<TypeP::SpectralGradientAlgorithm<Real>>(
list_);
122 algo->run(*xs,*qobj,nobj,outStream);
123 s->set(*xs); s->axpy(-one,x);
125 state_->nprox += staticPtrCast<const TypeP::AlgorithmState<Real>>(algo->getState())->nprox;
133 strial = sobj.
value(x,tol);
134 ntrial = nobj.
value(x,tol);
135 ftrial = strial + ntrial;
137 gs =
state_->gradientVec->apply(*s);
138 Qk = gs + ntrial -
state_->nvalue;
140 outStream <<
" In TypeP::QuasiNewtonAlgorithm: Line Search" << std::endl;
141 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
142 outStream <<
" Trial objective value: " << ftrial << std::endl;
143 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
144 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
145 outStream <<
" Sufficient decrease bound: " << -Qk*
c1_ << std::endl;
146 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
149 rhoTmp = -half * Qk / (strial-
state_->svalue-
state_->searchSize*gs);
155 strial = sobj.
value(x,tol);
156 ntrial = nobj.
value(x,tol);
157 ftrial = strial + ntrial;
161 outStream << std::endl;
162 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
163 outStream <<
" Trial objective value: " << ftrial << std::endl;
164 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
165 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
166 outStream <<
" Sufficient decrease bound: " << -Qk*
c1_ << std::endl;
167 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
179 state_->iterateVec->set(x);
188 gold->set(*
state_->gradientVec);
190 gp->set(
state_->gradientVec->dual());
205template<
typename Real>
207 std::ios_base::fmtflags osFlags(os.flags());
209 os << std::string(114,
'-') << std::endl;
210 os <<
"Line-Search Proximal Quasi-Newton with " <<
secantName_ <<
" Hessian approximation";
211 os <<
" status output definitions" << std::endl << std::endl;
212 os <<
" iter - Number of iterates (steps taken)" << std::endl;
213 os <<
" value - Objective function value" << std::endl;
214 os <<
" gnorm - Norm of the gradient" << std::endl;
215 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
216 os <<
" alpha - Line search step length" << std::endl;
217 os <<
" #sval - Cumulative number of times the smooth objective function was evaluated" << std::endl;
218 os <<
" #nval - Cumulative number of times the nonsmooth objective function was evaluated" << std::endl;
219 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
220 os <<
" #prox - Cumulative number of times the projection was computed" << std::endl;
221 os <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
222 os <<
" sp_iter - Number iterations to compute quasi-Newton step" << std::endl;
223 os << std::string(114,
'-') << std::endl;
227 os << std::setw(6) << std::left <<
"iter";
228 os << std::setw(15) << std::left <<
"value";
229 os << std::setw(15) << std::left <<
"gnorm";
230 os << std::setw(15) << std::left <<
"snorm";
231 os << std::setw(15) << std::left <<
"alpha";
232 os << std::setw(10) << std::left <<
"#sval";
233 os << std::setw(10) << std::left <<
"#nval";
234 os << std::setw(10) << std::left <<
"#grad";
235 os << std::setw(10) << std::left <<
"#prox";
236 os << std::setw(10) << std::left <<
"#ls_fval";
237 os << std::setw(10) << std::left <<
"sp_iter";
242template<
typename Real>
244 std::ios_base::fmtflags osFlags(os.flags());
245 os << std::endl <<
"Line-Search Proximal Quasi-Newton (Type P)" << std::endl;
249template<
typename Real>
251 std::ios_base::fmtflags osFlags(os.flags());
252 os << std::scientific << std::setprecision(6);
255 if (
state_->iter == 0 ) {
257 os << std::setw(6) << std::left <<
state_->iter;
258 os << std::setw(15) << std::left <<
state_->value;
259 os << std::setw(15) << std::left <<
state_->gnorm;
260 os << std::setw(15) << std::left <<
"---";
261 os << std::setw(15) << std::left <<
"---";
262 os << std::setw(10) << std::left <<
state_->nsval;
263 os << std::setw(10) << std::left <<
state_->nnval;
264 os << std::setw(10) << std::left <<
state_->ngrad;
265 os << std::setw(10) << std::left <<
state_->nprox;
266 os << std::setw(10) << std::left <<
"---";
267 os << std::setw(10) << std::left <<
"---";
272 os << std::setw(6) << std::left <<
state_->iter;
273 os << std::setw(15) << std::left <<
state_->value;
274 os << std::setw(15) << std::left <<
state_->gnorm;
275 os << std::setw(15) << std::left <<
state_->snorm;
276 os << std::setw(15) << std::left <<
state_->searchSize;
277 os << std::setw(10) << std::left <<
state_->nsval;
278 os << std::setw(10) << std::left <<
state_->nnval;
279 os << std::setw(10) << std::left <<
state_->ngrad;
280 os << std::setw(10) << std::left <<
state_->nprox;
281 os << std::setw(10) << std::left <<
ls_nfval_;
282 os << 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)
Compute the proximity operator.
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)