ROL
ROL_ProjectedNewtonStep.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_PROJECTEDNEWTONSTEP_H
45 #define ROL_PROJECTEDNEWTONSTEP_H
46 
47 #include "ROL_Types.hpp"
48 #include "ROL_Step.hpp"
49 
56 namespace ROL {
57 
58 template <class Real>
59 class ProjectedNewtonStep : public Step<Real> {
60 private:
61 
62  ROL::Ptr<Vector<Real> > gp_;
63  ROL::Ptr<Vector<Real> > d_;
64  int verbosity_;
65  const bool computeObj_;
67 
68 public:
69 
71  using Step<Real>::compute;
72  using Step<Real>::update;
73 
81  ProjectedNewtonStep( ROL::ParameterList &parlist, const bool computeObj = true )
82  : Step<Real>(), gp_(ROL::nullPtr), d_(ROL::nullPtr),
83  verbosity_(0), computeObj_(computeObj), useProjectedGrad_(false) {
84  // Parse ParameterList
85  ROL::ParameterList& Glist = parlist.sublist("General");
86  useProjectedGrad_ = Glist.get("Projected Gradient Criticality Measure", false);
87  verbosity_ = parlist.sublist("General").get("Print Verbosity",0);
88  }
89 
90  void initialize( Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g,
92  AlgorithmState<Real> &algo_state ) {
93  Step<Real>::initialize(x,s,g,obj,bnd,algo_state);
94  gp_ = g.clone();
95  d_ = s.clone();
96  }
97 
98  void compute( Vector<Real> &s, const Vector<Real> &x,
100  AlgorithmState<Real> &algo_state ) {
101  Real tol = std::sqrt(ROL_EPSILON<Real>()), one(1);
102  ROL::Ptr<StepState<Real> > step_state = Step<Real>::getState();
103 
104  // Compute projected Newton step
105  // ---> Apply inactive-inactive block of inverse hessian to gradient
106  gp_->set(*(step_state->gradientVec));
107  bnd.pruneActive(*gp_,*(step_state->gradientVec),x,algo_state.gnorm);
108  obj.invHessVec(s,*gp_,x,tol);
109  bnd.pruneActive(s,*(step_state->gradientVec),x,algo_state.gnorm);
110  // ---> Add in active gradient components
111  gp_->set(*(step_state->gradientVec));
112  bnd.pruneInactive(*gp_,*(step_state->gradientVec),x,algo_state.gnorm);
113  s.plus(gp_->dual());
114  s.scale(-one);
115  }
116 
117  void update( Vector<Real> &x, const Vector<Real> &s,
119  AlgorithmState<Real> &algo_state ) {
120  Real tol = std::sqrt(ROL_EPSILON<Real>()), one(1);
121  ROL::Ptr<StepState<Real> > step_state = Step<Real>::getState();
122 
123  // Update iterate and store previous step
124  algo_state.iter++;
125  d_->set(x);
126  x.plus(s);
127  bnd.project(x);
128  (step_state->descentVec)->set(x);
129  (step_state->descentVec)->axpy(-one,*d_);
130  algo_state.snorm = s.norm();
131 
132  // Compute new gradient
133  obj.update(x,true,algo_state.iter);
134  if ( computeObj_ ) {
135  algo_state.value = obj.value(x,tol);
136  algo_state.nfval++;
137  }
138  obj.gradient(*(step_state->gradientVec),x,tol);
139  algo_state.ngrad++;
140 
141  // Update algorithm state
142  (algo_state.iterateVec)->set(x);
143  if ( useProjectedGrad_ ) {
144  gp_->set(*(step_state->gradientVec));
145  bnd.computeProjectedGradient( *gp_, x );
146  algo_state.gnorm = gp_->norm();
147  }
148  else {
149  d_->set(x);
150  d_->axpy(-one,(step_state->gradientVec)->dual());
151  bnd.project(*d_);
152  d_->axpy(-one,x);
153  algo_state.gnorm = d_->norm();
154  }
155  }
156 
157  std::string printHeader( void ) const {
158  std::stringstream hist;
159 
160  if( verbosity_>0 ) {
161  hist << std::string(109,'-') << "\n";
163  hist << " status output definitions\n\n";
164  hist << " iter - Number of iterates (steps taken) \n";
165  hist << " value - Objective function value \n";
166  hist << " gnorm - Norm of the gradient\n";
167  hist << " snorm - Norm of the step (update to optimization vector)\n";
168  hist << " #fval - Cumulative number of times the objective function was evaluated\n";
169  hist << " #grad - Number of times the gradient was computed\n";
170  hist << std::string(109,'-') << "\n";
171  }
172 
173  hist << " ";
174  hist << std::setw(6) << std::left << "iter";
175  hist << std::setw(15) << std::left << "value";
176  hist << std::setw(15) << std::left << "gnorm";
177  hist << std::setw(15) << std::left << "snorm";
178  hist << std::setw(10) << std::left << "#fval";
179  hist << std::setw(10) << std::left << "#grad";
180  hist << "\n";
181  return hist.str();
182  }
183  std::string printName( void ) const {
184  std::stringstream hist;
185  hist << "\n" << EDescentToString(DESCENT_NEWTON) << "\n";
186  return hist.str();
187  }
188  std::string print( AlgorithmState<Real> &algo_state, bool print_header = false ) const {
189  std::stringstream hist;
190  hist << std::scientific << std::setprecision(6);
191  if ( algo_state.iter == 0 ) {
192  hist << printName();
193  }
194  if ( print_header ) {
195  hist << printHeader();
196  }
197  if ( algo_state.iter == 0 ) {
198  hist << " ";
199  hist << std::setw(6) << std::left << algo_state.iter;
200  hist << std::setw(15) << std::left << algo_state.value;
201  hist << std::setw(15) << std::left << algo_state.gnorm;
202  hist << "\n";
203  }
204  else {
205  hist << " ";
206  hist << std::setw(6) << std::left << algo_state.iter;
207  hist << std::setw(15) << std::left << algo_state.value;
208  hist << std::setw(15) << std::left << algo_state.gnorm;
209  hist << std::setw(15) << std::left << algo_state.snorm;
210  hist << std::setw(10) << std::left << algo_state.nfval;
211  hist << std::setw(10) << std::left << algo_state.ngrad;
212  hist << "\n";
213  }
214  return hist.str();
215  }
216 }; // class ProjectedNewtonStep
217 
218 } // namespace ROL
219 
220 #endif
Provides the interface to evaluate objective functions.
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 plus(const Vector &x)=0
Compute , where .
ROL::Ptr< Vector< Real > > gp_
Additional vector storage.
Provides the interface to compute optimization steps with projected Newton&#39;s method using line search...
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
Definition: ROL_Step.hpp:68
Contains definitions of custom data types in ROL.
void pruneInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=0)
Set variables to zero if they correspond to the -inactive set.
void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0)
Set variables to zero if they correspond to the -active set.
std::string printHeader(void) const
Print iterate header.
std::string printName(void) const
Print step name.
std::string EDescentToString(EDescent tr)
Definition: ROL_Types.hpp:418
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step.
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:143
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
ProjectedNewtonStep(ROL::ParameterList &parlist, const bool computeObj=true)
Constructor.
ROL::Ptr< StepState< Real > > getState(void)
Definition: ROL_Step.hpp:73
ROL::Ptr< Vector< Real > > iterateVec
Definition: ROL_Types.hpp:157
ROL::Ptr< Vector< Real > > d_
Additional vector storage.
virtual void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply inverse Hessian approximation to vector.
Provides the interface to apply upper and lower bound constraints.
void computeProjectedGradient(Vector< Real > &g, const Vector< Real > &x)
Compute projected gradient.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful.
bool useProjectedGrad_
Whether or not to use to the projected gradient criticality measure.
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:88
void initialize(Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
virtual Real norm() const =0
Returns where .
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.