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 NMstorage_ = trlist.get(
"Nonmonotone Storage Limit", 0);
75 useNM_ = (NMstorage_ <= 0 ?
false :
true);
77 ParameterList &glist = parlist.sublist(
"General");
79 useInexact_.push_back(glist.get(
"Inexact Objective Function",
false));
80 useInexact_.push_back(glist.get(
"Inexact Gradient",
false));
81 useInexact_.push_back(glist.get(
"Inexact Hessian-Times-A-Vector",
false));
83 ParameterList &ilist = trlist.sublist(
"Inexact").sublist(
"Gradient");
84 scale0_ = ilist.get(
"Tolerance Scaling", static_cast<Real>(0.1));
85 scale1_ = ilist.get(
"Relative Tolerance", static_cast<Real>(2));
87 ParameterList &vlist = trlist.sublist(
"Inexact").sublist(
"Value");
88 scale_ = vlist.get(
"Tolerance Scaling", static_cast<Real>(1.e-1));
89 omega_ = vlist.get(
"Exponent", static_cast<Real>(0.9));
90 force_ = vlist.get(
"Forcing Sequence Initial Value", static_cast<Real>(1.0));
91 updateIter_ = vlist.get(
"Forcing Sequence Update Frequency", static_cast<int>(10));
92 forceFactor_ = vlist.get(
"Forcing Sequence Reduction Factor", static_cast<Real>(0.1));
95 solver_ = TrustRegionUFactory<Real>(parlist);
100 if (secant == nullPtr) {
104 model_ = makePtr<TrustRegionModel_U<Real>>(parlist,secant);
108 template<
typename Real>
113 std::ostream &outStream) {
117 solver_->initialize(x,g);
118 model_->initialize(x,g);
120 Real ftol =
static_cast<Real
>(0.1)*ROL_OVERFLOW<Real>();
122 state_->value = obj.
value(x,ftol);
124 state_->snorm = ROL_INF<Real>();
125 state_->gnorm = ROL_INF<Real>();
126 Real Delta = state_->searchSize;
127 if (Delta <= zero) state_->searchSize = 1e2*x.
norm();
128 computeGradient(x,obj,
true);
130 model_->validate(obj,x,g,etr_);
132 if ( Delta <= zero ) {
135 = TRUtils::initialRadius<Real>(nfval,x,*state_->gradientVec,Bg,
136 state_->value,state_->gnorm,gtol_,obj,*model_,delMax_,
137 outStream,(verbosity_>1));
138 state_->nfval += nfval;
142 template<
typename Real>
147 Real tol(std::sqrt(ROL_EPSILON<Real>())), fval(0);
148 if ( useInexact_[0] ) {
149 if ( !(state_->iter%updateIter_) && (state_->iter != 0) ) {
150 force_ *= forceFactor_;
152 Real eta =
static_cast<Real
>(0.999)*std::min(eta1_,one-eta2_);
153 tol = scale_*std::pow(eta*std::min(pRed,force_),one/omega_);
154 state_->value = obj.
value(*state_->iterateVec,tol);
159 fval = obj.
value(x,tol);
164 template<
typename Real>
168 if ( useInexact_[1] ) {
169 Real gtol0 = scale0_*state_->searchSize;
170 if (accept) gtol_ = gtol0 +
static_cast<Real
>(1);
171 else gtol0 = scale0_*std::min(state_->gnorm,state_->searchSize);
172 while ( gtol_ > gtol0 ) {
174 obj.
gradient(*state_->gradientVec,x,gtol_); state_->ngrad++;
175 state_->gnorm = state_->gradientVec->norm();
176 gtol0 = scale0_*std::min(state_->gnorm,state_->searchSize);
181 gtol_ = std::sqrt(ROL_EPSILON<Real>());
182 obj.
gradient(*state_->gradientVec,x,gtol_); state_->ngrad++;
183 state_->gnorm = state_->gradientVec->norm();
188 template<
typename Real>
192 std::ostream &outStream ) {
195 Real ftrial(0), pRed(0), rho(0);
196 Ptr<Vector<Real>> gvec = g.
clone();
197 initialize(x,g,*gvec,obj,outStream);
199 Real rhoNM(0), sigmac(0), sigmar(0);
200 Real fr(state_->value), fc(state_->value), fmin(state_->value);
205 if (verbosity_ > 0) writeOutput(outStream,
true);
207 while (status_->check(*state_)) {
209 model_->setData(obj,x,*state_->gradientVec,gtol_);
212 SPflag_ = 0; SPiter_ = 0;
213 solver_->solve(*state_->stepVec,state_->snorm,pRed,SPflag_,SPiter_,
214 state_->searchSize,*model_);
216 x.
plus(*state_->stepVec);
217 ftrial = computeValue(x,obj,pRed);
220 TRUtils::analyzeRatio<Real>(rho,TRflag_,state_->value,ftrial,pRed,eps_,outStream,verbosity_>1);
222 TRUtils::analyzeRatio<Real>(rhoNM,TRflagNM,fr,ftrial,pRed+sigmar,eps_,outStream,verbosity_>1);
223 TRflag_ = (rho < rhoNM ? TRflagNM : TRflag_);
224 rho = (rho < rhoNM ? rhoNM : rho );
231 x.
set(*state_->iterateVec);
235 state_->searchSize = TRUtils::interpolateRadius<Real>(*state_->gradientVec,*state_->stepVec,
236 state_->snorm,pRed,state_->value,ftrial,state_->searchSize,gamma0_,gamma1_,eta2_,
237 outStream,verbosity_>1);
240 state_->searchSize = gamma1_*std::min(state_->snorm,state_->searchSize);
242 computeGradient(x,obj,
false);
246 state_->iterateVec->set(x);
247 state_->value = ftrial;
250 sigmac += pRed; sigmar += pRed;
251 if (ftrial < fmin) { fmin = ftrial; fc = fmin; sigmac =
zero; L = 0; }
254 if (ftrial > fc) { fc = ftrial; sigmac =
zero; }
255 if (L == NMstorage_) { fr = fc; sigmar = sigmac; }
259 if (rho >= eta2_) state_->searchSize = std::min(gamma2_*state_->searchSize, delMax_);
261 gvec->set(*state_->gradientVec);
262 computeGradient(x,obj,
true);
264 model_->update(x,*state_->stepVec,*gvec,*state_->gradientVec,
265 state_->snorm,state_->iter);
268 if (verbosity_ > 0) writeOutput(outStream,printHeader_);
273 template<
typename Real>
275 std::ios_base::fmtflags osFlags(os.flags());
277 os << std::string(114,
'-') << std::endl;
278 os <<
"Trust-Region status output definitions" << std::endl << std::endl;
279 os <<
" iter - Number of iterates (steps taken)" << std::endl;
280 os <<
" value - Objective function value" << std::endl;
281 os <<
" gnorm - Norm of the gradient" << std::endl;
282 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
283 os <<
" delta - Trust-Region radius" << std::endl;
284 os <<
" #fval - Number of times the objective function was evaluated" << std::endl;
285 os <<
" #grad - Number of times the gradient was computed" << std::endl;
287 os <<
" tr_flag - Trust-Region flag" << std::endl;
294 os <<
" iterCG - Number of Truncated CG iterations" << std::endl << std::endl;
295 os <<
" flagGC - Trust-Region Truncated CG flag" << std::endl;
303 os <<
" iterCG - Number of spectral projected gradient iterations" << std::endl << std::endl;
304 os <<
" flagGC - Trust-Region spectral projected gradient flag" << std::endl;
306 os << std::string(114,
'-') << std::endl;
309 os << std::setw(6) << std::left <<
"iter";
310 os << std::setw(15) << std::left <<
"value";
311 os << std::setw(15) << std::left <<
"gnorm";
312 os << std::setw(15) << std::left <<
"snorm";
313 os << std::setw(15) << std::left <<
"delta";
314 os << std::setw(10) << std::left <<
"#fval";
315 os << std::setw(10) << std::left <<
"#grad";
316 os << std::setw(10) << std::left <<
"tr_flag";
318 os << std::setw(10) << std::left <<
"iterCG";
319 os << std::setw(10) << std::left <<
"flagCG";
322 os << std::setw(10) << std::left <<
"iterSPG";
323 os << std::setw(10) << std::left <<
"flagSPG";
329 template<
typename Real>
331 std::ios_base::fmtflags osFlags(os.flags());
333 if ( useSecantPrecond_ || useSecantHessVec_ ) {
334 if ( useSecantPrecond_ && !useSecantHessVec_ ) {
335 os <<
" with " <<
ESecantToString(esec_) <<
" Preconditioning" << std::endl;
337 else if ( !useSecantPrecond_ && useSecantHessVec_ ) {
338 os <<
" with " <<
ESecantToString(esec_) <<
" Hessian Approximation" << std::endl;
341 os <<
" with " <<
ESecantToString(esec_) <<
" Preconditioning and Hessian Approximation" << std::endl;
350 template<
typename Real>
352 std::ios_base::fmtflags osFlags(os.flags());
353 os << std::scientific << std::setprecision(6);
354 if ( state_->iter == 0 ) {
357 if ( print_header ) {
360 if ( state_->iter == 0 ) {
362 os << std::setw(6) << std::left << state_->iter;
363 os << std::setw(15) << std::left << state_->value;
364 os << std::setw(15) << std::left << state_->gnorm;
365 os << std::setw(15) << std::left <<
"---";
366 os << std::setw(15) << std::left << state_->searchSize;
367 os << std::setw(10) << std::left << state_->nfval;
368 os << std::setw(10) << std::left << state_->ngrad;
369 os << std::setw(10) << std::left <<
"---";
371 os << std::setw(10) << std::left <<
"---";
372 os << std::setw(10) << std::left <<
"---";
378 os << std::setw(6) << std::left << state_->iter;
379 os << std::setw(15) << std::left << state_->value;
380 os << std::setw(15) << std::left << state_->gnorm;
381 os << std::setw(15) << std::left << state_->snorm;
382 os << std::setw(15) << std::left << state_->searchSize;
383 os << std::setw(10) << std::left << state_->nfval;
384 os << std::setw(10) << std::left << state_->ngrad;
385 os << std::setw(10) << std::left << TRflag_;
387 os << std::setw(10) << std::left << SPiter_;
388 os << 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.
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)
void computeGradient(const Vector< Real > &x, Objective< Real > &obj, bool accept)
Compute gradient to iteratively satisfy inexactness condition.
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, const bool print_header=false) const override
Print iterate status.
ETRFlag
Enumation of flags used by trust-region solvers.
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)
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 .
virtual Real norm() const =0
Returns where .
virtual void writeExitStatus(std::ostream &os) const
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)