85 std::ostream &outStream) {
87 if (proj_ == nullPtr) {
88 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
93 Real ftol = std::sqrt(ROL_EPSILON<Real>());
94 proj_->project(x,outStream);
95 state_->iterateVec->set(x);
97 state_->value = obj.
value(x,ftol); state_->nfval++;
98 obj.
gradient(*state_->gradientVec,x,ftol); state_->ngrad++;
99 state_->stepVec->set(x);
100 state_->stepVec->axpy(-one,state_->gradientVec->dual());
101 proj_->project(*state_->stepVec,outStream);
102 state_->stepVec->axpy(-one,x);
103 state_->gnorm = state_->stepVec->norm();
104 state_->snorm = ROL_INF<Real>();
105 if (!useralpha_) alpha0_ = one;
106 state_->searchSize = alpha0_;
114 std::ostream &outStream ) {
117 initialize(x,g,obj,bnd,outStream);
119 Ptr<Vector<Real>> pwa = x.
clone(), pwa1 = x.
clone();
120 Real ftrial(0), gs(0), tol(std::sqrt(ROL_EPSILON<Real>()));
122 Ptr<LinearOperator<Real>> hessian, precond;
125 if (verbosity_ > 0) writeOutput(outStream,
true);
128 gp->set(state_->gradientVec->dual());
129 while (status_->check(*state_)) {
131 hessian = makePtr<HessianPNK>(makePtrFromRef(obj),makePtrFromRef(bnd),
132 state_->iterateVec,state_->gradientVec,state_->gnorm,
133 secant_,useSecantHessVec_,pwa);
134 precond = makePtr<PrecondPNK>(makePtrFromRef(obj),makePtrFromRef(bnd),
135 state_->iterateVec,state_->gradientVec,state_->gnorm,
136 secant_,useSecantPrecond_,pwa1);
138 krylov_->run(*s,*hessian,*state_->gradientVec,*precond,iterKrylov_,flagKrylov_);
139 if (flagKrylov_ == 2 && iterKrylov_ <= 1) {
143 if (!usePrevAlpha_) state_->searchSize = alpha0_;
144 x.
set(*state_->iterateVec);
145 x.
axpy(-state_->searchSize,*s);
146 proj_->project(x,outStream);
148 ftrial = obj.
value(x,tol); ls_nfval_ = 1;
149 state_->stepVec->set(x);
150 state_->stepVec->axpy(-one,*state_->iterateVec);
151 gs = state_->stepVec->dot(*gp);
152 if (verbosity_ > 1) {
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;
161 while ( state_->value - ftrial < -c1_*gs && ls_nfval_ < maxit_ ) {
162 state_->searchSize *= rhodec_;
163 x.
set(*state_->iterateVec);
164 x.
axpy(-state_->searchSize,*s);
165 proj_->project(x,outStream);
167 ftrial = obj.
value(x,tol); ls_nfval_++;
168 state_->stepVec->set(x);
169 state_->stepVec->axpy(-one,*state_->iterateVec);
170 gs = state_->stepVec->dot(*gp);
171 if (verbosity_ > 1) {
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;
181 state_->nfval += ls_nfval_;
184 state_->snorm = state_->stepVec->norm();
187 state_->iterateVec->set(x);
191 state_->value = ftrial;
193 gold->set(*state_->gradientVec);
194 obj.
gradient(*state_->gradientVec,x,tol); state_->ngrad++;
195 gp->set(state_->gradientVec->dual());
198 s->set(x); s->axpy(-one,*gp);
199 proj_->project(*s,outStream);
201 state_->gnorm = s->norm();
204 secant_->updateStorage(x,*state_->gradientVec,*gold,*state_->stepVec,state_->snorm,state_->iter);
207 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
237 std::ios_base::fmtflags osFlags(os.flags());
238 if (verbosity_ > 1) {
239 os << std::string(114,
'-') << std::endl;
240 if (!useSecantHessVec_) {
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";
294 std::ios_base::fmtflags osFlags(os.flags());
295 os << std::scientific << std::setprecision(6);
296 if ( state_->iter == 0 ) writeName(os);
297 if ( write_header ) writeHeader(os);
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_;
322 os << std::setw(10) << std::left << iterKrylov_;
323 os << std::setw(10) << std::left << flagKrylov_;