44#ifndef ROL_TYPEB_SPECTRALGRADIENTALGORITHM_DEF_HPP
45#define ROL_TYPEB_SPECTRALGRADIENTALGORITHM_DEF_HPP
52template<
typename Real>
59 ParameterList &lslist = list.sublist(
"Step").sublist(
"Spectral Gradient");
60 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
61 lambda_ = lslist.get(
"Initial Spectral Step Size", -1.0);
62 lambdaMin_ = lslist.get(
"Minimum Spectral Step Size", 1e-8);
63 lambdaMax_ = lslist.get(
"Maximum Spectral Step Size", 1e8);
64 sigma1_ = lslist.get(
"Lower Step Size Safeguard", 0.1);
65 sigma2_ = lslist.get(
"Upper Step Size Safeguard", 0.9);
66 rhodec_ = lslist.get(
"Backtracking Rate", 0.5);
67 gamma_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
68 maxSize_ = lslist.get(
"Maximum Storage Size", 10);
69 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
73template<
typename Real>
78 std::ostream &outStream) {
79 const Real
zero(0), one(1);
81 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
93 state_->stepVec->axpy(-one,x);
96 if (lambda_ <= zero && state_->gnorm !=
zero)
100template<
typename Real>
105 std::ostream &outStream ) {
110 Real ftrial(0), fmax(0), gs(0), alpha(1), alphaTmp(1), fmin(0);
113 std::deque<Real> fqueue; fqueue.push_back(
state_->value);
125 state_->iterateVec->set(x);
128 s->set(*
state_->iterateVec);
134 ftrial = obj.
value(*
state_->iterateVec,tol); ls_nfval++;
136 fmax = *std::max_element(fqueue.begin(),fqueue.end());
137 gs =
state_->gradientVec->apply(*s);
139 outStream <<
" In TypeB::SpectralGradientAlgorithm Line Search" << std::endl;
140 outStream <<
" Step size: " << alpha << std::endl;
141 outStream <<
" Trial objective value: " << ftrial << std::endl;
142 outStream <<
" Max stored objective value: " << fmax << std::endl;
143 outStream <<
" Computed reduction: " << fmax-ftrial << std::endl;
144 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
145 outStream <<
" Sufficient decrease bound: " << -gs*
gamma_*alpha << std::endl;
146 outStream <<
" Number of function evaluations: " << ls_nfval << std::endl;
148 while (ftrial > fmax +
gamma_*alpha*gs && ls_nfval <
maxit_) {
149 alphaTmp = -half*alpha*alpha*gs/(ftrial-
state_->value-alpha*gs);
151 state_->iterateVec->set(x);
152 state_->iterateVec->axpy(alpha,*s);
154 ftrial = obj.
value(*
state_->iterateVec,tol); ls_nfval++;
156 outStream <<
" In TypeB::SpectralGradientAlgorithm: Line Search" << std::endl;
157 outStream <<
" Step size: " << alpha << std::endl;
158 outStream <<
" Trial objective value: " << ftrial << std::endl;
159 outStream <<
" Max stored objective value: " << fmax << std::endl;
160 outStream <<
" Computed reduction: " << fmax-ftrial << std::endl;
161 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
162 outStream <<
" Sufficient decrease bound: " << -gs*
gamma_*alpha << std::endl;
163 outStream <<
" Number of function evaluations: " << ls_nfval << std::endl;
166 state_->nfval += ls_nfval;
167 if (
static_cast<int>(fqueue.size()) ==
maxSize_) fqueue.pop_front();
168 fqueue.push_back(ftrial);
173 state_->searchSize = alpha;
178 if (
state_->value <= fmin) {
185 y->set(*
state_->gradientVec);
188 y->plus(*
state_->gradientVec);
192 state_->snorm = std::sqrt(ss);
198 s->set(x); s->axpy(-one,*
state_->stepVec);
201 state_->gnorm = s->norm();
211template<
typename Real>
213 std::ios_base::fmtflags osFlags(os.flags());
215 os << std::string(109,
'-') << std::endl;
216 os <<
"Spectral projected gradient descent";
217 os <<
" status output definitions" << std::endl << std::endl;
218 os <<
" iter - Number of iterates (steps taken)" << std::endl;
219 os <<
" value - Objective function value" << std::endl;
220 os <<
" gnorm - Norm of the gradient" << std::endl;
221 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
222 os <<
" alpha - Line search step length" << std::endl;
223 os <<
" lambda - Spectral step length" << std::endl;
224 os <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
225 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
226 os <<
" #proj - Cumulative number of times the projection was computed" << std::endl;
227 os << std::string(109,
'-') << std::endl;
231 os << std::setw(6) << std::left <<
"iter";
232 os << std::setw(15) << std::left <<
"value";
233 os << std::setw(15) << std::left <<
"gnorm";
234 os << std::setw(15) << std::left <<
"snorm";
235 os << std::setw(15) << std::left <<
"alpha";
236 os << std::setw(15) << std::left <<
"lambda";
237 os << std::setw(10) << std::left <<
"#fval";
238 os << std::setw(10) << std::left <<
"#grad";
239 os << std::setw(10) << std::left <<
"#proj";
244template<
typename Real>
246 std::ios_base::fmtflags osFlags(os.flags());
247 os << std::endl <<
"Projected Spectral Gradient Method (Type B, Bound Constraints)" << std::endl;
251template<
typename Real>
253 std::ios_base::fmtflags osFlags(os.flags());
254 os << std::scientific << std::setprecision(6);
257 if (
state_->iter == 0 ) {
259 os << std::setw(6) << std::left <<
state_->iter;
260 os << std::setw(15) << std::left <<
state_->value;
261 os << std::setw(15) << std::left <<
state_->gnorm;
262 os << std::setw(15) << std::left <<
"---";
263 os << std::setw(15) << std::left <<
"---";
264 os << std::setw(15) << std::left <<
lambda_;
265 os << std::setw(10) << std::left <<
state_->nfval;
266 os << std::setw(10) << std::left <<
state_->ngrad;
267 os << std::setw(10) << std::left <<
state_->nproj;
272 os << std::setw(6) << std::left <<
state_->iter;
273 os << std::setw(15) << std::left <<
state_->value;
274 os << std::setw(15) << std::left <<
state_->gnorm;
275 os << std::setw(15) << std::left <<
state_->snorm;
276 os << std::setw(15) << std::left <<
state_->searchSize;
277 os << std::setw(15) << std::left <<
lambda_;
278 os << std::setw(10) << std::left <<
state_->nfval;
279 os << std::setw(10) << std::left <<
state_->ngrad;
280 os << std::setw(10) << std::left <<
state_->nproj;
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.
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.
Provides an interface to check status of optimization algorithms.
Ptr< PolyhedralProjection< Real > > proj_
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_
void writeHeader(std::ostream &os) const override
Print iterate header.
SpectralGradientAlgorithm(ParameterList &list)
void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout)
void writeName(std::ostream &os) const override
Print step name.
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...
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.