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