ROL
ROL_SecantStep.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_SECANTSTEP_H
45#define ROL_SECANTSTEP_H
46
47#include "ROL_Types.hpp"
48#include "ROL_Step.hpp"
49#include "ROL_Secant.hpp"
50
57namespace ROL {
58
59template <class Real>
60class SecantStep : public Step<Real> {
61private:
62
63 ROL::Ptr<Secant<Real> > secant_;
65 ROL::Ptr<Vector<Real> > gp_;
68
69 std::string secantName_;
70
71public:
72
73 using Step<Real>::initialize;
74 using Step<Real>::compute;
75 using Step<Real>::update;
76
86 SecantStep( ROL::ParameterList &parlist,
87 const ROL::Ptr<Secant<Real> > &secant = ROL::nullPtr,
88 const bool computeObj = true )
89 : Step<Real>(), secant_(secant), esec_(SECANT_USERDEFINED),
90 gp_(ROL::nullPtr), verbosity_(0), computeObj_(computeObj) {
91 // Parse ParameterList
92 verbosity_ = parlist.sublist("General").get("Print Verbosity",0);
93 // Initialize secant object
94 if ( secant == ROL::nullPtr ) {
95 secantName_ = parlist.sublist("General").sublist("Secant").get("Type","Limited-Memory BFGS");
97 secant_ = SecantFactory<Real>(parlist);
98 }
99 else {
100 secantName_ = parlist.sublist("General").sublist("Secant").get("User Defined Secant Name",
101 "Unspecified User Defined Secant Method");
102 }
103 }
104
105 void initialize( Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g,
107 AlgorithmState<Real> &algo_state ) {
108 Step<Real>::initialize(x,s,g,obj,con,algo_state);
109 gp_ = g.clone();
110 }
111
114 AlgorithmState<Real> &algo_state ) {
115 Real one(1);
116 ROL::Ptr<StepState<Real> > step_state = Step<Real>::getState();
117
118 // Compute search direction
119 secant_->applyH(s,*(step_state->gradientVec));
120 s.scale(-one);
121 }
122
124 AlgorithmState<Real> &algo_state ) {
125 Real tol = std::sqrt(ROL_EPSILON<Real>());
126 ROL::Ptr<StepState<Real> > step_state = Step<Real>::getState();
127
128 // Update iterate
129 algo_state.iter++;
130 x.plus(s);
131 (step_state->descentVec)->set(s);
132 algo_state.snorm = s.norm();
133
134 // Compute new gradient
135 gp_->set(*(step_state->gradientVec));
136 obj.update(x,true,algo_state.iter);
137 if ( computeObj_ ) {
138 algo_state.value = obj.value(x,tol);
139 algo_state.nfval++;
140 }
141 obj.gradient(*(step_state->gradientVec),x,tol);
142 algo_state.ngrad++;
143
144 // Update Secant Information
145 secant_->updateStorage(x,*(step_state->gradientVec),*gp_,s,algo_state.snorm,algo_state.iter+1);
146
147 // Update algorithm state
148 (algo_state.iterateVec)->set(x);
149 algo_state.gnorm = (step_state->gradientVec)->norm();
150 }
151
152 std::string printHeader( void ) const {
153 std::stringstream hist;
154
155 if( verbosity_>0 ) {
156 hist << std::string(109,'-') << "\n";
158 hist << " status output definitions\n\n";
159 hist << " iter - Number of iterates (steps taken) \n";
160 hist << " value - Objective function value \n";
161 hist << " gnorm - Norm of the gradient\n";
162 hist << " snorm - Norm of the step (update to optimization vector)\n";
163 hist << " #fval - Cumulative number of times the objective function was evaluated\n";
164 hist << " #grad - Number of times the gradient was computed\n";
165 hist << std::string(109,'-') << "\n";
166 }
167
168 hist << " ";
169 hist << std::setw(6) << std::left << "iter";
170 hist << std::setw(15) << std::left << "value";
171 hist << std::setw(15) << std::left << "gnorm";
172 hist << std::setw(15) << std::left << "snorm";
173 hist << std::setw(10) << std::left << "#fval";
174 hist << std::setw(10) << std::left << "#grad";
175 hist << "\n";
176 return hist.str();
177 }
178 std::string printName( void ) const {
179 std::stringstream hist;
180 hist << "\n" << EDescentToString(DESCENT_SECANT);
181 hist << " with " << secantName_ << "\n";
182 return hist.str();
183 }
184 std::string print( AlgorithmState<Real> &algo_state, bool print_header = false ) const {
185 std::stringstream hist;
186 hist << std::scientific << std::setprecision(6);
187 if ( algo_state.iter == 0 ) {
188 hist << printName();
189 }
190 if ( print_header ) {
191 hist << printHeader();
192 }
193 if ( algo_state.iter == 0 ) {
194 hist << " ";
195 hist << std::setw(6) << std::left << algo_state.iter;
196 hist << std::setw(15) << std::left << algo_state.value;
197 hist << std::setw(15) << std::left << algo_state.gnorm;
198 hist << "\n";
199 }
200 else {
201 hist << " ";
202 hist << std::setw(6) << std::left << algo_state.iter;
203 hist << std::setw(15) << std::left << algo_state.value;
204 hist << std::setw(15) << std::left << algo_state.gnorm;
205 hist << std::setw(15) << std::left << algo_state.snorm;
206 hist << std::setw(10) << std::left << algo_state.nfval;
207 hist << std::setw(10) << std::left << algo_state.ngrad;
208 hist << "\n";
209 }
210 return hist.str();
211 }
212}; // class SecantStep
213
214} // namespace ROL
215
216#endif
Contains definitions of custom data types in ROL.
Provides the interface to apply upper and lower bound constraints.
Provides the interface to evaluate objective functions.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
Provides the interface to compute optimization steps with a secant method.
std::string printName(void) const
Print step name.
std::string secantName_
SecantStep(ROL::ParameterList &parlist, const ROL::Ptr< Secant< Real > > &secant=ROL::nullPtr, const bool computeObj=true)
Constructor.
std::string printHeader(void) const
Print iterate header.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step.
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
ROL::Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton)
int verbosity_
Verbosity setting.
void initialize(Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Update step, if successful.
ROL::Ptr< Vector< Real > > gp_
Additional vector storage.
Provides interface for and implements limited-memory secant operators.
Provides the interface to compute optimization steps.
Definition ROL_Step.hpp:68
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
ROL::Ptr< StepState< Real > > getState(void)
Definition ROL_Step.hpp:73
Defines the linear algebra or vector space interface.
virtual Real norm() const =0
Returns where .
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
@ DESCENT_SECANT
ESecant StringToESecant(std::string s)
@ SECANT_USERDEFINED
std::string EDescentToString(EDescent tr)
State for algorithm class. Will be used for restarts.
ROL::Ptr< Vector< Real > > iterateVec