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