44 #ifndef ROL_TRUSTREGIONSTEP_H 45 #define ROL_TRUSTREGIONSTEP_H 128 template <
class Real>
137 Teuchos::RCP<Vector<Real> >
gp_;
182 if ( useInexact_[1] ) {
183 Real c = scale0_*std::max(1.e-2,std::min(1.0,1.e4*algo_state.
gnorm));
184 Real gtol1 = c*(state->searchSize);
185 Real gtol0 = scale1_*gtol1 + 1.0;
186 while ( gtol0 > gtol1*scale1_ ) {
187 obj.
gradient(*(state->gradientVec),x,gtol1);
190 c = scale0_*std::max(1.e-2,std::min(1.0,1.e4*algo_state.
gnorm));
191 gtol1 = c*std::min(algo_state.
gnorm,state->searchSize);
197 obj.
gradient(*(state->gradientVec),x,gtol);
213 if ( useProjectedGrad_ ) {
220 xnew_->axpy(-1.0,g.
dual());
223 return xnew_->norm();
244 secant_(Teuchos::null), trustRegion_(Teuchos::null),
245 xnew_(Teuchos::null), xold_(Teuchos::null), gp_(Teuchos::null),
247 useSecantHessVec_(false), useSecantPrecond_(false),
248 useProjectedGrad_(false),
249 TRflag_(0), TR_nfval_(0), TR_ngrad_(0),
250 CGflag_(0), CGiter_(0),
252 alpha_init_(1.), max_fval_(20),
253 scale0_(1.), scale1_(1.),
254 softUp_(false), scaleEps_(1.) {
257 step_state->searchSize = parlist.sublist(
"Step").sublist(
"Trust Region").get(
"Initial Radius", -1.0);
258 delMax_ = parlist.sublist(
"Step").sublist(
"Trust Region").get(
"Maximum Radius", 1000.0);
261 useInexact_.push_back(parlist.sublist(
"General").get(
"Inexact Objective Function",
false));
262 useInexact_.push_back(parlist.sublist(
"General").get(
"Inexact Gradient",
false));
263 useInexact_.push_back(parlist.sublist(
"General").get(
"Inexact Hessian-Times-A-Vector",
false));
265 scale0_ = parlist.sublist(
"Step").sublist(
"Trust Region").sublist(
"Inexact").sublist(
"Gradient").get(
"Tolerance Scaling",1.e-1);
266 scale1_ = parlist.sublist(
"Step").sublist(
"Trust Region").sublist(
"Inexact").sublist(
"Gradient").get(
"Relative Tolerance",2.0);
268 etr_ =
StringToETrustRegion(parlist.sublist(
"Step").sublist(
"Trust Region").get(
"Subproblem Solver",
"Dogleg"));
269 useProjectedGrad_ = parlist.sublist(
"General").get(
"Projected Gradient Criticality Measure",
false);
270 max_fval_ = parlist.sublist(
"Step").sublist(
"Line Search").get(
"Function Evaluation Limit", 20);
271 alpha_init_ = parlist.sublist(
"Step").sublist(
"Line Search").get(
"Initial Step Size", 1.0);
272 trustRegion_ = TrustRegionFactory<Real>(parlist);
274 esec_ =
StringToESecant(parlist.sublist(
"General").sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS"));
275 useSecantPrecond_ = parlist.sublist(
"General").sublist(
"Secant").get(
"Use as Preconditioner",
false);
276 useSecantHessVec_ = parlist.sublist(
"General").sublist(
"Secant").get(
"Use as Hessian",
false);
277 secant_ = SecantFactory<Real>(parlist);
279 softUp_ = parlist.sublist(
"General").get(
"Variable Objective Function",
false);
281 scaleEps_ = parlist.sublist(
"General").get(
"Scale for Epsilon Active Sets",1.0);
295 secant_(secant), trustRegion_(Teuchos::null),
296 xnew_(Teuchos::null), xold_(Teuchos::null), gp_(Teuchos::null),
298 useSecantHessVec_(false), useSecantPrecond_(false),
299 useProjectedGrad_(false),
300 TRflag_(0), TR_nfval_(0), TR_ngrad_(0),
301 CGflag_(0), CGiter_(0),
303 alpha_init_(1.), max_fval_(20),
304 scale0_(1.), scale1_(1.),
305 softUp_(false), scaleEps_(1.) {
308 step_state->searchSize = parlist.sublist(
"Step").sublist(
"Trust Region").get(
"Initial Radius", -1.0);
309 delMax_ = parlist.sublist(
"Step").sublist(
"Trust Region").get(
"Maximum Radius", 1000.0);
312 useInexact_.push_back(parlist.sublist(
"General").get(
"Inexact Objective Function",
false));
313 useInexact_.push_back(parlist.sublist(
"General").get(
"Inexact Gradient",
false));
314 useInexact_.push_back(parlist.sublist(
"General").get(
"Inexact Hessian-Times-A-Vector",
false));
316 scale0_ = parlist.sublist(
"Step").sublist(
"Trust Region").sublist(
"Inexact").sublist(
"Gradient").get(
"Tolerance Scaling",1.e-1);
317 scale1_ = parlist.sublist(
"Step").sublist(
"Trust Region").sublist(
"Inexact").sublist(
"Gradient").get(
"Relative Tolerance",2.0);
319 etr_ =
StringToETrustRegion(parlist.sublist(
"Step").sublist(
"Trust Region").get(
"Subproblem Solver",
"Dogleg"));
320 useProjectedGrad_ = parlist.sublist(
"General").get(
"Projected Gradient Criticality Measure",
false);
321 max_fval_ = parlist.sublist(
"Step").sublist(
"Line Search").get(
"Function Evaluation Limit", 20);
322 alpha_init_ = parlist.sublist(
"Step").sublist(
"Line Search").get(
"Initial Step Size", 1.0);
323 trustRegion_ = TrustRegionFactory<Real>(parlist);
325 useSecantPrecond_ = parlist.sublist(
"General").sublist(
"Secant").get(
"Use as Preconditioner",
false);
326 useSecantHessVec_ = parlist.sublist(
"General").sublist(
"Secant").get(
"Use as Hessian",
false);
327 if ( secant_ == Teuchos::null ) {
328 Teuchos::ParameterList Slist;
329 Slist.sublist(
"General").sublist(
"Secant").set(
"Type",
"Limited-Memory BFGS");
330 Slist.sublist(
"General").sublist(
"Secant").set(
"Maximum Storage",10);
331 secant_ = SecantFactory<Real>(Slist);
334 softUp_ = parlist.sublist(
"General").get(
"Variable Objective Function",
false);
336 scaleEps_ = parlist.sublist(
"General").get(
"Scale for Epsilon Active Sets",1.0);
352 trustRegion_->initialize(x,s,g);
357 step_state->descentVec = s.
clone();
358 step_state->gradientVec = g.
clone();
370 algo_state.
snorm = 1.e10;
375 if ( !useSecantHessVec_ &&
378 Teuchos::RCP<Vector<Real> > v = g.
clone();
379 Teuchos::RCP<Vector<Real> > hv = x.
clone();
382 catch (std::exception &e) {
383 useSecantHessVec_ =
true;
388 if ( step_state->searchSize <= 0.0 ) {
389 Teuchos::RCP<Vector<Real> > Bg = g.
clone();
390 if ( useSecantHessVec_ ) {
391 secant_->applyB(*Bg,(step_state->gradientVec)->dual(),x);
394 obj.
hessVec(*Bg,(step_state->gradientVec)->dual(),x,htol);
396 Real gBg = Bg->dot(*(step_state->gradientVec));
399 alpha = algo_state.
gnorm*algo_state.
gnorm/gBg;
402 Teuchos::RCP<Vector<Real> > cp = s.
clone();
403 cp->set((step_state->gradientVec)->dual());
405 Teuchos::RCP<Vector<Real> > xcp = x.
clone();
412 Real fnew = obj.
value(*xcp,ftol);
415 Real gs = cp->dot((step_state->gradientVec)->dual());
416 Real a = fnew - algo_state.
value - gs - 0.5*alpha*alpha*gBg;
419 step_state->searchSize = std::min(alpha*algo_state.
gnorm,delMax_);
422 Real b = 0.5*alpha*alpha*gBg;
426 Real t1 = (-b-std::sqrt(b*b-3.0*a*c))/(3.0*a);
427 Real t2 = (-b+std::sqrt(b*b-3.0*a*c))/(3.0*a);
428 if ( 6.0*a*t1 + 2.0*b > 0.0 ) {
430 step_state->searchSize = std::min(t1*alpha*algo_state.
gnorm,delMax_);
434 step_state->searchSize = std::min(t2*alpha*algo_state.
gnorm,delMax_);
438 step_state->searchSize = std::min(alpha*algo_state.
gnorm,delMax_);
460 eps = scaleEps_*algo_state.
gnorm;
466 trustRegion_->run(s,algo_state.
snorm,step_state->searchSize,CGflag_,CGiter_,
467 x,*(step_state->gradientVec),algo_state.
gnorm,pObj);
497 eps = algo_state.
gnorm;
511 Real fold = algo_state.
value;
514 trustRegion_->update(x,fnew,state->searchSize,TR_nfval_,TR_ngrad_,TRflag_,
515 s,algo_state.
snorm,fold,*(state->gradientVec),algo_state.
iter,pObj);
518 algo_state.
value = fnew;
522 if ( TRflag_ == 0 || TRflag_ == 1 ) {
531 xnew_->axpy(-alpha*alpha_init_,gp_->dual());
540 Real ftmp = obj.
value(*xnew_,tol);
545 while ( (fnew-ftmp) <= 1.e-4*(fnew-fold) ) {
547 xnew_->axpy(-alpha*alpha_init_,gp_->dual());
555 ftmp = obj.
value(*xnew_,tol);
557 if ( cnt >= max_fval_ ) {
574 if ( useSecantHessVec_ || useSecantPrecond_ ) {
575 gp_->set(*(state->gradientVec));
582 if ( useSecantHessVec_ || useSecantPrecond_ ) {
585 xnew_->axpy(-1.0,*xold_);
586 secant_->update(*(state->gradientVec),*gp_,*xnew_,algo_state.
snorm,algo_state.
iter+1);
589 secant_->update(*(state->gradientVec),*gp_,s,algo_state.
snorm,algo_state.
iter+1);
599 fnew = pObj.
value(x,tol);
601 algo_state.
value = fnew;
612 std::stringstream hist;
614 hist << std::setw(6) << std::left <<
"iter";
615 hist << std::setw(15) << std::left <<
"value";
616 hist << std::setw(15) << std::left <<
"gnorm";
617 hist << std::setw(15) << std::left <<
"snorm";
618 hist << std::setw(15) << std::left <<
"delta";
619 hist << std::setw(10) << std::left <<
"#fval";
620 hist << std::setw(10) << std::left <<
"#grad";
621 hist << std::setw(10) << std::left <<
"tr_flag";
623 hist << std::setw(10) << std::left <<
"iterCG";
624 hist << std::setw(10) << std::left <<
"flagCG";
635 std::stringstream hist;
637 if ( useSecantPrecond_ || useSecantHessVec_ ) {
638 if ( useSecantPrecond_ && !useSecantHessVec_ ) {
641 else if ( !useSecantPrecond_ && useSecantHessVec_ ) {
642 hist <<
" with " <<
ESecantToString(esec_) <<
" Hessian approximation\n";
645 hist <<
" with " <<
ESecantToString(esec_) <<
" preconditioning and Hessian approximation\n";
664 std::stringstream hist;
665 hist << std::scientific << std::setprecision(6);
666 if ( algo_state.
iter == 0 ) {
669 if ( print_header ) {
672 if ( algo_state.
iter == 0 ) {
674 hist << std::setw(6) << std::left << algo_state.
iter;
675 hist << std::setw(15) << std::left << algo_state.
value;
676 hist << std::setw(15) << std::left << algo_state.
gnorm;
677 hist << std::setw(15) << std::left <<
" ";
678 hist << std::setw(15) << std::left << step_state->searchSize;
683 hist << std::setw(6) << std::left << algo_state.
iter;
684 hist << std::setw(15) << std::left << algo_state.
value;
685 hist << std::setw(15) << std::left << algo_state.
gnorm;
686 hist << std::setw(15) << std::left << algo_state.
snorm;
687 hist << std::setw(15) << std::left << step_state->searchSize;
688 hist << std::setw(10) << std::left << algo_state.
nfval;
689 hist << std::setw(10) << std::left << algo_state.
ngrad;
690 hist << std::setw(10) << std::left <<
TRflag_;
692 hist << std::setw(10) << std::left <<
CGiter_;
693 hist << std::setw(10) << std::left <<
CGflag_;
Provides the interface to evaluate objective functions.
ESecant esec_
Secant type.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Real value(const Vector< Real > &x, Real &tol)
Compute value.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
bool useSecantPrecond_
Flag whether to use a secant preconditioner.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Teuchos::RCP< StepState< Real > > getState(void)
Contains definitions of custom data types in ROL.
Real alpha_init_
Initial line-search parameter for projected methods.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
TrustRegionStep(Teuchos::RCP< Secant< Real > > &secant, Teuchos::ParameterList &parlist)
Constructor.
ESecant StringToESecant(std::string s)
Defines the linear algebra or vector space interface.
Teuchos::RCP< Vector< Real > > gp_
Container for previous gradient vector.
Teuchos::RCP< Vector< Real > > xold_
Container for previous iteration vector.
Teuchos::RCP< Secant< Real > > secant_
Container for secant approximation.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Compute step.
std::string printName(void) const
Print step name.
State for algorithm class. Will be used for restarts.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
bool isActivated(void)
Check if bounds are on.
ETrustRegion etr_
Trust-region subproblem solver type.
std::string printHeader(void) const
Print iterate header.
Teuchos::RCP< Vector< Real > > xnew_
Container for updated iteration vector.
ESecant
Enumeration of secant update algorithms.
int CGflag_
Truncated CG termination flag.
virtual Teuchos::RCP< const StepState< Real > > getStepState(void) const
Get state for step object.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Update step, if successful.
Real computeCriticalityMeasure(const Vector< Real > &g, const Vector< Real > &x, BoundConstraint< Real > &con)
Compute the criticality measure.
bool useSecantHessVec_
Flag whether to use a secant Hessian.
std::vector< bool > useInexact_
Contains flags for inexact (0) objective function, (1) gradient, (2) Hessian.
Provides interface for and implements limited-memory secant operators.
Real scale0_
Scale for inexact gradient computation.
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.
Real delMax_
Maximum trust-region radius.
virtual void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply inverse Hessian approximation to vector.
TrustRegionStep(Teuchos::ParameterList &parlist)
Constructor.
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
virtual ~TrustRegionStep()
Provides the interface to apply upper and lower bound constraints.
int TR_ngrad_
Trust-region gradient evaluation counter.
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
void computeProjectedGradient(Vector< Real > &g, const Vector< Real > &x)
Compute projected gradient.
ETrustRegion StringToETrustRegion(std::string s)
void updateGradient(Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Update gradient to iteratively satisfy inexactness condition.
int TR_nfval_
Trust-region function evaluation counter.
Teuchos::RCP< Vector< Real > > iterateVec
virtual void set(const Vector &x)
Set where .
virtual Real norm() const =0
Returns where .
int max_fval_
Maximum function evaluations in line-search for projected methods.
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
int TRflag_
Trust-region exit flag.
ETrustRegion
Enumeration of trust-region solver types.
std::string ETrustRegionToString(ETrustRegion tr)
int CGiter_
Truncated CG iteration count.
std::string ESecantToString(ESecant tr)
static const double ROL_OVERFLOW
Platform-dependent maximum double.
bool useProjectedGrad_
Flag whether to use the projected gradient criticality measure.
Teuchos::RCP< TrustRegion< Real > > trustRegion_
Container for trust-region object.
Real scale1_
Scale for inexact gradient computation.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
Provides the interface to compute optimization steps with trust regions.
static const double ROL_EPSILON
Platform-dependent machine epsilon.