ROL
ROL_QuasiNewton_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_QUASINEWTON_U_H
11 #define ROL_QUASINEWTON_U_H
12 
14 
15 #include "ROL_Types.hpp"
16 #include "ROL_SecantFactory.hpp"
17 
24 namespace ROL {
25 
26 template<typename Real>
27 class QuasiNewton_U : public DescentDirection_U<Real> {
28 private:
29 
30  Ptr<Secant<Real>> secant_;
32  std::string secantName_;
33 
34 public:
35 
45  QuasiNewton_U( ParameterList &parlist,
46  const Ptr<Secant<Real>> &secant = nullPtr)
47  : secant_(secant), esec_(SECANT_USERDEFINED) {
48  // Initialize secant object
49  if ( secant == nullPtr ) {
50  secantName_ = parlist.sublist("General").sublist("Secant").get("Type","Limited-Memory BFGS");
52  secant_ = SecantFactory<Real>(parlist);
53  }
54  else {
55  secantName_ = parlist.sublist("General").sublist("Secant").get("User Defined Secant Name",
56  "Unspecified User Defined Secant Method");
57  }
58  }
59 
60  void compute( Vector<Real> &s, Real &snorm, Real &sdotg, int &iter, int &flag,
61  const Vector<Real> &x, const Vector<Real> &g, Objective<Real> &obj) override {
62  secant_->applyH(s,g);
63  //sdotg = -s.dot(g.dual());
64  sdotg = -s.apply(g);
65  if (sdotg >= static_cast<Real>(0)) {
66  s.set(g.dual());
67  //sdotg = -s.dot(g.dual());
68  sdotg = -s.apply(g);
69  }
70  s.scale(static_cast<Real>(-1));
71  snorm = s.norm();
72  iter = 0;
73  flag = 0;
74  }
75 
76  void update(const Vector<Real> &x, const Vector<Real> &s,
77  const Vector<Real> &gold, const Vector<Real> &gnew,
78  const Real snorm, const int iter) override {
79  // Update Secant Information
80  secant_->updateStorage(x,gnew,gold,s,snorm,iter+1);
81  }
82 
83  std::string printName(void) const override {
84  std::stringstream name;
85  name << "Quasi-Newton Method with " << secantName_;
86  return name.str();
87  }
88 }; // class ROL::QuasiNewton_U
89 
90 } // namespace ROL
91 
92 #endif
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...
Definition: ROL_Vector.hpp:192
virtual void scale(const Real alpha)=0
Compute where .
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
Definition: ROL_Vector.hpp:204
std::string secantName_
Secant name.
Contains definitions of custom data types in ROL.
ESecant esec_
Secant type.
ESecant StringToESecant(std::string s)
Definition: ROL_Types.hpp:513
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton)
void compute(Vector< Real > &s, Real &snorm, Real &sdotg, int &iter, int &flag, const Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj) override
ESecant
Enumeration of secant update algorithms.
Definition: ROL_Types.hpp:456
std::string printName(void) const override
QuasiNewton_U(ParameterList &parlist, const Ptr< Secant< Real >> &secant=nullPtr)
Constructor.
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:45
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
virtual Real norm() const =0
Returns where .
Provides the interface to compute unconstrained optimization steps for line search.
void update(const Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &gold, const Vector< Real > &gnew, const Real snorm, const int iter) override
Provides the interface to compute optimization steps with a secant method.