44#ifndef ROL_NEWTONKRYLOVSTEP_H
45#define ROL_NEWTONKRYLOVSTEP_H
75 ROL::Ptr<Vector<Real> >
gp_;
90 const ROL::Ptr<Objective<Real> >
obj_;
91 const ROL::Ptr<Vector<Real> >
x_;
96 obj_->hessVec(Hv,v,*
x_,tol);
102 const ROL::Ptr<Objective<Real> >
obj_;
103 const ROL::Ptr<Vector<Real> >
x_;
111 obj_->precond(Hv,v,*
x_,tol);
133 ROL::ParameterList& Glist = parlist.sublist(
"General");
137 krylovName_ = Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients");
141 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
161 const bool computeObj =
true)
167 ROL::ParameterList& Glist = parlist.sublist(
"General");
173 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
178 secantName_ = Glist.sublist(
"Secant").get(
"User Defined Secant Name",
179 "Unspecified User Defined Secant Method");
183 if (
krylov_ == ROL::nullPtr ) {
184 krylovName_ = Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients");
189 krylovName_ = Glist.sublist(
"Krylov").get(
"User Defined Krylov Name",
190 "Unspecified User Defined Krylov Method");
210 ROL::Ptr<Objective<Real> > obj_ptr = ROL::makePtrFromRef(obj);
211 ROL::Ptr<LinearOperator<Real> > hessian
212 = ROL::makePtr<HessianNK>(obj_ptr,algo_state.
iterateVec);
213 ROL::Ptr<LinearOperator<Real> > precond;
218 precond = ROL::makePtr<PrecondNK>(obj_ptr,algo_state.
iterateVec);
227 s.
set((step_state->gradientVec)->dual());
243 (step_state->descentVec)->set(s);
248 gp_->set(*(step_state->gradientVec));
255 obj.
gradient(*(step_state->gradientVec),x,tol);
260 secant_->updateStorage(x,*(step_state->gradientVec),*
gp_,s,algo_state.
snorm,algo_state.
iter+1);
265 algo_state.
gnorm = step_state->gradientVec->norm();
269 std::stringstream hist;
272 hist << std::string(109,
'-') <<
"\n";
274 hist <<
" status output definitions\n\n";
275 hist <<
" iter - Number of iterates (steps taken) \n";
276 hist <<
" value - Objective function value \n";
277 hist <<
" gnorm - Norm of the gradient\n";
278 hist <<
" snorm - Norm of the step (update to optimization vector)\n";
279 hist <<
" #fval - Cumulative number of times the objective function was evaluated\n";
280 hist <<
" #grad - Number of times the gradient was computed\n";
281 hist <<
" iterCG - Number of Krylov iterations used to compute search direction\n";
282 hist <<
" flagCG - Krylov solver flag" <<
"\n";
283 hist << std::string(109,
'-') <<
"\n";
287 hist << std::setw(6) << std::left <<
"iter";
288 hist << std::setw(15) << std::left <<
"value";
289 hist << std::setw(15) << std::left <<
"gnorm";
290 hist << std::setw(15) << std::left <<
"snorm";
291 hist << std::setw(10) << std::left <<
"#fval";
292 hist << std::setw(10) << std::left <<
"#grad";
293 hist << std::setw(10) << std::left <<
"iterCG";
294 hist << std::setw(10) << std::left <<
"flagCG";
299 std::stringstream hist;
309 std::stringstream hist;
310 hist << std::scientific << std::setprecision(6);
311 if ( algo_state.
iter == 0 ) {
314 if ( print_header ) {
317 if ( algo_state.
iter == 0 ) {
319 hist << std::setw(6) << std::left << algo_state.
iter;
320 hist << std::setw(15) << std::left << algo_state.
value;
321 hist << std::setw(15) << std::left << algo_state.
gnorm;
326 hist << std::setw(6) << std::left << algo_state.
iter;
327 hist << std::setw(15) << std::left << algo_state.
value;
328 hist << std::setw(15) << std::left << algo_state.
gnorm;
329 hist << std::setw(15) << std::left << algo_state.
snorm;
330 hist << std::setw(10) << std::left << algo_state.
nfval;
331 hist << std::setw(10) << std::left << algo_state.
ngrad;
virtual void update(const Vector< Real > &u_old, const Vector< Real > &u_new, const Vector< Real > &z, bool flag=true, int iter=-1)
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Contains definitions of custom data types in ROL.
Provides the interface to apply upper and lower bound constraints.
Provides definitions for Krylov solvers.
Provides the interface to apply a linear operator.
const ROL::Ptr< Objective< Real > > obj_
HessianNK(const ROL::Ptr< Objective< Real > > &obj, const ROL::Ptr< Vector< Real > > &x)
const ROL::Ptr< Vector< Real > > x_
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
const ROL::Ptr< Vector< Real > > x_
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
const ROL::Ptr< Objective< Real > > obj_
PrecondNK(const ROL::Ptr< Objective< Real > > &obj, const ROL::Ptr< Vector< Real > > &x)
ROL::Ptr< Vector< Real > > gp_
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
ROL::Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton).
int flagKrylov_
Termination flag for Krylov method (used for inexact Newton).
int verbosity_
Verbosity level.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
bool useSecantPrecond_
Whether or not a secant approximation is used for preconditioning inexact Newton.
void initialize(Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
int iterKrylov_
Number of Krylov iterations (used for inexact Newton).
std::string printName(void) const
Print step name.
NewtonKrylovStep(ROL::ParameterList &parlist, const bool computeObj=true)
Constructor.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
std::string printHeader(void) const
Print iterate header.
NewtonKrylovStep(ROL::ParameterList &parlist, const ROL::Ptr< Krylov< Real > > &krylov, const ROL::Ptr< Secant< Real > > &secant, const bool computeObj=true)
Constructor.
ROL::Ptr< Krylov< Real > > krylov_
Krylov solver object (used for inexact Newton).
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 interface for and implements limited-memory secant operators.
Provides the interface to compute optimization steps.
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.
ROL::Ptr< StepState< Real > > getState(void)
Defines the linear algebra or vector space interface.
virtual Real norm() const =0
Returns where .
virtual void set(const Vector &x)
Set where .
virtual void scale(const Real alpha)=0
Compute where .
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
EKrylov StringToEKrylov(std::string s)
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
ESecant StringToESecant(std::string s)
Ptr< Krylov< Real > > KrylovFactory(ParameterList &parlist)
std::string EDescentToString(EDescent tr)
ROL::Ptr< Secant< Real > > SecantFactory(ROL::ParameterList &parlist, ESecantMode mode=SECANTMODE_BOTH)
std::string ESecantToString(ESecant tr)
State for algorithm class. Will be used for restarts.
ROL::Ptr< Vector< Real > > iterateVec