ROL
ROL_BundleStep.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_BUNDLE_STEP_H
45 #define ROL_BUNDLE_STEP_H
46 
47 #include "ROL_Bundle.hpp"
48 #include "ROL_Bundle_TT.hpp"
49 #include "ROL_Types.hpp"
50 #include "ROL_Step.hpp"
51 #include "ROL_Vector.hpp"
52 #include "ROL_Objective.hpp"
53 #include "ROL_BoundConstraint.hpp"
54 #include "ROL_LineSearch.hpp"
55 
56 #include "Teuchos_ParameterList.hpp"
57 #include "Teuchos_RCP.hpp"
58 
64 namespace ROL {
65 
66 template <class Real>
67 class BundleStep : public Step<Real> {
68 private:
69  // Bundle
70  Teuchos::RCP<Bundle<Real> > bundle_; // Bundle of subgradients and linearization errors
71  Teuchos::RCP<LineSearch<Real> > lineSearch_; // Line-search object for nonconvex problems
72 
73  // Dual cutting plane solution
74  unsigned QPiter_; // Number of QP solver iterations
75  unsigned QPmaxit_; // Maximum number of QP iterations
76  Real QPtol_; // QP subproblem tolerance
77 
78  // Step flag
79  int step_flag_; // Whether serious or null step
80 
81  // Additional storage
82  Teuchos::RCP<Vector<Real> > y_;
83 
84  // Updated iterate storage
85  Real linErrNew_;
86  Real valueNew_;
87 
88  // Aggregate subgradients, linearizations, and distance measures
89  Teuchos::RCP<Vector<Real> > aggSubGradNew_; // New aggregate subgradient
90  Real aggSubGradOldNorm_; // Old aggregate subgradient norm
91  Real aggLinErrNew_; // New aggregate linearization error
92  Real aggLinErrOld_; // Old aggregate linearization error
93  Real aggDistMeasNew_; // New aggregate distance measure
94 
95  // Algorithmic parameters
96  Real T_;
97  Real tol_;
98  Real m1_;
99  Real m2_;
100  Real m3_;
101  Real nu_;
102 
103  // Line-search parameters
105 
107  bool isConvex_;
108 
109  Real ftol_;
110 
111 public:
112 
113  BundleStep(Teuchos::ParameterList &parlist)
114  : bundle_(Teuchos::null), lineSearch_(Teuchos::null),
115  QPiter_(0), QPmaxit_(0), QPtol_(0.), step_flag_(0),
116  y_(Teuchos::null), linErrNew_(0.), valueNew_(0.),
117  aggSubGradNew_(Teuchos::null), aggSubGradOldNorm_(0.),
118  aggLinErrNew_(0.), aggLinErrOld_(0.), aggDistMeasNew_(0.),
119  T_(0.), tol_(0.), m1_(0.), m2_(0.), m3_(0.), nu_(0.),
120  ls_maxit_(0), first_print_(true), isConvex_(false),
121  ftol_(ROL_EPSILON) {
122  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
123  state->searchSize = parlist.sublist("Step").sublist("Bundle").get("Initial Trust-Region Parameter", 1.e3);
124  T_ = parlist.sublist("Step").sublist("Bundle").get("Maximum Trust-Region Parameter", 1.e8);
125  tol_ = parlist.sublist("Step").sublist("Bundle").get("Epsilon Solution Tolerance", 1.e-6);
126  m1_ = parlist.sublist("Step").sublist("Bundle").get("Upper Threshold for Serious Step", 0.1);
127  m2_ = parlist.sublist("Step").sublist("Bundle").get("Lower Threshold for Serious Step", 0.2);
128  m3_ = parlist.sublist("Step").sublist("Bundle").get("Upper Threshold for Null Step", 0.9);
129  nu_ = parlist.sublist("Step").sublist("Bundle").get("Tolerance for Trust-Region Parameter", 1.e-3);
130 
131  // Initialize bundle
132  Real coeff = parlist.sublist("Step").sublist("Bundle").get("Distance Measure Coefficient", 0.0);
133  unsigned maxSize = parlist.sublist("Step").sublist("Bundle").get("Maximum Bundle Size", 200);
134  unsigned remSize = parlist.sublist("Step").sublist("Bundle").get("Removal Size for Bundle Update", 2);
135  if ( parlist.sublist("Step").sublist("Bundle").get("Cutting Plane Solver",0) == 1 ) {
136  bundle_ = Teuchos::rcp(new Bundle_TT<Real>(maxSize,coeff,remSize));
137  }
138  else {
139  bundle_ = Teuchos::rcp(new Bundle<Real>(maxSize,coeff,remSize));
140  }
141  isConvex_ = ((coeff == 0.0) ? true : false);
142 
143  // Initialize QP solver
144  QPtol_ = parlist.sublist("Step").sublist("Bundle").get("Cutting Plane Tolerance", 1.e-8);
145  QPmaxit_ = parlist.sublist("Step").sublist("Bundle").get("Cutting Plane Iteration Limit", 1000);
146 
147  // Initialize Line Search
148  ls_maxit_
149  = parlist.sublist("Step").sublist("Line Search").get("Maximum Number of Function Evaluations",20);
150  if ( !isConvex_ ) {
151  lineSearch_ = LineSearchFactory<Real>(parlist);
152  }
153  }
154 
155  void initialize( Vector<Real> &x, const Vector<Real> &g,
157  AlgorithmState<Real> &algo_state ) {
158  // Call default initializer, but maintain current searchSize
159  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
160  Real searchSize = state->searchSize;
161  Step<Real>::initialize(x,x,g,obj,con,algo_state);
162  state->searchSize = searchSize;
163  // Initialize bundle
164  bundle_->initialize(*(state->gradientVec));
165  // Initialize storage for updated iterate
166  y_ = x.clone();
167  // Initialize storage for aggregate subgradients
168  aggSubGradNew_ = x.clone();
169  aggSubGradOldNorm_ = algo_state.gnorm;
170  }
171 
173  BoundConstraint<Real> &con, AlgorithmState<Real> &algo_state ) {
174  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
175  first_print_ = false; // Print header only on first serious step
176  QPiter_ = (step_flag_ ? 0 : QPiter_); // Reset QPiter only on serious steps
177  Real v = 0.0, l = 0.0, u = T_, gd = 0.0; // Scalar storage
178  bool flag = true;
179  while (flag) {
180  /*************************************************************/
181  /******** Solve Dual Cutting Plane QP Problem ****************/
182  /*************************************************************/
183  QPiter_ += bundle_->solveDual(state->searchSize,QPmaxit_,QPtol_); // Solve QP subproblem
184  bundle_->aggregate(*aggSubGradNew_,aggLinErrNew_,aggDistMeasNew_); // Compute aggregate info
185  algo_state.aggregateGradientNorm = aggSubGradNew_->norm(); // Aggregate subgradient norm
186  /*************************************************************/
187  /******** Construct Cutting Plane Solution *******************/
188  /*************************************************************/
189  v = -state->searchSize*std::pow(algo_state.aggregateGradientNorm,2.0)-aggLinErrNew_; // CP objective value
190  s.set(*aggSubGradNew_); s.scale(-state->searchSize); // CP solution
191  algo_state.snorm = state->searchSize*algo_state.aggregateGradientNorm; // Step norm
192  /*************************************************************/
193  /******** Decide Whether Step is Serious or Null *************/
194  /*************************************************************/
195  if (std::max(algo_state.aggregateGradientNorm,aggLinErrNew_) <= tol_) {
196  // Current iterate is already epsilon optimal!
197  s.zero(); algo_state.snorm = 0.0;
198  flag = false;
199  step_flag_ = 1;
200  algo_state.flag = true;
201  break;
202  }
203  else {
204  // Current iterate is not epsilon optimal.
205  y_->set(x); y_->plus(s); // y is the candidate iterate
206  obj.update(*y_,true,algo_state.iter); // Update objective at y
207  valueNew_ = obj.value(*y_,ftol_); // Compute objective value at y
208  algo_state.nfval++;
209  obj.gradient(*(state->gradientVec),*y_,ftol_); // Compute objective (sub)gradient at y
210  algo_state.ngrad++;
211  // Compute new linearization error and distance measure
212  gd = s.dot(*(state->gradientVec));
213  linErrNew_ = algo_state.value - (valueNew_ - gd); // Linearization error
214  // Determine whether to take a serious or null step
215  bool SS1 = (valueNew_-algo_state.value < m1_*v);
216  //bool NS1 = (valueNew_-algo_state.value >= m1_*v);
217  bool NS2a = (bundle_->computeAlpha(algo_state.snorm,linErrNew_) <= m3_*aggLinErrOld_);
218  bool NS2b = (std::abs(algo_state.value-valueNew_) <= aggSubGradOldNorm_ + aggLinErrOld_);
219  if ( isConvex_ ) {
220  /************* Convex objective ****************/
221  if ( SS1 ) {
222  bool SS2 = (gd >= m2_*v || state->searchSize >= T_-nu_);
223  if ( SS2 ) { // Serious Step
224  step_flag_ = 1;
225  flag = false;
226  break;
227  }
228  else { // Increase trust-region radius
229  l = state->searchSize;
230  state->searchSize = 0.5*(u+l);
231  }
232  }
233  else {
234  if ( NS2a || NS2b ) { // Null step
235  s.zero(); algo_state.snorm = 0.0;
236  step_flag_ = 0;
237  flag = false;
238  break;
239  }
240  else { // Decrease trust-region radius
241  u = state->searchSize;
242  state->searchSize = 0.5*(u+l);
243  }
244  }
245  }
246  else {
247  /************* Nonconvex objective *************/
248  bool NS3 = (gd - bundle_->computeAlpha(algo_state.snorm,linErrNew_) >= m2_*v);
249  if ( SS1 ) { // Serious step
250  step_flag_ = 1;
251  flag = false;
252  break;
253  }
254  else {
255  if ( NS2a || NS2b ) {
256  if ( NS3 ) { // Null step
257  s.zero();
258  step_flag_ = 0;
259  flag = false;
260  break;
261  }
262  else {
263  if ( NS2b ) { // Line search
264  Real alpha = 0.0;
265  int ls_nfval = 0, ls_ngrad = 0;
266  lineSearch_->run(alpha,valueNew_,ls_nfval,ls_ngrad,gd,s,x,obj,con);
267  if ( ls_nfval == ls_maxit_ ) { // Null step
268  s.zero();
269  step_flag_ = 0;
270  flag = false;
271  break;
272  }
273  else { // Serious step
274  s.scale(alpha);
275  step_flag_ = 1;
276  flag = false;
277  break;
278  }
279  }
280  else { // Decrease trust-region radius
281  u = state->searchSize;
282  state->searchSize = 0.5*(u+l);
283  }
284  }
285  }
286  else { // Decrease trust-region radius
287  u = state->searchSize;
288  state->searchSize = 0.5*(u+l);
289  }
290  }
291  }
292  }
293  } // End While
294  /*************************************************************/
295  /******** Update Algorithm State *****************************/
296  /*************************************************************/
297  algo_state.aggregateModelError = aggLinErrNew_;
298  aggSubGradOldNorm_ = algo_state.aggregateGradientNorm;
299  aggLinErrOld_ = aggLinErrNew_;
300  } // End Compute
301 
302  void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj,
303  BoundConstraint<Real> &con, AlgorithmState<Real> &algo_state ) {
304  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
305  if ( !algo_state.flag ) {
306  /*************************************************************/
307  /******** Reset Bundle If Maximum Size Reached ***************/
308  /*************************************************************/
309  bundle_->reset(*aggSubGradNew_,aggLinErrNew_,algo_state.snorm);
310  /*************************************************************/
311  /******** Update Bundle with Step Information ****************/
312  /*************************************************************/
313  if ( step_flag_ ) {
314  // Serious step was taken
315  x.plus(s); // Update iterate
316  Real valueOld = algo_state.value; // Store previous objective value
317  algo_state.value = valueNew_; // Add new objective value to state
318  bundle_->update(step_flag_,valueNew_-valueOld,algo_state.snorm,*(state->gradientVec),s);
319  }
320  else {
321  // Null step was taken
322  bundle_->update(step_flag_,linErrNew_,algo_state.snorm,*(state->gradientVec),s);
323  }
324  }
325  /*************************************************************/
326  /******** Update Algorithm State *****************************/
327  /*************************************************************/
328  algo_state.iterateVec->set(x);
329  algo_state.gnorm = (state->gradientVec)->norm();
330  if ( step_flag_ ) {
331  algo_state.iter++;
332  }
333  } // End Update
334 
335  std::string printHeader( void ) const {
336  std::stringstream hist;
337  hist << " ";
338  hist << std::setw(6) << std::left << "iter";
339  hist << std::setw(15) << std::left << "value";
340  hist << std::setw(15) << std::left << "gnorm";
341  hist << std::setw(15) << std::left << "snorm";
342  hist << std::setw(10) << std::left << "#fval";
343  hist << std::setw(10) << std::left << "#grad";
344  hist << std::setw(15) << std::left << "znorm";
345  hist << std::setw(15) << std::left << "alpha";
346  hist << std::setw(15) << std::left << "TRparam";
347  hist << std::setw(10) << std::left << "QPiter";
348  hist << "\n";
349  return hist.str();
350  }
351 
352  std::string printName( void ) const {
353  std::stringstream hist;
354  hist << "\n" << "Bundle Trust-Region Algorithm \n";
355  return hist.str();
356  }
357 
358  std::string print( AlgorithmState<Real> &algo_state, bool print_header = false ) const {
359  Teuchos::RCP<const StepState<Real> > state = Step<Real>::getStepState();
360  std::stringstream hist;
361  hist << std::scientific << std::setprecision(6);
362  if ( algo_state.iter == 0 && first_print_ ) {
363  hist << printName();
364  if ( print_header ) {
365  hist << printHeader();
366  }
367  hist << " ";
368  hist << std::setw(6) << std::left << algo_state.iter;
369  hist << std::setw(15) << std::left << algo_state.value;
370  hist << std::setw(15) << std::left << algo_state.gnorm;
371  hist << "\n";
372  }
373  if ( step_flag_ && algo_state.iter > 0 ) {
374  if ( print_header ) {
375  hist << printHeader();
376  }
377  else {
378  hist << " ";
379  hist << std::setw(6) << std::left << algo_state.iter;
380  hist << std::setw(15) << std::left << algo_state.value;
381  hist << std::setw(15) << std::left << algo_state.gnorm;
382  hist << std::setw(15) << std::left << algo_state.snorm;
383  hist << std::setw(10) << std::left << algo_state.nfval;
384  hist << std::setw(10) << std::left << algo_state.ngrad;
385  hist << std::setw(15) << std::left << algo_state.aggregateGradientNorm;
386  hist << std::setw(15) << std::left << algo_state.aggregateModelError;
387  hist << std::setw(15) << std::left << state->searchSize;
388  hist << std::setw(10) << std::left << QPiter_;
389  hist << "\n";
390  }
391  }
392  return hist.str();
393  };
394 
395 }; // class BundleStep
396 
397 } // namespace ROL
398 
399 #endif
Provides the interface to evaluate objective functions.
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
Definition: ROL_Step.hpp:67
Teuchos::RCP< StepState< Real > > getState(void)
Definition: ROL_Step.hpp:72
Contains definitions of custom data types in ROL.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
std::string printName(void) const
Print step name.
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:157
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
virtual Real dot(const Vector &x) const =0
Compute where .
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:77
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual Teuchos::RCP< const StepState< Real > > getStepState(void) const
Get state for step object.
Definition: ROL_Step.hpp:192
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
Teuchos::RCP< Vector< Real > > y_
std::string printHeader(void) const
Print iterate header.
Provides the interface to apply upper and lower bound constraints.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Update step, if successful.
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Compute step.
Provides the interface to compute bundle trust-region steps.
Teuchos::RCP< Bundle< Real > > bundle_
virtual void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
Definition: ROL_Step.hpp:87
Teuchos::RCP< Vector< Real > > iterateVec
Definition: ROL_Types.hpp:91
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
Provides the interface for and implements a bundle. The semidefinite quadratic subproblem is solved u...
Teuchos::RCP< Vector< Real > > aggSubGradNew_
Teuchos::RCP< LineSearch< Real > > lineSearch_
BundleStep(Teuchos::ParameterList &parlist)
Provides the interface for and implments a bundle.
Definition: ROL_Bundle.hpp:62
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:118