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");
105 krylov_ = KrylovFactory<Real>(parlist);
107 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
110 secant_ = SecantFactory<Real>(parlist);
127 const bool computeObj =
true)
133 ROL::ParameterList& Glist = parlist.sublist(
"General");
139 secantName_ = Glist.sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
141 secant_ = SecantFactory<Real>(parlist);
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");
152 krylov_ = KrylovFactory<Real>(parlist);
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());
201 Real tol = std::sqrt(ROL_EPSILON<Real>());
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;
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.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
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 .
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_