ROL
ROL_TypeP_InexactNewtonAlgorithm.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_TYPEP_INEXACTNEWTONALGORITHM_HPP
45 #define ROL_TYPEP_INEXACTNEWTONALGORITHM_HPP
46 
47 #include "ROL_TypeP_Algorithm.hpp"
48 
53 namespace ROL {
54 namespace TypeP {
55 
56 template<typename Real>
58 private:
59  int t0_;
60  bool initProx_;
61 
62  int maxit_;
63  Real rhodec_;
64  Real c1_;
65  Real sigma1_;
66  Real sigma2_;
67  Real sp_tol1_;
68  Real sp_tol2_;
69  Real sp_exp_;
71  std::string algoName_;
72 
73  ParameterList list_;
74 
78 
82 
83  class NewtonObj : public Objective<Real> {
84  private:
85  const Ptr<Objective<Real>> obj_;
86  const Ptr<Vector<Real>> x_;
87  const Ptr<Vector<Real>> g_;
88  Ptr<Vector<Real>> pwa_, dwa_, Hx_;
90  int nhess_;
91 
92  public:
93  NewtonObj(const Ptr<Objective<Real>> &obj, const Vector<Real> &x, const Vector<Real> &g)
94  : obj_(obj), x_(x.clone()), g_(g.clone()), pwa_(x.clone()),
95  dwa_(g.clone()), Hx_(g.clone()), isHessApplied_(false), nhess_(0) {}
96  void update(const Vector<Real> &x, UpdateType type, int iter) {
97  isHessApplied_ = false;
98  }
99  Real value(const Vector<Real> &x, Real &tol) {
100  const Real half(0.5), one(1);
101  pwa_->set(x); pwa_->axpy(-one,*x_);
102  if (!isHessApplied_) {
103  obj_->hessVec(*Hx_,*pwa_,*x_,tol); nhess_++;
104  isHessApplied_ = true;
105  }
106  dwa_->set(*Hx_);
107  dwa_->scale(half);
108  dwa_->plus(*g_);
109  return dwa_->apply(*pwa_);
110  }
111  void gradient(Vector<Real> &g, const Vector<Real> &x, Real &tol) {
112  const Real one(1);
113  if (!isHessApplied_) {
114  pwa_->set(x); pwa_->axpy(-one,*x_);
115  obj_->hessVec(*Hx_,*pwa_,*x_,tol); nhess_++;
116  isHessApplied_ = true;
117  }
118  g.set(*Hx_);
119  g.plus(*g_);
120  }
121  void hessVec(Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol) {
122  obj_->hessVec(hv,v,*x_,tol); nhess_++;
123  }
124  int numHessVec(bool reset = true) {
125  int nhess = nhess_;
126  if (reset) nhess_ = 0;
127  return nhess;
128  }
129  void setData(const Vector<Real> &x, const Vector<Real> &g) {
130  x_->set(x);
131  g_->set(g);
132  }
133  };
134 
135  void initialize(Vector<Real> &x,
136  const Vector<Real> &g,
137  Objective<Real> &sobj,
138  Objective<Real> &nobj,
139  Vector<Real> &dg,
140  Vector<Real> &px,
141  std::ostream &outStream = std::cout);
142 
143 public:
144 
145  InexactNewtonAlgorithm(ParameterList &list);
146 
148 
149  void run( Vector<Real> &x,
150  const Vector<Real> &g,
151  Objective<Real> &sobj,
152  Objective<Real> &nobj,
153  std::ostream &outStream = std::cout) override;
154 
155  void writeHeader( std::ostream& os ) const override;
156 
157  void writeName( std::ostream& os ) const override;
158 
159  void writeOutput( std::ostream &os, bool write_header = false ) const override;
160 
161 }; // class ROL::TypeP::InexactNewtonAlgorithm
162 
163 } // namespace TypeP
164 } // namespace ROL
165 
167 
168 #endif
Provides the interface to evaluate objective functions.
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
virtual void plus(const Vector &x)=0
Compute , where .
int maxit_
Maximum number of line search steps (default: 20)
void update(const Vector< Real > &x, UpdateType type, int iter)
Update objective function.
Real sigma1_
Lower safeguard for quadratic line search (default: 0.1)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
NewtonObj(const Ptr< Objective< Real >> &obj, const Vector< Real > &x, const Vector< Real > &g)
void setData(const Vector< Real > &x, const Vector< Real > &g)
Real sigma2_
Upper safeguard for quadratic line search (default: 0.9)
Real c1_
Sufficient Decrease Parameter (default: 1e-4)
Real rhodec_
Backtracking rate (default: 0.5)
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void writeName(std::ostream &os) const override
Print step name.
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, Vector< Real > &dg, Vector< Real > &px, std::ostream &outStream=std::cout)
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:209
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, std::ostream &outStream=std::cout) override
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Provides an interface to run optimization algorithms to minimize composite optimization problems f+ph...
void writeHeader(std::ostream &os) const override
Print iterate header.
Provides an interface to run the inexact proximal Newton algorithm.