ROL
step/trustregion/ROL_ConicApproximationModel.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_CONICAPPROXIMATIONMODEL_H
11#define ROL_CONICAPPROXIMATIONMODEL_H
12
13#include "ROL_Objective.hpp"
15
29namespace ROL {
30
31template <class Real>
32class ConicApproximationModel : public Objective<Real> {
33
34 using V = Vector<Real>;
36
37private:
38 Ptr<Obj> obj_;
39 const Ptr<const V> x_, a_;
40 Ptr<V> g_, s_, Hs_;
41 Real f_, gamma_, sHs_;
42
44
45public:
46
48
49 ConicApproximationModel( const Ptr<Obj>& obj, const Ptr<const V>& x,
50 const Ptr<V>& s, const Ptr<const V>& a ) :
51 obj_( obj ), x_( x ), a_( a ), g_( x_->dual().clone() ), s_( s ),
52 Hs_( x->dual().clone() ) {
53 Real tol = sqrt(ROL_EPSILON<Real>());
54 gamma_ = 1.0-a_->dot(*s_);
55 f_ = obj_->value( *x_, tol );
56 obj_->gradient( *g_,*x,tol );
57 obj_->hessVec( *Hs_, *s_, *x_, tol );
58 }
59
60 virtual void update( const V& s, bool flag=true, int iter=-1 ) override {
61 Real tol = sqrt(ROL_EPSILON<Real>());
62 s_->set(s);
63 gamma_ = 1.0-a_->dot(*s_);
64 obj_->hessVec( *Hs_, *s_, *x_, tol );
65 }
66
67 virtual Real value( const V& s, Real& tol ) override {
68 return f_ + ( g_->dot(*s_) + 0.5*sHs_/gamma_ )/gamma_;
69 }
70
71 virtual void gradient( V &g, const V &s, Real &tol ) override {
72
73 g.set( *g_ ); // g0
74 g.scale( gamma_ ); // gamma*g0
75 g.plus( *Hs_ ); // gamma*g0 + Hs
76
77 auto u = workspace_.copy(*a_);
78 u->scale( s_->dot(g) );
79 g.scale( gamma_ );
80 g.plus( *u );
81 g.scale( std::pow(gamma_,-3) );
82
83 }
84
85 virtual void hessVec( V &hv, const V &v, const V &s, Real &tol ) override {
86
87 auto u = workspace_.copy(v);
88
89 u->scale( gamma_ ); // gamma*v
90 u->axpy( a_->dot(v), s ); // gamma*v + (a,v)*s
91 obj_->hessVec( hv, *u, *x_, tol ); // gamma*Hv + (a,v)*Hs
92 hv.set(*u);
93 hv.scale( gamma_ );
94 hv.axpy(u->dot(s),*a_);
95 hv.scale(std::pow( gamma_ ,-4));
96 }
97
98 virtual void invHessVec( V& hv, const V& v, const V& s, Real& tol ) override {
99
100 auto u = workspace_.copy(v);
101
102 u->axpy( -a_->dot(v), s ); // v - (a,v)*s
103 obj_->invHessVec( hv, *u, *x_, tol ); // Hv - (a,v)*Hs
104 hv.set(*u);
105 hv.axpy(-u->dot(*s_),*a_);
106 hv.scale(std::pow(gamma_,2));
107 }
108
109 virtual void precond( V& Pv, const V& v, const V& s, Real &tol ) override {
110
111 auto u = workspace_.copy(v);
112
113 u->axpy( -a_->dot(v), *s_ ); // v - (a,v)*s
114 obj_->precond( Pv, *u, *x_, tol ); // Hv - (a,v)*Hs
115 Pv.set(*u);
116 Pv.axpy(-u->dot(s),*a_);
117 Pv.scale(std::pow(gamma_,2));
118}
119
120
121
122}; // class ConicApproximationModel
123
124} // namespace ROL
125
126
127#endif
Provides the interface to evaluate conic approximation function.
ConicApproximationModel(const Ptr< Obj > &obj, const Ptr< const V > &x, const Ptr< V > &s, const Ptr< const V > &a)
virtual void invHessVec(V &hv, const V &v, const V &s, Real &tol) override
Apply inverse Hessian approximation to vector.
virtual void precond(V &Pv, const V &v, const V &s, Real &tol) override
Apply preconditioner to vector.
virtual Real value(const V &s, Real &tol) override
Compute value.
virtual void hessVec(V &hv, const V &v, const V &s, Real &tol) override
Apply Hessian approximation to vector.
virtual void update(const V &s, bool flag=true, int iter=-1) override
Update objective function.
virtual void gradient(V &g, const V &s, Real &tol) override
Compute gradient.
Provides the interface to evaluate objective functions.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
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 .