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.sublist("Step").sublist("Trust Region").get("Safeguard Size",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:
110  Real &snorm,
111  Real &del,
112  int &iflag,
113  int &iter,
114  const Vector<Real> &x,
115  const Vector<Real> &grad,
116  const Real &gnorm,
117  ProjectedObjective<Real> &pObj ) {
118  Real tol = std::sqrt(ROL_EPSILON);
119  pObj.hessVec(*Hp_,grad.dual(),x,tol);
120  Real gBg = Hp_->dot(grad);
121  Real gg = gnorm*gnorm;
122  Real alpha = del/gnorm;
123  if ( gBg > ROL_EPSILON ) {
124  alpha = std::min(gg/gBg, del/gnorm);
125  }
126 
127  s.set(grad.dual());
128  s.scale(-alpha);
129  snorm = alpha*gnorm;
130  iflag = 0;
131  iter = 0;
132  pRed_ = alpha*(gg - 0.5*alpha*gBg);
133  }
134 
135  void cauchypoint_M( Vector<Real> &s, Real &snorm, Real &del, int &iflag, int &iter, const Vector<Real> &x,
136  const Vector<Real> &grad, const Real &gnorm, ProjectedObjective<Real> &pObj ) {
137  Real tol = std::sqrt(ROL_EPSILON);
138 
139  // Parameters
140  Real mu0 = 1.e-2;
141  Real mu1 = 1.0;
142  Real beta1 = 0.0;
143  Real beta2 = 0.0;
144  bool decr = true;
145  bool stat = true;
146 
147  // Initial step length
148  Real alpha = 1.0;
149  if ( alpha_ > 0.0 ) {
150  alpha = alpha_;
151  }
152  Real alpha0 = alpha;
153  Real alphamax = 1.e4*alpha;
154 
155  // Initial model value
156  s.set(grad.dual());
157  s.scale(-alpha);
158  pObj.computeProjectedStep(s,x);
159  snorm = s.norm();
160  pObj.hessVec(*Hp_,s,x,tol);
161  Real gs = s.dot(grad.dual());
162  Real val = gs + 0.5*s.dot(Hp_->dual());
163  Real val0 = val;
164 
165  // Determine whether to increase or decrease alpha
166  if ( val > mu0 * gs || snorm > mu1 * del ) {
167  beta1 = 0.5;
168  beta2 = 0.5;
169  decr = true;
170  }
171  else {
172  beta1 = 2.0;
173  beta2 = 2.0;
174  decr = false;
175  }
176 
177  while ( stat ) {
178  // Update step length
179  alpha0 = alpha;
180  val0 = val;
181  alpha *= (beta1+beta2)*0.5;
182 
183  // Update model value
184  s.set(grad.dual());
185  s.scale(-alpha);
186  pObj.computeProjectedStep(s,x);
187  snorm = s.norm();
188  pObj.hessVec(*Hp_,s,x,tol);
189  gs = s.dot(grad.dual());
190  val = gs + 0.5*s.dot(Hp_->dual());
191 
192  // Update termination criterion
193  if ( decr ) {
194  stat = ( val > mu0 * gs || snorm > mu1 * del );
195  if ( std::abs(val) < eps_ && std::abs(mu0 *gs) < eps_ ) {
196  stat = (snorm > mu1 * del);
197  }
198  }
199  else {
200  stat = !( val > mu0 * gs || snorm > mu1 * del );
201  if ( std::abs(val) < eps_ && std::abs(mu0 *gs) < eps_ ) {
202  stat = !(snorm > mu1 * del);
203  }
204  if ( alpha > alphamax ) {
205  stat = false;
206  }
207  }
208  }
209  // Reset to last 'successful' step
210  val = val0;
211  alpha = alpha0;
212  s.set(grad.dual());
213  s.scale(-alpha);
214  pObj.computeProjectedStep(s,x);
215  snorm = s.norm();
216 
217  alpha_ = alpha;
218  pRed_ = -val;
219  }
220 
221  void cauchypoint_CGT( Vector<Real> &s, Real &snorm, Real &del, int &iflag, int &iter, const Vector<Real> &x,
222  const Vector<Real> &grad, const Real &gnorm, ProjectedObjective<Real> &pObj ) {
223  Real tol = std::sqrt(ROL_EPSILON);
224  bool tmax_flag = true;
225  int maxit = 20;
226  Real t = del/gnorm;
227  Real tmax = 1.e10;
228  Real tmin = 0.0;
229  Real gs = 0.0;
230  Real c1 = 0.25;
231  Real c2 = 0.75;
232  Real c3 = 0.9;
233  Real c4 = 0.25;
234  Real pgnorm = 0.0;
235  for ( int i = 0; i < maxit; i++ ) {
236  // Compute p = x + s = P(x - t*g)
237  p_->set(x);
238  p_->axpy(-t,grad.dual());
239  pObj.project(*p_);
240  // Compute s = p - x = P(x - t*g) - x
241  s.set(*p_);
242  s.axpy(-1.0,x);
243  snorm = s.norm();
244  // Evaluate Model
245  pObj.hessVec(*Hp_,s,x,tol);
246  gs = s.dot(grad.dual());
247  pRed_ = -gs - 0.5*s.dot(Hp_->dual());
248 
249  // Check Stopping Conditions
250  g_->set(grad);
251  pObj.pruneActive(*g_,grad,*p_); // Project gradient onto tangent cone at p
252  pgnorm = g_->norm();
253  if ( snorm > del || pRed_ < -c2*gs ) {
254  tmax = t;
255  tmax_flag = false;
256  }
257  else if ( snorm < c3*del && pRed_ > -c1*gs && pgnorm > c4*std::abs(gs)/del ) {
258  tmin = t;
259  }
260  else {
261  break;
262  }
263 
264  // Update t
265  if ( tmax_flag ) {
266  t *= 2.0;
267  }
268  else {
269  t = 0.5*(tmax + tmin);
270  }
271  }
272  }
273 };
274 
275 }
276 
277 #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:213
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:143
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:74
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:196
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:118