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 bool inexactObj = glist.get(
"Inexact Objective Function",
false);
160 bool inexactGrad = glist.get(
"Inexact Gradient",
false);
161 bool inexactHessVec = glist.get(
"Inexact Hessian-Times-A-Vector",
false);
166 ROL::ParameterList &ilist = list.sublist(
"Inexact").sublist(
"Gradient");
167 scale0_ = ilist.get(
"Tolerance Scaling", static_cast<Real>(0.1));
168 scale1_ = ilist.get(
"Relative Tolerance", static_cast<Real>(2));
170 std::string solverName = list.get(
"Subproblem Solver",
"Dogleg");
172 std::string modelName = list.get(
"Subproblem Model",
"Kelley-Sachs");
177 scaleEps_ = glist.get(
"Scale for Epsilon Active Sets", static_cast<Real>(1));
180 max_fval_ = list.sublist(
"Post-Smoothing").get(
"Function Evaluation Limit", 20);
181 alpha_init_ = list.sublist(
"Post-Smoothing").get(
"Initial Step Size", static_cast<Real>(1));
182 mu_ = list.sublist(
"Post-Smoothing").get(
"Tolerance", static_cast<Real>(0.9999));
183 beta_ = list.sublist(
"Post-Smoothing").get(
"Rate", static_cast<Real>(0.01));
185 stepBackMax_ = list.sublist(
"Coleman-Li").get(
"Maximum Step Back", static_cast<Real>(0.9999));
186 stepBackScale_ = list.sublist(
"Coleman-Li").get(
"Maximum Step Scale", static_cast<Real>(1));
187 singleReflect_ = list.sublist(
"Coleman-Li").get(
"Single Reflection",
true);
221 Real gtol1 =
scale0_*state->searchSize;
223 Real gtol0 = gtol1 + one;
224 while ( gtol0 > gtol1 ) {
225 obj.
gradient(*(state->gradientVec),x,gtol1);
228 gtol1 =
scale0_*std::min(algo_state.
gnorm,state->searchSize);
233 Real gtol = std::sqrt(ROL_EPSILON<Real>());
234 obj.
gradient(*(state->gradientVec),x,gtol);
261 return xnew_->norm();
301 ROL::ParameterList &glist = parlist.sublist(
"General");
302 std::string secantName = glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
306 secant_ = SecantFactory<Real>(parlist);
335 ROL::ParameterList &glist = parlist.sublist(
"General");
338 if ( ROL::is_nullPtr(
secant_) ) {
339 ROL::ParameterList Slist;
340 Slist.sublist(
"General").sublist(
"Secant").set(
"Type",
"Limited-Memory BFGS");
341 Slist.sublist(
"General").sublist(
"Secant").set(
"Maximum Storage",10);
342 secant_ = SecantFactory<Real>(Slist);
360 Real p1(0.1), oe10(1.e10),
zero(0), one(1), half(0.5), three(3), two(2), six(6);
366 Real htol = std::sqrt(ROL_EPSILON<Real>());
367 Real ftol = p1*ROL_OVERFLOW<Real>();
369 step_state->descentVec = s.
clone();
370 step_state->gradientVec = g.
clone();
387 algo_state.
snorm = oe10;
390 algo_state.
gnorm = ROL_INF<Real>();
397 Ptr<Vector<Real>> v = g.
clone();
398 Ptr<Vector<Real>> hv = x.
clone();
401 catch (std::exception &e) {
407 bool autoRad =
false;
408 if ( step_state->searchSize <=
zero ) {
410 Ptr<Vector<Real>> Bg = g.
clone();
412 secant_->applyB(*Bg,(step_state->gradientVec)->dual());
415 obj.
hessVec(*Bg,(step_state->gradientVec)->dual(),x,htol);
417 Real gBg = Bg->dot(*(step_state->gradientVec));
419 if ( gBg > ROL_EPSILON<Real>() ) {
420 alpha = algo_state.
gnorm*algo_state.
gnorm/gBg;
423 Ptr<Vector<Real>> cp = s.
clone();
424 cp->set((step_state->gradientVec)->dual());
426 Ptr<Vector<Real>> xcp = x.
clone();
433 Real fnew = obj.
value(*xcp,ftol);
436 Real gs = cp->dot((step_state->gradientVec)->dual());
437 Real a = fnew - algo_state.
value - gs - half*alpha*alpha*gBg;
438 if ( std::abs(a) < ROL_EPSILON<Real>() ) {
440 step_state->searchSize = std::min(alpha*algo_state.
gnorm,
delMax_);
443 Real b = half*alpha*alpha*gBg;
445 if ( b*b-three*a*c > ROL_EPSILON<Real>() ) {
447 Real t1 = (-b-std::sqrt(b*b-three*a*c))/(three*a);
448 Real t2 = (-b+std::sqrt(b*b-three*a*c))/(three*a);
449 if ( six*a*t1 + two*b >
zero ) {
451 step_state->searchSize = std::min(t1*alpha*algo_state.
gnorm,
delMax_);
455 step_state->searchSize = std::min(t2*alpha*algo_state.
gnorm,
delMax_);
459 step_state->searchSize = std::min(alpha*algo_state.
gnorm,
delMax_);
462 if (step_state->searchSize <= ROL_EPSILON<Real>()*algo_state.
gnorm && autoRad) {
463 step_state->searchSize = one;
470 model_ = makePtr<KelleySachsModel<Real>>(obj,
473 *(step_state->gradientVec),
479 model_ = makePtr<ColemanLiModel<Real>>(obj,
482 *(step_state->gradientVec),
491 model_ = makePtr<LinMoreModel<Real>>(obj,
494 *(step_state->gradientVec),
500 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
501 ">>> ERROR (TrustRegionStep): Invalid trust-region model!");
505 model_ = makePtr<TrustRegionModel<Real>>(obj,
508 *(step_state->gradientVec),
535 Real eps =
scaleEps_ * std::min(std::pow(algo_state.
gnorm,static_cast<Real>(0.75)),
536 static_cast<Real>(0.001));
537 dynamicPtrCast<KelleySachsModel<Real>>(
model_)->setEpsilon(eps);
540 dynamicPtrCast<ColemanLiModel<Real>>(
model_)->setRadius(step_state->searchSize);
575 Real fold = algo_state.
value;
579 s,algo_state.
snorm,fold,*(state->gradientVec),algo_state.
iter,
581 algo_state.
nfval += state->nfval;
582 algo_state.
ngrad += state->ngrad;
583 state->flag =
static_cast<int>(
TRflag_);
592 gp_->set(*(state->gradientVec));
617 algo_state.
value = fnew;
625 std::stringstream hist;
628 hist << std::string(114,
'-') <<
"\n";
630 hist <<
"Trust-Region status output definitions\n\n";
632 hist <<
" iter - Number of iterates (steps taken) \n";
633 hist <<
" value - Objective function value \n";
634 hist <<
" gnorm - Norm of the gradient\n";
635 hist <<
" snorm - Norm of the step (update to optimization vector)\n";
636 hist <<
" delta - Trust-Region radius\n";
637 hist <<
" #fval - Number of times the objective function was evaluated\n";
638 hist <<
" #grad - Number of times the gradient was computed\n";
643 hist <<
" tr_flag - Trust-Region flag" <<
"\n";
652 hist <<
" iterCG - Number of Truncated CG iterations\n\n";
653 hist <<
" flagGC - Trust-Region Truncated CG flag" <<
"\n";
660 hist << std::string(114,
'-') <<
"\n";
664 hist << std::setw(6) << std::left <<
"iter";
665 hist << std::setw(15) << std::left <<
"value";
666 hist << std::setw(15) << std::left <<
"gnorm";
667 hist << std::setw(15) << std::left <<
"snorm";
668 hist << std::setw(15) << std::left <<
"delta";
669 hist << std::setw(10) << std::left <<
"#fval";
670 hist << std::setw(10) << std::left <<
"#grad";
671 hist << std::setw(10) << std::left <<
"tr_flag";
673 hist << std::setw(10) << std::left <<
"iterCG";
674 hist << std::setw(10) << std::left <<
"flagCG";
685 std::stringstream hist;
717 std::stringstream hist;
718 hist << std::scientific << std::setprecision(6);
719 if ( algo_state.
iter == 0 ) {
722 if ( print_header ) {
725 if ( algo_state.
iter == 0 ) {
727 hist << std::setw(6) << std::left << algo_state.
iter;
728 hist << std::setw(15) << std::left << algo_state.
value;
729 hist << std::setw(15) << std::left << algo_state.
gnorm;
730 hist << std::setw(15) << std::left <<
" ";
731 hist << std::setw(15) << std::left << step_state->searchSize;
736 hist << std::setw(6) << std::left << algo_state.
iter;
737 hist << std::setw(15) << std::left << algo_state.
value;
738 hist << std::setw(15) << std::left << algo_state.
gnorm;
739 hist << std::setw(15) << std::left << algo_state.
snorm;
740 hist << std::setw(15) << std::left << step_state->searchSize;
741 hist << std::setw(10) << std::left << algo_state.
nfval;
742 hist << std::setw(10) << std::left << algo_state.
ngrad;
743 hist << std::setw(10) << std::left <<
TRflag_;
745 hist << std::setw(10) << std::left <<
SPiter_;
746 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.