10#ifndef ROL_TYPEP_INEXACTNEWTONALGORITHM_DEF_HPP
11#define ROL_TYPEP_INEXACTNEWTONALGORITHM_DEF_HPP
21template<
typename Real>
29 ParameterList &lslist = list.sublist(
"Step").sublist(
"Line Search");
30 t0_ = list.sublist(
"Status Test").get(
"Gradient Scale" , 1.0);
31 initProx_ = lslist.get(
"Apply Prox to Initial Guess",
false);
32 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
33 c1_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
34 rhodec_ = lslist.sublist(
"Line-Search Method").get(
"Backtracking Rate", 0.5);
35 sigma1_ = lslist.sublist(
"Inexact Newton").get(
"Lower Step Size Safeguard", 0.1);
36 sigma2_ = lslist.sublist(
"Inexact Newton").get(
"Upper Step Size Safeguard", 0.9);
37 algoName_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Solver",
"Spectral Gradient");
38 int sp_maxit = lslist.sublist(
"Inexact Newton").get(
"Subproblem Iteration Limit", 1000);
39 sp_tol1_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Absolute Tolerance", 1e-4);
40 sp_tol2_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Relative Tolerance", 1e-2);
41 sp_exp_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Tolerance Exponent", 1.0);
42 Real opt_tol = lslist.sublist(
"Status Test").get(
"Gradient Tolerance", 1e-8);
44 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
47 list_.sublist(
"Status Test").set(
"Iteration Limit", sp_maxit);
52template<
typename Real>
59 std::ostream &outStream) {
67 state_->iterateVec->set(x);
83template<
typename Real>
88 std::ostream &outStream ) {
93 Real strial(0), ntrial(0), ftrial(0), gs(0), Qk(0), rhoTmp(0);
96 Ptr<TypeP::Algorithm<Real>> algo;
97 Ptr<NewtonObj> qobj = makePtr<NewtonObj>(makePtrFromRef(sobj),x,g);
103 xs->set(*
state_->iterateVec);
104 state_->iterateVec->set(x);
106 qobj->setData(x,*
state_->gradientVec);
109 list_.sublist(
"Status Test").set(
"Gradient Tolerance",gtol);
110 if (
algoName_ ==
"Line Search") algo = makePtr<TypeP::ProxGradientAlgorithm<Real>>(
list_);
111 else if (
algoName_ ==
"iPiano") algo = makePtr<TypeP::iPianoAlgorithm<Real>>(
list_);
112 else if (
algoName_ ==
"Trust Region") algo = makePtr<TypeP::TrustRegionAlgorithm<Real>>(
list_);
113 else algo = makePtr<TypeP::SpectralGradientAlgorithm<Real>>(
list_);
114 algo->run(*xs,*qobj,nobj,outStream);
115 s->set(*xs); s->axpy(-one,x);
117 nhess_ += qobj->numHessVec();
118 state_->nprox += staticPtrCast<const TypeP::AlgorithmState<Real>>(algo->getState())->nprox;
126 strial = sobj.
value(x,tol);
127 ntrial = nobj.
value(x,tol);
128 ftrial = strial + ntrial;
130 gs =
state_->gradientVec->apply(*s);
131 Qk = gs + ntrial -
state_->nvalue;
133 outStream <<
" In TypeP::InexactNewtonAlgorithm: Line Search" << std::endl;
134 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
135 outStream <<
" Trial objective value: " << ftrial << std::endl;
136 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
137 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
138 outStream <<
" Sufficient decrease bound: " << -Qk*
c1_ << std::endl;
139 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
147 strial = sobj.
value(x,tol);
148 ntrial = nobj.
value(x,tol);
149 ftrial = strial + ntrial;
151 gs =
state_->gradientVec->apply(*s);
152 Qk = gs + ntrial -
state_->nvalue;
155 rhoTmp = -half * Qk / (strial-
state_->svalue-
state_->searchSize*gs);
161 strial = sobj.
value(x,tol);
162 ntrial = nobj.
value(x,tol);
163 ftrial = strial + ntrial;
167 outStream << std::endl;
168 outStream <<
" Step size: " <<
state_->searchSize << std::endl;
169 outStream <<
" Trial objective value: " << ftrial << std::endl;
170 outStream <<
" Computed reduction: " <<
state_->value-ftrial << std::endl;
171 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
172 outStream <<
" Sufficient decrease bound: " << -Qk*
c1_ << std::endl;
173 outStream <<
" Number of function evaluations: " <<
ls_nfval_ << std::endl;
185 state_->iterateVec->set(x);
195 gp->set(
state_->gradientVec->dual());
207template<
typename Real>
209 std::ios_base::fmtflags osFlags(os.flags());
211 os << std::string(114,
'-') << std::endl;
212 os <<
"Line-Search Inexact Proximal Newton";
213 os <<
" status output definitions" << std::endl << std::endl;
214 os <<
" iter - Number of iterates (steps taken)" << std::endl;
215 os <<
" value - Objective function value" << std::endl;
216 os <<
" gnorm - Norm of the gradient" << std::endl;
217 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
218 os <<
" alpha - Line search step length" << std::endl;
219 os <<
" #sval - Cumulative number of times the smooth objective function was evaluated" << std::endl;
220 os <<
" #nval - Cumulative number of times the nonsmooth objective function was evaluated" << std::endl;
221 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
222 os <<
" #hess - Cumulative number of times the Hessian was applied" << std::endl;
223 os <<
" #prox - Cumulative number of times the projection was computed" << std::endl;
224 os <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
225 os <<
" sp_iter - Number iterations to compute quasi-Newton step" << std::endl;
226 os << std::string(114,
'-') << std::endl;
230 os << std::setw(6) << std::left <<
"iter";
231 os << std::setw(15) << std::left <<
"value";
232 os << std::setw(15) << std::left <<
"gnorm";
233 os << std::setw(15) << std::left <<
"snorm";
234 os << std::setw(15) << std::left <<
"alpha";
235 os << std::setw(10) << std::left <<
"#sval";
236 os << std::setw(10) << std::left <<
"#nval";
237 os << std::setw(10) << std::left <<
"#grad";
238 os << std::setw(10) << std::left <<
"#hess";
239 os << std::setw(10) << std::left <<
"#prox";
240 os << std::setw(10) << std::left <<
"#ls_fval";
241 os << std::setw(10) << std::left <<
"sp_iter";
246template<
typename Real>
248 std::ios_base::fmtflags osFlags(os.flags());
249 os << std::endl <<
"Line-Search Inexact Proximal Newton (Type P)" << std::endl;
253template<
typename Real>
255 std::ios_base::fmtflags osFlags(os.flags());
256 os << std::scientific << std::setprecision(6);
259 if (
state_->iter == 0 ) {
261 os << std::setw(6) << std::left <<
state_->iter;
262 os << std::setw(15) << std::left <<
state_->value;
263 os << std::setw(15) << std::left <<
state_->gnorm;
264 os << std::setw(15) << std::left <<
"---";
265 os << std::setw(15) << std::left <<
"---";
266 os << std::setw(10) << std::left <<
state_->nsval;
267 os << std::setw(10) << std::left <<
state_->nnval;
268 os << std::setw(10) << std::left <<
state_->ngrad;
269 os << std::setw(10) << std::left <<
nhess_;
270 os << std::setw(10) << std::left <<
state_->nprox;
271 os << std::setw(10) << std::left <<
"---";
272 os << std::setw(10) << std::left <<
"---";
277 os << std::setw(6) << std::left <<
state_->iter;
278 os << std::setw(15) << std::left <<
state_->value;
279 os << std::setw(15) << std::left <<
state_->gnorm;
280 os << std::setw(15) << std::left <<
state_->snorm;
281 os << std::setw(15) << std::left <<
state_->searchSize;
282 os << std::setw(10) << std::left <<
state_->nsval;
283 os << std::setw(10) << std::left <<
state_->nnval;
284 os << std::setw(10) << std::left <<
state_->ngrad;
285 os << std::setw(10) << std::left <<
nhess_;
286 os << std::setw(10) << std::left <<
state_->nprox;
287 os << std::setw(10) << std::left <<
ls_nfval_;
288 os << std::setw(10) << std::left <<
spgIter_;
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Provides the interface to evaluate objective functions.
virtual void prox(Vector< Real > &Pv, const Vector< Real > &v, Real t, Real &tol)
Compute the proximity operator.
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 an interface to check status of optimization algorithms.
void pgstep(Vector< Real > &pgiter, Vector< Real > &pgstep, Objective< Real > &nobj, const Vector< Real > &x, const Vector< Real > &dg, Real t, Real &tol) const
const Ptr< AlgorithmState< Real > > state_
virtual void writeExitStatus(std::ostream &os) const
const Ptr< CombinedStatusTest< Real > > status_
void initialize(const Vector< Real > &x, const Vector< Real > &g)
Real c1_
Sufficient Decrease Parameter (default: 1e-4).
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, std::ostream &outStream=std::cout) override
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
InexactNewtonAlgorithm(ParameterList &list)
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, Vector< Real > &dg, Vector< Real > &px, std::ostream &outStream=std::cout)
Real sigma2_
Upper safeguard for quadratic line search (default: 0.9).
Real sigma1_
Lower safeguard for quadratic line search (default: 0.1).
void writeName(std::ostream &os) const override
Print step name.
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
int maxit_
Maximum number of line search steps (default: 20).
Real rhodec_
Backtracking rate (default: 0.5).
void writeHeader(std::ostream &os) const override
Print iterate header.
Defines the linear algebra or vector space interface.
virtual Real norm() const =0
Returns where .
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 .
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.