10#ifndef ROL_NEWTONKRYLOVSTEP_H
11#define ROL_NEWTONKRYLOVSTEP_H
41 ROL::Ptr<Vector<Real> >
gp_;
56 const ROL::Ptr<Objective<Real> >
obj_;
57 const ROL::Ptr<Vector<Real> >
x_;
62 obj_->hessVec(Hv,v,*
x_,tol);
68 const ROL::Ptr<Objective<Real> >
obj_;
69 const ROL::Ptr<Vector<Real> >
x_;
77 obj_->precond(Hv,v,*
x_,tol);
99 ROL::ParameterList& Glist = parlist.sublist(
"General");
103 krylovName_ = Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients");
107 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
127 const bool computeObj =
true)
133 ROL::ParameterList& Glist = parlist.sublist(
"General");
139 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
144 secantName_ = Glist.sublist(
"Secant").get(
"User Defined Secant Name",
145 "Unspecified User Defined Secant Method");
149 if (
krylov_ == ROL::nullPtr ) {
150 krylovName_ = Glist.sublist(
"Krylov").get(
"Type",
"Conjugate Gradients");
155 krylovName_ = Glist.sublist(
"Krylov").get(
"User Defined Krylov Name",
156 "Unspecified User Defined Krylov Method");
176 ROL::Ptr<Objective<Real> > obj_ptr = ROL::makePtrFromRef(obj);
177 ROL::Ptr<LinearOperator<Real> > hessian
178 = ROL::makePtr<HessianNK>(obj_ptr,algo_state.
iterateVec);
179 ROL::Ptr<LinearOperator<Real> > precond;
184 precond = ROL::makePtr<PrecondNK>(obj_ptr,algo_state.
iterateVec);
193 s.
set((step_state->gradientVec)->dual());
209 (step_state->descentVec)->set(s);
214 gp_->set(*(step_state->gradientVec));
221 obj.
gradient(*(step_state->gradientVec),x,tol);
226 secant_->updateStorage(x,*(step_state->gradientVec),*
gp_,s,algo_state.
snorm,algo_state.
iter+1);
231 algo_state.
gnorm = step_state->gradientVec->norm();
235 std::stringstream hist;
238 hist << std::string(109,
'-') <<
"\n";
240 hist <<
" status output definitions\n\n";
241 hist <<
" iter - Number of iterates (steps taken) \n";
242 hist <<
" value - Objective function value \n";
243 hist <<
" gnorm - Norm of the gradient\n";
244 hist <<
" snorm - Norm of the step (update to optimization vector)\n";
245 hist <<
" #fval - Cumulative number of times the objective function was evaluated\n";
246 hist <<
" #grad - Number of times the gradient was computed\n";
247 hist <<
" iterCG - Number of Krylov iterations used to compute search direction\n";
248 hist <<
" flagCG - Krylov solver flag" <<
"\n";
249 hist << std::string(109,
'-') <<
"\n";
253 hist << std::setw(6) << std::left <<
"iter";
254 hist << std::setw(15) << std::left <<
"value";
255 hist << std::setw(15) << std::left <<
"gnorm";
256 hist << std::setw(15) << std::left <<
"snorm";
257 hist << std::setw(10) << std::left <<
"#fval";
258 hist << std::setw(10) << std::left <<
"#grad";
259 hist << std::setw(10) << std::left <<
"iterCG";
260 hist << std::setw(10) << std::left <<
"flagCG";
265 std::stringstream hist;
275 std::stringstream hist;
276 hist << std::scientific << std::setprecision(6);
277 if ( algo_state.
iter == 0 ) {
280 if ( print_header ) {
283 if ( algo_state.
iter == 0 ) {
285 hist << std::setw(6) << std::left << algo_state.
iter;
286 hist << std::setw(15) << std::left << algo_state.
value;
287 hist << std::setw(15) << std::left << algo_state.
gnorm;
292 hist << std::setw(6) << std::left << algo_state.
iter;
293 hist << std::setw(15) << std::left << algo_state.
value;
294 hist << std::setw(15) << std::left << algo_state.
gnorm;
295 hist << std::setw(15) << std::left << algo_state.
snorm;
296 hist << std::setw(10) << std::left << algo_state.
nfval;
297 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
Print iterate status.
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)
Compute step.
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)
Initialize step with bound constraint.
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)
Update step, if successful.
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