10 #ifndef ROL_TRUSTREGIONUTILITIES_U_H
11 #define ROL_TRUSTREGIONUTILITIES_U_H
39 std::string retString;
42 retString =
"Both actual and predicted reductions are positive (success)";
45 retString =
"Actual reduction is positive and predicted reduction is negative (impossible)";
48 retString =
"Actual reduction is nonpositive and predicted reduction is positive";
51 retString =
"Actual reduction is nonpositive and predicted reduction is negative (impossible)";
54 retString =
"Actual and/or predicted reduction is a NaN";
57 retString =
"Subproblem solution did not produce sufficient decrease";
60 retString =
"INVALID ETRFlag";
65 template<
typename Real>
76 std::ostream &outStream,
77 const bool print =
false) {
78 const Real
zero(0), half(0.5), one(1), two(2), three(3), six(6);
79 const Real eps(ROL_EPSILON<Real>());
80 Real del(ROL_INF<Real>());
82 Ptr<Vector<Real>> xcp = x.
clone();
86 Real alpha = (gBg > eps ? gnorm*gnorm/gBg : one);
91 Real gs = xcp->apply(g);
94 Real ftol =
static_cast<Real
>(0.1)*ROL_OVERFLOW<Real>();
95 Real fnew = obj.
value(*xcp,ftol);
98 Real a = fnew - fx - gs - half*alpha*alpha*gBg;
99 if ( std::abs(a) < eps ) {
101 del = std::min(alpha*gnorm,delMax);
104 Real b = half*alpha*alpha*gBg;
106 if ( b*b-three*a*c > eps ) {
108 Real t1 = (-b-std::sqrt(b*b-three*a*c))/(three*a);
109 Real t2 = (-b+std::sqrt(b*b-three*a*c))/(three*a);
110 if ( six*a*t1 + two*b >
zero ) {
112 del = std::min(t1*alpha*gnorm,delMax);
116 del = std::min(t2*alpha*gnorm,delMax);
120 del = std::min(alpha*gnorm,delMax);
123 if (del <= eps*gnorm) {
128 outStream <<
" In TrustRegionUtilities::initialRadius" << std::endl;
129 outStream <<
" Initial radius: " << del << std::endl;
134 template<
typename Real>
141 std::ostream &outStream = std::cout,
142 const bool print =
false) {
143 const Real
zero(0), one(1);
144 Real eps = epsi*std::max(one,fold);
145 Real aRed = fold - ftrial;
146 Real aRed_safe = aRed + eps, pRed_safe = pRed + eps;
147 if (((std::abs(aRed_safe) < epsi) && (std::abs(pRed_safe) < epsi)) || aRed == pRed) {
151 else if ( std::isnan(aRed_safe) || std::isnan(pRed_safe) ) {
156 rho = aRed_safe/pRed_safe;
157 if (pRed_safe < zero && aRed_safe >
zero) {
160 else if (aRed_safe <= zero && pRed_safe > zero) {
163 else if (aRed_safe <= zero && pRed_safe < zero) {
171 outStream <<
" In TrustRegionUtilities::analyzeRatio" << std::endl;
172 outStream <<
" Current objective function value: " << fold << std::endl;
173 outStream <<
" New objective function value: " << ftrial << std::endl;
174 outStream <<
" Actual reduction: " << aRed << std::endl;
175 outStream <<
" Predicted reduction: " << pRed << std::endl;
176 outStream <<
" Safeguard: " << epsi << std::endl;
177 outStream <<
" Actual reduction with safeguard: " << aRed_safe << std::endl;
178 outStream <<
" Predicted reduction with safeguard: " << pRed_safe << std::endl;
179 outStream <<
" Ratio of actual and predicted reduction: " << rho << std::endl;
180 outStream <<
" Trust-region flag: " << flag << std::endl;
181 outStream << std::endl;
185 template<
typename Real>
196 std::ostream &outStream = std::cout,
197 const bool print =
false) {
200 Real gs = g.
apply(s);
201 Real modelVal = fold - pRed;
202 Real theta = (one-eta2)*gs/((one-eta2)*(fold+gs)+eta2*modelVal-ftrial);
204 outStream <<
" In TrustRegionUtilities::interpolateRadius" << std::endl;
205 outStream <<
" Interpolation model value: " << modelVal << std::endl;
206 outStream <<
" Interpolation step length: " << theta << std::endl;
207 outStream << std::endl;
209 return std::min(gamma1*std::min(snorm,del),std::max(gamma0,theta)*del);
Provides the interface to evaluate objective functions.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real interpolateRadius(const Vector< Real > &g, const Vector< Real > &s, const Real snorm, const Real pRed, const Real fold, const Real ftrial, const Real del, const Real gamma0, const Real gamma1, const Real eta2, std::ostream &outStream=std::cout, const bool print=false)
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Real initialRadius(int &nfval, const Vector< Real > &x, const Vector< Real > &g, Vector< Real > &Bg, const Real fx, const Real gnorm, const Real gtol, Objective< Real > &obj, TrustRegionModel_U< Real > &model, const Real delMax, std::ostream &outStream, const bool print=false)
Defines the linear algebra or vector space interface.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
virtual Real dot(const Vector &x) const =0
Compute where .
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &s, Real &tol) override
Apply Hessian approximation to vector.
ETRFlag
Enumation of flags used by trust-region solvers.
Provides the interface to evaluate trust-region model functions.
std::string ETRFlagToString(ETRFlag trf)
void analyzeRatio(Real &rho, ETRFlag &flag, const Real fold, const Real ftrial, const Real pRed, const Real epsi, std::ostream &outStream=std::cout, const bool print=false)
virtual void setData(Objective< Real > &obj, const Vector< Real > &x, const Vector< Real > &g, Real &tol)