68 std::ostream &outStream) {
70 if (proj_ == nullPtr) {
71 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
77 Real ftol = std::sqrt(ROL_EPSILON<Real>());
78 proj_->project(x,outStream); state_->nproj++;
79 state_->iterateVec->set(x);
81 state_->value = obj.
value(x,ftol); state_->nfval++;
82 obj.
gradient(*state_->gradientVec,x,ftol); state_->ngrad++;
83 state_->stepVec->set(x);
84 state_->stepVec->axpy(-one,state_->gradientVec->dual());
85 proj_->project(*state_->stepVec,outStream); state_->nproj++;
86 state_->stepVec->axpy(-one,x);
87 state_->gnorm = state_->stepVec->norm();
88 state_->snorm = ROL_INF<Real>();
96 std::ostream &outStream ) {
97 const Real half(0.5), one(1);
99 initialize(x,g,obj,bnd,outStream);
101 Real ftrial(0), gs(0), alphaTmp(0), tol(std::sqrt(ROL_EPSILON<Real>())), gtol(1);
103 Ptr<TypeB::Algorithm<Real>> algo;
104 Ptr<PQNObjective<Real>> qobj = makePtr<PQNObjective<Real>>(secant_,x,g);
105 Ptr<Problem<Real>> problem = makePtr<Problem<Real>>(qobj,xs);
106 problem->addBoundConstraint(makePtrFromRef(bnd));
108 problem->addLinearConstraint(
"LEC",proj_->getLinearConstraint(),
109 proj_->getMultiplier(),
110 proj_->getResidual());
111 problem->setProjectionAlgorithm(list_);
113 problem->finalize(
false,verbosity_>2,outStream);
116 if (verbosity_ > 0) writeOutput(outStream,
true);
119 gp->set(state_->gradientVec->dual());
120 while (status_->check(*state_)) {
122 qobj->setAnchor(x,*state_->gradientVec);
123 xs->set(x); xs->axpy(-one,*gp); proj_->project(*xs,outStream); state_->nproj++;
124 gtol = std::max(sp_tol_min_,std::min(sp_tol1_,sp_tol2_*state_->gnorm));
125 list_.sublist(
"Status Test").set(
"Gradient Tolerance",gtol);
126 if (algoName_ ==
"Trust Region") algo = makePtr<TypeB::LinMoreAlgorithm<Real>>(list_);
127 else if (algoName_ ==
"Line Search") algo = makePtr<TypeB::GradientAlgorithm<Real>>(list_);
128 else if (algoName_ ==
"Primal Dual Active Set") algo = makePtr<TypeB::PrimalDualActiveSetAlgorithm<Real>>(list_);
129 else if (algoName_ ==
"Moreau-Yosida") algo = makePtr<TypeB::MoreauYosidaAlgorithm<Real>>(list_);
130 else if (algoName_ ==
"Interior Point") algo = makePtr<TypeB::InteriorPointAlgorithm<Real>>(list_);
131 else algo = makePtr<TypeB::SpectralGradientAlgorithm<Real>>(list_);
132 algo->run(*problem,outStream);
133 s->set(*xs); s->axpy(-one,x);
134 spgIter_ = algo->getState()->iter;
135 state_->nproj += staticPtrCast<const TypeB::AlgorithmState<Real>>(algo->getState())->nproj;
138 state_->searchSize = one;
139 x.
set(*state_->iterateVec);
140 x.
axpy(state_->searchSize,*s);
142 ftrial = obj.
value(x,tol); ls_nfval_ = 1;
143 gs = state_->gradientVec->apply(*s);
144 if (verbosity_ > 1) {
145 outStream <<
" In TypeB::QuasiNewtonAlgorithm: Line Search" << std::endl;
146 outStream <<
" Step size: " << state_->searchSize << std::endl;
147 outStream <<
" Trial objective value: " << ftrial << std::endl;
148 outStream <<
" Computed reduction: " << state_->value-ftrial << std::endl;
149 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
150 outStream <<
" Sufficient decrease bound: " << -gs*state_->searchSize*c1_ << std::endl;
151 outStream <<
" Number of function evaluations: " << ls_nfval_ << std::endl;
153 while ( ftrial > state_->value + c1_*state_->searchSize*gs && ls_nfval_ < maxit_ ) {
154 alphaTmp = -half*state_->searchSize*state_->searchSize*gs
155 / (ftrial-state_->value-state_->searchSize*gs);
156 state_->searchSize = (sigma1_*state_->searchSize <= alphaTmp && alphaTmp <= sigma2_*state_->searchSize)
157 ? alphaTmp : rhodec_*state_->searchSize;
159 x.
set(*state_->iterateVec);
160 x.
axpy(state_->searchSize,*s);
162 ftrial = obj.
value(x,tol); ls_nfval_++;
163 if (verbosity_ > 1) {
164 outStream << std::endl;
165 outStream <<
" Step size: " << state_->searchSize << std::endl;
166 outStream <<
" Trial objective value: " << ftrial << std::endl;
167 outStream <<
" Computed reduction: " << state_->value-ftrial << std::endl;
168 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
169 outStream <<
" Sufficient decrease bound: " << -gs*state_->searchSize*c1_ << std::endl;
170 outStream <<
" Number of function evaluations: " << ls_nfval_ << std::endl;
173 state_->nfval += ls_nfval_;
176 state_->stepVec->set(*s);
177 state_->stepVec->scale(state_->searchSize);
178 state_->snorm = state_->stepVec->norm();
181 state_->iterateVec->set(x);
185 state_->value = ftrial;
187 gold->set(*state_->gradientVec);
188 obj.
gradient(*state_->gradientVec,x,tol); state_->ngrad++;
189 gp->set(state_->gradientVec->dual());
192 s->set(x); s->axpy(-one,*gp);
193 proj_->project(*s,outStream); state_->nproj++;
195 state_->gnorm = s->norm();
198 secant_->updateStorage(x,*state_->gradientVec,*gold,*state_->stepVec,state_->snorm,state_->iter);
201 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
208 std::ios_base::fmtflags osFlags(os.flags());
209 if (verbosity_ > 1) {
210 os << std::string(114,
'-') << std::endl;
211 os <<
"Line-Search Projected Quasi-Newton with " << secantName_ <<
" Hessian approximation";
212 os <<
" status output definitions" << std::endl << std::endl;
213 os <<
" iter - Number of iterates (steps taken)" << std::endl;
214 os <<
" value - Objective function value" << std::endl;
215 os <<
" gnorm - Norm of the gradient" << std::endl;
216 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
217 os <<
" alpha - Line search step length" << std::endl;
218 os <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
219 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
220 os <<
" #proj - Cumulative number of times the projection was computed" << std::endl;
221 os <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
222 os <<
" sp_iter - Number iterations to compute quasi-Newton step" << std::endl;
223 os << std::string(114,
'-') << std::endl;
227 os << std::setw(6) << std::left <<
"iter";
228 os << std::setw(15) << std::left <<
"value";
229 os << std::setw(15) << std::left <<
"gnorm";
230 os << std::setw(15) << std::left <<
"snorm";
231 os << std::setw(15) << std::left <<
"alpha";
232 os << std::setw(10) << std::left <<
"#fval";
233 os << std::setw(10) << std::left <<
"#grad";
234 os << std::setw(10) << std::left <<
"#proj";
235 os << std::setw(10) << std::left <<
"#ls_fval";
236 os << std::setw(10) << std::left <<
"sp_iter";
250 std::ios_base::fmtflags osFlags(os.flags());
251 os << std::scientific << std::setprecision(6);
252 if ( state_->iter == 0 ) writeName(os);
253 if ( write_header ) writeHeader(os);
254 if ( state_->iter == 0 ) {
256 os << std::setw(6) << std::left << state_->iter;
257 os << std::setw(15) << std::left << state_->value;
258 os << std::setw(15) << std::left << state_->gnorm;
259 os << std::setw(15) << std::left <<
"---";
260 os << std::setw(15) << std::left <<
"---";
261 os << std::setw(10) << std::left << state_->nfval;
262 os << std::setw(10) << std::left << state_->ngrad;
263 os << std::setw(10) << std::left << state_->nproj;
264 os << std::setw(10) << std::left <<
"---";
265 os << std::setw(10) << std::left <<
"---";
270 os << std::setw(6) << std::left << state_->iter;
271 os << std::setw(15) << std::left << state_->value;
272 os << std::setw(15) << std::left << state_->gnorm;
273 os << std::setw(15) << std::left << state_->snorm;
274 os << std::setw(15) << std::left << state_->searchSize;
275 os << std::setw(10) << std::left << state_->nfval;
276 os << std::setw(10) << std::left << state_->ngrad;
277 os << std::setw(10) << std::left << state_->nproj;
278 os << std::setw(10) << std::left << ls_nfval_;
279 os << std::setw(10) << std::left << spgIter_;