ROL
ROL_CauchyPoint.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_CAUCHYPOINT_H
45 #define ROL_CAUCHYPOINT_H
46 
51 #include "ROL_TrustRegion.hpp"
52 #include "ROL_Vector.hpp"
53 #include "ROL_Types.hpp"
54 #include "ROL_HelperFunctions.hpp"
55 #include "Teuchos_ParameterList.hpp"
56 
57 namespace ROL {
58 
59 template<class Real>
60 class CauchyPoint : public TrustRegion<Real> {
61 private:
62 
63  Teuchos::RCP<Vector<Real> > g_;
64  Teuchos::RCP<Vector<Real> > p_;
65  Teuchos::RCP<Vector<Real> > Hp_;
66 
67  Real pRed_;
68  Real eps_;
69  Real alpha_;
70 
71  bool useCGTCP_;
72 
73 public:
74 
75  // Constructor
76  CauchyPoint( Teuchos::ParameterList &parlist )
77  : TrustRegion<Real>(parlist), pRed_(0.0), alpha_(-1.0), useCGTCP_(false) {
78  // Unravel Parameter List
79  Real TRsafe = parlist.get("Trust-Region Safeguard",100.0);
80  eps_ = TRsafe*ROL_EPSILON;
81  }
82 
83  void initialize( const Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g) {
85  Hp_ = g.clone();
86  if ( useCGTCP_ ) {
87  g_ = g.clone();
88  p_ = s.clone();
89  }
90  }
91 
92  void run( Vector<Real> &s, Real &snorm, Real &del, int &iflag, int &iter, const Vector<Real> &x,
93  const Vector<Real> &grad, const Real &gnorm, ProjectedObjective<Real> &pObj ) {
94  if ( pObj.isConActivated() ) {
95  if ( useCGTCP_ ) {
96  cauchypoint_CGT( s, snorm, del, iflag, iter, x, grad, gnorm, pObj );
97  }
98  else {
99  cauchypoint_M( s, snorm, del, iflag, iter, x, grad, gnorm, pObj );
100  }
101  }
102  else {
103  cauchypoint_unc( s, snorm, del, iflag, iter, x, grad, gnorm, pObj );
104  }
106  }
107 
108 private:
109  void cauchypoint_unc( Vector<Real> &s, Real &snorm, Real &del, int &iflag, int &iter, const Vector<Real> &x,
110  const Vector<Real> &grad, const Real &gnorm, ProjectedObjective<Real> &pObj ) {
111  Real tol = std::sqrt(ROL_EPSILON);
112  pObj.hessVec(*Hp_,grad.dual(),x,tol);
113  Real gBg = Hp_->dot(grad);
114  Real tau = 1.0;
115  if ( gBg > 0.0 ) {
116  tau = std::min(1.0, gnorm*gnorm*gnorm/gBg);
117  }
118 
119  s.set(grad.dual());
120  s.scale(-tau*del/gnorm);
121  snorm = tau*del;
122  iflag = 0;
123  iter = 0;
124  pRed_ = tau*del/gnorm * pow(gnorm,2.0) - 0.5*pow(tau*del/gnorm,2.0)*gBg;
125  }
126 
127  void cauchypoint_M( Vector<Real> &s, Real &snorm, Real &del, int &iflag, int &iter, const Vector<Real> &x,
128  const Vector<Real> &grad, const Real &gnorm, ProjectedObjective<Real> &pObj ) {
129  Real tol = std::sqrt(ROL_EPSILON);
130 
131  // Parameters
132  Real mu0 = 1.e-2;
133  Real mu1 = 1.0;
134  Real beta1 = 0.0;
135  Real beta2 = 0.0;
136  bool decr = true;
137  bool stat = true;
138 
139  // Initial step length
140  Real alpha = 1.0;
141  if ( alpha_ > 0.0 ) {
142  alpha = alpha_;
143  }
144  Real alpha0 = alpha;
145  Real alphamax = 1.e4*alpha;
146 
147  // Initial model value
148  s.set(grad.dual());
149  s.scale(-alpha);
150  pObj.computeProjectedStep(s,x);
151  snorm = s.norm();
152  pObj.hessVec(*Hp_,s,x,tol);
153  Real gs = s.dot(grad.dual());
154  Real val = gs + 0.5*s.dot(Hp_->dual());
155  Real val0 = val;
156 
157  // Determine whether to increase or decrease alpha
158  if ( val > mu0 * gs || snorm > mu1 * del ) {
159  beta1 = 0.5;
160  beta2 = 0.5;
161  decr = true;
162  }
163  else {
164  beta1 = 2.0;
165  beta2 = 2.0;
166  decr = false;
167  }
168 
169  while ( stat ) {
170  // Update step length
171  alpha0 = alpha;
172  val0 = val;
173  alpha *= (beta1+beta2)*0.5;
174 
175  // Update model value
176  s.set(grad.dual());
177  s.scale(-alpha);
178  pObj.computeProjectedStep(s,x);
179  snorm = s.norm();
180  pObj.hessVec(*Hp_,s,x,tol);
181  gs = s.dot(grad.dual());
182  val = gs + 0.5*s.dot(Hp_->dual());
183 
184  // Update termination criterion
185  if ( decr ) {
186  stat = ( val > mu0 * gs || snorm > mu1 * del );
187  if ( std::abs(val) < eps_ && std::abs(mu0 *gs) < eps_ ) {
188  stat = (snorm > mu1 * del);
189  }
190  }
191  else {
192  stat = !( val > mu0 * gs || snorm > mu1 * del );
193  if ( std::abs(val) < eps_ && std::abs(mu0 *gs) < eps_ ) {
194  stat = !(snorm > mu1 * del);
195  }
196  if ( alpha > alphamax ) {
197  stat = false;
198  }
199  }
200  }
201  // Reset to last 'successful' step
202  val = val0;
203  alpha = alpha0;
204  s.set(grad.dual());
205  s.scale(-alpha);
206  pObj.computeProjectedStep(s,x);
207  snorm = s.norm();
208 
209  alpha_ = alpha;
210  pRed_ = -val;
211  }
212 
213  void cauchypoint_CGT( Vector<Real> &s, Real &snorm, Real &del, int &iflag, int &iter, const Vector<Real> &x,
214  const Vector<Real> &grad, const Real &gnorm, ProjectedObjective<Real> &pObj ) {
215  Real tol = std::sqrt(ROL_EPSILON);
216  bool tmax_flag = true;
217  int maxit = 20;
218  Real t = del/gnorm;
219  Real tmax = 1.e10;
220  Real tmin = 0.0;
221  Real gs = 0.0;
222  Real c1 = 0.25;
223  Real c2 = 0.75;
224  Real c3 = 0.9;
225  Real c4 = 0.25;
226  Real pgnorm = 0.0;
227  for ( int i = 0; i < maxit; i++ ) {
228  // Compute p = x + s = P(x - t*g)
229  p_->set(x);
230  p_->axpy(-t,grad.dual());
231  pObj.project(*p_);
232  // Compute s = p - x = P(x - t*g) - x
233  s.set(*p_);
234  s.axpy(-1.0,x);
235  snorm = s.norm();
236  // Evaluate Model
237  pObj.hessVec(*Hp_,s,x,tol);
238  gs = s.dot(grad.dual());
239  pRed_ = -gs - 0.5*s.dot(Hp_->dual());
240 
241  // Check Stopping Conditions
242  g_->set(grad);
243  pObj.pruneActive(*g_,grad,*p_); // Project gradient onto tangent cone at p
244  pgnorm = g_->norm();
245  if ( snorm > del || pRed_ < -c2*gs ) {
246  tmax = t;
247  tmax_flag = false;
248  }
249  else if ( snorm < c3*del && pRed_ > -c1*gs && pgnorm > c4*std::abs(gs)/del ) {
250  tmin = t;
251  }
252  else {
253  break;
254  }
255 
256  // Update t
257  if ( tmax_flag ) {
258  t *= 2.0;
259  }
260  else {
261  t = 0.5*(tmax + tmin);
262  }
263  }
264  }
265 };
266 
267 }
268 
269 #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 .
CauchyPoint(Teuchos::ParameterList &parlist)
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)
Teuchos::RCP< Vector< Real > > p_
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.
void pruneActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x)
Contains definitions for helper functions in ROL.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:72
void hessVec(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
virtual Real dot(const Vector &x) const =0
Compute where .
void cauchypoint_CGT(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)
void cauchypoint_unc(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)
void setPredictedReduction(const Real pRed)
void cauchypoint_M(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)
Teuchos::RCP< Vector< Real > > Hp_
void initialize(const Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g)
Teuchos::RCP< Vector< Real > > g_
Provides interface for the Cauchy point trust-region subproblem solver.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:194
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)
virtual Real norm() const =0
Returns where .
void computeProjectedStep(Vector< Real > &v, const Vector< Real > &x)
void project(Vector< Real > &x)
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:115