ROL
ROL_ConicApproximationModel.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_CONICAPPROXIMATIONMODEL_H
45 #define ROL_CONICAPPROXIMATIONMODEL_H
46 
47 #include "ROL_Objective.hpp"
48 #include "ROL_VectorWorkspace.hpp"
49 
63 namespace ROL {
64 
65 template <class Real>
66 class ConicApproximationModel : public Objective<Real> {
67 
68  using V = Vector<Real>;
70 
71 private:
72  Ptr<Obj> obj_;
73  const Ptr<const V> x_, a_;
74  Ptr<V> g_, s_, Hs_;
75  Real f_, gamma_, sHs_;
76 
78 
79 public:
80 
82 
83  ConicApproximationModel( const Ptr<Obj>& obj, const Ptr<const V>& x,
84  const Ptr<V>& s, const Ptr<const V>& a ) :
85  obj_( obj ), x_( x ), a_( a ), g_( x_->dual().clone() ), s_( s ),
86  Hs_( x->dual().clone() ) {
87  Real tol = sqrt(ROL_EPSILON<Real>());
88  gamma_ = 1.0-a_->dot(*s_);
89  f_ = obj_->value( *x_, tol );
90  obj_->gradient( *g_,*x,tol );
91  obj_->hessVec( *Hs_, *s_, *x_, tol );
92  }
93 
94  virtual void update( const V& s, bool flag=true, int iter=-1 ) override {
95  Real tol = sqrt(ROL_EPSILON<Real>());
96  s_->set(s);
97  gamma_ = 1.0-a_->dot(*s_);
98  obj_->hessVec( *Hs_, *s_, *x_, tol );
99  }
100 
101  virtual Real value( const V& s, Real& tol ) override {
102  return f_ + ( g_->dot(*s_) + 0.5*sHs_/gamma_ )/gamma_;
103  }
104 
105  virtual void gradient( V &g, const V &s, Real &tol ) override {
106 
107  g.set( *g_ ); // g0
108  g.scale( gamma_ ); // gamma*g0
109  g.plus( *Hs_ ); // gamma*g0 + Hs
110 
111  auto u = workspace_.copy(*a_);
112  u->scale( s_->dot(g) );
113  g.scale( gamma_ );
114  g.plus( *u );
115  g.scale( std::pow(gamma_,-3) );
116 
117  }
118 
119  virtual void hessVec( V &hv, const V &v, const V &s, Real &tol ) override {
120 
121  auto u = workspace_.copy(v);
122 
123  u->scale( gamma_ ); // gamma*v
124  u->axpy( a_->dot(v), s ); // gamma*v + (a,v)*s
125  obj_->hessVec( hv, *u, *x_, tol ); // gamma*Hv + (a,v)*Hs
126  hv.set(*u);
127  hv.scale( gamma_ );
128  hv.axpy(u->dot(s),*a_);
129  hv.scale(std::pow( gamma_ ,-4));
130  }
131 
132  virtual void invHessVec( V& hv, const V& v, const V& s, Real& tol ) override {
133 
134  auto u = workspace_.copy(v);
135 
136  u->axpy( -a_->dot(v), s ); // v - (a,v)*s
137  obj_->invHessVec( hv, *u, *x_, tol ); // Hv - (a,v)*Hs
138  hv.set(*u);
139  hv.axpy(-u->dot(*s_),*a_);
140  hv.scale(std::pow(gamma_,2));
141  }
142 
143  virtual void precond( V& Pv, const V& v, const V& s, Real &tol ) override {
144 
145  auto u = workspace_.copy(v);
146 
147  u->axpy( -a_->dot(v), *s_ ); // v - (a,v)*s
148  obj_->precond( Pv, *u, *x_, tol ); // Hv - (a,v)*Hs
149  Pv.set(*u);
150  Pv.axpy(-u->dot(s),*a_);
151  Pv.scale(std::pow(gamma_,2));
152 }
153 
154 
155 
156 }; // class ConicApproximationModel
157 
158 } // namespace ROL
159 
160 
161 #endif
Provides the interface to evaluate objective functions.
virtual void precond(V &Pv, const V &v, const V &s, Real &tol) override
Apply preconditioner to vector.
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153
virtual void hessVec(V &hv, const V &v, const V &s, Real &tol) override
Apply Hessian approximation to vector.
ConicApproximationModel(const Ptr< Obj > &obj, const Ptr< const V > &x, const Ptr< V > &s, const Ptr< const V > &a)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
virtual Real value(const V &s, Real &tol) override
Compute value.
virtual void update(const V &s, bool flag=true, int iter=-1) override
Update objective function.
virtual void invHessVec(V &hv, const V &v, const V &s, Real &tol) override
Apply inverse Hessian approximation to vector.
virtual void gradient(V &g, const V &s, Real &tol) override
Compute gradient.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:209