ROL
ROL_DogLeg.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_DOGLEG_H
45 #define ROL_DOGLEG_H
46 
51 #include "ROL_TrustRegion.hpp"
52 #include "ROL_Types.hpp"
53 #include "ROL_HelperFunctions.hpp"
54 
55 namespace ROL {
56 
57 template<class Real>
58 class DogLeg : public TrustRegion<Real> {
59 private:
60 
61  Teuchos::RCP<CauchyPoint<Real> > cpt_;
62 
63  Teuchos::RCP<Vector<Real> > s_;
64  Teuchos::RCP<Vector<Real> > Hp_;
65 
66  Real pRed_;
67 
68 public:
69 
70  // Constructor
71  DogLeg( Teuchos::ParameterList &parlist ) : TrustRegion<Real>(parlist), pRed_(0.0) {
72  cpt_ = Teuchos::rcp(new CauchyPoint<Real>(parlist));
73  }
74 
75  void initialize( const Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g) {
77  s_ = s.clone();
78  Hp_ = g.clone();
79  }
80 
81  void run( Vector<Real> &s, Real &snorm, Real &del, int &iflag, int &iter, const Vector<Real> &x,
82  const Vector<Real> &grad, const Real &gnorm, ProjectedObjective<Real> &pObj ) {
83  Real tol = std::sqrt(ROL_EPSILON);
84  // Compute quasi-Newton step
85  pObj.reducedInvHessVec(*s_,grad,x,grad,x,tol);
86  s_->scale(-1.0);
87  Real sNnorm = s_->norm();
88  Real gsN = s_->dot(grad.dual());
89  bool negCurv = false;
90  if ( gsN >= 0.0 ) {
91  negCurv = true;
92  }
93 
94  if ( negCurv ) {
95  cpt_->run(s,snorm,del,iflag,iter,x,grad,gnorm,pObj);
96  pRed_ = cpt_->getPredictedReduction();
97  iflag = 2;
98  }
99  else {
100  // Approximately solve trust region subproblem using double dogleg curve
101  if (sNnorm <= del) { // Use the quasi-Newton step
102  s.set(*s_);
103  snorm = sNnorm;
104  pRed_ = -0.5*gsN;
105  iflag = 0;
106  }
107  else { // quasi-Newton step is outside of trust region
108  pObj.reducedHessVec(*Hp_,grad,x,grad,x,tol);
109  Real alpha = 0.0;
110  Real beta = 0.0;
111  Real gnorm2 = gnorm*gnorm;
112  Real gBg = grad.dot(*Hp_);
113  Real gamma = gnorm2/gBg;
114  if ( gamma*gnorm >= del || gBg <= 0.0 ) {
115  alpha = 0.0;
116  beta = del/gnorm;
117  s.set(grad.dual());
118  s.scale(-beta);
119  snorm = del;
120  iflag = 2;
121  }
122  else {
123  Real a = sNnorm*sNnorm + 2.0*gamma*gsN + gamma*gamma*gnorm2;
124  Real b = -gamma*gsN - gamma*gamma*gnorm2;
125  Real c = gamma*gamma*gnorm2 - del*del;
126  alpha = (-b + sqrt(b*b - a*c))/a;
127  beta = gamma*(1.0-alpha);
128  s.set(grad.dual());
129  s.scale(-beta);
130  s.axpy(alpha,*s_);
131  snorm = del;
132  iflag = 1;
133  }
134  pRed_ = (alpha*(0.5*alpha-1)*gsN - 0.5*beta*beta*gBg + beta*(1-alpha)*gnorm2);
135  }
136  }
138  }
139 };
140 
141 }
142 
143 #endif
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:211
virtual void scale(const Real alpha)=0
Compute where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:141
virtual void initialize(const Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g)
void reducedHessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &p, const Vector< Real > &d, const Vector< Real > &x, Real &tol)
Apply the reduced Hessian to a vector, v. The reduced Hessian first removes elements of v correspondi...
Contains definitions of custom data types in ROL.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Provides interface for and implements trust-region subproblem solvers.
Contains definitions for helper functions in ROL.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:72
Teuchos::RCP< Vector< Real > > Hp_
Definition: ROL_DogLeg.hpp:64
virtual Real dot(const Vector &x) const =0
Compute where .
Teuchos::RCP< CauchyPoint< Real > > cpt_
Definition: ROL_DogLeg.hpp:61
void run(Vector< Real > &s, Real &snorm, Real &del, int &iflag, int &iter, const Vector< Real > &x, const Vector< Real > &grad, const Real &gnorm, ProjectedObjective< Real > &pObj)
Definition: ROL_DogLeg.hpp:81
void setPredictedReduction(const Real pRed)
void reducedInvHessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &p, const Vector< Real > &d, const Vector< Real > &x, Real &tol)
Apply the reduced inverse Hessian to a vector, v. The reduced inverse Hessian first removes elements ...
Teuchos::RCP< Vector< Real > > s_
Definition: ROL_DogLeg.hpp:63
Provides interface for dog leg trust-region subproblem solver.
Definition: ROL_DogLeg.hpp:58
Provides interface for the Cauchy point trust-region subproblem solver.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:194
void initialize(const Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g)
Definition: ROL_DogLeg.hpp:75
DogLeg(Teuchos::ParameterList &parlist)
Definition: ROL_DogLeg.hpp:71
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:115