10#ifndef ROL_TYPEB_SPECTRALGRADIENTALGORITHM_DEF_HPP
11#define ROL_TYPEB_SPECTRALGRADIENTALGORITHM_DEF_HPP
18template<
typename Real>
25 ParameterList &lslist = list.sublist(
"Step").sublist(
"Spectral Gradient");
26 maxit_ = lslist.get(
"Function Evaluation Limit", 20);
27 lambda_ = lslist.get(
"Initial Spectral Step Size", -1.0);
28 lambdaMin_ = lslist.get(
"Minimum Spectral Step Size", 1e-8);
29 lambdaMax_ = lslist.get(
"Maximum Spectral Step Size", 1e8);
30 sigma1_ = lslist.get(
"Lower Step Size Safeguard", 0.1);
31 sigma2_ = lslist.get(
"Upper Step Size Safeguard", 0.9);
32 rhodec_ = lslist.get(
"Backtracking Rate", 0.5);
33 gamma_ = lslist.get(
"Sufficient Decrease Tolerance", 1e-4);
34 maxSize_ = lslist.get(
"Maximum Storage Size", 10);
35 verbosity_ = list.sublist(
"General").get(
"Output Level", 0);
39template<
typename Real>
44 std::ostream &outStream) {
45 const Real
zero(0), one(1);
47 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
59 state_->stepVec->axpy(-one,x);
62 if (lambda_ <= zero && state_->gnorm !=
zero)
66template<
typename Real>
71 std::ostream &outStream ) {
76 Real ftrial(0), fmax(0), gs(0), alpha(1), alphaTmp(1), fmin(0);
79 std::deque<Real> fqueue; fqueue.push_back(
state_->value);
91 state_->iterateVec->set(x);
94 s->set(*
state_->iterateVec);
100 ftrial = obj.
value(*
state_->iterateVec,tol); ls_nfval++;
102 fmax = *std::max_element(fqueue.begin(),fqueue.end());
103 gs =
state_->gradientVec->apply(*s);
105 outStream <<
" In TypeB::SpectralGradientAlgorithm Line Search" << std::endl;
106 outStream <<
" Step size: " << alpha << std::endl;
107 outStream <<
" Trial objective value: " << ftrial << std::endl;
108 outStream <<
" Max stored objective value: " << fmax << std::endl;
109 outStream <<
" Computed reduction: " << fmax-ftrial << std::endl;
110 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
111 outStream <<
" Sufficient decrease bound: " << -gs*
gamma_*alpha << std::endl;
112 outStream <<
" Number of function evaluations: " << ls_nfval << std::endl;
114 while (ftrial > fmax +
gamma_*alpha*gs && ls_nfval <
maxit_) {
115 alphaTmp = -half*alpha*alpha*gs/(ftrial-
state_->value-alpha*gs);
117 state_->iterateVec->set(x);
118 state_->iterateVec->axpy(alpha,*s);
120 ftrial = obj.
value(*
state_->iterateVec,tol); ls_nfval++;
122 outStream <<
" In TypeB::SpectralGradientAlgorithm: Line Search" << std::endl;
123 outStream <<
" Step size: " << alpha << std::endl;
124 outStream <<
" Trial objective value: " << ftrial << std::endl;
125 outStream <<
" Max stored objective value: " << fmax << std::endl;
126 outStream <<
" Computed reduction: " << fmax-ftrial << std::endl;
127 outStream <<
" Dot product of gradient and step: " << gs << std::endl;
128 outStream <<
" Sufficient decrease bound: " << -gs*
gamma_*alpha << std::endl;
129 outStream <<
" Number of function evaluations: " << ls_nfval << std::endl;
132 state_->nfval += ls_nfval;
133 if (
static_cast<int>(fqueue.size()) ==
maxSize_) fqueue.pop_front();
134 fqueue.push_back(ftrial);
139 state_->searchSize = alpha;
144 if (
state_->value <= fmin) {
151 y->set(*
state_->gradientVec);
154 y->plus(*
state_->gradientVec);
158 state_->snorm = std::sqrt(ss);
164 s->set(x); s->axpy(-one,*
state_->stepVec);
167 state_->gnorm = s->norm();
177template<
typename Real>
179 std::ios_base::fmtflags osFlags(os.flags());
181 os << std::string(109,
'-') << std::endl;
182 os <<
"Spectral projected gradient descent";
183 os <<
" status output definitions" << std::endl << std::endl;
184 os <<
" iter - Number of iterates (steps taken)" << std::endl;
185 os <<
" value - Objective function value" << std::endl;
186 os <<
" gnorm - Norm of the gradient" << std::endl;
187 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
188 os <<
" alpha - Line search step length" << std::endl;
189 os <<
" lambda - Spectral step length" << std::endl;
190 os <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
191 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
192 os <<
" #proj - Cumulative number of times the projection was computed" << std::endl;
193 os << std::string(109,
'-') << std::endl;
197 os << std::setw(6) << std::left <<
"iter";
198 os << std::setw(15) << std::left <<
"value";
199 os << std::setw(15) << std::left <<
"gnorm";
200 os << std::setw(15) << std::left <<
"snorm";
201 os << std::setw(15) << std::left <<
"alpha";
202 os << std::setw(15) << std::left <<
"lambda";
203 os << std::setw(10) << std::left <<
"#fval";
204 os << std::setw(10) << std::left <<
"#grad";
205 os << std::setw(10) << std::left <<
"#proj";
210template<
typename Real>
212 std::ios_base::fmtflags osFlags(os.flags());
213 os << std::endl <<
"Projected Spectral Gradient Method (Type B, Bound Constraints)" << std::endl;
217template<
typename Real>
219 std::ios_base::fmtflags osFlags(os.flags());
220 os << std::scientific << std::setprecision(6);
223 if (
state_->iter == 0 ) {
225 os << std::setw(6) << std::left <<
state_->iter;
226 os << std::setw(15) << std::left <<
state_->value;
227 os << std::setw(15) << std::left <<
state_->gnorm;
228 os << std::setw(15) << std::left <<
"---";
229 os << std::setw(15) << std::left <<
"---";
230 os << std::setw(15) << std::left <<
lambda_;
231 os << std::setw(10) << std::left <<
state_->nfval;
232 os << std::setw(10) << std::left <<
state_->ngrad;
233 os << std::setw(10) << std::left <<
state_->nproj;
238 os << std::setw(6) << std::left <<
state_->iter;
239 os << std::setw(15) << std::left <<
state_->value;
240 os << std::setw(15) << std::left <<
state_->gnorm;
241 os << std::setw(15) << std::left <<
state_->snorm;
242 os << std::setw(15) << std::left <<
state_->searchSize;
243 os << std::setw(15) << std::left <<
lambda_;
244 os << std::setw(10) << std::left <<
state_->nfval;
245 os << std::setw(10) << std::left <<
state_->ngrad;
246 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 writeOutput(std::ostream &os, const bool write_header=false) const override
Print iterate status.
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...
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.