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");
139 krylov_ = KrylovFactory<Real>(parlist);
141 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
144 secant_ = SecantFactory<Real>(parlist);
161 const bool computeObj =
true)
167 ROL::ParameterList& Glist = parlist.sublist(
"General");
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_ == ROL::nullPtr ) {
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");
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());
235 Real tol = std::sqrt(ROL_EPSILON<Real>());
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;
Provides the interface to evaluate objective functions.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
virtual void scale(const Real alpha)=0
Compute where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
PrecondNK(const ROL::Ptr< Objective< Real > > &obj, const ROL::Ptr< Vector< Real > > &x)
virtual void plus(const Vector &x)=0
Compute , where .
NewtonKrylovStep(ROL::ParameterList &parlist, const ROL::Ptr< Krylov< Real > > &krylov, const ROL::Ptr< Secant< Real > > &secant, 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.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
ROL::Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton)
int verbosity_
Verbosity level.
Contains definitions of custom data types in ROL.
std::string printName(void) const
Print step name.
ROL::Ptr< Krylov< Real > > krylov_
Krylov solver object (used for inexact Newton)
ESecant StringToESecant(std::string s)
std::string EDescentToString(EDescent tr)
int flagKrylov_
Termination flag for Krylov method (used for inexact Newton)
Defines the linear algebra or vector space interface.
const ROL::Ptr< Vector< Real > > x_
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.
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
ESecant
Enumeration of secant update algorithms.
ROL::Ptr< StepState< Real > > getState(void)
HessianNK(const ROL::Ptr< Objective< Real > > &obj, const ROL::Ptr< Vector< Real > > &x)
NewtonKrylovStep(ROL::ParameterList &parlist, const bool computeObj=true)
Constructor.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step.
Provides interface for and implements limited-memory secant operators.
ROL::Ptr< Vector< Real > > iterateVec
std::string printHeader(void) const
Print iterate header.
void applyInverse(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply inverse of linear operator.
ROL::Ptr< Vector< Real > > gp_
Provides definitions for Krylov solvers.
Provides the interface to apply a linear operator.
const ROL::Ptr< Vector< Real > > x_
Provides the interface to apply upper and lower bound constraints.
Provides the interface to compute optimization steps with projected inexact Newton's method using lin...
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
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.
const ROL::Ptr< Objective< Real > > obj_
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.
bool useSecantPrecond_
Whether or not a secant approximation is used for preconditioning inexact Newton. ...
std::string ESecantToString(ESecant tr)
const ROL::Ptr< Objective< Real > > obj_