131 std::ostream &outStream ) {
132 const Real one(1), xeps(ROL_EPSILON<Real>());
133 Real ftol = std::sqrt(ROL_EPSILON<Real>());
134 Real gfnorm(0), gfnormf(0), tol(0), stol(0), eps(0);
135 Real ftrial(0), fnew(0), pRed(0), rho(1), alpha(1), lambda(1);
138 initialize(x,g,obj,bnd,outStream);
139 Ptr<Vector<Real>> s = x.
clone(), gfree = g.
clone();
140 Ptr<Vector<Real>> pwa1 = x.
clone(), pwa2 = x.
clone(), pwa3 = x.
clone();
141 Ptr<Vector<Real>> dwa1 = g.
clone(), dwa2 = g.
clone(), dwa3 = g.
clone();
144 if (verbosity_ > 0) writeOutput(outStream,
true);
147 gfree->set(*state_->gradientVec);
150 pwa1->set(gfree->dual());
151 bnd.
pruneActive(*pwa1,state_->gradientVec->dual(),x,xeps,eps);
152 gfree->set(pwa1->dual());
153 gfnorm = gfree->norm();
156 eps = std::min(eps0_,std::sqrt(state_->gnorm));
157 tol = tol2_*std::sqrt(state_->gnorm);
158 stol = std::min(tol1_,tol*gfnorm);
160 while (status_->check(*state_)) {
162 model_->setData(obj,*state_->iterateVec,*state_->gradientVec);
165 pRed = trpcg(*s,SPflag_,SPiter_,*gfree,x,*state_->gradientVec,
166 state_->searchSize,*model_,bnd,eps,stol,maxit_,
167 *pwa1,*dwa1,*pwa2,*dwa2,*pwa3,*dwa3,outStream);
173 ftrial = obj.
value(x,ftol); state_->nfval++;
177 TRUtils::analyzeRatio<Real>(rho,TRflag_,state_->value,ftrial,pRed,eps_,outStream,verbosity_>1);
180 if ( rho >= eta0_ ) {
181 lambda = std::min(one, state_->searchSize/gfnorm);
183 pwa1->set(*state_->iterateVec);
184 pwa1->axpy(-lambda,gfree->dual());
186 pwa1->axpy(-one,*state_->iterateVec);
187 gfnormf = pwa1->norm();
189 if (state_->value-ftrial < mu0_*gfnormf*state_->gnorm) {
192 if ( verbosity_ > 1 ) {
193 outStream <<
" Norm of projected free gradient: " << gfnormf << std::endl;
194 outStream <<
" Decrease lower bound (constraints): " << mu0_*gfnormf*state_->gnorm << std::endl;
195 outStream <<
" Trust-region flag (constraints): " << TRflag_ << std::endl;
196 outStream << std::endl;
204 state_->stepVec->set(x);
205 state_->stepVec->axpy(-one,*state_->iterateVec);
206 state_->snorm = state_->stepVec->norm();
207 x.
set(*state_->iterateVec);
210 state_->searchSize = gamma1_*std::min(state_->snorm,state_->searchSize);
214 if (rho >= eta0_ && rho < eta1_) {
216 state_->searchSize = gamma1_*std::min(state_->snorm,state_->searchSize);
218 else if (rho >= eta2_) {
220 state_->searchSize = std::min(delMax_,gamma2_*state_->searchSize);
225 obj.
gradient(*dwa1,x,ftol); state_->ngrad++;
226 pwa2->set(dwa1->dual());
227 pwa1->set(x); pwa1->axpy(-alpha/alpha0_,*pwa2);
230 fnew = obj.
value(*pwa1,ftol); state_->nfval++;
231 while ((fnew-ftrial) >= mu1_*(state_->value-ftrial)) {
233 pwa1->set(x); pwa1->axpy(-alpha/alpha0_,*pwa2);
236 fnew = obj.
value(*pwa1,ftol); state_->nfval++;
237 if ( cnt >= minit_ )
break;
240 state_->stepVec->set(*pwa1);
241 state_->stepVec->axpy(-one,*state_->iterateVec);
242 state_->snorm = state_->stepVec->norm();
244 if (std::isnan(fnew)) {
247 x.
set(*state_->iterateVec);
250 state_->searchSize = gamma1_*std::min(state_->snorm,state_->searchSize);
255 state_->iterateVec->set(x);
256 state_->value = fnew;
257 dwa1->set(*state_->gradientVec);
259 obj.
gradient(*state_->gradientVec,x,ftol); state_->ngrad++;
261 gfree->set(*state_->gradientVec);
264 pwa1->set(gfree->dual());
265 bnd.
pruneActive(*pwa1,state_->gradientVec->dual(),x,xeps,eps);
266 gfree->set(pwa1->dual());
267 gfnorm = gfree->norm();
270 pwa1->axpy(-one,state_->gradientVec->dual());
273 state_->gnorm = pwa1->norm();
275 model_->update(x,*state_->stepVec,*dwa1,*state_->gradientVec,
276 state_->snorm,state_->iter);
278 eps = std::min(eps0_,std::sqrt(state_->gnorm));
279 tol = tol2_*std::sqrt(state_->gnorm);
280 stol = std::min(tol1_,tol*gfnorm);
285 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
341 const Real tol,
const int itermax,
344 std::ostream &outStream)
const {
349 Real ftol = std::sqrt(ROL_EPSILON<Real>());
350 const Real
zero(0), half(0.5), one(1), two(2);
351 Real rho(0), kappa(0), beta(0), sigma(0), alpha(0), pRed(0);
352 Real rtr(0), tnorm(0), rnorm0(0), sMs(0), pMp(0), sMp(0);
359 applyFreePrecond(r,t,x,g0,eps,model,bnd,ftol,pwa,dwa);
362 rnorm0 = std::sqrt(rho);
363 if ( rnorm0 ==
zero ) {
370 for (iter = 0; iter < itermax; ++iter) {
372 applyFreeHessian(q,p,x,g0,eps,model,bnd,ftol,pwa,dwa);
376 alpha = (kappa>
zero) ? rho/kappa :
zero;
377 sigma = trqsol(sMs,pMp,sMp,del);
379 if (kappa <= zero || alpha >= sigma) {
382 iflag = (kappa<=
zero) ? 2 : 3;
385 pRed += half*alpha*rho;
389 applyFreePrecond(r,t,x,g0,eps,model,bnd,ftol,pwa,dwa);
394 if (rtr <= tol*tol || tnorm <= tol) {
395 sMs = sMs + two*alpha*sMp + alpha*alpha*pMp;
407 sMs = sMs + two*alpha*sMp + alpha*alpha*pMp;
408 sMp = beta*(sMp + alpha*pMp);
409 pMp = rho + beta*beta*pMp;
412 if (iter == itermax) {
416 pRed += sigma*(rho-half*sigma*kappa);
541 std::stringstream hist;
542 hist << std::scientific << std::setprecision(6);
543 if ( state_->iter == 0 ) writeName(os);
544 if ( write_header ) writeHeader(os);
545 if ( state_->iter == 0 ) {
547 hist << std::setw(6) << std::left << state_->iter;
548 hist << std::setw(15) << std::left << state_->value;
549 hist << std::setw(15) << std::left << state_->gnorm;
550 hist << std::setw(15) << std::left <<
"---";
551 hist << std::setw(15) << std::left << state_->searchSize;
552 hist << std::setw(10) << std::left << state_->nfval;
553 hist << std::setw(10) << std::left << state_->ngrad;
554 hist << std::setw(10) << std::left << nhess_;
555 hist << std::setw(10) << std::left <<
"---";
556 hist << std::setw(10) << std::left <<
"---";
557 hist << std::setw(10) << std::left <<
"---";
562 hist << std::setw(6) << std::left << state_->iter;
563 hist << std::setw(15) << std::left << state_->value;
564 hist << std::setw(15) << std::left << state_->gnorm;
565 hist << std::setw(15) << std::left << state_->snorm;
566 hist << std::setw(15) << std::left << state_->searchSize;
567 hist << std::setw(10) << std::left << state_->nfval;
568 hist << std::setw(10) << std::left << state_->ngrad;
569 hist << std::setw(10) << std::left << nhess_;
570 hist << std::setw(10) << std::left << TRflag_;
571 hist << std::setw(10) << std::left << SPiter_;
572 hist << 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