44#ifndef ROL_TYPEB_QUASINEWTONALGORITHM_DEF_HPP
45#define ROL_TYPEB_QUASINEWTONALGORITHM_DEF_HPP
58template<
typename Real>
67 ParameterList &lslist = list.sublist(
"Step").sublist(
"Line Search");
68 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
69 c1_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
70 rhodec_ = lslist.sublist(
"Line-Search Method").get(
"Backtracking Rate", 0.5);
71 sigma1_ = lslist.sublist(
"PQN").get(
"Lower Step Size Safeguard", 0.1);
72 sigma2_ = lslist.sublist(
"PQN").get(
"Upper Step Size Safeguard", 0.9);
73 algoName_ = lslist.sublist(
"PQN").get(
"Subproblem Solver",
"Spectral Gradient");
74 int sp_maxit = lslist.sublist(
"PQN").get(
"Subproblem Iteration Limit", 1000);
75 sp_tol1_ = lslist.sublist(
"PQN").get(
"Subproblem Absolute Tolerance", 1e-4);
76 sp_tol2_ = lslist.sublist(
"PQN").get(
"Subproblem Relative Tolerance", 1e-2);
77 Real opt_tol = lslist.sublist(
"Status Test").get(
"Gradient Tolerance", 1e-8);
79 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
82 list_.sublist(
"Status Test").set(
"Iteration Limit", sp_maxit);
86 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
91 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"User Defined Secant Name",
92 "Unspecified User Defined Secant Method");
97template<
typename Real>
102 std::ostream &outStream) {
104 if (
proj_ == nullPtr) {
105 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
113 state_->iterateVec->set(x);
118 state_->stepVec->axpy(-one,
state_->gradientVec->dual());
120 state_->stepVec->axpy(-one,x);
125template<
typename Real>
130 std::ostream &outStream ) {
131 const Real half(0.5), one(1);
135 Real ftrial(0), gs(0), alphaTmp(0), tol(std::sqrt(
ROL_EPSILON<Real>())), gtol(1);
137 Ptr<TypeB::Algorithm<Real>> algo;
138 Ptr<PQNObjective<Real>> qobj = makePtr<PQNObjective<Real>>(
secant_,x,g);
139 Ptr<Problem<Real>> problem = makePtr<Problem<Real>>(qobj,xs);
140 problem->addBoundConstraint(makePtrFromRef(bnd));
142 problem->addLinearConstraint(
"LEC",
proj_->getLinearConstraint(),
143 proj_->getMultiplier(),
144 proj_->getResidual());
145 problem->setProjectionAlgorithm(
list_);
147 problem->finalize(
false,
verbosity_>2,outStream);
153 gp->set(
state_->gradientVec->dual());
156 qobj->setAnchor(x,*
state_->gradientVec);
157 xs->set(x); xs->axpy(-one,*gp);
proj_->project(*xs,outStream);
state_->nproj++;
159 list_.sublist(
"Status Test").set(
"Gradient Tolerance",gtol);
160 if (
algoName_ ==
"Trust Region") algo = makePtr<TypeB::LinMoreAlgorithm<Real>>(
list_);
161 else if (
algoName_ ==
"Line Search") algo = makePtr<TypeB::GradientAlgorithm<Real>>(
list_);
162 else if (
algoName_ ==
"Primal Dual Active Set") algo = makePtr<TypeB::PrimalDualActiveSetAlgorithm<Real>>(
list_);
163 else if (
algoName_ ==
"Moreau-Yosida") algo = makePtr<TypeB::MoreauYosidaAlgorithm<Real>>(
list_);
164 else if (
algoName_ ==
"Interior Point") algo = makePtr<TypeB::InteriorPointAlgorithm<Real>>(
list_);
165 else algo = makePtr<TypeB::SpectralGradientAlgorithm<Real>>(
list_);
166 algo->run(*problem,outStream);
167 s->set(*xs); s->axpy(-one,x);
169 state_->nproj += staticPtrCast<const TypeB::AlgorithmState<Real>>(algo->getState())->nproj;
177 gs =
state_->gradientVec->apply(*s);
179 outStream <<
" In TypeB::QuasiNewtonAlgorithm: Line Search" << std::endl;
180 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
181 outStream <<
" Trial objective value: " << ftrial << std::endl;
182 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
183 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
184 outStream <<
" Sufficient decrease bound: " << -gs*
state_->searchSize*
c1_ << std::endl;
185 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
188 alphaTmp = -half*
state_->searchSize*
state_->searchSize*gs
198 outStream << std::endl;
199 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
200 outStream <<
" Trial objective value: " << ftrial << std::endl;
201 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
202 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
203 outStream <<
" Sufficient decrease bound: " << -gs*
state_->searchSize*
c1_ << std::endl;
204 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
215 state_->iterateVec->set(x);
221 gold->set(*
state_->gradientVec);
223 gp->set(
state_->gradientVec->dual());
226 s->set(x); s->axpy(-one,*gp);
229 state_->gnorm = s->norm();
240template<
typename Real>
242 std::stringstream hist;
244 hist << std::string(114,
'-') << std::endl;
245 hist <<
"Line-Search Projected Quasi-Newton with " <<
secantName_ <<
" Hessian approximation";
246 hist <<
" status output definitions" << std::endl << std::endl;
247 hist <<
" iter - Number of iterates (steps taken)" << std::endl;
248 hist <<
" value - Objective function value" << std::endl;
249 hist <<
" gnorm - Norm of the gradient" << std::endl;
250 hist <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
251 hist <<
" alpha - Line search step length" << std::endl;
252 hist <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
253 hist <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
254 hist <<
" #proj - 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 <<
"#fval";
267 hist << std::setw(10) << std::left <<
"#grad";
268 hist << std::setw(10) << std::left <<
"#proj";
269 hist << std::setw(10) << std::left <<
"#ls_fval";
270 hist << std::setw(10) << std::left <<
"sp_iter";
275template<
typename Real>
277 std::stringstream hist;
278 hist << std::endl <<
"Line-Search Projected Quasi-Newton (Type B, Bound Constraints)" << std::endl;
282template<
typename Real>
284 std::stringstream hist;
285 hist << std::scientific << std::setprecision(6);
288 if (
state_->iter == 0 ) {
290 hist << std::setw(6) << std::left <<
state_->iter;
291 hist << std::setw(15) << std::left <<
state_->value;
292 hist << std::setw(15) << std::left <<
state_->gnorm;
293 hist << std::setw(15) << std::left <<
"---";
294 hist << std::setw(15) << std::left <<
"---";
295 hist << std::setw(10) << std::left <<
state_->nfval;
296 hist << std::setw(10) << std::left <<
state_->ngrad;
297 hist << std::setw(10) << std::left <<
state_->nproj;
298 hist << std::setw(10) << std::left <<
"---";
299 hist << std::setw(10) << std::left <<
"---";
304 hist << std::setw(6) << std::left <<
state_->iter;
305 hist << std::setw(15) << std::left <<
state_->value;
306 hist << std::setw(15) << std::left <<
state_->gnorm;
307 hist << std::setw(15) << std::left <<
state_->snorm;
308 hist << std::setw(15) << std::left <<
state_->searchSize;
309 hist << std::setw(10) << std::left <<
state_->nfval;
310 hist << std::setw(10) << std::left <<
state_->ngrad;
311 hist << std::setw(10) << std::left <<
state_->nproj;
312 hist << std::setw(10) << std::left <<
ls_nfval_;
313 hist << std::setw(10) << std::left <<
spgIter_;
Provides the interface to apply upper and lower bound constraints.
Provides the interface to evaluate objective functions.
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.
Ptr< PolyhedralProjection< Real > > proj_
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeExitStatus(std::ostream &os) const
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
Real sigma2_
Upper safeguard for quadratic line search (default: 0.9)
Real c1_
Sufficient Decrease Parameter (default: 1e-4)
int maxit_
Maximum number of line search steps (default: 20)
Real sigma1_
Lower safeguard for quadratic line search (default: 0.1)
Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton)
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
void writeHeader(std::ostream &os) const override
Print iterate header.
void writeName(std::ostream &os) const override
Print step name.
Real rhodec_
Backtracking rate (default: 0.5)
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout) override
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
QuasiNewtonAlgorithm(ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout)
std::string secantName_
Secant name.
ESecant esec_
Secant type.
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)