ROL
ROL_TypeB_NewtonKrylovAlgorithm.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_TYPEB_NEWTONKRYLOVALGORITHM_HPP
11 #define ROL_TYPEB_NEWTONKRYLOVALGORITHM_HPP
12 
13 #include "ROL_TypeB_Algorithm.hpp"
14 #include "ROL_KrylovFactory.hpp"
15 #include "ROL_SecantFactory.hpp"
16 
21 namespace ROL {
22 namespace TypeB {
23 
24 template<typename Real>
26 private:
27  Ptr<Secant<Real>> secant_;
29  std::string secantName_;
30 
31  Ptr<Krylov<Real>> krylov_;
33  std::string krylovName_;
34 
37 
40 
41  int maxit_;
42  Real alpha0_;
43  Real rhodec_;
44  Real c1_;
45  bool useralpha_;
47 
48  int ls_nfval_;
51 
52  class HessianPNK : public LinearOperator<Real> {
53  private:
54  const Ptr<Objective<Real>> obj_;
55  const Ptr<BoundConstraint<Real>> bnd_;
56  const Ptr<const Vector<Real>> x_;
57  const Ptr<const Vector<Real>> g_;
58  const Real eps_;
59  const Ptr<Secant<Real>> secant_;
60  const bool useSecant_;
61  const Ptr<Vector<Real>> v_;
62  public:
63  HessianPNK(const Ptr<Objective<Real>> &obj,
64  const Ptr<BoundConstraint<Real>> &bnd,
65  const Ptr<const Vector<Real>> &x,
66  const Ptr<const Vector<Real>> &g,
67  Real eps,
68  const Ptr<Secant<Real>> &secant,
69  bool useSecant,
70  const Ptr<Vector<Real>> &pwa)
71  : obj_(obj), bnd_(bnd), x_(x), g_(g), eps_(eps),
72  secant_(secant), useSecant_(useSecant), v_(pwa) {}
73  void apply(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
74  v_->set(v);
75  bnd_->pruneActive(*v_,g_->dual(),*x_,eps_);
76  if (!useSecant_) obj_->hessVec(Hv,*v_,*x_,tol);
77  else secant_->applyB(Hv,*v_);
78  v_->set(Hv.dual());
79  bnd_->pruneActive(*v_,g_->dual(),*x_,eps_);
80  Hv.set(v_->dual());
81  v_->set(v);
82  bnd_->pruneInactive(*v_,g_->dual(),*x_,eps_);
83  Hv.plus(v_->dual());
84  }
85  };
86 
87  class PrecondPNK : public LinearOperator<Real> {
88  private:
89  const Ptr<Objective<Real>> obj_;
90  const Ptr<BoundConstraint<Real>> bnd_;
91  const Ptr<const Vector<Real>> x_;
92  const Ptr<const Vector<Real>> g_;
93  const Real eps_;
94  const Ptr<Secant<Real>> secant_;
95  const bool useSecant_;
96  const Ptr<Vector<Real>> v_;
97  public:
98  PrecondPNK(const Ptr<Objective<Real>> &obj,
99  const Ptr<BoundConstraint<Real>> &bnd,
100  const Ptr<const Vector<Real>> &x,
101  const Ptr<const Vector<Real>> &g,
102  Real eps,
103  const Ptr<Secant<Real>> &secant,
104  bool useSecant,
105  const Ptr<Vector<Real>> &pwa)
106  : obj_(obj), bnd_(bnd), x_(x), g_(g), eps_(eps),
107  secant_(secant), useSecant_(useSecant), v_(pwa) {}
108  void apply(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
109  Hv.set(v.dual());
110  }
111  void applyInverse(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
112  v_->set(v.dual());
113  bnd_->pruneActive(*v_,g_->dual(),*x_,eps_);
114  if ( useSecant_ ) secant_->applyH(Hv,v_->dual());
115  else obj_->precond(Hv,v_->dual(),*x_,tol);
116  bnd_->pruneActive(Hv,g_->dual(),*x_,eps_);
117  v_->set(v.dual());
118  bnd_->pruneInactive(*v_,g_->dual(),*x_,eps_);
119  Hv.plus(*v_);
120  }
121  };
122 
126 
127  void initialize(Vector<Real> &x,
128  const Vector<Real> &g,
129  Objective<Real> &obj,
131  std::ostream &outStream = std::cout);
132 
133  void parseParameterList(ParameterList &list);
134 
135 public:
136 
137  NewtonKrylovAlgorithm(ParameterList &list, const Ptr<Secant<Real>> &secant = nullPtr);
138  NewtonKrylovAlgorithm(ParameterList &list, const Ptr<Krylov<Real>> &krylov,
139  const Ptr<Secant<Real>> &secant = nullPtr);
140 
142  void run( Vector<Real> &x,
143  const Vector<Real> &g,
144  Objective<Real> &obj,
146  std::ostream &outStream = std::cout) override;
147 
148  void run( Problem<Real> &problem,
149  std::ostream &outStream = std::cout ) override;
150 
151  void run( Vector<Real> &x,
152  const Vector<Real> &g,
153  Objective<Real> &obj,
155  Constraint<Real> &linear_econ,
156  Vector<Real> &linear_emul,
157  const Vector<Real> &linear_eres,
158  std::ostream &outStream = std::cout ) override;
159 
160  void writeHeader( std::ostream& os ) const override;
161 
162  void writeName( std::ostream& os ) const override;
163 
164  void writeOutput( std::ostream& os, const bool write_header = false ) const override;
165 
166 }; // class ROL::TypeB::NewtonKrylovAlgorithm
167 
168 } // namespace TypeB
169 } // namespace ROL
170 
172 
173 #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
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
void writeHeader(std::ostream &os) const override
Print iterate header.
virtual void plus(const Vector &x)=0
Compute , where .
NewtonKrylovAlgorithm(ParameterList &list, const Ptr< Secant< Real >> &secant=nullPtr)
int maxit_
Maximum number of line search steps (default: 20)
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout)
Real rhodec_
Backtracking rate (default: 0.5)
int iterKrylov_
Number of Krylov iterations (used for inexact Newton)
int flagKrylov_
Termination flag for Krylov method (used for inexact Newton)
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout) override
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
EKrylov
Enumeration of Krylov methods.
Provides an interface to run the projected secant algorithm.
Real alpha0_
Initial line search step size (default: 1.0)
bool useSecantHessVec_
Whether or not to use to a secant approximation as the Hessian.
Provides an interface to run bound constrained optimization algorithms.
ESecant
Enumeration of secant update algorithms.
Definition: ROL_Types.hpp:456
bool useralpha_
Flag to use user-defined initial step size (default: false)
void writeOutput(std::ostream &os, const bool write_header=false) const override
Print iterate status.
PrecondPNK(const Ptr< Objective< Real >> &obj, const Ptr< BoundConstraint< Real >> &bnd, const Ptr< const Vector< Real >> &x, const Ptr< const Vector< Real >> &g, Real eps, const Ptr< Secant< Real >> &secant, bool useSecant, const Ptr< Vector< Real >> &pwa)
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:45
Provides definitions for Krylov solvers.
Definition: ROL_Krylov.hpp:24
Provides the interface to apply a linear operator.
Real c1_
Sufficient Decrease Parameter (default: 1e-4)
Provides the interface to apply upper and lower bound constraints.
HessianPNK(const Ptr< Objective< Real >> &obj, const Ptr< BoundConstraint< Real >> &bnd, const Ptr< const Vector< Real >> &x, const Ptr< const Vector< Real >> &g, Real eps, const Ptr< Secant< Real >> &secant, bool useSecant, const Ptr< Vector< Real >> &pwa)
Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton)
Ptr< Krylov< Real > > krylov_
Krylov solver object (used for inexact Newton)
bool useSecantPrecond_
Whether or not to use a secant approximation to precondition inexact Newton.
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
bool usePrevAlpha_
Flag to use previous step size as next initial step size (default: false)
void writeName(std::ostream &os) const override
Print step name.
Defines the general constraint operator interface.