44 #ifndef ROL_TRUSTREGIONALGORITHM_U_DEF_H 45 #define ROL_TRUSTREGIONALGORITHM_U_DEF_H 52 template<
typename Real>
61 ParameterList &slist = parlist.sublist(
"Step");
62 ParameterList &trlist = slist.sublist(
"Trust Region");
63 state_->searchSize = trlist.get(
"Initial Radius", static_cast<Real>(-1));
64 delMax_ = trlist.get(
"Maximum Radius", ROL_INF<Real>());
65 eta0_ = trlist.get(
"Step Acceptance Threshold", static_cast<Real>(0.05));
66 eta1_ = trlist.get(
"Radius Shrinking Threshold", static_cast<Real>(0.05));
67 eta2_ = trlist.get(
"Radius Growing Threshold", static_cast<Real>(0.9));
68 gamma0_ = trlist.get(
"Radius Shrinking Rate (Negative rho)", static_cast<Real>(0.0625));
69 gamma1_ = trlist.get(
"Radius Shrinking Rate (Positive rho)", static_cast<Real>(0.25));
70 gamma2_ = trlist.get(
"Radius Growing Rate", static_cast<Real>(2.5));
71 TRsafe_ = trlist.get(
"Safeguard Size", static_cast<Real>(100.0));
74 ParameterList &glist = parlist.sublist(
"General");
76 useInexact_.push_back(glist.get(
"Inexact Objective Function",
false));
77 useInexact_.push_back(glist.get(
"Inexact Gradient",
false));
78 useInexact_.push_back(glist.get(
"Inexact Hessian-Times-A-Vector",
false));
80 ParameterList &ilist = trlist.sublist(
"Inexact").sublist(
"Gradient");
81 scale0_ = ilist.get(
"Tolerance Scaling", static_cast<Real>(0.1));
82 scale1_ = ilist.get(
"Relative Tolerance", static_cast<Real>(2));
84 ParameterList &vlist = trlist.sublist(
"Inexact").sublist(
"Value");
85 scale_ = vlist.get(
"Tolerance Scaling", static_cast<Real>(1.e-1));
86 omega_ = vlist.get(
"Exponent", static_cast<Real>(0.9));
87 force_ = vlist.get(
"Forcing Sequence Initial Value", static_cast<Real>(1.0));
88 updateIter_ = vlist.get(
"Forcing Sequence Update Frequency", static_cast<int>(10));
89 forceFactor_ = vlist.get(
"Forcing Sequence Reduction Factor", static_cast<Real>(0.1));
92 solver_ = TrustRegionUFactory<Real>(parlist);
97 if (secant == nullPtr) {
101 model_ = makePtr<TrustRegionModel_U<Real>>(parlist,secant);
105 template<
typename Real>
110 std::ostream &outStream) {
113 solver_->initialize(x,g);
114 model_->initialize(x,g);
116 Real ftol =
static_cast<Real
>(0.1)*ROL_OVERFLOW<Real>();
118 state_->value = obj.
value(x,ftol);
120 state_->snorm = ROL_INF<Real>();
121 state_->gnorm = ROL_INF<Real>();
122 computeGradient(x,obj);
124 model_->validate(obj,x,g,etr_);
126 if ( state_->searchSize <= static_cast<Real>(0) ) {
129 = TRUtils::initialRadius<Real>(nfval,x,*state_->gradientVec,Bg,
130 state_->value,state_->gnorm,obj,*model_,delMax_,
131 outStream,(verbosity_>1));
132 state_->nfval += nfval;
136 template<
typename Real>
141 Real tol(std::sqrt(ROL_EPSILON<Real>())), fval(0);
142 if ( useInexact_[0] ) {
143 if ( !(state_->iter%updateIter_) && (state_->iter != 0) ) {
144 force_ *= forceFactor_;
146 Real eta =
static_cast<Real
>(0.999)*std::min(eta1_,one-eta2_);
147 tol = scale_*std::pow(eta*std::min(pRed,force_),one/omega_);
148 state_->value = obj.
value(*state_->iterateVec,tol);
153 fval = obj.
value(x,tol);
158 template<
typename Real>
161 if ( useInexact_[1] ) {
163 Real gtol1 = scale0_*state_->searchSize;
164 Real gtol0 = gtol1 + one;
165 while ( gtol0 > gtol1 ) {
166 obj.
gradient(*state_->gradientVec,x,gtol1);
167 state_->gnorm = state_->gradientVec->norm();
169 gtol1 = scale0_*std::min(state_->gnorm,state_->searchSize);
173 Real gtol = std::sqrt(ROL_EPSILON<Real>());
174 obj.
gradient(*state_->gradientVec,x,gtol);
175 state_->gnorm = state_->gradientVec->norm();
180 template<
typename Real>
184 std::ostream &outStream ) {
187 Real ftrial(0), pRed(0), rho(0);
188 Ptr<Vector<Real>> gvec = g.
clone();
189 initialize(x,g,*gvec,obj,outStream);
192 if (verbosity_ > 0) writeOutput(outStream,
true);
194 while (status_->check(*state_)) {
196 model_->setData(obj,x,*state_->gradientVec);
199 SPflag_ = 0; SPiter_ = 0;
200 solver_->solve(*state_->stepVec,state_->snorm,pRed,SPflag_,SPiter_,
201 state_->searchSize,*model_);
203 x.
plus(*state_->stepVec);
204 ftrial = computeValue(x,obj,pRed);
207 TRUtils::analyzeRatio<Real>(rho,TRflag_,state_->value,ftrial,pRed,eps_,outStream,verbosity_>1);
213 x.
set(*state_->iterateVec);
217 state_->searchSize = TRUtils::interpolateRadius<Real>(*state_->gradientVec,*state_->stepVec,
218 state_->snorm,pRed,state_->value,ftrial,state_->searchSize,gamma0_,gamma1_,eta2_,
219 outStream,verbosity_>1);
222 state_->searchSize = gamma1_*std::min(state_->snorm,state_->searchSize);
224 if (useInexact_[1]) computeGradient(x,obj);
228 state_->iterateVec->set(x);
229 state_->value = ftrial;
232 if (rho >= eta2_) state_->searchSize = std::min(gamma2_*state_->searchSize, delMax_);
234 gvec->set(*state_->gradientVec);
235 computeGradient(x,obj);
237 model_->update(x,*state_->stepVec,*gvec,*state_->gradientVec,
238 state_->snorm,state_->iter);
241 if (verbosity_ > 0) writeOutput(outStream,printHeader_);
246 template<
typename Real>
248 std::stringstream hist;
250 hist << std::string(114,
'-') << std::endl;
251 hist <<
"Trust-Region status output definitions" << std::endl << std::endl;
252 hist <<
" iter - Number of iterates (steps taken)" << std::endl;
253 hist <<
" value - Objective function value" << std::endl;
254 hist <<
" gnorm - Norm of the gradient" << std::endl;
255 hist <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
256 hist <<
" delta - Trust-Region radius" << std::endl;
257 hist <<
" #fval - Number of times the objective function was evaluated" << std::endl;
258 hist <<
" #grad - Number of times the gradient was computed" << std::endl;
260 hist <<
" tr_flag - Trust-Region flag" << std::endl;
267 hist <<
" iterCG - Number of Truncated CG iterations" << std::endl << std::endl;
268 hist <<
" flagGC - Trust-Region Truncated CG flag" << std::endl;
276 hist <<
" iterCG - Number of spectral projected gradient iterations" << std::endl << std::endl;
277 hist <<
" flagGC - Trust-Region spectral projected gradient flag" << std::endl;
279 hist << std::string(114,
'-') << std::endl;
282 hist << std::setw(6) << std::left <<
"iter";
283 hist << std::setw(15) << std::left <<
"value";
284 hist << std::setw(15) << std::left <<
"gnorm";
285 hist << std::setw(15) << std::left <<
"snorm";
286 hist << std::setw(15) << std::left <<
"delta";
287 hist << std::setw(10) << std::left <<
"#fval";
288 hist << std::setw(10) << std::left <<
"#grad";
289 hist << std::setw(10) << std::left <<
"tr_flag";
291 hist << std::setw(10) << std::left <<
"iterCG";
292 hist << std::setw(10) << std::left <<
"flagCG";
295 hist << std::setw(10) << std::left <<
"iterSPG";
296 hist << std::setw(10) << std::left <<
"flagSPG";
302 template<
typename Real>
304 std::stringstream hist;
306 if ( useSecantPrecond_ || useSecantHessVec_ ) {
307 if ( useSecantPrecond_ && !useSecantHessVec_ ) {
308 hist <<
" with " <<
ESecantToString(esec_) <<
" Preconditioning" << std::endl;
310 else if ( !useSecantPrecond_ && useSecantHessVec_ ) {
311 hist <<
" with " <<
ESecantToString(esec_) <<
" Hessian Approximation" << std::endl;
314 hist <<
" with " <<
ESecantToString(esec_) <<
" Preconditioning and Hessian Approximation" << std::endl;
323 template<
typename Real>
325 std::stringstream hist;
326 hist << std::scientific << std::setprecision(6);
327 if ( state_->iter == 0 ) {
330 if ( print_header ) {
333 if ( state_->iter == 0 ) {
335 hist << std::setw(6) << std::left << state_->iter;
336 hist << std::setw(15) << std::left << state_->value;
337 hist << std::setw(15) << std::left << state_->gnorm;
338 hist << std::setw(15) << std::left <<
"---";
339 hist << std::setw(15) << std::left << state_->searchSize;
340 hist << std::setw(10) << std::left << state_->nfval;
341 hist << std::setw(10) << std::left << state_->ngrad;
342 hist << std::setw(10) << std::left <<
"---";
344 hist << std::setw(10) << std::left <<
"---";
345 hist << std::setw(10) << std::left <<
"---";
351 hist << std::setw(6) << std::left << state_->iter;
352 hist << std::setw(15) << std::left << state_->value;
353 hist << std::setw(15) << std::left << state_->gnorm;
354 hist << std::setw(15) << std::left << state_->snorm;
355 hist << std::setw(15) << std::left << state_->searchSize;
356 hist << std::setw(10) << std::left << state_->nfval;
357 hist << std::setw(10) << std::left << state_->ngrad;
358 hist << std::setw(10) << std::left << TRflag_;
360 hist << std::setw(10) << std::left << SPiter_;
361 hist << std::setw(10) << std::left << SPflag_;
std::string ECGFlagToString(ECGFlag cgf)
int verbosity_
Print additional information to screen if > 0.
Provides the interface to evaluate objective functions.
void computeGradient(const Vector< Real > &x, Objective< Real > &obj)
Compute gradient to iteratively satisfy inexactness condition.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void initialize(const Vector< Real > &x, const Vector< Real > &g, Vector< Real > &Bg, Objective< Real > &obj, std::ostream &outStream=std::cout)
virtual void plus(const Vector &x)=0
Compute , where .
const Ptr< AlgorithmState< Real > > state_
Real scale1_
Scale for inexact gradient computation.
ETrustRegionU StringToETrustRegionU(std::string s)
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
TrustRegionAlgorithm(ParameterList &parlist, const Ptr< Secant< Real >> &secant=nullPtr)
void initialize(const Vector< Real > &x, const Vector< Real > &g)
Real delMax_
Maximum trust-region radius.
ESecant StringToESecant(std::string s)
ESecant esec_
Secant type.
Ptr< TrustRegion_U< Real > > solver_
Container for trust-region solver object.
bool printHeader_
Print header at every iteration.
Defines the linear algebra or vector space interface.
Contains definitions of enums for trust region algorithms.
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()
Ptr< TrustRegionModel_U< Real > > model_
Container for trust-region model.
Real gamma0_
Radius decrease rate (negative rho).
void writeOutput(std::ostream &os, bool print_header=false) const override
Print iterate status.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
std::string NumberToString(T Number)
Real eta2_
Radius increase threshold.
Provides an interface to run unconstrained optimization algorithms.
Real eta1_
Radius decrease threshold.
Real gamma2_
Radius increase rate.
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, std::ostream &outStream=std::cout) override
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
void writeName(std::ostream &os) const override
Print step name.
Provides interface for and implements limited-memory secant operators.
Provides an interface to check status of optimization algorithms.
std::string ETRFlagToString(ETRFlag trf)
virtual void writeExitStatus(std::ostream &os) const
Real scale0_
Scale for inexact gradient computation.
void writeHeader(std::ostream &os) const override
Print iterate header.
Real TRsafe_
Safeguard size for numerically evaluating ratio.
Real gamma1_
Radius decrease rate (positive rho).
Real eta0_
Step acceptance threshold.
virtual void set(const Vector &x)
Set where .
ETrustRegionU etr_
Trust-region subproblem solver type.
const Ptr< CombinedStatusTest< Real > > status_
std::vector< bool > useInexact_
Flags for inexact (0) objective function, (1) gradient, (2) Hessian.
std::string ESecantToString(ESecant tr)
Real eps_
Safeguard for numerically evaluating ratio.
Real computeValue(const Vector< Real > &x, Objective< Real > &obj, Real pRed)
std::string ETrustRegionUToString(ETrustRegionU tr)