44 #ifndef ROL_TYPEP_QUASINEWTONALGORITHM_DEF_HPP
45 #define ROL_TYPEP_QUASINEWTONALGORITHM_DEF_HPP
55 template<
typename Real>
63 ParameterList &lslist = list.sublist(
"Step").sublist(
"Line Search");
64 t0_ = list.sublist(
"Status Test").get(
"Gradient Scale" , 1.0);
65 initProx_ = lslist.get(
"Apply Prox to Initial Guess",
false);
66 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
67 c1_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
68 rhodec_ = lslist.sublist(
"Line-Search Method").get(
"Backtracking Rate", 0.5);
69 sigma1_ = lslist.sublist(
"Inexact Newton").get(
"Lower Step Size Safeguard", 0.1);
70 sigma2_ = lslist.sublist(
"Inexact Newton").get(
"Upper Step Size Safeguard", 0.9);
71 algoName_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Solver",
"Spectral Gradient");
72 int sp_maxit = lslist.sublist(
"Inexact Newton").get(
"Subproblem Iteration Limit", 1000);
73 sp_tol1_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Absolute Tolerance", 1e-4);
74 sp_tol2_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Relative Tolerance", 1e-2);
75 sp_exp_ = lslist.sublist(
"Inexact Newton").get(
"Subproblem Tolerance Exponent", 1.0);
76 Real opt_tol = lslist.sublist(
"Status Test").get(
"Gradient Tolerance", 1e-8);
78 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
81 list_.sublist(
"Status Test").set(
"Iteration Limit", sp_maxit);
86 template<
typename Real>
93 std::ostream &outStream) {
95 Real tol(std::sqrt(ROL_EPSILON<Real>()));
99 Real ftol = std::sqrt(ROL_EPSILON<Real>());
101 state_->iterateVec->set(x);
102 nobj.
prox(x,*state_->iterateVec,one,tol); state_->nprox++;
106 state_->svalue = sobj.
value(x,ftol); state_->nsval++;
107 state_->nvalue = nobj.
value(x,ftol); state_->nnval++;
108 state_->value = state_->svalue + state_->nvalue;
109 sobj.
gradient(*state_->gradientVec,x,ftol); state_->ngrad++;
110 dg.
set(state_->gradientVec->dual());
111 pgstep(*state_->iterateVec,px,nobj,x,dg,t0_,tol);
112 state_->gnorm = px.
norm() / t0_;
113 state_->snorm = ROL_INF<Real>();
117 template<
typename Real>
122 std::ostream &outStream ) {
123 const Real half(0.5), one(1), eps(ROL_EPSILON<Real>());
126 initialize(x,g,sobj,nobj,*gp,*px,outStream);
127 Real strial(0), ntrial(0), ftrial(0), gs(0), Qk(0), rhoTmp(0);
128 Real tol(std::sqrt(ROL_EPSILON<Real>())), gtol(1);
130 Ptr<TypeP::Algorithm<Real>> algo;
131 Ptr<NewtonObj> qobj = makePtr<NewtonObj>(makePtrFromRef(sobj),x,g);
134 if (verbosity_ > 0) writeOutput(outStream,
true);
137 xs->set(*state_->iterateVec);
138 state_->iterateVec->set(x);
139 while (status_->check(*state_)) {
140 qobj->setData(x,*state_->gradientVec);
142 gtol = std::max(sp_tol_min_,std::min(sp_tol1_,sp_tol2_*std::pow(state_->gnorm,sp_exp_)));
143 list_.sublist(
"Status Test").set(
"Gradient Tolerance",gtol);
144 if (algoName_ ==
"Line Search") algo = makePtr<TypeP::ProxGradientAlgorithm<Real>>(list_);
145 else if (algoName_ ==
"iPiano") algo = makePtr<TypeP::iPianoAlgorithm<Real>>(list_);
146 else if (algoName_ ==
"Trust Region") algo = makePtr<TypeP::TrustRegionAlgorithm<Real>>(list_);
147 else algo = makePtr<TypeP::SpectralGradientAlgorithm<Real>>(list_);
148 algo->run(*xs,*qobj,nobj,outStream);
149 s->set(*xs); s->axpy(-one,x);
150 spgIter_ = algo->getState()->iter;
151 nhess_ += qobj->numHessVec();
152 state_->nprox += staticPtrCast<const TypeP::AlgorithmState<Real>>(algo->getState())->nprox;
155 state_->searchSize = one;
156 x.set(*state_->iterateVec);
157 x.axpy(state_->searchSize,*s);
160 strial = sobj.
value(x,tol);
161 ntrial = nobj.
value(x,tol);
162 ftrial = strial + ntrial;
164 gs = state_->gradientVec->apply(*s);
165 Qk = gs + ntrial - state_->nvalue;
166 if (verbosity_ > 1) {
167 outStream <<
" In TypeP::InexactNewtonAlgorithm: Line Search" << 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;
177 x.set(*state_->iterateVec);
178 x.axpy(state_->searchSize,*s);
181 strial = sobj.
value(x,tol);
182 ntrial = nobj.
value(x,tol);
183 ftrial = strial + ntrial;
185 gs = state_->gradientVec->apply(*s);
186 Qk = gs + ntrial - state_->nvalue;
188 while ( ftrial > state_->value + c1_*Qk && ls_nfval_ < maxit_ ) {
189 rhoTmp = -half * Qk / (strial-state_->svalue-state_->searchSize*gs);
190 state_->searchSize = ((sigma1_ <= rhoTmp && rhoTmp <= sigma2_) ? rhoTmp : rhodec_) * state_->searchSize;
191 x.set(*state_->iterateVec);
192 x.axpy(state_->searchSize,*s);
195 strial = sobj.
value(x,tol);
196 ntrial = nobj.
value(x,tol);
197 ftrial = strial + ntrial;
198 Qk = state_->searchSize * gs + ntrial - state_->nvalue;
200 if (verbosity_ > 1) {
201 outStream << std::endl;
202 outStream <<
" Step size: " << state_->searchSize << std::endl;
203 outStream <<
" Trial objective value: " << ftrial << std::endl;
204 outStream <<
" Computed reduction: " << state_->value-ftrial << std::endl;
205 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
206 outStream <<
" Sufficient decrease bound: " << -Qk*c1_ << std::endl;
207 outStream <<
" Number of function evaluations: " << ls_nfval_ << std::endl;
210 state_->nsval += ls_nfval_;
211 state_->nnval += ls_nfval_;
214 state_->stepVec->set(*s);
215 state_->stepVec->scale(state_->searchSize);
216 state_->snorm = state_->stepVec->norm();
219 state_->iterateVec->set(x);
223 state_->value = ftrial;
224 state_->svalue = strial;
225 state_->nvalue = ntrial;
228 sobj.
gradient(*state_->gradientVec,x,tol); state_->ngrad++;
229 gp->set(state_->gradientVec->dual());
232 pgstep(*xs,*px,nobj,x,*gp,t0_,tol);
233 state_->gnorm = s->norm() / t0_;
236 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
241 template<
typename Real>
243 std::ios_base::fmtflags osFlags(os.flags());
244 if (verbosity_ > 1) {
245 os << std::string(114,
'-') << std::endl;
246 os <<
"Line-Search Inexact Proximal Newton";
247 os <<
" status output definitions" << std::endl << std::endl;
248 os <<
" iter - Number of iterates (steps taken)" << std::endl;
249 os <<
" value - Objective function value" << std::endl;
250 os <<
" gnorm - Norm of the gradient" << std::endl;
251 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
252 os <<
" alpha - Line search step length" << std::endl;
253 os <<
" #sval - Cumulative number of times the smooth objective function was evaluated" << std::endl;
254 os <<
" #nval - Cumulative number of times the nonsmooth objective function was evaluated" << std::endl;
255 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
256 os <<
" #hess - Cumulative number of times the Hessian was applied" << std::endl;
257 os <<
" #prox - Cumulative number of times the projection was computed" << std::endl;
258 os <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
259 os <<
" sp_iter - Number iterations to compute quasi-Newton step" << std::endl;
260 os << std::string(114,
'-') << std::endl;
264 os << std::setw(6) << std::left <<
"iter";
265 os << std::setw(15) << std::left <<
"value";
266 os << std::setw(15) << std::left <<
"gnorm";
267 os << std::setw(15) << std::left <<
"snorm";
268 os << std::setw(15) << std::left <<
"alpha";
269 os << std::setw(10) << std::left <<
"#sval";
270 os << std::setw(10) << std::left <<
"#nval";
271 os << std::setw(10) << std::left <<
"#grad";
272 os << std::setw(10) << std::left <<
"#hess";
273 os << std::setw(10) << std::left <<
"#prox";
274 os << std::setw(10) << std::left <<
"#ls_fval";
275 os << std::setw(10) << std::left <<
"sp_iter";
280 template<
typename Real>
282 std::ios_base::fmtflags osFlags(os.flags());
283 os << std::endl <<
"Line-Search Inexact Proximal Newton (Type P)" << std::endl;
287 template<
typename Real>
289 std::ios_base::fmtflags osFlags(os.flags());
290 os << std::scientific << std::setprecision(6);
291 if ( state_->iter == 0 ) writeName(os);
292 if ( write_header ) writeHeader(os);
293 if ( state_->iter == 0 ) {
295 os << std::setw(6) << std::left << state_->iter;
296 os << std::setw(15) << std::left << state_->value;
297 os << std::setw(15) << std::left << state_->gnorm;
298 os << std::setw(15) << std::left <<
"---";
299 os << std::setw(15) << std::left <<
"---";
300 os << std::setw(10) << std::left << state_->nsval;
301 os << std::setw(10) << std::left << state_->nnval;
302 os << std::setw(10) << std::left << state_->ngrad;
303 os << std::setw(10) << std::left << nhess_;
304 os << std::setw(10) << std::left << state_->nprox;
305 os << std::setw(10) << std::left <<
"---";
306 os << std::setw(10) << std::left <<
"---";
311 os << std::setw(6) << std::left << state_->iter;
312 os << std::setw(15) << std::left << state_->value;
313 os << std::setw(15) << std::left << state_->gnorm;
314 os << std::setw(15) << std::left << state_->snorm;
315 os << std::setw(15) << std::left << state_->searchSize;
316 os << std::setw(10) << std::left << state_->nsval;
317 os << std::setw(10) << std::left << state_->nnval;
318 os << std::setw(10) << std::left << state_->ngrad;
319 os << std::setw(10) << std::left << nhess_;
320 os << std::setw(10) << std::left << state_->nprox;
321 os << std::setw(10) << std::left << ls_nfval_;
322 os << std::setw(10) << std::left << spgIter_;
Provides the interface to evaluate objective functions.
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
int maxit_
Maximum number of line search steps (default: 20)
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual void prox(Vector< Real > &Pv, const Vector< Real > &v, Real t, Real &tol)
Real sigma1_
Lower safeguard for quadratic line search (default: 0.1)
Defines the linear algebra or vector space interface.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
Real sigma2_
Upper safeguard for quadratic line search (default: 0.9)
Real c1_
Sufficient Decrease Parameter (default: 1e-4)
Real rhodec_
Backtracking rate (default: 0.5)
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
void writeName(std::ostream &os) const override
Print step name.
Provides an interface to check status of optimization algorithms.
InexactNewtonAlgorithm(ParameterList &list)
const Ptr< CombinedStatusTest< Real > > status_
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)
virtual void set(const Vector &x)
Set where .
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...
virtual Real norm() const =0
Returns where .
virtual void writeExitStatus(std::ostream &os) const
void initialize(const Vector< Real > &x, const Vector< Real > &g)
void writeHeader(std::ostream &os) const override
Print iterate header.