10#ifndef ROL_TYPEB_KELLEYSACHSALGORITHM_DEF_HPP
11#define ROL_TYPEB_KELLEYSACHSALGORITHM_DEF_HPP
16template<
typename Real>
23 ParameterList &trlist = list.sublist(
"Step").sublist(
"Trust Region");
25 state_->searchSize = trlist.get(
"Initial Radius", -1.0);
27 eta0_ = trlist.get(
"Step Acceptance Threshold", 0.05);
28 eta1_ = trlist.get(
"Radius Shrinking Threshold", 0.05);
29 eta2_ = trlist.get(
"Radius Growing Threshold", 0.9);
30 gamma0_ = trlist.get(
"Radius Shrinking Rate (Negative rho)", 0.0625);
31 gamma1_ = trlist.get(
"Radius Shrinking Rate (Positive rho)", 0.25);
32 gamma2_ = trlist.get(
"Radius Growing Rate", 2.5);
33 TRsafe_ = trlist.get(
"Safeguard Size", 100.0);
36 maxit_ = list.sublist(
"General").sublist(
"Krylov").get(
"Iteration Limit", 20);
37 tol1_ = list.sublist(
"General").sublist(
"Krylov").get(
"Absolute Tolerance", 1e-4);
38 tol2_ = list.sublist(
"General").sublist(
"Krylov").get(
"Relative Tolerance", 1e-2);
40 minit_ = trlist.sublist(
"Kelley-Sachs").get(
"Maximum Number of Smoothing Iterations", 20);
41 mu0_ = trlist.sublist(
"Kelley-Sachs").get(
"Sufficient Decrease Parameter", 1e-4);
42 mu1_ = trlist.sublist(
"Kelley-Sachs").get(
"Post-Smoothing Decrease Parameter", 0.9999);
43 eps0_ = trlist.sublist(
"Kelley-Sachs").get(
"Binding Set Tolerance", 1e-3);
44 beta_ = trlist.sublist(
"Kelley-Sachs").get(
"Post-Smoothing Backtracking Rate", 1e-2);
45 alpha0_ = trlist.sublist(
"Kelley-Sachs").get(
"Initial Post-Smoothing Step Size", 1.0);
47 verbosity_ = list.sublist(
"General").get(
"Output Level",0);
50 useSecantPrecond_ = list.sublist(
"General").sublist(
"Secant").get(
"Use as Preconditioner",
false);
51 useSecantHessVec_ = list.sublist(
"General").sublist(
"Secant").get(
"Use as Hessian",
false);
53 model_ = makePtr<TrustRegionModel_U<Real>>(list,secant);
54 useSecantPrecond_ = list.sublist(
"General").sublist(
"Secant").get(
"Use as Preconditioner",
false);
55 useSecantHessVec_ = list.sublist(
"General").sublist(
"Secant").get(
"Use as Hessian",
false);
56 if (secant == nullPtr) {
57 std::string secantType = list.sublist(
"General").sublist(
"Secant").get(
"Type",
"Limited-Memory BFGS");
62template<
typename Real>
67 std::ostream &outStream) {
75 state_->iterateVec->set(x);
84 state_->stepVec->axpy(-one,x);
88 if (
state_->searchSize <=
static_cast<Real
>(0) ) {
93template<
typename Real>
98 std::ostream &outStream ) {
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);
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();
114 gfree->set(*
state_->gradientVec);
117 pwa1->set(gfree->dual());
119 gfree->set(pwa1->dual());
120 gfnorm = gfree->norm();
125 stol = std::min(
tol1_,tol*gfnorm);
134 *pwa1,*dwa1,*pwa2,*dwa2,*pwa3,*dwa3,outStream);
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) {
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;
185 else if (rho >=
eta2_) {
193 pwa2->set(dwa1->dual());
194 pwa1->set(x); pwa1->axpy(-alpha/
alpha0_,*pwa2);
198 while ((fnew-ftrial) >=
mu1_*(
state_->value-ftrial)) {
200 pwa1->set(x); pwa1->axpy(-alpha/
alpha0_,*pwa2);
204 if ( cnt >=
minit_ )
break;
207 state_->stepVec->set(*pwa1);
211 if (std::isnan(fnew)) {
222 state_->iterateVec->set(x);
224 dwa1->set(*
state_->gradientVec);
228 gfree->set(*
state_->gradientVec);
231 pwa1->set(gfree->dual());
233 gfree->set(pwa1->dual());
234 gfnorm = gfree->norm();
237 pwa1->axpy(-one,
state_->gradientVec->dual());
240 state_->gnorm = pwa1->norm();
247 stol = std::min(
tol1_,tol*gfnorm);
257template<
typename Real>
259 std::ostream &outStream ) {
264 throw Exception::NotImplemented(
">>> TypeB::KelleySachsAlgorithm::run : This algorithm cannot solve problems with linear equality constraints!");
268template<
typename Real>
276 std::ostream &outStream ) {
277 throw Exception::NotImplemented(
">>> TypeB::KelleySachsAlgorithm::run : This algorithm cannot solve problems with linear equality constraints!");
280template<
typename Real>
284 const Real del)
const {
287 Real rad = ptx*ptx + ptp*(dsq-xtx);
288 rad = std::sqrt(std::max(rad,
zero));
291 sigma = (dsq-xtx)/(ptx+rad);
293 else if (rad >
zero) {
294 sigma = (rad-ptx)/ptp;
302template<
typename Real>
308 const Real tol,
const int itermax,
311 std::ostream &outStream)
const {
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);
329 rnorm0 = std::sqrt(rho);
330 if ( rnorm0 ==
zero ) {
337 for (iter = 0; iter < itermax; ++iter) {
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;
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);
391template<
typename Real>
423template<
typename Real>
454template<
typename Real>
456 std::ios_base::fmtflags osFlags(os.flags());
458 os << std::string(114,
'-') << std::endl;
459 os <<
" Kelley-Sachs trust-region method status output definitions" << std::endl << std::endl;
460 os <<
" iter - Number of iterates (steps taken)" << std::endl;
461 os <<
" value - Objective function value" << std::endl;
462 os <<
" gnorm - Norm of the gradient" << std::endl;
463 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
464 os <<
" delta - Trust-Region radius" << std::endl;
465 os <<
" #fval - Number of times the objective function was evaluated" << std::endl;
466 os <<
" #grad - Number of times the gradient was computed" << std::endl;
467 os <<
" #hess - Number of times the Hessian was applied" << std::endl;
469 os <<
" tr_flag - Trust-Region flag" << std::endl;
475 os <<
" iterCG - Number of Truncated CG iterations" << std::endl << std::endl;
476 os <<
" flagGC - Trust-Region Truncated CG flag" << std::endl;
481 os << std::string(114,
'-') << std::endl;
484 os << std::setw(6) << std::left <<
"iter";
485 os << std::setw(15) << std::left <<
"value";
486 os << std::setw(15) << std::left <<
"gnorm";
487 os << std::setw(15) << std::left <<
"snorm";
488 os << std::setw(15) << std::left <<
"delta";
489 os << std::setw(10) << std::left <<
"#fval";
490 os << std::setw(10) << std::left <<
"#grad";
491 os << std::setw(10) << std::left <<
"#hess";
492 os << std::setw(10) << std::left <<
"tr_flag";
493 os << std::setw(10) << std::left <<
"iterCG";
494 os << std::setw(10) << std::left <<
"flagCG";
499template<
typename Real>
501 std::ios_base::fmtflags osFlags(os.flags());
502 os << std::endl <<
"Kelley-Sachs Trust-Region Method (Type B, Bound Constraints)" << std::endl;
506template<
typename Real>
508 std::ios_base::fmtflags osFlags(os.flags());
509 os << std::scientific << std::setprecision(6);
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_;
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0 zero)()
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Provides the interface to apply upper and lower bound constraints.
void pruneInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the -inactive set.
void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the -active set.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
Provides interface for and implements limited-memory secant operators.
Provides an interface to check status of optimization algorithms.
Provides the interface to evaluate trust-region model functions.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &s, Real &tol) override
virtual void precond(Vector< Real > &Pv, const Vector< Real > &v, const Vector< Real > &s, Real &tol) override
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on bound constrained problems (Type-B). This is the primary Type-B interface.
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeExitStatus(std::ostream &os) const
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
Real eta1_
Radius decrease threshold (default: 0.05).
Real gamma1_
Radius decrease rate (positive rho) (default: 0.25).
int minit_
Maximum number of minor (subproblem solve) iterations (default: 10).
Real eta2_
Radius increase threshold (default: 0.9).
Real eps0_
Epsilon binding set tolerance (default: 1e-3).
Real trqsol(const Real xtx, const Real ptp, const Real ptx, const Real del) const
Real eta0_
Step acceptance threshold (default: 0.05).
Real mu1_
Sufficient decrease parameter postsmoothing (default: 0.9999).
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout) override
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
unsigned verbosity_
Output level (default: 0).
int maxit_
Maximum number of CG iterations (default: 20).
Real alpha0_
Initial step size for projected search (default: 1).
Real tol2_
Relative tolerance for truncated CG (default: 1e-2).
void writeOutput(std::ostream &os, const bool write_header=false) const override
Print iterate status.
Real mu0_
Sufficient decrease parameter (default: 1e-2).
KelleySachsAlgorithm(ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
bool writeHeader_
Flag to write header at every iteration.
Ptr< TrustRegionModel_U< Real > > model_
Container for trust-region model.
void applyFreePrecond(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g, Real eps, TrustRegionModel_U< Real > &model, BoundConstraint< Real > &bnd, Real &tol, Vector< Real > &pwa, Vector< Real > &dwa) const
TRUtils::ETRFlag TRflag_
Trust-region exit flag.
int SPflag_
Subproblem solver termination flag.
Real beta_
Projected search backtracking rate (default: 1e-2).
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout)
Real gamma2_
Radius increase rate (default: 2.5).
Real delMax_
Maximum trust-region radius (default: ROL_INF).
ESecant esec_
Secant type (default: Limited-Memory BFGS).
void writeName(std::ostream &os) const override
Print step name.
int SPiter_
Subproblem solver iteration count.
Real eps_
Safeguard for numerically evaluating ratio.
Real tol1_
Absolute tolerance for truncated CG (default: 1e-4).
Real TRsafe_
Safeguard size for numerically evaluating ratio (default: 1e2).
void writeHeader(std::ostream &os) const override
Print iterate header.
int nhess_
Number of Hessian applications.
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
Real gamma0_
Radius decrease rate (negative rho) (default: 0.0625).
void applyFreeHessian(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g, Real eps, TrustRegionModel_U< Real > &model, BoundConstraint< Real > &bnd, Real &tol, Vector< Real > &pwa, Vector< Real > &dwa) const
bool useSecantPrecond_
Flag to use secant as a preconditioner (default: false).
bool useSecantHessVec_
Flag to use secant as Hessian (default: false).
Defines the linear algebra or vector space interface.
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
virtual Real norm() const =0
Returns where .
virtual void set(const Vector &x)
Set where .
virtual void scale(const Real alpha)=0
Compute where .
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual void plus(const Vector &x)=0
Compute , where .
virtual void zero()
Set to zero vector.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
void analyzeRatio(Real &rho, ETRFlag &flag, const Real fold, const Real ftrial, const Real pRed, const Real epsi, std::ostream &outStream=std::cout, const bool print=false)
std::string ETRFlagToString(ETRFlag trf)
std::string NumberToString(T Number)
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
ESecant StringToESecant(std::string s)
Real ROL_OVERFLOW(void)
Platform-dependent maximum double.
std::string ECGFlagToString(ECGFlag cgf)