44 #ifndef ROL_NEWTONKRYLOVSTEP_H 45 #define ROL_NEWTONKRYLOVSTEP_H 75 Teuchos::RCP<Vector<Real> >
gp_;
90 const Teuchos::RCP<Objective<Real> >
obj_;
91 const Teuchos::RCP<Vector<Real> >
x_;
94 const Teuchos::RCP<
Vector<Real> > &x) : obj_(obj), x_(x) {}
96 obj_->hessVec(Hv,v,*x_,tol);
102 const Teuchos::RCP<Objective<Real> >
obj_;
103 const Teuchos::RCP<Vector<Real> >
x_;
106 const Teuchos::RCP<
Vector<Real> > &x) : obj_(obj), x_(x) {}
111 obj_->precond(Hv,v,*x_,tol);
129 :
Step<Real>(), secant_(Teuchos::null), krylov_(Teuchos::null),
130 gp_(Teuchos::null), iterKrylov_(0), flagKrylov_(0),
131 verbosity_(0), computeObj_(computeObj), useSecantPrecond_(false) {
133 Teuchos::ParameterList& Glist = parlist.sublist(
"General");
134 useSecantPrecond_ = Glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
135 verbosity_ = Glist.get(
"Print Verbosity",0);
137 krylovName_ = Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients");
139 krylov_ = KrylovFactory<Real>(parlist);
141 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
143 if ( useSecantPrecond_ ) {
144 secant_ = SecantFactory<Real>(parlist);
161 const bool computeObj =
true)
162 :
Step<Real>(), secant_(secant), krylov_(krylov),
164 gp_(Teuchos::null), iterKrylov_(0), flagKrylov_(0),
165 verbosity_(0), computeObj_(computeObj), useSecantPrecond_(false) {
167 Teuchos::ParameterList& Glist = parlist.sublist(
"General");
168 useSecantPrecond_ = Glist.sublist(
"Secant").get(
"Use as Preconditioner",
false);
169 verbosity_ = Glist.get(
"Print Verbosity",0);
171 if ( useSecantPrecond_ ) {
172 if(secant_ == Teuchos::null ) {
173 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
175 secant_ = SecantFactory<Real>(parlist);
178 secantName_ = Glist.sublist(
"Secant").get(
"User Defined Secant Name",
179 "Unspecified User Defined Secant Method");
183 if ( krylov_ == Teuchos::null ) {
184 krylovName_ = Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients");
186 krylov_ = KrylovFactory<Real>(parlist);
189 krylovName_ = Glist.sublist(
"Krylov").get(
"User Defined Krylov Name",
190 "Unspecified User Defined Krylov Method");
198 if ( useSecantPrecond_ ) {
210 Teuchos::RCP<Objective<Real> > obj_ptr = Teuchos::rcpFromRef(obj);
211 Teuchos::RCP<LinearOperator<Real> > hessian
213 Teuchos::RCP<LinearOperator<Real> > precond;
214 if ( useSecantPrecond_ ) {
223 krylov_->run(s,*hessian,*(step_state->gradientVec),*precond,iterKrylov_,flagKrylov_);
226 if ( flagKrylov_ == 2 && iterKrylov_ <= 1 ) {
227 s.
set((step_state->gradientVec)->dual());
235 Real tol = std::sqrt(ROL_EPSILON<Real>());
241 (step_state->descentVec)->
set(s);
245 if ( useSecantPrecond_ ) {
246 gp_->set(*(step_state->gradientVec));
253 obj.
gradient(*(step_state->gradientVec),x,tol);
257 if ( useSecantPrecond_ ) {
258 secant_->updateStorage(x,*(step_state->gradientVec),*gp_,s,algo_state.
snorm,algo_state.
iter+1);
263 algo_state.
gnorm = step_state->gradientVec->norm();
267 std::stringstream hist;
270 hist << std::string(109,
'-') <<
"\n";
272 hist <<
" status output definitions\n\n";
273 hist <<
" iter - Number of iterates (steps taken) \n";
274 hist <<
" value - Objective function value \n";
275 hist <<
" gnorm - Norm of the gradient\n";
276 hist <<
" snorm - Norm of the step (update to optimization vector)\n";
277 hist <<
" #fval - Cumulative number of times the objective function was evaluated\n";
278 hist <<
" #grad - Number of times the gradient was computed\n";
279 hist <<
" iterCG - Number of Krylov iterations used to compute search direction\n";
280 hist <<
" flagCG - Krylov solver flag" <<
"\n";
281 hist << std::string(109,
'-') <<
"\n";
285 hist << std::setw(6) << std::left <<
"iter";
286 hist << std::setw(15) << std::left <<
"value";
287 hist << std::setw(15) << std::left <<
"gnorm";
288 hist << std::setw(15) << std::left <<
"snorm";
289 hist << std::setw(10) << std::left <<
"#fval";
290 hist << std::setw(10) << std::left <<
"#grad";
291 hist << std::setw(10) << std::left <<
"iterCG";
292 hist << std::setw(10) << std::left <<
"flagCG";
297 std::stringstream hist;
300 if ( useSecantPrecond_ ) {
307 std::stringstream hist;
308 hist << std::scientific << std::setprecision(6);
309 if ( algo_state.
iter == 0 ) {
312 if ( print_header ) {
315 if ( algo_state.
iter == 0 ) {
317 hist << std::setw(6) << std::left << algo_state.
iter;
318 hist << std::setw(15) << std::left << algo_state.
value;
319 hist << std::setw(15) << std::left << algo_state.
gnorm;
324 hist << std::setw(6) << std::left << algo_state.
iter;
325 hist << std::setw(15) << std::left << algo_state.
value;
326 hist << std::setw(15) << std::left << algo_state.
gnorm;
327 hist << std::setw(15) << std::left << algo_state.
snorm;
328 hist << std::setw(10) << std::left << algo_state.
nfval;
329 hist << std::setw(10) << std::left << algo_state.
ngrad;
const Teuchos::RCP< Vector< Real > > x_
Provides the interface to evaluate objective functions.
virtual void scale(const Real alpha)=0
Compute where .
Teuchos::RCP< Vector< Real > > gp_
virtual void plus(const Vector &x)=0
Compute , where .
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
int verbosity_
Verbosity level.
const Teuchos::RCP< Objective< Real > > obj_
Teuchos::RCP< StepState< Real > > getState(void)
Contains definitions of custom data types in ROL.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Teuchos::RCP< Krylov< Real > > krylov_
Krylov solver object (used for inexact Newton)
ESecant StringToESecant(std::string s)
std::string EDescentToString(EDescent tr)
PrecondNK(const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< Vector< Real > > &x)
int flagKrylov_
Termination flag for Krylov method (used for inexact Newton)
Defines the linear algebra or vector space interface.
EKrylov
Enumeration of Krylov methods.
EKrylov StringToEKrylov(std::string s)
State for algorithm class. Will be used for restarts.
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 void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
std::string printHeader(void) const
Print iterate header.
HessianNK(const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< Vector< Real > > &x)
ESecant
Enumeration of secant update algorithms.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step.
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
Provides interface for and implements limited-memory secant operators.
Provides definitions for Krylov solvers.
Provides the interface to apply a linear operator.
Provides the interface to apply upper and lower bound constraints.
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
NewtonKrylovStep(Teuchos::ParameterList &parlist, const bool computeObj=true)
Constructor.
Provides the interface to compute optimization steps with projected inexact Newton's method using lin...
int iterKrylov_
Number of Krylov iterations (used for inexact Newton)
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.
Teuchos::RCP< Vector< Real > > iterateVec
virtual void set(const Vector &x)
Set where .
virtual Real norm() const =0
Returns where .
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
Teuchos::RCP< Secant< Real > > secant_
Secant object (used for quasi-Newton)
std::string printName(void) const
Print step name.
const Teuchos::RCP< Vector< Real > > x_
bool useSecantPrecond_
Whether or not a secant approximation is used for preconditioning inexact Newton. ...
std::string ESecantToString(ESecant tr)
const Teuchos::RCP< Objective< Real > > obj_
NewtonKrylovStep(Teuchos::ParameterList &parlist, const Teuchos::RCP< Krylov< Real > > &krylov, const Teuchos::RCP< Secant< Real > > &secant, const bool computeObj=true)
Constructor.