ROL
ROL_BackTracking_U.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_BACKTRACKING_U_H
11 #define ROL_BACKTRACKING_U_H
12 
13 #include "ROL_LineSearch_U.hpp"
14 
19 namespace ROL {
20 
21 template<typename Real>
22 class BackTracking_U : public LineSearch_U<Real> {
23 private:
24  Real rho_;
25  Ptr<Vector<Real>> xnew_;
26 
29 
30 public:
31 
32  BackTracking_U(ParameterList &parlist) : LineSearch_U<Real>(parlist) {
33  const Real half(0.5);
34  rho_ = parlist.sublist("Step").sublist("Line Search").sublist("Line-Search Method").get("Backtracking Rate",half);
35  }
36 
37  void initialize(const Vector<Real> &x, const Vector<Real> &g) override {
39  xnew_ = x.clone();
40  }
41 
42  void run( Real &alpha, Real &fval, int &ls_neval, int &ls_ngrad,
43  const Real &gs, const Vector<Real> &s, const Vector<Real> &x,
44  Objective<Real> &obj ) override {
45  Real tol = std::sqrt(ROL_EPSILON<Real>());
46  ls_neval = 0;
47  ls_ngrad = 0;
48  // Get initial line search parameter
49  alpha = getInitialAlpha(ls_neval,ls_ngrad,fval,gs,x,s,obj);
50  // Update iterate
51  xnew_->set(x); xnew_->axpy(alpha,s);
52  // Get objective value at xnew
53  Real fold = fval;
55  fval = obj.value(*xnew_,tol);
56  ls_neval++;
57  // Perform backtracking
58  while ( !status(LINESEARCH_U_BACKTRACKING,ls_neval,ls_ngrad,alpha,fold,gs,fval,*xnew_,s,obj) ) {
59  alpha *= rho_;
60  // Update iterate
61  xnew_->set(x); xnew_->axpy(alpha,s);
62  // Get objective value at xnew
64  fval = obj.value(*xnew_,tol);
65  ls_neval++;
66  }
67  }
68 }; // class ROL::BackTracking_U
69 
70 } // namespace ROL
71 
72 #endif
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.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual bool status(const ELineSearchU type, int &ls_neval, int &ls_ngrad, const Real alpha, const Real fold, const Real sgold, const Real fnew, const Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj)
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Ptr< Vector< Real > > xnew_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
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)
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
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
void initialize(const Vector< Real > &x, const Vector< Real > &g) override
BackTracking_U(ParameterList &parlist)
Implements a simple back tracking line search.