44 #ifndef ROL_TRUSTREGIONSTEP_H 45 #define ROL_TRUSTREGIONSTEP_H 128 template <
class Real>
135 Teuchos::RCP<Vector<Real> >
gp_;
139 Teuchos::RCP<TrustRegionModel<Real> >
model_;
186 Teuchos::ParameterList &slist = parlist.sublist(
"Step");
187 Teuchos::ParameterList &list = slist.sublist(
"Trust Region");
188 step_state->searchSize = list.get(
"Initial Radius", static_cast<Real>(-1));
189 delMax_ = list.get(
"Maximum Radius", static_cast<Real>(1.e8));
191 Teuchos::ParameterList &glist = parlist.sublist(
"General");
193 useInexact_.push_back(glist.get(
"Inexact Objective Function",
false));
194 useInexact_.push_back(glist.get(
"Inexact Gradient",
false));
195 useInexact_.push_back(glist.get(
"Inexact Hessian-Times-A-Vector",
false));
197 Teuchos::ParameterList &ilist = list.sublist(
"Inexact").sublist(
"Gradient");
198 scale0_ = ilist.get(
"Tolerance Scaling", static_cast<Real>(0.1));
199 scale1_ = ilist.get(
"Relative Tolerance", static_cast<Real>(2));
203 useProjectedGrad_ = glist.get(
"Projected Gradient Criticality Measure",
false);
204 trustRegion_ = TrustRegionFactory<Real>(parlist);
206 scaleEps_ = glist.get(
"Scale for Epsilon Active Sets", static_cast<Real>(1));
207 verbosity_ = glist.get(
"Print Verbosity", 0);
209 max_fval_ = list.sublist(
"Post-Smoothing").get(
"Function Evaluation Limit", 20);
210 alpha_init_ = list.sublist(
"Post-Smoothing").get(
"Initial Step Size", static_cast<Real>(1));
211 mu_ = list.sublist(
"Post-Smoothing").get(
"Tolerance", static_cast<Real>(0.9999));
212 beta_ = list.sublist(
"Post-Smoothing").get(
"Rate", static_cast<Real>(0.01));
214 stepBackMax_ = list.sublist(
"Coleman-Li").get(
"Maximum Step Back", static_cast<Real>(0.9999));
215 stepBackScale_ = list.sublist(
"Coleman-Li").get(
"Maximum Step Scale", static_cast<Real>(1));
216 singleReflect_ = list.sublist(
"Coleman-Li").get(
"Single Reflection",
true);
236 if ( useInexact_[1] ) {
250 Real gtol1 = scale0_*std::min(algo_state.
gnorm,state->searchSize);
251 Real gtol0 = gtol1 + one;
252 while ( gtol0 > gtol1 ) {
253 obj.
gradient(*(state->gradientVec),x,gtol1);
256 gtol1 = scale0_*std::min(algo_state.
gnorm,state->searchSize);
261 Real gtol = std::sqrt(ROL_EPSILON<Real>());
262 obj.
gradient(*(state->gradientVec),x,gtol);
278 if ( useProjectedGrad_ ) {
286 xnew_->axpy(-one,g.
dual());
289 return xnew_->norm();
314 xnew_(Teuchos::null), xold_(Teuchos::null), gp_(Teuchos::null),
315 trustRegion_(Teuchos::null), model_(Teuchos::null),
318 SPflag_(0), SPiter_(0), bndActive_(false),
320 useSecantHessVec_(false), useSecantPrecond_(false),
321 scaleEps_(1), useProjectedGrad_(false),
322 alpha_init_(1), max_fval_(20), mu_(0.9999), beta_(0.01),
323 stepBackMax_(0.9999), stepBackScale_(1), singleReflect_(true),
324 scale0_(1), scale1_(1),
329 Teuchos::ParameterList &glist = parlist.sublist(
"General");
330 esec_ =
StringToESecant(glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS"));
331 useSecantPrecond_ = glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
332 useSecantHessVec_ = glist.sublist(
"Secant").get(
"Use as Hessian",
false);
333 secant_ = SecantFactory<Real>(parlist);
347 xnew_(Teuchos::null), xold_(Teuchos::null), gp_(Teuchos::null),
348 trustRegion_(Teuchos::null), model_(Teuchos::null),
351 SPflag_(0), SPiter_(0), bndActive_(false),
353 useSecantHessVec_(false), useSecantPrecond_(false),
354 scaleEps_(1), useProjectedGrad_(false),
355 alpha_init_(1), max_fval_(20), mu_(0.9999), beta_(0.01),
356 stepBackMax_(0.9999), stepBackScale_(1), singleReflect_(true),
357 scale0_(1), scale1_(1),
362 Teuchos::ParameterList &glist = parlist.sublist(
"General");
363 useSecantPrecond_ = glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
364 useSecantHessVec_ = glist.sublist(
"Secant").get(
"Use as Hessian",
false);
365 if ( secant_ == Teuchos::null ) {
366 Teuchos::ParameterList Slist;
367 Slist.sublist(
"General").sublist(
"Secant").set(
"Type",
"Limited-Memory BFGS");
368 Slist.sublist(
"General").sublist(
"Secant").set(
"Maximum Storage",10);
369 secant_ = SecantFactory<Real>(Slist);
384 Real p1(0.1), oe10(1.e10), zero(0), one(1), half(0.5), three(3), two(2), six(6);
388 trustRegion_->initialize(x,s,g);
390 Real htol = std::sqrt(ROL_EPSILON<Real>());
391 Real ftol = p1*ROL_OVERFLOW<Real>();
393 step_state->descentVec = s.
clone();
394 step_state->gradientVec = g.
clone();
406 Real minDiff =
static_cast<Real
>(1e-1)
407 * std::min(one, half * xold_->reduce(Elementwise::ReductionMin<Real>()));
409 class LowerFeasible :
public Elementwise::BinaryFunction<Real> {
413 LowerFeasible(
const Real eps) : eps_(eps) {}
414 Real
apply(
const Real &x,
const Real &y )
const {
415 const Real tol =
static_cast<Real
>(100)*ROL_EPSILON<Real>();
416 return (x < y+tol) ? y+eps_ : x;
421 class UpperFeasible :
public Elementwise::BinaryFunction<Real> {
425 UpperFeasible(
const Real eps) : eps_(eps) {}
426 Real
apply(
const Real &x,
const Real &y )
const {
427 const Real tol =
static_cast<Real
>(100)*ROL_EPSILON<Real>();
428 return (x > y-tol) ? y-eps_ : x;
439 algo_state.
snorm = oe10;
444 if ( !useSecantHessVec_ &&
447 Teuchos::RCP<Vector<Real> > v = g.
clone();
448 Teuchos::RCP<Vector<Real> > hv = x.
clone();
451 catch (std::exception &e) {
452 useSecantHessVec_ =
true;
457 if ( step_state->searchSize <= zero ) {
458 Teuchos::RCP<Vector<Real> > Bg = g.
clone();
459 if ( useSecantHessVec_ ) {
460 secant_->applyB(*Bg,(step_state->gradientVec)->dual());
463 obj.
hessVec(*Bg,(step_state->gradientVec)->dual(),x,htol);
465 Real gBg = Bg->dot(*(step_state->gradientVec));
467 if ( gBg > ROL_EPSILON<Real>() ) {
468 alpha = algo_state.
gnorm*algo_state.
gnorm/gBg;
471 Teuchos::RCP<Vector<Real> > cp = s.
clone();
472 cp->set((step_state->gradientVec)->dual());
474 Teuchos::RCP<Vector<Real> > xcp = x.
clone();
481 Real fnew = obj.
value(*xcp,ftol);
484 Real gs = cp->dot((step_state->gradientVec)->dual());
485 Real a = fnew - algo_state.
value - gs - half*alpha*alpha*gBg;
486 if ( std::abs(a) < ROL_EPSILON<Real>() ) {
488 step_state->searchSize = std::min(alpha*algo_state.
gnorm,delMax_);
491 Real b = half*alpha*alpha*gBg;
493 if ( b*b-three*a*c > ROL_EPSILON<Real>() ) {
495 Real t1 = (-b-std::sqrt(b*b-three*a*c))/(three*a);
496 Real t2 = (-b+std::sqrt(b*b-three*a*c))/(three*a);
497 if ( six*a*t1 + two*b > zero ) {
499 step_state->searchSize = std::min(t1*alpha*algo_state.
gnorm,delMax_);
503 step_state->searchSize = std::min(t2*alpha*algo_state.
gnorm,delMax_);
507 step_state->searchSize = std::min(alpha*algo_state.
gnorm,delMax_);
531 Real eps = scaleEps_ * std::min(std::pow(algo_state.
gnorm,static_cast<Real>(0.75)),
532 static_cast<Real>(0.01));
536 *(step_state->gradientVec),
546 *(step_state->gradientVec),
550 step_state->searchSize,
556 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
557 ">>> ERROR (ROL::TrustRegionStep): Invalid trust-region model!");
563 *(step_state->gradientVec),
569 SPflag_ = 0; SPiter_ = 0;
570 trustRegion_->run(s,algo_state.
snorm,SPflag_,SPiter_,step_state->searchSize,*model_);
600 Real fold = algo_state.
value;
603 trustRegion_->update(x,fnew,state->searchSize,state->nfval,state->ngrad,TRflag_,
604 s,algo_state.
snorm,fold,*(state->gradientVec),algo_state.
iter,
606 algo_state.
nfval += state->nfval;
607 algo_state.
ngrad += state->ngrad;
614 Real tol = std::sqrt(ROL_EPSILON<Real>());
621 xnew_->axpy(-alpha*alpha_init_,gp_->dual());
625 Real ftmp = obj.
value(*xnew_,tol);
629 alpha =
static_cast<Real
>(1)/alpha_init_;
630 while ( (fnew-ftmp) <= mu_*(fnew-fold) ) {
632 xnew_->axpy(-alpha*alpha_init_,gp_->dual());
635 ftmp = obj.
value(*xnew_,tol);
637 if ( cnt >= max_fval_ ) {
648 if ( useSecantHessVec_ || useSecantPrecond_ ) {
649 gp_->set(*(state->gradientVec));
654 if ( useSecantHessVec_ || useSecantPrecond_ ) {
657 xnew_->axpy(-static_cast<Real>(1),*xold_);
658 secant_->updateStorage(x,*(state->gradientVec),*gp_,*xnew_,algo_state.
snorm,algo_state.
iter+1);
661 secant_->updateStorage(x,*(state->gradientVec),*gp_,s,algo_state.
snorm,algo_state.
iter+1);
668 if ( useInexact_[1] ) {
674 algo_state.
value = fnew;
682 std::stringstream hist;
685 hist << std::string(114,
'-') <<
"\n";
687 hist <<
"Trust-Region status output definitions\n\n";
689 hist <<
" iter - Number of iterates (steps taken) \n";
690 hist <<
" value - Objective function value \n";
691 hist <<
" gnorm - Norm of the gradient\n";
692 hist <<
" snorm - Norm of the step (update to optimization vector)\n";
693 hist <<
" delta - Trust-Region radius\n";
694 hist <<
" #fval - Number of times the objective function was evaluated\n";
695 hist <<
" #grad - Number of times the gradient was computed\n";
700 hist <<
" tr_flag - Trust-Region flag" <<
"\n";
709 hist <<
" iterCG - Number of Truncated CG iterations\n\n";
710 hist <<
" flagGC - Trust-Region Truncated CG flag" <<
"\n";
717 hist << std::string(114,
'-') <<
"\n";
721 hist << std::setw(6) << std::left <<
"iter";
722 hist << std::setw(15) << std::left <<
"value";
723 hist << std::setw(15) << std::left <<
"gnorm";
724 hist << std::setw(15) << std::left <<
"snorm";
725 hist << std::setw(15) << std::left <<
"delta";
726 hist << std::setw(10) << std::left <<
"#fval";
727 hist << std::setw(10) << std::left <<
"#grad";
728 hist << std::setw(10) << std::left <<
"tr_flag";
730 hist << std::setw(10) << std::left <<
"iterCG";
731 hist << std::setw(10) << std::left <<
"flagCG";
742 std::stringstream hist;
744 if ( useSecantPrecond_ || useSecantHessVec_ ) {
745 if ( useSecantPrecond_ && !useSecantHessVec_ ) {
748 else if ( !useSecantPrecond_ && useSecantHessVec_ ) {
749 hist <<
" with " <<
ESecantToString(esec_) <<
" Hessian Approximation\n";
752 hist <<
" with " <<
ESecantToString(esec_) <<
" Preconditioning and Hessian Approximation\n";
774 std::stringstream hist;
775 hist << std::scientific << std::setprecision(6);
776 if ( algo_state.
iter == 0 ) {
779 if ( print_header ) {
782 if ( algo_state.
iter == 0 ) {
784 hist << std::setw(6) << std::left << algo_state.
iter;
785 hist << std::setw(15) << std::left << algo_state.
value;
786 hist << std::setw(15) << std::left << algo_state.
gnorm;
787 hist << std::setw(15) << std::left <<
" ";
788 hist << std::setw(15) << std::left << step_state->searchSize;
793 hist << std::setw(6) << std::left << algo_state.
iter;
794 hist << std::setw(15) << std::left << algo_state.
value;
795 hist << std::setw(15) << std::left << algo_state.
gnorm;
796 hist << std::setw(15) << std::left << algo_state.
snorm;
797 hist << std::setw(15) << std::left << step_state->searchSize;
798 hist << std::setw(10) << std::left << algo_state.
nfval;
799 hist << std::setw(10) << std::left << algo_state.
ngrad;
800 hist << std::setw(10) << std::left <<
TRflag_;
802 hist << std::setw(10) << std::left <<
SPiter_;
803 hist << std::setw(10) << std::left <<
SPflag_;
std::string ECGFlagToString(ECGFlag cgf)
Provides the interface to evaluate objective functions.
void parseParameterList(Teuchos::ParameterList &parlist)
Parse input ParameterList.
ESecant esec_
Secant type.
bool bndActive_
Flag whether bound is activated.
std::string ETrustRegionModelToString(ETrustRegionModel tr)
std::string printHeader(void) const
Print iterate header.
Real mu_
Post-Smoothing tolerance for projected methods.
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
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 applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
void initialize(Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Initialize step.
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.
Provides the interface to evaluate trust-region model functions.
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.
Real computeCriticalityMeasure(const Vector< Real > &g, const Vector< Real > &x, BoundConstraint< Real > &bnd)
Compute the criticality measure.
ETrustRegionModel TRmodel_
Trust-region subproblem model type.
State for algorithm class. Will be used for restarts.
Real scaleEps_
Scaling for epsilon-active sets.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
bool isActivated(void)
Check if bounds are on.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
std::string NumberToString(T Number)
ETrustRegion etr_
Trust-region subproblem solver type.
Teuchos::RCP< Vector< Real > > xnew_
Container for updated iteration vector.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step.
ESecant
Enumeration of secant update algorithms.
ETrustRegionModel StringToETrustRegionModel(std::string s)
int SPflag_
Subproblem solver termination flag.
const Teuchos::RCP< const StepState< Real > > getStepState(void) const
Get state for step object.
ETrustRegionFlag TRflag_
Trust-region exit flag.
bool useSecantHessVec_
Flag whether to use a secant Hessian.
int SPiter_
Subproblem solver iteration count.
std::vector< bool > useInexact_
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.
virtual const Teuchos::RCP< const Vector< Real > > getUpperVectorRCP(void) const
Return the ref count pointer to the upper bound vector.
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.
Provides the interface to evaluate interior trust-region model functions from the Coleman-Li bound co...
virtual ~TrustRegionStep()
ETrustRegionModel
Enumeration of trust-region model types.
Provides the interface to apply upper and lower bound constraints.
void computeProjectedGradient(Vector< Real > &g, const Vector< Real > &x)
Compute projected gradient.
int verbosity_
Print additional information to screen if > 0.
std::string printName(void) const
Print step name.
ETrustRegion StringToETrustRegion(std::string s)
Provides the interface to evaluate projected trust-region model functions from the Kelley-Sachs bound...
ROL::DiagonalOperator apply
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful.
virtual const Teuchos::RCP< const Vector< Real > > getLowerVectorRCP(void) const
Return the ref count pointer to the lower bound vector.
Teuchos::RCP< TrustRegionModel< Real > > model_
Container for trust-region model.
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.
ETrustRegion
Enumeration of trust-region solver types.
std::string ETrustRegionFlagToString(ETrustRegionFlag trf)
ETrustRegionFlag
Enumation of flags used by trust-region solvers.
std::string ETrustRegionToString(ETrustRegion tr)
std::string ESecantToString(ESecant tr)
bool useProjectedGrad_
Flag whether to use the projected gradient criticality measure.
Teuchos::RCP< TrustRegion< Real > > trustRegion_
Container for trust-region solver object.
Real beta_
Post-Smoothing rate for projected methods.
Real scale1_
Scale for inexact gradient computation.
void updateGradient(Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update gradient to iteratively satisfy inexactness condition.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
Provides the interface to compute optimization steps with trust regions.