ROL
ROL_TypeB_NewtonKrylovAlgorithm.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #ifndef ROL_TYPEB_NEWTONKRYLOVALGORITHM_HPP
45 #define ROL_TYPEB_NEWTONKRYLOVALGORITHM_HPP
46 
47 #include "ROL_TypeB_Algorithm.hpp"
48 #include "ROL_KrylovFactory.hpp"
49 #include "ROL_SecantFactory.hpp"
50 
55 namespace ROL {
56 namespace TypeB {
57 
58 template<typename Real>
60 private:
61  Ptr<Secant<Real>> secant_;
63  std::string secantName_;
64 
65  Ptr<Krylov<Real>> krylov_;
67  std::string krylovName_;
68 
71 
74 
75  int maxit_;
76  Real alpha0_;
77  Real rhodec_;
78  Real c1_;
79  bool useralpha_;
81 
82  int ls_nfval_;
85 
86  class HessianPNK : public LinearOperator<Real> {
87  private:
88  const Ptr<Objective<Real>> obj_;
89  const Ptr<BoundConstraint<Real>> bnd_;
90  const Ptr<const Vector<Real>> x_;
91  const Ptr<const Vector<Real>> g_;
92  const Real eps_;
93  const Ptr<Secant<Real>> secant_;
94  const bool useSecant_;
95  const Ptr<Vector<Real>> v_;
96  public:
97  HessianPNK(const Ptr<Objective<Real>> &obj,
98  const Ptr<BoundConstraint<Real>> &bnd,
99  const Ptr<const Vector<Real>> &x,
100  const Ptr<const Vector<Real>> &g,
101  Real eps,
102  const Ptr<Secant<Real>> &secant,
103  bool useSecant,
104  const Ptr<Vector<Real>> &pwa)
105  : obj_(obj), bnd_(bnd), x_(x), g_(g), eps_(eps),
106  secant_(secant), useSecant_(useSecant), v_(pwa) {}
107  void apply(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
108  v_->set(v);
109  bnd_->pruneActive(*v_,g_->dual(),*x_,eps_);
110  if (!useSecant_) obj_->hessVec(Hv,*v_,*x_,tol);
111  else secant_->applyB(Hv,*v_);
112  v_->set(Hv.dual());
113  bnd_->pruneActive(*v_,g_->dual(),*x_,eps_);
114  Hv.set(v_->dual());
115  v_->set(v);
116  bnd_->pruneInactive(*v_,g_->dual(),*x_,eps_);
117  Hv.plus(v_->dual());
118  }
119  };
120 
121  class PrecondPNK : public LinearOperator<Real> {
122  private:
123  const Ptr<Objective<Real>> obj_;
124  const Ptr<BoundConstraint<Real>> bnd_;
125  const Ptr<const Vector<Real>> x_;
126  const Ptr<const Vector<Real>> g_;
127  const Real eps_;
128  const Ptr<Secant<Real>> secant_;
129  const bool useSecant_;
130  const Ptr<Vector<Real>> v_;
131  public:
132  PrecondPNK(const Ptr<Objective<Real>> &obj,
133  const Ptr<BoundConstraint<Real>> &bnd,
134  const Ptr<const Vector<Real>> &x,
135  const Ptr<const Vector<Real>> &g,
136  Real eps,
137  const Ptr<Secant<Real>> &secant,
138  bool useSecant,
139  const Ptr<Vector<Real>> &pwa)
140  : obj_(obj), bnd_(bnd), x_(x), g_(g), eps_(eps),
141  secant_(secant), useSecant_(useSecant), v_(pwa) {}
142  void apply(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
143  Hv.set(v.dual());
144  }
145  void applyInverse(Vector<Real> &Hv, const Vector<Real> &v, Real &tol) const {
146  v_->set(v.dual());
147  bnd_->pruneActive(*v_,g_->dual(),*x_,eps_);
148  if ( useSecant_ ) secant_->applyH(Hv,v_->dual());
149  else obj_->precond(Hv,v_->dual(),*x_,tol);
150  bnd_->pruneActive(Hv,g_->dual(),*x_,eps_);
151  v_->set(v.dual());
152  bnd_->pruneInactive(*v_,g_->dual(),*x_,eps_);
153  Hv.plus(*v_);
154  }
155  };
156 
160 
161  void initialize(Vector<Real> &x,
162  const Vector<Real> &g,
163  Objective<Real> &obj,
165  std::ostream &outStream = std::cout);
166 
167  void parseParameterList(ParameterList &list);
168 
169 public:
170 
171  NewtonKrylovAlgorithm(ParameterList &list, const Ptr<Secant<Real>> &secant = nullPtr);
172  NewtonKrylovAlgorithm(ParameterList &list, const Ptr<Krylov<Real>> &krylov,
173  const Ptr<Secant<Real>> &secant = nullPtr);
174 
176  void run( Vector<Real> &x,
177  const Vector<Real> &g,
178  Objective<Real> &obj,
180  std::ostream &outStream = std::cout) override;
181 
182  void run( Problem<Real> &problem,
183  std::ostream &outStream = std::cout ) override;
184 
185  void run( Vector<Real> &x,
186  const Vector<Real> &g,
187  Objective<Real> &obj,
189  Constraint<Real> &linear_econ,
190  Vector<Real> &linear_emul,
191  const Vector<Real> &linear_eres,
192  std::ostream &outStream = std::cout ) override;
193 
194  void writeHeader( std::ostream& os ) const override;
195 
196  void writeName( std::ostream& os ) const override;
197 
198  void writeOutput( std::ostream& os, const bool write_header = false ) const override;
199 
200 }; // class ROL::TypeB::NewtonKrylovAlgorithm
201 
202 } // namespace TypeB
203 } // namespace ROL
204 
206 
207 #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:226
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:80
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:486
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:79
Provides definitions for Krylov solvers.
Definition: ROL_Krylov.hpp:58
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:209
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.