ROL
ROL_CubicInterp_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_CUBICINTERP_U_H
11#define ROL_CUBICINTERP_U_H
12
17#include "ROL_LineSearch_U.hpp"
18
19namespace ROL {
20
21template<typename Real>
22class CubicInterp_U : public LineSearch_U<Real> {
23private:
24 Real rho_;
25 Ptr<Vector<Real>> xnew_;
26
28 using LineSearch_U<Real>::status;
29
30public:
31
32 CubicInterp_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 // Initialize
58 Real fvalp(0), alpha1(0), alpha2(0), a(0), b(0), x1(0), x2(0);
59 const Real one(1), two(2), three(3), half(0.5), p1(0.1);
60 bool first_iter = true;
61 // Perform cubic interpolation back tracking
62 while (!status(LINESEARCH_U_CUBICINTERP,ls_neval,ls_ngrad,alpha,fold,gs,fval,x,s,obj)) {
63 if (first_iter) { // Minimize quadratic interpolate
64 alpha1 = -gs*alpha*alpha/(two*(fval-fold-gs*alpha));
65 first_iter = false;
66 }
67 else { // Minimize cubic interpolate
68 x1 = fval-fold-alpha*gs;
69 x2 = fvalp-fval-alpha2*gs;
70 a = (one/(alpha - alpha2))*( x1/(alpha*alpha) - x2/(alpha2*alpha2));
71 b = (one/(alpha - alpha2))*(-x1*alpha2/(alpha*alpha) + x2*alpha/(alpha2*alpha2));
72 if (std::abs(a) < ROL_EPSILON<Real>()) {
73 alpha1 = -gs/(two*b);
74 }
75 else {
76 alpha1 = (-b+sqrt(b*b-three*a*gs))/(three*a);
77 }
78 if ( alpha1 > half*alpha ) {
79 alpha1 = half*alpha;
80 }
81 }
82 alpha2 = alpha;
83 fvalp = fval;
84 // Back track if necessary
85 if (alpha1 <= p1*alpha) {
86 alpha *= p1;
87 }
88 else if (alpha1 >= half*alpha) {
89 alpha *= half;
90 }
91 else {
92 alpha = alpha1;
93 }
94 // Update iterate
95 xnew_->set(x); xnew_->axpy(alpha,s);
96 // Get objective value at xnew
98 fval = obj.value(*xnew_,tol);
99 ls_neval++;
100 }
101 }
102}; // class ROL::CubicInterp_U
103
104} // namespace ROL
105
106#endif
Implements cubic interpolation back tracking line search.
Ptr< Vector< Real > > xnew_
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
CubicInterp_U(ParameterList &parlist)
void initialize(const Vector< Real > &x, const Vector< Real > &g) override
Provides interface for and implements line searches.
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 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 initialize(const Vector< Real > &x, const Vector< Real > &g)
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.
Defines the linear algebra or vector space interface.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.