98 std::ostream &outStream ) {
99 const Real one(1), xeps(ROL_EPSILON<Real>());
100 Real ftol = std::sqrt(ROL_EPSILON<Real>());
101 Real gfnorm(0), gfnormf(0), tol(0), stol(0), eps(0);
102 Real ftrial(0), fnew(0), pRed(0), rho(1), alpha(1), lambda(1);
105 initialize(x,g,obj,bnd,outStream);
106 Ptr<Vector<Real>> s = x.
clone(), gfree = g.
clone();
107 Ptr<Vector<Real>> pwa1 = x.
clone(), pwa2 = x.
clone(), pwa3 = x.
clone();
108 Ptr<Vector<Real>> dwa1 = g.
clone(), dwa2 = g.
clone(), dwa3 = g.
clone();
111 if (verbosity_ > 0) writeOutput(outStream,
true);
114 gfree->set(*state_->gradientVec);
117 pwa1->set(gfree->dual());
118 bnd.
pruneActive(*pwa1,state_->gradientVec->dual(),x,xeps,eps);
119 gfree->set(pwa1->dual());
120 gfnorm = gfree->norm();
123 eps = std::min(eps0_,std::sqrt(state_->gnorm));
124 tol = tol2_*std::sqrt(state_->gnorm);
125 stol = std::min(tol1_,tol*gfnorm);
127 while (status_->check(*state_)) {
129 model_->setData(obj,*state_->iterateVec,*state_->gradientVec,ftol);
132 pRed = trpcg(*s,SPflag_,SPiter_,*gfree,x,*state_->gradientVec,
133 state_->searchSize,*model_,bnd,eps,stol,maxit_,
134 *pwa1,*dwa1,*pwa2,*dwa2,*pwa3,*dwa3,outStream);
140 ftrial = obj.
value(x,ftol); state_->nfval++;
144 TRUtils::analyzeRatio<Real>(rho,TRflag_,state_->value,ftrial,pRed,eps_,outStream,verbosity_>1);
147 if ( rho >= eta0_ ) {
148 lambda = std::min(one, state_->searchSize/gfnorm);
150 pwa1->set(*state_->iterateVec);
151 pwa1->axpy(-lambda,gfree->dual());
153 pwa1->axpy(-one,*state_->iterateVec);
154 gfnormf = pwa1->norm();
156 if (state_->value-ftrial < mu0_*gfnormf*state_->gnorm) {
159 if ( verbosity_ > 1 ) {
160 outStream <<
" Norm of projected free gradient: " << gfnormf << std::endl;
161 outStream <<
" Decrease lower bound (constraints): " << mu0_*gfnormf*state_->gnorm << std::endl;
162 outStream <<
" Trust-region flag (constraints): " << TRflag_ << std::endl;
163 outStream << std::endl;
171 state_->stepVec->set(x);
172 state_->stepVec->axpy(-one,*state_->iterateVec);
173 state_->snorm = state_->stepVec->norm();
174 x.
set(*state_->iterateVec);
177 state_->searchSize = gamma1_*std::min(state_->snorm,state_->searchSize);
181 if (rho >= eta0_ && rho < eta1_) {
183 state_->searchSize = gamma1_*std::min(state_->snorm,state_->searchSize);
185 else if (rho >= eta2_) {
187 state_->searchSize = std::min(delMax_,gamma2_*state_->searchSize);
192 obj.
gradient(*dwa1,x,ftol); state_->ngrad++;
193 pwa2->set(dwa1->dual());
194 pwa1->set(x); pwa1->axpy(-alpha/alpha0_,*pwa2);
197 fnew = obj.
value(*pwa1,ftol); state_->nfval++;
198 while ((fnew-ftrial) >= mu1_*(state_->value-ftrial)) {
200 pwa1->set(x); pwa1->axpy(-alpha/alpha0_,*pwa2);
203 fnew = obj.
value(*pwa1,ftol); state_->nfval++;
204 if ( cnt >= minit_ )
break;
207 state_->stepVec->set(*pwa1);
208 state_->stepVec->axpy(-one,*state_->iterateVec);
209 state_->snorm = state_->stepVec->norm();
211 if (std::isnan(fnew)) {
214 x.
set(*state_->iterateVec);
217 state_->searchSize = gamma1_*std::min(state_->snorm,state_->searchSize);
222 state_->iterateVec->set(x);
223 state_->value = fnew;
224 dwa1->set(*state_->gradientVec);
226 obj.
gradient(*state_->gradientVec,x,ftol); state_->ngrad++;
228 gfree->set(*state_->gradientVec);
231 pwa1->set(gfree->dual());
232 bnd.
pruneActive(*pwa1,state_->gradientVec->dual(),x,xeps,eps);
233 gfree->set(pwa1->dual());
234 gfnorm = gfree->norm();
237 pwa1->axpy(-one,state_->gradientVec->dual());
240 state_->gnorm = pwa1->norm();
242 model_->update(x,*state_->stepVec,*dwa1,*state_->gradientVec,
243 state_->snorm,state_->iter);
245 eps = std::min(eps0_,std::sqrt(state_->gnorm));
246 tol = tol2_*std::sqrt(state_->gnorm);
247 stol = std::min(tol1_,tol*gfnorm);
252 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
308 const Real tol,
const int itermax,
311 std::ostream &outStream)
const {
316 Real ftol = std::sqrt(ROL_EPSILON<Real>());
317 const Real
zero(0), half(0.5), one(1), two(2);
318 Real rho(0), kappa(0), beta(0), sigma(0), alpha(0), pRed(0);
319 Real rtr(0), tnorm(0), rnorm0(0), sMs(0), pMp(0), sMp(0);
326 applyFreePrecond(r,t,x,g0,eps,model,bnd,ftol,pwa,dwa);
329 rnorm0 = std::sqrt(rho);
330 if ( rnorm0 ==
zero ) {
337 for (iter = 0; iter < itermax; ++iter) {
339 applyFreeHessian(q,p,x,g0,eps,model,bnd,ftol,pwa,dwa);
343 alpha = (kappa>
zero) ? rho/kappa :
zero;
344 sigma = trqsol(sMs,pMp,sMp,del);
346 if (kappa <= zero || alpha >= sigma) {
349 iflag = (kappa<=
zero) ? 2 : 3;
352 pRed += half*alpha*rho;
356 applyFreePrecond(r,t,x,g0,eps,model,bnd,ftol,pwa,dwa);
361 if (rtr <= tol*tol || tnorm <= tol) {
362 sMs = sMs + two*alpha*sMp + alpha*alpha*pMp;
374 sMs = sMs + two*alpha*sMp + alpha*alpha*pMp;
375 sMp = beta*(sMp + alpha*pMp);
376 pMp = rho + beta*beta*pMp;
379 if (iter == itermax) {
383 pRed += sigma*(rho-half*sigma*kappa);
508 std::ios_base::fmtflags osFlags(os.flags());
509 os << std::scientific << std::setprecision(6);
510 if ( state_->iter == 0 ) writeName(os);
511 if ( write_header ) writeHeader(os);
512 if ( state_->iter == 0 ) {
514 os << std::setw(6) << std::left << state_->iter;
515 os << std::setw(15) << std::left << state_->value;
516 os << std::setw(15) << std::left << state_->gnorm;
517 os << std::setw(15) << std::left <<
"---";
518 os << std::setw(15) << std::left << state_->searchSize;
519 os << std::setw(10) << std::left << state_->nfval;
520 os << std::setw(10) << std::left << state_->ngrad;
521 os << std::setw(10) << std::left << nhess_;
522 os << std::setw(10) << std::left <<
"---";
523 os << std::setw(10) << std::left <<
"---";
524 os << std::setw(10) << std::left <<
"---";
529 os << std::setw(6) << std::left << state_->iter;
530 os << std::setw(15) << std::left << state_->value;
531 os << std::setw(15) << std::left << state_->gnorm;
532 os << std::setw(15) << std::left << state_->snorm;
533 os << std::setw(15) << std::left << state_->searchSize;
534 os << std::setw(10) << std::left << state_->nfval;
535 os << std::setw(10) << std::left << state_->ngrad;
536 os << std::setw(10) << std::left << nhess_;
537 os << std::setw(10) << std::left << TRflag_;
538 os << std::setw(10) << std::left << SPiter_;
539 os << std::setw(10) << std::left << SPflag_;
Real trpcg(Vector< Real > &w, int &iflag, int &iter, const Vector< Real > &g, const Vector< Real > &x, const Vector< Real > &g0, const Real del, TrustRegionModel_U< Real > &model, BoundConstraint< Real > &bnd, Real eps, const Real tol, const int itermax, Vector< Real > &p, Vector< Real > &q, Vector< Real > &r, Vector< Real > &t, Vector< Real > &pwa, Vector< Real > &dwa, std::ostream &outStream=std::cout) const