10 #ifndef ROL_TRUSTREGIONSTEP_H
11 #define ROL_TRUSTREGIONSTEP_H
152 ROL::ParameterList &slist = parlist.sublist(
"Step");
153 ROL::ParameterList &list = slist.sublist(
"Trust Region");
154 step_state->searchSize = list.get(
"Initial Radius", static_cast<Real>(-1));
155 delMax_ = list.get(
"Maximum Radius", static_cast<Real>(1.e8));
157 ROL::ParameterList &glist = parlist.sublist(
"General");
159 useInexact_.push_back(glist.get(
"Inexact Objective Function",
false));
160 useInexact_.push_back(glist.get(
"Inexact Gradient",
false));
161 useInexact_.push_back(glist.get(
"Inexact Hessian-Times-A-Vector",
false));
163 ROL::ParameterList &ilist = list.sublist(
"Inexact").sublist(
"Gradient");
164 scale0_ = ilist.get(
"Tolerance Scaling", static_cast<Real>(0.1));
165 scale1_ = ilist.get(
"Relative Tolerance", static_cast<Real>(2));
172 scaleEps_ = glist.get(
"Scale for Epsilon Active Sets", static_cast<Real>(1));
175 max_fval_ = list.sublist(
"Post-Smoothing").get(
"Function Evaluation Limit", 20);
176 alpha_init_ = list.sublist(
"Post-Smoothing").get(
"Initial Step Size", static_cast<Real>(1));
177 mu_ = list.sublist(
"Post-Smoothing").get(
"Tolerance", static_cast<Real>(0.9999));
178 beta_ = list.sublist(
"Post-Smoothing").get(
"Rate", static_cast<Real>(0.01));
180 stepBackMax_ = list.sublist(
"Coleman-Li").get(
"Maximum Step Back", static_cast<Real>(0.9999));
181 stepBackScale_ = list.sublist(
"Coleman-Li").get(
"Maximum Step Scale", static_cast<Real>(1));
182 singleReflect_ = list.sublist(
"Coleman-Li").get(
"Single Reflection",
true);
216 Real gtol1 =
scale0_*state->searchSize;
218 Real gtol0 = gtol1 + one;
219 while ( gtol0 > gtol1 ) {
220 obj.
gradient(*(state->gradientVec),x,gtol1);
223 gtol1 =
scale0_*std::min(algo_state.
gnorm,state->searchSize);
228 Real gtol = std::sqrt(ROL_EPSILON<Real>());
229 obj.
gradient(*(state->gradientVec),x,gtol);
256 return xnew_->norm();
296 ROL::ParameterList &glist = parlist.sublist(
"General");
300 secant_ = SecantFactory<Real>(parlist);
329 ROL::ParameterList &glist = parlist.sublist(
"General");
332 if ( ROL::is_nullPtr(
secant_) ) {
333 ROL::ParameterList Slist;
334 Slist.sublist(
"General").sublist(
"Secant").set(
"Type",
"Limited-Memory BFGS");
335 Slist.sublist(
"General").sublist(
"Secant").set(
"Maximum Storage",10);
336 secant_ = SecantFactory<Real>(Slist);
354 Real p1(0.1), oe10(1.e10),
zero(0), one(1), half(0.5), three(3), two(2), six(6);
360 Real htol = std::sqrt(ROL_EPSILON<Real>());
361 Real ftol = p1*ROL_OVERFLOW<Real>();
363 step_state->descentVec = s.
clone();
364 step_state->gradientVec = g.
clone();
381 algo_state.
snorm = oe10;
384 algo_state.
gnorm = ROL_INF<Real>();
391 Ptr<Vector<Real>> v = g.
clone();
392 Ptr<Vector<Real>> hv = x.
clone();
395 catch (std::exception &e) {
401 bool autoRad =
false;
402 if ( step_state->searchSize <=
zero ) {
404 Ptr<Vector<Real>> Bg = g.
clone();
406 secant_->applyB(*Bg,(step_state->gradientVec)->dual());
409 obj.
hessVec(*Bg,(step_state->gradientVec)->dual(),x,htol);
411 Real gBg = Bg->dot(*(step_state->gradientVec));
413 if ( gBg > ROL_EPSILON<Real>() ) {
414 alpha = algo_state.
gnorm*algo_state.
gnorm/gBg;
417 Ptr<Vector<Real>> cp = s.
clone();
418 cp->set((step_state->gradientVec)->dual());
420 Ptr<Vector<Real>> xcp = x.
clone();
427 Real fnew = obj.
value(*xcp,ftol);
430 Real gs = cp->dot((step_state->gradientVec)->dual());
431 Real a = fnew - algo_state.
value - gs - half*alpha*alpha*gBg;
432 if ( std::abs(a) < ROL_EPSILON<Real>() ) {
434 step_state->searchSize = std::min(alpha*algo_state.
gnorm,
delMax_);
437 Real b = half*alpha*alpha*gBg;
439 if ( b*b-three*a*c > ROL_EPSILON<Real>() ) {
441 Real t1 = (-b-std::sqrt(b*b-three*a*c))/(three*a);
442 Real t2 = (-b+std::sqrt(b*b-three*a*c))/(three*a);
443 if ( six*a*t1 + two*b >
zero ) {
445 step_state->searchSize = std::min(t1*alpha*algo_state.
gnorm,
delMax_);
449 step_state->searchSize = std::min(t2*alpha*algo_state.
gnorm,
delMax_);
453 step_state->searchSize = std::min(alpha*algo_state.
gnorm,
delMax_);
456 if (step_state->searchSize <= ROL_EPSILON<Real>()*algo_state.
gnorm && autoRad) {
457 step_state->searchSize = one;
464 model_ = makePtr<KelleySachsModel<Real>>(obj,
467 *(step_state->gradientVec),
473 model_ = makePtr<ColemanLiModel<Real>>(obj,
476 *(step_state->gradientVec),
485 model_ = makePtr<LinMoreModel<Real>>(obj,
488 *(step_state->gradientVec),
494 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
495 ">>> ERROR (TrustRegionStep): Invalid trust-region model!");
499 model_ = makePtr<TrustRegionModel<Real>>(obj,
502 *(step_state->gradientVec),
529 Real eps =
scaleEps_ * std::min(std::pow(algo_state.
gnorm,static_cast<Real>(0.75)),
530 static_cast<Real>(0.001));
531 dynamicPtrCast<KelleySachsModel<Real>>(
model_)->setEpsilon(eps);
534 dynamicPtrCast<ColemanLiModel<Real>>(
model_)->setRadius(step_state->searchSize);
569 Real fold = algo_state.
value;
573 s,algo_state.
snorm,fold,*(state->gradientVec),algo_state.
iter,
575 algo_state.
nfval += state->nfval;
576 algo_state.
ngrad += state->ngrad;
577 state->flag =
static_cast<int>(
TRflag_);
586 gp_->set(*(state->gradientVec));
611 algo_state.
value = fnew;
619 std::stringstream hist;
622 hist << std::string(114,
'-') <<
"\n";
624 hist <<
"Trust-Region status output definitions\n\n";
626 hist <<
" iter - Number of iterates (steps taken) \n";
627 hist <<
" value - Objective function value \n";
628 hist <<
" gnorm - Norm of the gradient\n";
629 hist <<
" snorm - Norm of the step (update to optimization vector)\n";
630 hist <<
" delta - Trust-Region radius\n";
631 hist <<
" #fval - Number of times the objective function was evaluated\n";
632 hist <<
" #grad - Number of times the gradient was computed\n";
637 hist <<
" tr_flag - Trust-Region flag" <<
"\n";
646 hist <<
" iterCG - Number of Truncated CG iterations\n\n";
647 hist <<
" flagGC - Trust-Region Truncated CG flag" <<
"\n";
654 hist << std::string(114,
'-') <<
"\n";
658 hist << std::setw(6) << std::left <<
"iter";
659 hist << std::setw(15) << std::left <<
"value";
660 hist << std::setw(15) << std::left <<
"gnorm";
661 hist << std::setw(15) << std::left <<
"snorm";
662 hist << std::setw(15) << std::left <<
"delta";
663 hist << std::setw(10) << std::left <<
"#fval";
664 hist << std::setw(10) << std::left <<
"#grad";
665 hist << std::setw(10) << std::left <<
"tr_flag";
667 hist << std::setw(10) << std::left <<
"iterCG";
668 hist << std::setw(10) << std::left <<
"flagCG";
679 std::stringstream hist;
711 std::stringstream hist;
712 hist << std::scientific << std::setprecision(6);
713 if ( algo_state.
iter == 0 ) {
716 if ( print_header ) {
719 if ( algo_state.
iter == 0 ) {
721 hist << std::setw(6) << std::left << algo_state.
iter;
722 hist << std::setw(15) << std::left << algo_state.
value;
723 hist << std::setw(15) << std::left << algo_state.
gnorm;
724 hist << std::setw(15) << std::left <<
" ";
725 hist << std::setw(15) << std::left << step_state->searchSize;
730 hist << std::setw(6) << std::left << algo_state.
iter;
731 hist << std::setw(15) << std::left << algo_state.
value;
732 hist << std::setw(15) << std::left << algo_state.
gnorm;
733 hist << std::setw(15) << std::left << algo_state.
snorm;
734 hist << std::setw(15) << std::left << step_state->searchSize;
735 hist << std::setw(10) << std::left << algo_state.
nfval;
736 hist << std::setw(10) << std::left << algo_state.
ngrad;
737 hist << std::setw(10) << std::left <<
TRflag_;
739 hist << std::setw(10) << std::left <<
SPiter_;
740 hist << std::setw(10) << std::left <<
SPflag_;
std::string ECGFlagToString(ECGFlag cgf)
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...
bool bndActive_
Flag whether bound is activated.
std::string ETrustRegionModelToString(ETrustRegionModel tr)
Real mu_
Post-Smoothing tolerance for projected methods.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void projectInterior(Vector< Real > &x)
Project optimization variables into the interior of the feasible set.
bool useSecantPrecond_
Flag whether to use a secant preconditioner.
bool isActivated(void) const
Check if bounds are on.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
TrustRegionStep(ROL::Ptr< Secant< Real > > &secant, ROL::ParameterList &parlist)
Constructor.
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.
Contains definitions of custom data types in ROL.
bool isValidTrustRegionSubproblem(ETrustRegion etr, ETrustRegionModel etrm, bool isBnd)
Real alpha_init_
Initial line-search parameter for projected methods.
ESecant StringToESecant(std::string s)
Defines the linear algebra or vector space interface.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
std::string printName(void) const
Print step name.
TrustRegionStep(ROL::ParameterList &parlist)
Constructor.
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.
std::string NumberToString(T Number)
ETrustRegion etr_
Trust-region subproblem solver type.
std::string printHeader(void) const
Print iterate header.
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.
ROL::Ptr< StepState< Real > > getState(void)
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.
Ptr< TrustRegionModel< Real > > model_
Container for trust-region model.
ROL::Ptr< Vector< Real > > iterateVec
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.
Ptr< Vector< Real > > xnew_
Container for updated iteration vector.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
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.
Ptr< TrustRegion< Real > > trustRegion_
Container for trust-region solver object.
ETrustRegion StringToETrustRegion(std::string s)
Ptr< Vector< Real > > xold_
Container for previous iteration vector.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful.
virtual Real norm() const =0
Returns where .
int max_fval_
Maximum function evaluations in line-search for projected methods.
Ptr< Secant< Real > > secant_
Container for secant approximation.
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.
Real beta_
Post-Smoothing rate for projected methods.
Real scale1_
Scale for inexact gradient computation.
void parseParameterList(ROL::ParameterList &parlist)
Parse input ParameterList.
void updateGradient(Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update gradient to iteratively satisfy inexactness condition.
Provides the interface to compute optimization steps with trust regions.
const ROL::Ptr< const StepState< Real > > getStepState(void) const
Get state for step object.
Ptr< Vector< Real > > gp_
Container for previous gradient vector.