ROL
ROL_TrustRegion.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_TRUSTREGION_H
45 #define ROL_TRUSTREGION_H
46 
51 #include "ROL_Types.hpp"
52 #include "ROL_TrustRegionTypes.hpp"
53 #include "ROL_TrustRegionModel.hpp"
54 #include "ROL_ColemanLiModel.hpp"
55 #include "ROL_KelleySachsModel.hpp"
56 
57 namespace ROL {
58 
59 template<class Real>
60 class TrustRegion {
61 private:
62 
63  Teuchos::RCP<Vector<Real> > prim_, dual_;
64 
66 
67  Real delmax_;
68  Real eta0_, eta1_, eta2_;
70  Real pRed_;
71  Real TRsafe_, eps_;
72  Real mu0_;
73 
74  std::vector<bool> useInexact_;
75 
76  Real ftol_old_;
77 
80 
81  unsigned verbosity_;
82 
83 public:
84 
85  virtual ~TrustRegion() {}
86 
87  // Constructor
88  TrustRegion( Teuchos::ParameterList &parlist )
89  : ftol_old_(ROL_OVERFLOW<Real>()), cnt_(0), verbosity_(0) {
90  // Trust-Region Parameters
91  Teuchos::ParameterList list = parlist.sublist("Step").sublist("Trust Region");
92  TRmodel_ = StringToETrustRegionModel(list.get("Subproblem Model", "Kelley-Sachs"));
93  delmax_ = list.get("Maximum Radius", static_cast<Real>(5000.0));
94  eta0_ = list.get("Step Acceptance Threshold", static_cast<Real>(0.05));
95  eta1_ = list.get("Radius Shrinking Threshold", static_cast<Real>(0.05));
96  eta2_ = list.get("Radius Growing Threshold", static_cast<Real>(0.9));
97  gamma0_ = list.get("Radius Shrinking Rate (Negative rho)", static_cast<Real>(0.0625));
98  gamma1_ = list.get("Radius Shrinking Rate (Positive rho)", static_cast<Real>(0.25));
99  gamma2_ = list.get("Radius Growing Rate", static_cast<Real>(2.5));
100  mu0_ = list.get("Sufficient Decrease Parameter", static_cast<Real>(1.e-4));
101  TRsafe_ = list.get("Safeguard Size", static_cast<Real>(100.0));
102  eps_ = TRsafe_*ROL_EPSILON<Real>();
103  // General Inexactness Information
104  Teuchos::ParameterList &glist = parlist.sublist("General");
105  useInexact_.clear();
106  useInexact_.push_back(glist.get("Inexact Objective Function", false));
107  useInexact_.push_back(glist.get("Inexact Gradient", false));
108  useInexact_.push_back(glist.get("Inexact Hessian-Times-A-Vector", false));
109  // Inexact Function Evaluation Information
110  Teuchos::ParameterList &ilist = list.sublist("Inexact").sublist("Value");
111  scale_ = ilist.get("Tolerance Scaling", static_cast<Real>(1.e-1));
112  omega_ = ilist.get("Exponent", static_cast<Real>(0.9));
113  force_ = ilist.get("Forcing Sequence Initial Value", static_cast<Real>(1.0));
114  updateIter_ = ilist.get("Forcing Sequence Update Frequency", static_cast<int>(10));
115  forceFactor_ = ilist.get("Forcing Sequence Reduction Factor", static_cast<Real>(0.1));
116  // Get verbosity level
117  verbosity_ = glist.get("Print Verbosity", 0);
118  }
119 
120  virtual void initialize( const Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g) {
121  prim_ = x.clone();
122  dual_ = g.clone();
123  }
124 
125  virtual void update( Vector<Real> &x,
126  Real &fnew,
127  Real &del,
128  int &nfval,
129  int &ngrad,
130  ETrustRegionFlag &flagTR,
131  const Vector<Real> &s,
132  const Real snorm,
133  const Real fold,
134  const Vector<Real> &g,
135  int iter,
136  Objective<Real> &obj,
138  TrustRegionModel<Real> &model ) {
139  Real tol = std::sqrt(ROL_EPSILON<Real>());
140  const Real one(1), zero(0);
141 
142  /***************************************************************************************************/
143  // BEGIN INEXACT OBJECTIVE FUNCTION COMPUTATION
144  /***************************************************************************************************/
145  // Update inexact objective function
146  Real fold1 = fold, ftol = tol; // TOL(1.e-2);
147  if ( useInexact_[0] ) {
148  if ( !(cnt_%updateIter_) && (cnt_ != 0) ) {
149  force_ *= forceFactor_;
150  }
151  //const Real oe4(1e4);
152  //Real c = scale_*std::max(TOL,std::min(one,oe4*std::max(pRed_,std::sqrt(ROL_EPSILON<Real>()))));
153  //ftol = c*std::pow(std::min(eta1_,one-eta2_)
154  // *std::min(std::max(pRed_,std::sqrt(ROL_EPSILON<Real>())),force_),one/omega_);
155  //if ( ftol_old_ > ftol || cnt_ == 0 ) {
156  // ftol_old_ = ftol;
157  // fold1 = obj.value(x,ftol_old_);
158  //}
159  //cnt_++;
160  Real eta = static_cast<Real>(0.999)*std::min(eta1_,one-eta2_);
161  ftol = scale_*std::pow(eta*std::min(pRed_,force_),one/omega_);
162  ftol_old_ = ftol;
163  fold1 = obj.value(x,ftol_old_);
164  cnt_++;
165  }
166  // Evaluate objective function at new iterate
167  prim_->set(x); prim_->plus(s);
168  obj.update(*prim_,true);
169  fnew = obj.value(*prim_,ftol);
170 
171  nfval = 1;
172  Real aRed = fold1 - fnew;
173  /***************************************************************************************************/
174  // FINISH INEXACT OBJECTIVE FUNCTION COMPUTATION
175  /***************************************************************************************************/
176 
177  /***************************************************************************************************/
178  // BEGIN COMPUTE RATIO OF ACTUAL AND PREDICTED REDUCTION
179  /***************************************************************************************************/
180  // Modify Actual and Predicted Reduction According to Model
181  model.updateActualReduction(aRed,s);
182  model.updatePredictedReduction(pRed_,s);
183 
184  if ( verbosity_ > 0 ) {
185  std::cout << std::endl;
186  std::cout << " Computation of actual and predicted reduction" << std::endl;
187  std::cout << " Current objective function value: " << fold1 << std::endl;
188  std::cout << " New objective function value: " << fnew << std::endl;
189  std::cout << " Actual reduction: " << aRed << std::endl;
190  std::cout << " Predicted reduction: " << pRed_ << std::endl;
191  }
192 
193  // Compute Ratio of Actual and Predicted Reduction
194  Real EPS = eps_*((one > std::abs(fold1)) ? one : std::abs(fold1));
195  Real aRed_safe = aRed + EPS, pRed_safe = pRed_ + EPS;
196  Real rho(0);
197  if (((std::abs(aRed_safe) < eps_) && (std::abs(pRed_safe) < eps_)) || aRed == pRed_) {
198  rho = one;
199  flagTR = TRUSTREGION_FLAG_SUCCESS;
200  }
201  else if ( std::isnan(aRed_safe) || std::isnan(pRed_safe) ) {
202  rho = -one;
203  flagTR = TRUSTREGION_FLAG_NAN;
204  }
205  else {
206  rho = aRed_safe/pRed_safe;
207  if (pRed_safe < zero && aRed_safe > zero) {
209  }
210  else if (aRed_safe <= zero && pRed_safe > zero) {
212  }
213  else if (aRed_safe <= zero && pRed_safe < zero) {
215  }
216  else {
217  flagTR = TRUSTREGION_FLAG_SUCCESS;
218  }
219  }
220 
221  if ( verbosity_ > 0 ) {
222  std::cout << " Safeguard: " << eps_ << std::endl;
223  std::cout << " Actual reduction with safeguard: " << aRed_safe << std::endl;
224  std::cout << " Predicted reduction with safeguard: " << pRed_safe << std::endl;
225  std::cout << " Ratio of actual and predicted reduction: " << rho << std::endl;
226  std::cout << " Trust-region flag: " << flagTR << std::endl;
227  }
228  /***************************************************************************************************/
229  // FINISH COMPUTE RATIO OF ACTUAL AND PREDICTED REDUCTION
230  /***************************************************************************************************/
231 
232 
233  /***************************************************************************************************/
234  // BEGIN CHECK SUFFICIENT DECREASE FOR BOUND CONSTRAINED PROBLEMS
235  /***************************************************************************************************/
236  bool decr = true;
237  if ( bnd.isActivated() && TRmodel_ == TRUSTREGION_MODEL_KELLEYSACHS ) {
238  if ( rho >= eta0_ && (std::abs(aRed_safe) > eps_) ) {
239  // Compute Criticality Measure || x - P( x - g ) ||
240  prim_->set(x);
241  prim_->axpy(-one,g.dual());
242  bnd.project(*prim_);
243  prim_->scale(-one);
244  prim_->plus(x);
245  Real pgnorm = prim_->norm();
246  // Compute Scaled Measure || x - P( x - lam * PI(g) ) ||
247  prim_->set(g.dual());
248  bnd.pruneActive(*prim_,g,x);
249  Real lam = std::min(one, del/prim_->norm());
250  prim_->scale(-lam);
251  prim_->plus(x);
252  bnd.project(*prim_);
253  prim_->scale(-one);
254  prim_->plus(x);
255  pgnorm *= prim_->norm();
256  // Sufficient decrease?
257  decr = ( aRed_safe >= mu0_*eta0_*pgnorm );
258  flagTR = (!decr ? TRUSTREGION_FLAG_QMINSUFDEC : flagTR);
259 
260  if ( verbosity_ > 0 ) {
261  std::cout << " Decrease lower bound (constraints): " << 0.1*eta0_*pgnorm << std::endl;
262  std::cout << " Trust-region flag (constraints): " << flagTR << std::endl;
263  std::cout << " Is step feasible: " << bnd.isFeasible(x) << std::endl;
264  }
265  }
266  }
267  /***************************************************************************************************/
268  // FINISH CHECK SUFFICIENT DECREASE FOR BOUND CONSTRAINED PROBLEMS
269  /***************************************************************************************************/
270 
271  /***************************************************************************************************/
272  // BEGIN STEP ACCEPTANCE AND TRUST REGION RADIUS UPDATE
273  /***************************************************************************************************/
274  if ( verbosity_ > 0 ) {
275  std::cout << " Norm of step: " << snorm << std::endl;
276  std::cout << " Trust-region radius before update: " << del << std::endl;
277  }
278  if ((rho < eta0_ && flagTR == TRUSTREGION_FLAG_SUCCESS) || flagTR >= 2 || !decr ) { // Step Rejected
279  fnew = fold1;
280  if (rho < zero) { // Negative reduction, interpolate to find new trust-region radius
281  Real gs(0);
282  if ( bnd.isActivated() ) {
283  model.dualTransform(*dual_, *model.getGradient());
284  gs = dual_->dot(s.dual());
285  }
286  else {
287  gs = g.dot(s.dual());
288  }
289  Real modelVal = model.value(s,tol);
290  modelVal += fold1;
291  Real theta = (one-eta2_)*gs/((one-eta2_)*(fold1+gs)+eta2_*modelVal-fnew);
292  del = std::min(gamma1_*std::min(snorm,del),std::max(gamma0_,theta)*del);
293  if ( verbosity_ > 0 ) {
294  std::cout << " Interpolation model value: " << modelVal << std::endl;
295  std::cout << " Interpolation step length: " << theta << std::endl;
296  }
297  }
298  else { // Shrink trust-region radius
299  del = gamma1_*std::min(snorm,del);
300  }
301  obj.update(x,true,iter);
302  }
303  else if ((rho >= eta0_ && flagTR != TRUSTREGION_FLAG_NPOSPREDNEG) ||
304  (flagTR == TRUSTREGION_FLAG_POSPREDNEG)) { // Step Accepted
305  x.plus(s);
306  obj.update(x,true,iter);
307  if (rho >= eta2_) { // Increase trust-region radius
308  del = std::min(gamma2_*del,delmax_);
309  }
310  }
311  if ( verbosity_ > 0 ) {
312  std::cout << " Trust-region radius after update: " << del << std::endl;
313  std::cout << std::endl;
314  }
315  /***************************************************************************************************/
316  // FINISH STEP ACCEPTANCE AND TRUST REGION RADIUS UPDATE
317  /***************************************************************************************************/
318  }
319 
320  virtual void run( Vector<Real> &s, // Step (to be computed)
321  Real &snorm, // Step norm (to be computed)
322  int &iflag, // Exit flag (to be computed)
323  int &iter, // Iteration count (to be computed)
324  const Real del, // Trust-region radius
325  TrustRegionModel<Real> &model ) = 0; // Trust-region model
326 
327  void setPredictedReduction(const Real pRed) {
328  pRed_ = pRed;
329  }
330 
331  Real getPredictedReduction(void) const {
332  return pRed_;
333  }
334 };
335 
336 }
337 
339 
340 #endif
Provides the interface to evaluate objective functions.
TrustRegion(Teuchos::ParameterList &parlist)
virtual void plus(const Vector &x)=0
Compute , where .
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual void initialize(const Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g)
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.
Provides the interface to evaluate trust-region model functions.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:76
virtual void updatePredictedReduction(Real &pred, const Vector< Real > &s)
virtual Real dot(const Vector &x) const =0
Compute where .
virtual void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0)
Set variables to zero if they correspond to the -active set.
virtual void dualTransform(Vector< Real > &tv, const Vector< Real > &v)
Teuchos::RCP< Vector< Real > > prim_
bool isActivated(void)
Check if bounds are on.
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:215
ETrustRegionModel StringToETrustRegionModel(std::string s)
Real getPredictedReduction(void) const
virtual Real value(const Vector< Real > &s, Real &tol)
Compute value.
virtual const Teuchos::RCP< const Vector< Real > > getGradient(void) const
void setPredictedReduction(const Real pRed)
Real ROL_OVERFLOW(void)
Platform-dependent maximum double.
Definition: ROL_Types.hpp:151
ETrustRegionModel
Enumeration of trust-region model types.
Provides the interface to apply upper and lower bound constraints.
Teuchos::RCP< Vector< Real > > dual_
virtual void updateActualReduction(Real &ared, const Vector< Real > &s)
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
ETrustRegionFlag
Enumation of flags used by trust-region solvers.
ETrustRegionModel TRmodel_
virtual bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
Contains definitions of enums for trust region algorithms.
std::vector< bool > useInexact_
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
virtual void run(Vector< Real > &s, Real &snorm, int &iflag, int &iter, const Real del, TrustRegionModel< Real > &model)=0
virtual void update(Vector< Real > &x, Real &fnew, Real &del, int &nfval, int &ngrad, ETrustRegionFlag &flagTR, const Vector< Real > &s, const Real snorm, const Real fold, const Vector< Real > &g, int iter, Objective< Real > &obj, BoundConstraint< Real > &bnd, TrustRegionModel< Real > &model)