10 #ifndef ROL_SCALARMINIMIZATIONLINESEARCH_U_H
11 #define ROL_SCALARMINIMIZATIONLINESEARCH_U_H
19 #include "ROL_BrentsScalarMinimization.hpp"
20 #include "ROL_BisectionScalarMinimization.hpp"
21 #include "ROL_GoldenSectionScalarMinimization.hpp"
22 #include "ROL_ScalarFunction.hpp"
23 #include "ROL_Bracketing.hpp"
27 template<
typename Real>
32 Ptr<ScalarMinimization<Real>>
sm_;
33 Ptr<Bracketing<Real>>
br_;
34 Ptr<ScalarFunction<Real>>
sf_;
44 class Phi :
public ScalarFunction<Real> {
47 const Ptr<const Vector<Real>>
x_,
s_;
48 const Ptr<Objective<Real>>
obj_;
56 const bool FDdirDeriv =
false)
71 Real tol = std::sqrt(ROL_EPSILON<Real>());
75 Real snorm =
s_->norm();
76 if (snorm > static_cast<Real>(0)) {
77 Real xnorm =
xnew_->norm();
78 Real cbrteps = std::cbrt(ROL_EPSILON<Real>());
79 Real h = cbrteps*std::max(xnorm/snorm,static_cast<Real>(1));
80 Real fnew =
value(alpha);
84 val = (ftrial - fnew) / h;
94 class StatusTest :
public ScalarMinimizationStatusTest<Real> {
96 Ptr<ScalarFunction<Real>>
phi_;
109 const Real c1,
const Real c2,
const Real c3,
111 const Ptr<ScalarFunction<Real>> &phi)
115 bool check(Real &x, Real &fx, Real &gx,
116 int &nfval,
int &ngval,
const bool deriv =
false) {
120 bool curvcond =
false;
124 curvcond = (fx >=
f0_ + (one-
c1_)*x*
g0_);
131 gx =
phi_->deriv(x); ngval++;
134 curvcond = (gx >=
c2_*
g0_);
137 curvcond = (std::abs(gx) <=
c2_*std::abs(
g0_));
143 curvcond = (
c2_*
g0_ <= gx && gx <= (two*
c1_ - one)*g0_);
148 return (armijo && curvcond);
158 const Ptr<ScalarMinimization<Real>> &sm = nullPtr,
159 const Ptr<Bracketing<Real>> &br = nullPtr,
160 const Ptr<ScalarFunction<Real>> &sf = nullPtr )
162 const Real
zero(0), p4(0.4), p6(0.6), p9(0.9), oem4(1.e-4), oem10(1.e-10), one(1);
163 ParameterList &list0 = parlist.sublist(
"Step").sublist(
"Line Search");
164 FDdirDeriv_ = list0.get(
"Finite Difference Directional Derivative",
false);
165 ParameterList &list = list0.sublist(
"Line-Search Method");
167 if( br == nullPtr ) {
168 br_ = makePtr<Bracketing<Real>>();
174 std::string type = list.get(
"Type",
"Brent's");
175 Real tol = list.sublist(type).get(
"Tolerance",oem10);
176 int niter = list.sublist(type).get(
"Iteration Limit",1000);
177 ROL::ParameterList plist;
178 plist.sublist(
"Scalar Minimization").set(
"Type",type);
179 plist.sublist(
"Scalar Minimization").sublist(type).set(
"Tolerance",tol);
180 plist.sublist(
"Scalar Minimization").sublist(type).set(
"Iteration Limit",niter);
182 if( sm == nullPtr ) {
183 if ( type ==
"Brent's" ) {
184 sm_ = makePtr<BrentsScalarMinimization<Real>>(plist);
186 else if ( type ==
"Bisection" ) {
187 sm_ = makePtr<BisectionScalarMinimization<Real>>(plist);
189 else if ( type ==
"Golden Section" ) {
190 sm_ = makePtr<GoldenSectionScalarMinimization<Real>>(plist);
193 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
194 ">>> (ROL::ScalarMinimizationLineSearch): Undefined ScalarMinimization type!");
203 std::string condName = list0.sublist(
"Curvature Condition").get(
"Type",
"Strong Wolfe Conditions");
205 max_nfval_ = list0.get(
"Function Evaluation Limit",20);
206 c1_ = list0.get(
"Sufficient Decrease Tolerance",oem4);
207 c2_ = list0.sublist(
"Curvature Condition").get(
"General Parameter",p9);
208 c3_ = list0.sublist(
"Curvature Condition").get(
"Generalized Wolfe Parameter",p6);
217 std::string descentName = list0.sublist(
"Descent Method").get(
"Type",
"Quasi-Newton Method");
221 c3_ = std::min(one-c2_,c3_);
232 void run( Real &alpha, Real &fval,
int &ls_neval,
int &ls_ngrad,
235 ls_neval = 0; ls_ngrad = 0;
241 Ptr<const Vector<Real>> x_ptr = ROL::makePtrFromRef(x);
242 Ptr<const Vector<Real>> s_ptr = ROL::makePtrFromRef(s);
243 Ptr<Objective<Real>> obj_ptr = ROL::makePtrFromRef(obj);
245 Ptr<ScalarFunction<Real>> phi;
246 if(
sf_ == ROL::nullPtr ) {
253 Ptr<ScalarMinimizationStatusTest<Real>> test
257 int nfval = 0, ngrad = 0;
258 Real A(0), fA = fval;
259 Real B = alpha, fB = phi->value(B);
260 br_->run(alpha,fval,A,fA,B,fB,nfval,ngrad,*phi,*test);
262 ls_neval += nfval; ls_ngrad += ngrad;
265 nfval = 0, ngrad = 0;
266 sm_->run(fval, alpha, nfval, ngrad, *phi, A, B, *test);
267 ls_neval += nfval; ls_ngrad += ngrad;
Provides interface for and implements line searches.
virtual void initialize(const Vector< Real > &x, const Vector< Real > &g)
Provides the interface to evaluate objective functions.
void setNextInitialAlpha(Real alpha)
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
EDescentU
Enumeration of descent direction types.
const Ptr< Vector< Real > > xnew_
Implements line search methods that attempt to minimize the scalar function .
Phi(const Ptr< Vector< Real >> &xnew, const Ptr< const Vector< Real >> &x, const Ptr< const Vector< Real >> &s, const Ptr< Objective< Real >> &obj, const bool FDdirDeriv=false)
ECurvatureConditionU
Enumeration of line-search curvature conditions.
Defines the linear algebra or vector space interface.
ScalarMinimizationLineSearch_U(ParameterList &parlist, const Ptr< ScalarMinimization< Real >> &sm=nullPtr, const Ptr< Bracketing< Real >> &br=nullPtr, const Ptr< ScalarFunction< Real >> &sf=nullPtr)
virtual Real getInitialAlpha(int &ls_neval, int &ls_ngrad, const Real fval, const Real gs, const Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj)
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
EDescentU StringToEDescentU(std::string s)
Ptr< ScalarFunction< Real > > phi_
StatusTest(const Real f0, const Real g0, const Real c1, const Real c2, const Real c3, const int max_nfval, ECurvatureConditionU econd, const Ptr< ScalarFunction< Real >> &phi)
const Ptr< const Vector< Real > > s_
Ptr< ScalarFunction< Real > > sf_
ECurvatureConditionU econd_
Ptr< Bracketing< Real > > br_
Ptr< Vector< Real > > xnew_
void initialize(const Vector< Real > &x, const Vector< Real > &g) override
Ptr< ScalarMinimization< Real > > sm_
const Ptr< Objective< Real > > obj_
void run(Real &alpha, Real &fval, int &ls_neval, int &ls_ngrad, const Real &gs, const Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj) override
Real value(const Real alpha)
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
bool check(Real &x, Real &fx, Real &gx, int &nfval, int &ngval, const bool deriv=false)
Real deriv(const Real alpha)
ECurvatureConditionU StringToECurvatureConditionU(std::string s)
const Ptr< const Vector< Real > > x_
const ECurvatureConditionU econd_