ROL
ROL_TrustRegionModel.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_TRUSTREGIONMODEL_H
45 #define ROL_TRUSTREGIONMODEL_H
46 
47 #include "ROL_Objective.hpp"
48 #include "ROL_BoundConstraint.hpp"
49 #include "ROL_Secant.hpp"
50 
64 namespace ROL {
65 
66 template <class Real>
67 class TrustRegionModel : public Objective<Real> {
68 private:
69  Teuchos::RCP<Objective<Real> > obj_;
70  Teuchos::RCP<const Vector<Real> > x_, g_;
71  Teuchos::RCP<Vector<Real> > dual_;
72  Teuchos::RCP<Secant<Real> > secant_;
73 
74  const bool useSecantPrecond_;
75  const bool useSecantHessVec_;
76 
77 public:
78 
79  virtual ~TrustRegionModel() {}
80 
81  TrustRegionModel(Objective<Real> &obj, const Vector<Real> &x, const Vector<Real> &g, const bool init = true)
82  : secant_(Teuchos::null), useSecantPrecond_(false), useSecantHessVec_(false) {
83  obj_ = Teuchos::rcpFromRef(obj);
84  x_ = Teuchos::rcpFromRef(x);
85  g_ = Teuchos::rcpFromRef(g);
86  if ( init ) {
87  dual_ = g.clone();
88  }
89  }
90 
92  const Teuchos::RCP<Secant<Real> > &secant,
93  const bool useSecantPrecond, const bool useSecantHessVec)
94  : secant_(secant), useSecantPrecond_(useSecantPrecond), useSecantHessVec_(useSecantHessVec) {
95  obj_ = Teuchos::rcpFromRef(obj);
96  x_ = Teuchos::rcpFromRef(x);
97  g_ = Teuchos::rcpFromRef(g);
98  dual_ = g.clone();
99  }
100 
101  virtual Real value( const Vector<Real> &s, Real &tol ) {
102  if ( useSecantHessVec_ ) {
103  secant_->applyB(*dual_,s);
104  }
105  else {
106  obj_->hessVec(*dual_,s,*x_,tol);
107  }
108  dual_->scale(static_cast<Real>(0.5));
109  dual_->plus(*g_);
110  return dual_->dot(s.dual());
111  }
112 
113  virtual void gradient( Vector<Real> &g, const Vector<Real> &s, Real &tol ) {
114  if ( useSecantHessVec_ ) {
115  secant_->applyB(g,s);
116  }
117  else {
118  obj_->hessVec(g,s,*x_,tol);
119  }
120  g.plus(*g_);
121  }
122 
123  virtual void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &s, Real &tol ) {
124  if ( useSecantHessVec_ ) {
125  secant_->applyB(hv,v);
126  }
127  else {
128  obj_->hessVec(hv,v,*x_,tol);
129  }
130  }
131 
132  virtual void invHessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &s, Real &tol ) {
133  if ( useSecantHessVec_ ) {
134  secant_->applyH(hv,v);
135  }
136  else {
137  obj_->invHessVec(hv,v,*x_,tol);
138  }
139  }
140 
141  virtual void precond( Vector<Real> &Pv, const Vector<Real> &v, const Vector<Real> &s, Real &tol ) {
142  if ( useSecantPrecond_ ) {
143  secant_->applyH(Pv,v);
144  }
145  else {
146  obj_->precond(Pv,v,*x_,tol);
147  }
148  }
149 
150  virtual void dualTransform( Vector<Real> &tv, const Vector<Real> &v ) {
151  tv.set(v);
152  }
153 
154  virtual void primalTransform( Vector<Real> &tv, const Vector<Real> &v ) {
155  tv.set(v);
156  }
157 
158  virtual void updatePredictedReduction(Real &pred, const Vector<Real> &s) {}
159 
160  virtual void updateActualReduction(Real &ared, const Vector<Real> &s) {}
161 
162  virtual const Teuchos::RCP<const Vector<Real> > getGradient(void) const {
163  return g_;
164  }
165 
166  virtual const Teuchos::RCP<const Vector<Real> > getIterate(void) const {
167  return x_;
168  }
169 
170  virtual const Teuchos::RCP<Objective<Real> > getObjective(void) const {
171  return obj_;
172  }
173 
174  virtual const Teuchos::RCP<BoundConstraint<Real> > getBoundConstraint(void) const {
175  return Teuchos::null;
176  }
177 
178  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {}
179 
180 }; // class TrustRegionModel
181 
182 } // namespace ROL
183 
184 
185 #endif
Provides the interface to evaluate objective functions.
virtual void plus(const Vector &x)=0
Compute , where .
TrustRegionModel(Objective< Real > &obj, const Vector< Real > &x, const Vector< Real > &g, const Teuchos::RCP< Secant< Real > > &secant, const bool useSecantPrecond, const bool useSecantHessVec)
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual const Teuchos::RCP< BoundConstraint< Real > > getBoundConstraint(void) const
Provides the interface to evaluate trust-region model functions.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
virtual void updatePredictedReduction(Real &pred, const Vector< Real > &s)
virtual void dualTransform(Vector< Real > &tv, const Vector< Real > &v)
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
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:213
virtual Real value(const Vector< Real > &s, Real &tol)
Compute value.
virtual const Teuchos::RCP< const Vector< Real > > getGradient(void) const
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:70
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &s, Real &tol)
Apply Hessian approximation to vector.
virtual void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &s, Real &tol)
Apply inverse Hessian approximation to vector.
virtual void gradient(Vector< Real > &g, const Vector< Real > &s, Real &tol)
Compute gradient.
Teuchos::RCP< Objective< Real > > obj_
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
virtual void updateActualReduction(Real &ared, const Vector< Real > &s)
Teuchos::RCP< Secant< Real > > secant_
Teuchos::RCP< const Vector< Real > > g_
virtual void precond(Vector< Real > &Pv, const Vector< Real > &v, const Vector< Real > &s, Real &tol)
Apply preconditioner to vector.
TrustRegionModel(Objective< Real > &obj, const Vector< Real > &x, const Vector< Real > &g, const bool init=true)
Teuchos::RCP< const Vector< Real > > x_
Teuchos::RCP< Vector< Real > > dual_
virtual void primalTransform(Vector< Real > &tv, const Vector< Real > &v)
virtual const Teuchos::RCP< Objective< Real > > getObjective(void) const
virtual const Teuchos::RCP< const Vector< Real > > getIterate(void) const