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";
99 template<
typename Real>
110 std::ostream &outStream,
111 const bool print =
false) {
112 const Real
zero(0), half(0.5), one(1), two(2), three(3), six(6);
113 const Real eps(ROL_EPSILON<Real>());
114 Real del(ROL_INF<Real>());
116 Ptr<Vector<Real>> xcp = x.
clone();
119 Real gBg = Bg.
dot(g);
120 Real alpha = (gBg > eps ? gnorm*gnorm/gBg : one);
125 Real gs = xcp->apply(g);
128 Real ftol =
static_cast<Real
>(0.1)*ROL_OVERFLOW<Real>();
129 Real fnew = obj.
value(*xcp,ftol);
132 Real a = fnew - fx - gs - half*alpha*alpha*gBg;
133 if ( std::abs(a) < eps ) {
135 del = std::min(alpha*gnorm,delMax);
138 Real b = half*alpha*alpha*gBg;
140 if ( b*b-three*a*c > eps ) {
142 Real t1 = (-b-std::sqrt(b*b-three*a*c))/(three*a);
143 Real t2 = (-b+std::sqrt(b*b-three*a*c))/(three*a);
144 if ( six*a*t1 + two*b >
zero ) {
146 del = std::min(t1*alpha*gnorm,delMax);
150 del = std::min(t2*alpha*gnorm,delMax);
154 del = std::min(alpha*gnorm,delMax);
157 if (del <= eps*gnorm) {
162 outStream <<
" In TrustRegionUtilities::initialRadius" << std::endl;
163 outStream <<
" Initial radius: " << del << std::endl;
168 template<
typename Real>
175 std::ostream &outStream = std::cout,
176 const bool print =
false) {
177 const Real
zero(0), one(1);
178 Real eps = epsi*std::max(one,fold);
179 Real aRed = fold - ftrial;
180 Real aRed_safe = aRed + eps, pRed_safe = pRed + eps;
181 if (((std::abs(aRed_safe) < epsi) && (std::abs(pRed_safe) < epsi)) || aRed == pRed) {
185 else if ( std::isnan(aRed_safe) || std::isnan(pRed_safe) ) {
190 rho = aRed_safe/pRed_safe;
191 if (pRed_safe < zero && aRed_safe >
zero) {
194 else if (aRed_safe <= zero && pRed_safe > zero) {
197 else if (aRed_safe <= zero && pRed_safe < zero) {
205 outStream <<
" In TrustRegionUtilities::analyzeRatio" << std::endl;
206 outStream <<
" Current objective function value: " << fold << std::endl;
207 outStream <<
" New objective function value: " << ftrial << std::endl;
208 outStream <<
" Actual reduction: " << aRed << std::endl;
209 outStream <<
" Predicted reduction: " << pRed << std::endl;
210 outStream <<
" Safeguard: " << epsi << std::endl;
211 outStream <<
" Actual reduction with safeguard: " << aRed_safe << std::endl;
212 outStream <<
" Predicted reduction with safeguard: " << pRed_safe << std::endl;
213 outStream <<
" Ratio of actual and predicted reduction: " << rho << std::endl;
214 outStream <<
" Trust-region flag: " << flag << std::endl;
215 outStream << std::endl;
219 template<
typename Real>
230 std::ostream &outStream = std::cout,
231 const bool print =
false) {
234 Real gs = g.
apply(s);
235 Real modelVal = fold - pRed;
236 Real theta = (one-eta2)*gs/((one-eta2)*(fold+gs)+eta2*modelVal-ftrial);
238 outStream <<
" In TrustRegionUtilities::interpolateRadius" << std::endl;
239 outStream <<
" Interpolation model value: " << modelVal << std::endl;
240 outStream <<
" Interpolation step length: " << theta << std::endl;
241 outStream << std::endl;
243 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)