44 #ifndef ROL_LINESEARCHSTEP_H 45 #define ROL_LINESEARCHSTEP_H 132 template <
class Real>
138 Teuchos::RCP<NonlinearCG<Real> >
nlcg_;
142 Teuchos::RCP<ProjectedPreconditioner<Real> >
precond_;
144 Teuchos::RCP<Vector<Real> >
d_;
145 Teuchos::RCP<Vector<Real> >
gp_;
184 secant_(Teuchos::null), krylov_(Teuchos::null),
185 nlcg_(Teuchos::null), lineSearch_(Teuchos::null),
186 hessian_(Teuchos::null), precond_(Teuchos::null),
187 d_(Teuchos::null), gp_(Teuchos::null),
188 iterKrylov_(0), flagKrylov_(0),
195 ls_nfval_(0), ls_ngrad_(0),
196 useSecantHessVec_(false), useSecantPrecond_(false),
197 useProjectedGrad_(false), softUp_(false) {
198 Teuchos::ParameterList& Llist = parlist.sublist(
"Step").sublist(
"Line Search");
199 Teuchos::ParameterList& Glist = parlist.sublist(
"General");
201 edesc_ =
StringToEDescent(Llist.sublist(
"Descent Method").get(
"Type",
"Quasi-Newton Method") );
202 els_ =
StringToELineSearch(Llist.sublist(
"Line-Search Method").get(
"Type",
"Cubic Interpolation") );
204 useProjectedGrad_ = Glist.get(
"Projected Gradient Criticality Measure",
false);
205 acceptLastAlpha_ = Llist.get(
"Accept Last Alpha",
false);
206 lineSearch_ = LineSearchFactory<Real>(parlist);
209 useInexact_.push_back(Glist.get(
"Inexact Objective Function",
false));
210 useInexact_.push_back(Glist.get(
"Inexact Gradient",
false));
211 useInexact_.push_back(Glist.get(
"Inexact Hessian-Times-A-Vector",
false));
213 softUp_ = Glist.get(
"Variable Objective Function",
false);
215 ekv_ =
StringToEKrylov(Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients"));
217 krylov_ = KrylovFactory<Real>(parlist);
220 esec_ =
StringToESecant(Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS"));
221 useSecantHessVec_ = Glist.sublist(
"Secant").get(
"Use as Hessian",
false);
222 useSecantHessVec_ = ((edesc_==
DESCENT_SECANT) ?
true : useSecantHessVec_);
223 useSecantPrecond_ = Glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
225 secant_ = SecantFactory<Real>(parlist);
228 enlcg_ =
StringToENonlinearCG(Llist.sublist(
"Descent Method").get(
"Nonlinear CG Type",
"Oren-Luenberger"));
230 nlcg_ = Teuchos::rcp(
new NonlinearCG<Real>(enlcg_) );
244 secant_(Teuchos::null), krylov_(Teuchos::null),
245 nlcg_(Teuchos::null), lineSearch_(lineSearch),
246 hessian_(Teuchos::null), precond_(Teuchos::null),
247 d_(Teuchos::null), gp_(Teuchos::null),
248 iterKrylov_(0), flagKrylov_(0),
255 ls_nfval_(0), ls_ngrad_(0),
256 useSecantHessVec_(false), useSecantPrecond_(false),
257 useProjectedGrad_(false), softUp_(false) {
258 Teuchos::ParameterList& Llist = parlist.sublist(
"Step").sublist(
"Line Search");
259 Teuchos::ParameterList& Glist = parlist.sublist(
"General");
261 edesc_ =
StringToEDescent(Llist.sublist(
"Descent Method").get(
"Type",
"Quasi-Newton Method") );
264 useProjectedGrad_ = Glist.get(
"Projected Gradient Criticality Measure",
false);
265 acceptLastAlpha_ = Llist.get(
"Accept Last Alpha",
false);
268 useInexact_.push_back(Glist.get(
"Inexact Objective Function",
false));
269 useInexact_.push_back(Glist.get(
"Inexact Gradient",
false));
270 useInexact_.push_back(Glist.get(
"Inexact Hessian-Times-A-Vector",
false));
272 softUp_ = Glist.get(
"Variable Objective Function",
false);
274 ekv_ =
StringToEKrylov(Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients"));
276 krylov_ = KrylovFactory<Real>(parlist);
279 esec_ =
StringToESecant(Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS"));
280 useSecantHessVec_ = Glist.sublist(
"Secant").get(
"Use as Hessian",
false);
281 useSecantHessVec_ = ((edesc_==
DESCENT_SECANT) ?
true : useSecantHessVec_);
282 useSecantPrecond_ = Glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
284 secant_ = SecantFactory<Real>(parlist);
287 enlcg_ =
StringToENonlinearCG(Llist.sublist(
"Descent Method").get(
"Nonlinear CG Type",
"Oren-Luenberger"));
289 nlcg_ = Teuchos::rcp(
new NonlinearCG<Real>(enlcg_) );
304 secant_(secant), krylov_(Teuchos::null),
305 nlcg_(Teuchos::null), lineSearch_(Teuchos::null),
306 hessian_(Teuchos::null), precond_(Teuchos::null),
307 d_(Teuchos::null), gp_(Teuchos::null),
308 iterKrylov_(0), flagKrylov_(0),
315 ls_nfval_(0), ls_ngrad_(0),
316 useSecantHessVec_(false), useSecantPrecond_(false),
317 useProjectedGrad_(false), softUp_(false) {
318 Teuchos::ParameterList& Llist = parlist.sublist(
"Step").sublist(
"Line Search");
319 Teuchos::ParameterList& Glist = parlist.sublist(
"General");
321 edesc_ =
StringToEDescent(Llist.sublist(
"Descent Method").get(
"Type",
"Quasi-Newton Method"));
322 els_ =
StringToELineSearch(Llist.sublist(
"Line-Search Method").get(
"Type",
"Cubic Interpolation") );
324 useProjectedGrad_ = Glist.get(
"Projected Gradient Criticality Measure",
false);
325 acceptLastAlpha_ = Llist.get(
"Accept Last Alpha",
false);
326 lineSearch_ = LineSearchFactory<Real>(parlist);
329 useInexact_.push_back(Glist.get(
"Inexact Objective Function",
false));
330 useInexact_.push_back(Glist.get(
"Inexact Gradient",
false));
331 useInexact_.push_back(Glist.get(
"Inexact Hessian-Times-A-Vector",
false));
333 softUp_ = Glist.get(
"Variable Objective Function",
false);
335 ekv_ =
StringToEKrylov(Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients"));
337 krylov_ = KrylovFactory<Real>(parlist);
340 useSecantHessVec_ = Glist.sublist(
"Secant").get(
"Use as Hessian",
false);
341 useSecantHessVec_ = ((edesc_==
DESCENT_SECANT) ?
true : useSecantHessVec_);
342 useSecantPrecond_ = Glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
344 enlcg_ =
StringToENonlinearCG(Llist.sublist(
"Descent Method").get(
"Nonlinear CG Type",
"Oren-Luenberger"));
346 nlcg_ = Teuchos::rcp(
new NonlinearCG<Real>(enlcg_) );
360 secant_(Teuchos::null), krylov_(krylov),
361 nlcg_(Teuchos::null), lineSearch_(Teuchos::null),
362 hessian_(Teuchos::null), precond_(Teuchos::null),
363 d_(Teuchos::null), gp_(Teuchos::null),
364 iterKrylov_(0), flagKrylov_(0),
371 ls_nfval_(0), ls_ngrad_(0),
372 useSecantHessVec_(false), useSecantPrecond_(false),
373 useProjectedGrad_(false), softUp_(false) {
374 Teuchos::ParameterList& Llist = parlist.sublist(
"Step").sublist(
"Line Search");
375 Teuchos::ParameterList& Glist = parlist.sublist(
"General");
377 edesc_ =
StringToEDescent(Llist.sublist(
"Descent Method").get(
"Type",
"Quasi-Newton Method") );
378 els_ =
StringToELineSearch(Llist.sublist(
"Line-Search Method").get(
"Type",
"Cubic Interpolation") );
380 useProjectedGrad_ = Glist.get(
"Projected Gradient Criticality Measure",
false);
381 acceptLastAlpha_ = Llist.get(
"Accept Last Alpha",
false);
382 lineSearch_ = LineSearchFactory<Real>(parlist);
385 useInexact_.push_back(Glist.get(
"Inexact Objective Function",
false));
386 useInexact_.push_back(Glist.get(
"Inexact Gradient",
false));
387 useInexact_.push_back(Glist.get(
"Inexact Hessian-Times-A-Vector",
false));
389 softUp_ = Glist.get(
"Variable Objective Function",
false);
391 esec_ =
StringToESecant(Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS"));
392 useSecantHessVec_ = Glist.sublist(
"Secant").get(
"Use as Hessian",
false);
393 useSecantHessVec_ = ((edesc_==
DESCENT_SECANT) ?
true : useSecantHessVec_);
394 useSecantPrecond_ = Glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
396 secant_ = SecantFactory<Real>(parlist);
399 enlcg_ =
StringToENonlinearCG(Llist.sublist(
"Descent Method").get(
"Nonlinear CG Type",
"Oren-Luenberger"));
401 nlcg_ = Teuchos::rcp(
new NonlinearCG<Real>(enlcg_) );
416 Teuchos::ParameterList &parlist )
418 secant_(secant), krylov_(Teuchos::null),
419 nlcg_(Teuchos::null), lineSearch_(lineSearch),
420 hessian_(Teuchos::null), precond_(Teuchos::null),
421 d_(Teuchos::null), gp_(Teuchos::null),
422 iterKrylov_(0), flagKrylov_(0),
429 ls_nfval_(0), ls_ngrad_(0),
430 useSecantHessVec_(false), useSecantPrecond_(false),
431 useProjectedGrad_(false), softUp_(false) {
432 Teuchos::ParameterList& Llist = parlist.sublist(
"Step").sublist(
"Line Search");
433 Teuchos::ParameterList& Glist = parlist.sublist(
"General");
435 edesc_ =
StringToEDescent(Llist.sublist(
"Descent Method").get(
"Type",
"Quasi-Newton Method") );
437 useProjectedGrad_ = Glist.get(
"Projected Gradient Criticality Measure",
false);
438 acceptLastAlpha_ = Llist.get(
"Accept Last Alpha",
false);
441 useInexact_.push_back(Glist.get(
"Inexact Objective Function",
false));
442 useInexact_.push_back(Glist.get(
"Inexact Gradient",
false));
443 useInexact_.push_back(Glist.get(
"Inexact Hessian-Times-A-Vector",
false));
445 softUp_ = Glist.get(
"Variable Objective Function",
false);
447 ekv_ =
StringToEKrylov(Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients"));
449 krylov_ = KrylovFactory<Real>(parlist);
452 useSecantHessVec_ = Glist.sublist(
"Secant").get(
"Use as Hessian",
false);
453 useSecantHessVec_ = ((edesc_==
DESCENT_SECANT) ?
true : useSecantHessVec_);
454 useSecantPrecond_ = Glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
456 enlcg_ =
StringToENonlinearCG(Llist.sublist(
"Descent Method").get(
"Nonlinear CG Type",
"Oren-Luenberger"));
458 nlcg_ = Teuchos::rcp(
new NonlinearCG<Real>(enlcg_) );
467 lineSearch_->initialize(x, s, *(step_state->gradientVec),obj,con);
469 Teuchos::RCP<Objective<Real> > obj_ptr = Teuchos::rcp(&obj,
false);
470 Teuchos::RCP<BoundConstraint<Real> > con_ptr = Teuchos::rcp(&con,
false);
471 hessian_ = Teuchos::rcp(
474 precond_ = Teuchos::rcp(
476 step_state->gradientVec,useSecantPrecond_));
510 eps = algo_state.
gnorm;
512 lineSearch_->setData(eps);
513 if ( hessian_ != Teuchos::null ) {
514 hessian_->setData(eps);
516 if ( precond_ != Teuchos::null ) {
517 precond_->setData(eps);
524 krylov_->run(s,*hessian_,*(step_state->gradientVec),*precond_,iterKrylov_,flagKrylov_);
528 hessian_->applyInverse(s,*(step_state->gradientVec),tol);
531 nlcg_->run(s,*(step_state->gradientVec),x,obj);
534 s.
set(step_state->gradientVec->dual());
542 gs = -s.
dot((step_state->gradientVec)->dual());
554 gs = -d_->dot((step_state->gradientVec)->dual());
558 con.
pruneActive(*d_,*(step_state->gradientVec),x,eps);
559 gs = -d_->dot((step_state->gradientVec)->dual());
561 d_->axpy(-1.0,(step_state->gradientVec)->dual());
566 gs -= d_->dot((step_state->gradientVec)->dual());
571 if ( gs >= 0.0 || (flagKrylov_ == 2 && iterKrylov_ <= 1) ) {
572 s.
set((step_state->gradientVec)->dual());
576 gs = -d_->dot((step_state->gradientVec)->dual());
579 gs = -s.
dot((step_state->gradientVec)->dual());
585 Real fnew = algo_state.
value;
588 lineSearch_->run(step_state->searchSize,fnew,ls_nfval_,ls_ngrad_,gs,s,x,obj,con);
591 if(!acceptLastAlpha_)
593 lineSearch_->setMaxitUpdate(step_state->searchSize,fnew,algo_state.
value);
600 s.
scale(step_state->searchSize);
608 (step_state->descentVec)->
set(s);
612 algo_state.
value = fnew;
645 gp_->set(*(step_state->gradientVec));
647 obj.
gradient(*(step_state->gradientVec),x,tol);
653 secant_->update(*(step_state->gradientVec),*gp_,s,algo_state.
snorm,algo_state.
iter+1);
659 if ( useProjectedGrad_ ) {
660 gp_->set(*(step_state->gradientVec));
662 algo_state.
gnorm = gp_->norm();
666 d_->axpy(-1.0,(step_state->gradientVec)->dual());
669 algo_state.
gnorm = d_->norm();
673 algo_state.
gnorm = (step_state->gradientVec)->norm();
682 std::stringstream hist;
684 hist << std::setw(6) << std::left <<
"iter";
685 hist << std::setw(15) << std::left <<
"value";
686 hist << std::setw(15) << std::left <<
"gnorm";
687 hist << std::setw(15) << std::left <<
"snorm";
688 hist << std::setw(10) << std::left <<
"#fval";
689 hist << std::setw(10) << std::left <<
"#grad";
690 hist << std::setw(10) << std::left <<
"ls_#fval";
691 hist << std::setw(10) << std::left <<
"ls_#grad";
693 hist << std::setw(10) << std::left <<
"iterCG";
694 hist << std::setw(10) << std::left <<
"flagCG";
705 std::stringstream hist;
708 <<
" Linesearch satisfying " 731 std::stringstream hist;
732 hist << std::scientific << std::setprecision(6);
733 if ( algo_state.
iter == 0 ) {
736 if ( print_header ) {
739 if ( algo_state.
iter == 0 ) {
741 hist << std::setw(6) << std::left << algo_state.
iter;
742 hist << std::setw(15) << std::left << algo_state.
value;
743 hist << std::setw(15) << std::left << algo_state.
gnorm;
748 hist << std::setw(6) << std::left << algo_state.
iter;
749 hist << std::setw(15) << std::left << algo_state.
value;
750 hist << std::setw(15) << std::left << algo_state.
gnorm;
751 hist << std::setw(15) << std::left << algo_state.
snorm;
752 hist << std::setw(10) << std::left << algo_state.
nfval;
753 hist << std::setw(10) << std::left << algo_state.
ngrad;
754 hist << std::setw(10) << std::left <<
ls_nfval_;
755 hist << std::setw(10) << std::left <<
ls_ngrad_;
Provides the interface to evaluate objective functions.
int ls_nfval_
Number of function evaluations during line search.
virtual void scale(const Real alpha)=0
Compute where .
LineSearchStep(Teuchos::RCP< Krylov< Real > > &krylov, Teuchos::ParameterList &parlist)
Constructor.
virtual void plus(const Vector &x)=0
Compute , where .
bool acceptLastAlpha_
For backwards compatibility. When max function evaluations are reached take last step.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
ELineSearch StringToELineSearch(std::string s)
std::string printName(void) const
Print step name.
EKrylov ekv_
enum determines type of Krylov solver
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
Teuchos::RCP< ProjectedPreconditioner< Real > > precond_
Teuchos::RCP< StepState< Real > > getState(void)
Contains definitions of custom data types in ROL.
bool useSecantHessVec_
Whether or not a secant approximation is used for Hessian-times-a-vector.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ELineSearch
Enumeration of line-search types.
LineSearchStep(Teuchos::RCP< Secant< Real > > &secant, Teuchos::ParameterList &parlist)
Constructor.
ESecant StringToESecant(std::string s)
std::string EDescentToString(EDescent tr)
Contains definitions for helper functions in ROL.
std::string printHeader(void) const
Print iterate header.
Defines the linear algebra or vector space interface.
std::vector< bool > useInexact_
Flags for inexact objective function, gradient, and Hessian evaluation.
virtual Real dot(const Vector &x) const =0
Compute where .
int iterKrylov_
Number of Krylov iterations (used for inexact Newton)
EKrylov
Enumeration of Krylov methods.
EKrylov StringToEKrylov(std::string s)
EDescent StringToEDescent(std::string s)
State for algorithm class. Will be used for restarts.
Provides the interface to compute optimization steps with line search.
Teuchos::RCP< Vector< Real > > gp_
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Teuchos::RCP< Krylov< Real > > krylov_
Krylov solver object (used for inexact Newton)
bool isActivated(void)
Check if bounds are on.
ENonlinearCG
Enumeration of nonlinear CG algorithms.
std::string ECurvatureConditionToString(ECurvatureCondition ls)
Provides interface for and implements line searches.
ESecant
Enumeration of secant update algorithms.
ENonlinearCG enlcg_
enum determines type of nonlinear CG
bool useSecantPrecond_
Whether or not a secant approximation is used for preconditioning inexact Newton. ...
int ls_ngrad_
Number of gradient evaluations during line search.
Provides interface for and implements limited-memory secant operators.
std::string ENonlinearCGToString(ENonlinearCG tr)
ENonlinearCG StringToENonlinearCG(std::string s)
EDescent edesc_
enum determines type of descent step
std::string ELineSearchToString(ELineSearch ls)
void pruneInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the -inactive set.
Teuchos::RCP< LineSearch< Real > > lineSearch_
Line-search object.
void initialize(Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
int flagKrylov_
Termination flag for Krylov method (used for inexact Newton)
ELineSearch els_
enum determines type of line search
virtual ~LineSearchStep()
Teuchos::RCP< ProjectedHessian< Real > > hessian_
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
Provides definitions for Krylov solvers.
Provides the interface to apply upper and lower bound constraints.
bool useProjectedGrad_
Whether or not to use to the projected gradient criticality measure.
void computeProjectedGradient(Vector< Real > &g, const Vector< Real > &x)
Compute projected gradient.
std::string EKrylovToString(EKrylov tr)
ECurvatureCondition
Enumeration of line-search curvature conditions.
Teuchos::RCP< NonlinearCG< Real > > nlcg_
Nonlinear CG object (used for nonlinear CG)
Teuchos::RCP< Vector< Real > > d_
virtual void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Compute step.
Teuchos::RCP< Vector< Real > > iterateVec
virtual void set(const Vector &x)
Set where .
virtual void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the -active set.
ECurvatureCondition StringToECurvatureCondition(std::string s)
virtual Real norm() const =0
Returns where .
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
std::string ESecantToString(ESecant tr)
EDescent
Enumeration of descent direction types.
LineSearchStep(Teuchos::RCP< LineSearch< Real > > &lineSearch, Teuchos::RCP< Secant< Real > > &secant, Teuchos::ParameterList &parlist)
Constructor.
ECurvatureCondition econd_
enum determines type of curvature condition
Teuchos::RCP< Secant< Real > > secant_
Secant object (used for quasi-Newton)
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
LineSearchStep(Teuchos::RCP< LineSearch< Real > > &lineSearch, Teuchos::ParameterList &parlist)
Constructor.
ESecant esec_
enum determines type of secant approximation
static const double ROL_EPSILON
Platform-dependent machine epsilon.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Update step, if successful.
LineSearchStep(Teuchos::ParameterList &parlist)
Constructor.