44#ifndef ROL_TRUSTREGIONUTILITIES_U_H
45#define ROL_TRUSTREGIONUTILITIES_U_H
73 std::string retString;
76 retString =
"Both actual and predicted reductions are positive (success)";
79 retString =
"Actual reduction is positive and predicted reduction is negative (impossible)";
82 retString =
"Actual reduction is nonpositive and predicted reduction is positive";
85 retString =
"Actual reduction is nonpositive and predicted reduction is negative (impossible)";
88 retString =
"Actual and/or predicted reduction is a NaN";
91 retString =
"Subproblem solution did not produce sufficient decrease";
94 retString =
"INVALID ETRFlag";
99template<
typename Real>
109 std::ostream &outStream,
110 const bool print =
false) {
111 const Real
zero(0), half(0.5), one(1), two(2), three(3), six(6);
112 const Real eps(ROL_EPSILON<Real>());
113 Real del(ROL_INF<Real>());
114 Ptr<Vector<Real>> xcp = x.
clone();
116 Real htol = std::sqrt(eps);
118 Real gBg = Bg.
dot(g);
121 alpha = gnorm*gnorm/gBg;
127 Real gs = xcp->apply(g);
130 Real ftol =
static_cast<Real
>(0.1)*ROL_OVERFLOW<Real>();
131 Real fnew = obj.
value(*xcp,ftol);
134 Real a = fnew - fx - gs - half*alpha*alpha*gBg;
135 if ( std::abs(a) < eps ) {
137 del = std::min(alpha*gnorm,delMax);
140 Real b = half*alpha*alpha*gBg;
142 if ( b*b-three*a*c > eps ) {
144 Real t1 = (-b-std::sqrt(b*b-three*a*c))/(three*a);
145 Real t2 = (-b+std::sqrt(b*b-three*a*c))/(three*a);
146 if ( six*a*t1 + two*b >
zero ) {
148 del = std::min(t1*alpha*gnorm,delMax);
152 del = std::min(t2*alpha*gnorm,delMax);
156 del = std::min(alpha*gnorm,delMax);
159 if (del <= eps*gnorm) {
164 outStream <<
" In TrustRegionUtilities::initialRadius" << std::endl;
165 outStream <<
" Initial radius: " << del << std::endl;
170template<
typename Real>
177 std::ostream &outStream = std::cout,
178 const bool print =
false) {
179 const Real
zero(0), one(1);
180 Real eps = epsi*std::max(one,fold);
181 Real aRed = fold - ftrial;
182 Real aRed_safe = aRed + eps, pRed_safe = pRed + eps;
183 if (((std::abs(aRed_safe) < epsi) && (std::abs(pRed_safe) < epsi)) || aRed == pRed) {
187 else if ( std::isnan(aRed_safe) || std::isnan(pRed_safe) ) {
192 rho = aRed_safe/pRed_safe;
193 if (pRed_safe < zero && aRed_safe >
zero) {
196 else if (aRed_safe <= zero && pRed_safe >
zero) {
199 else if (aRed_safe <=
zero && pRed_safe <
zero) {
207 outStream <<
" In TrustRegionUtilities::analyzeRatio" << std::endl;
208 outStream <<
" Current objective function value: " << fold << std::endl;
209 outStream <<
" New objective function value: " << ftrial << std::endl;
210 outStream <<
" Actual reduction: " << aRed << std::endl;
211 outStream <<
" Predicted reduction: " << pRed << std::endl;
212 outStream <<
" Safeguard: " << epsi << std::endl;
213 outStream <<
" Actual reduction with safeguard: " << aRed_safe << std::endl;
214 outStream <<
" Predicted reduction with safeguard: " << pRed_safe << std::endl;
215 outStream <<
" Ratio of actual and predicted reduction: " << rho << std::endl;
216 outStream <<
" Trust-region flag: " << flag << std::endl;
217 outStream << std::endl;
221template<
typename Real>
232 std::ostream &outStream = std::cout,
233 const bool print =
false) {
236 Real gs = g.
apply(s);
237 Real modelVal = fold - pRed;
238 Real theta = (one-eta2)*gs/((one-eta2)*(fold+gs)+eta2*modelVal-ftrial);
240 outStream <<
" In TrustRegionUtilities::interpolateRadius" << std::endl;
241 outStream <<
" Interpolation model value: " << modelVal << std::endl;
242 outStream <<
" Interpolation step length: " << theta << std::endl;
243 outStream << std::endl;
245 return std::min(gamma1*std::min(snorm,del),std::max(gamma0,theta)*del);
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Provides the interface to evaluate objective functions.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
Provides the interface to evaluate trust-region model functions.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &s, Real &tol) override
Apply Hessian approximation to vector.
virtual void setData(Objective< Real > &obj, const Vector< Real > &x, const Vector< Real > &g)
Defines the linear algebra or vector space interface.
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
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.
virtual Real dot(const Vector &x) const =0
Compute where .
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)
std::string ETRFlagToString(ETRFlag trf)
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)
Real initialRadius(int &nfval, const Vector< Real > &x, const Vector< Real > &g, Vector< Real > &Bg, const Real fx, const Real gnorm, Objective< Real > &obj, TrustRegionModel_U< Real > &model, const Real delMax, std::ostream &outStream, const bool print=false)