10#ifndef ROL_TYPEB_NEWTONKRYLOVALGORITHM_DEF_HPP
11#define ROL_TYPEB_NEWTONKRYLOVALGORITHM_DEF_HPP
16template<
typename Real>
23 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
28 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"User Defined Secant Name",
29 "Unspecified User Defined Secant Method");
32 krylovName_ = list.sublist(
"General").sublist(
"Krylov").get(
"Type",
"Conjugate Gradients");
37template<
typename Real>
45 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
50 secantName_ = list.sublist(
"General").sublist(
"Secant").get(
"User Defined Secant Name",
51 "Unspecified User Defined Secant Method");
54 krylovName_ = list.sublist(
"General").sublist(
"Krylov").get(
"User Defined Krylov Name",
55 "Unspecified User Defined Krylov Method");
58template<
typename Real>
65 ParameterList &lslist = list.sublist(
"Step").sublist(
"Line Search");
66 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
67 alpha0_ = lslist.get(
"Initial Step Size", 1.0);
68 useralpha_ = lslist.get(
"User Defined Initial Step Size",
false);
69 usePrevAlpha_ = lslist.get(
"Use Previous Step Length as Initial Guess",
false);
70 c1_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
71 rhodec_ = lslist.sublist(
"Line-Search Method").get(
"Backtracking Rate", 0.5);
73 useSecantHessVec_ = list.sublist(
"General").sublist(
"Secant").get(
"Use as Hessian",
false);
74 useSecantPrecond_ = list.sublist(
"General").sublist(
"Secant").get(
"Use as Preconditioner",
false);
76 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
80template<
typename Real>
85 std::ostream &outStream) {
87 if (
proj_ == nullPtr) {
88 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
94 proj_->project(x,outStream);
95 state_->iterateVec->set(x);
100 state_->stepVec->axpy(-one,
state_->gradientVec->dual());
102 state_->stepVec->axpy(-one,x);
109template<
typename Real>
114 std::ostream &outStream ) {
119 Ptr<Vector<Real>> pwa = x.
clone(), pwa1 = x.
clone();
122 Ptr<LinearOperator<Real>> hessian, precond;
128 gp->set(
state_->gradientVec->dual());
131 hessian = makePtr<HessianPNK>(makePtrFromRef(obj),makePtrFromRef(bnd),
134 precond = makePtr<PrecondPNK>(makePtrFromRef(obj),makePtrFromRef(bnd),
146 proj_->project(x,outStream);
151 gs =
state_->stepVec->dot(*gp);
153 outStream <<
" In TypeB::NewtonKrylovAlgorithm: Line Search" << std::endl;
154 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
155 outStream <<
" Trial objective value: " << ftrial << std::endl;
156 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
157 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
158 outStream <<
" Sufficient decrease bound: " << -gs*
c1_ << std::endl;
159 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
165 proj_->project(x,outStream);
170 gs =
state_->stepVec->dot(*gp);
172 outStream << std::endl;
173 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
174 outStream <<
" Trial objective value: " << ftrial << std::endl;
175 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
176 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
177 outStream <<
" Sufficient decrease bound: " << -gs*
c1_ << std::endl;
178 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
187 state_->iterateVec->set(x);
193 gold->set(*
state_->gradientVec);
195 gp->set(
state_->gradientVec->dual());
198 s->set(x); s->axpy(-one,*gp);
199 proj_->project(*s,outStream);
201 state_->gnorm = s->norm();
212template<
typename Real>
214 std::ostream &outStream ) {
219 throw Exception::NotImplemented(
">>> TypeB::NewtonKrylovAlgorithm::run : This algorithm cannot solve problems with linear equality constraints!");
223template<
typename Real>
231 std::ostream &outStream ) {
232 throw Exception::NotImplemented(
">>> TypeB::NewtonKrylovAlgorithm::run : This algorithm cannot solve problems with linear equality constraints!");
235template<
typename Real>
237 std::ios_base::fmtflags osFlags(os.flags());
239 os << std::string(114,
'-') << std::endl;
241 os <<
"Line-Search Projected Newton";
244 os <<
"Line-Search Projected Quasi-Newton with " <<
secantName_ <<
" Hessian approximation";
246 os <<
" status output definitions" << std::endl << std::endl;
247 os <<
" iter - Number of iterates (steps taken)" << std::endl;
248 os <<
" value - Objective function value" << std::endl;
249 os <<
" gnorm - Norm of the gradient" << std::endl;
250 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
251 os <<
" alpha - Line search step length" << std::endl;
252 os <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
253 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
254 os <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
255 os <<
" iterCG - Number of Krylov iterations" << std::endl << std::endl;
256 os <<
" flagGC - Krylov flag" << std::endl;
261 os << std::string(114,
'-') << std::endl;
265 os << std::setw(6) << std::left <<
"iter";
266 os << std::setw(15) << std::left <<
"value";
267 os << std::setw(15) << std::left <<
"gnorm";
268 os << std::setw(15) << std::left <<
"snorm";
269 os << std::setw(15) << std::left <<
"alpha";
270 os << std::setw(10) << std::left <<
"#fval";
271 os << std::setw(10) << std::left <<
"#grad";
272 os << std::setw(10) << std::left <<
"#ls_fval";
273 os << std::setw(10) << std::left <<
"iterCG";
274 os << std::setw(10) << std::left <<
"flagCG";
279template<
typename Real>
281 std::ios_base::fmtflags osFlags(os.flags());
283 os << std::endl <<
"Line-Search Projected Newton (Type B, Bound Constraints)" << std::endl;
286 os << std::endl <<
"Line-Search Projected Quasi-Newton with "
287 <<
secantName_ <<
" Hessian approximation" << std::endl;
292template<
typename Real>
294 std::ios_base::fmtflags osFlags(os.flags());
295 os << std::scientific << std::setprecision(6);
298 if (
state_->iter == 0 ) {
300 os << std::setw(6) << std::left <<
state_->iter;
301 os << std::setw(15) << std::left <<
state_->value;
302 os << std::setw(15) << std::left <<
state_->gnorm;
303 os << std::setw(15) << std::left <<
"---";
304 os << std::setw(15) << std::left <<
"---";
305 os << std::setw(10) << std::left <<
state_->nfval;
306 os << std::setw(10) << std::left <<
state_->ngrad;
307 os << std::setw(10) << std::left <<
"---";
308 os << std::setw(10) << std::left <<
"---";
309 os << std::setw(10) << std::left <<
"---";
314 os << std::setw(6) << std::left <<
state_->iter;
315 os << std::setw(15) << std::left <<
state_->value;
316 os << std::setw(15) << std::left <<
state_->gnorm;
317 os << std::setw(15) << std::left <<
state_->snorm;
318 os << std::setw(15) << std::left <<
state_->searchSize;
319 os << std::setw(10) << std::left <<
state_->nfval;
320 os << std::setw(10) << std::left <<
state_->ngrad;
321 os << std::setw(10) << std::left <<
ls_nfval_;
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Provides the interface to apply upper and lower bound constraints.
Defines the general constraint operator interface.
Provides definitions for Krylov solvers.
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.
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
Provides interface for and implements limited-memory secant operators.
Provides an interface to check status of optimization algorithms.
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on bound constrained problems (Type-B). This is the primary Type-B interface.
Ptr< PolyhedralProjection< Real > > proj_
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeExitStatus(std::ostream &os) const
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
Ptr< Secant< Real > > secant_
Secant object (used for quasi-Newton).
Real alpha0_
Initial line search step size (default: 1.0).
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout) override
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
ESecant esec_
Secant type.
bool useSecantPrecond_
Whether or not to use a secant approximation to precondition inexact Newton.
int maxit_
Maximum number of line search steps (default: 20).
void parseParameterList(ParameterList &list)
std::string secantName_
Secant name.
int flagKrylov_
Termination flag for Krylov method (used for inexact Newton).
bool useralpha_
Flag to use user-defined initial step size (default: false).
NewtonKrylovAlgorithm(ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
Real c1_
Sufficient Decrease Parameter (default: 1e-4).
bool useSecantHessVec_
Whether or not to use to a secant approximation as the Hessian.
std::string krylovName_
Krylov name.
void writeName(std::ostream &os) const override
Print step name.
Real rhodec_
Backtracking rate (default: 0.5).
int iterKrylov_
Number of Krylov iterations (used for inexact Newton).
Ptr< Krylov< Real > > krylov_
Krylov solver object (used for inexact Newton).
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout)
bool usePrevAlpha_
Flag to use previous step size as next initial step size (default: false).
void writeHeader(std::ostream &os) const override
Print iterate header.
void writeOutput(std::ostream &os, const bool write_header=false) const override
Print iterate status.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
EKrylov StringToEKrylov(std::string s)
std::string NumberToString(T Number)
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
ESecant StringToESecant(std::string s)
Ptr< Krylov< Real > > KrylovFactory(ParameterList &parlist)
ROL::Ptr< Secant< Real > > SecantFactory(ROL::ParameterList &parlist, ESecantMode mode=SECANTMODE_BOTH)
std::string ECGFlagToString(ECGFlag cgf)