44 std::ostream &outStream) {
45 const Real
zero(0), one(1);
47 proj_ = makePtr<PolyhedralProjection<Real>>(makePtrFromRef(bnd));
51 Real ftol = std::sqrt(ROL_EPSILON<Real>());
52 proj_->project(x,outStream); state_->nproj++;
54 state_->value = obj.
value(x,ftol); state_->nfval++;
55 obj.
gradient(*state_->gradientVec,x,ftol); state_->ngrad++;
56 state_->stepVec->set(x);
57 state_->stepVec->axpy(-one,state_->gradientVec->dual());
58 proj_->project(*state_->stepVec,outStream); state_->nproj++;
59 state_->stepVec->axpy(-one,x);
60 state_->gnorm = state_->stepVec->norm();
61 state_->snorm = ROL_INF<Real>();
62 if (lambda_ <= zero && state_->gnorm !=
zero)
63 lambda_ = std::max(lambdaMin_,std::min(one/state_->gnorm,lambdaMax_));
71 std::ostream &outStream ) {
72 const Real half(0.5), one(1), eps(std::sqrt(ROL_EPSILON<Real>()));
74 initialize(x,g,obj,bnd,outStream);
76 Real ftrial(0), fmax(0), gs(0), alpha(1), alphaTmp(1), fmin(0);
77 Real ys(0), ss(0), tol(std::sqrt(ROL_EPSILON<Real>()));
79 std::deque<Real> fqueue; fqueue.push_back(state_->value);
85 if (verbosity_ > 0) writeOutput(outStream,
true);
88 state_->stepVec->set(state_->gradientVec->dual());
89 while (status_->check(*state_)) {
91 state_->iterateVec->set(x);
92 state_->iterateVec->axpy(-lambda_,*state_->stepVec);
93 proj_->project(*state_->iterateVec,outStream); state_->nproj++;
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);
104 if (verbosity_ > 1) {
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);
116 alpha = (sigma1_*alpha <= alphaTmp && alphaTmp <= sigma2_*alpha) ? alphaTmp : rhodec_*alpha;
117 state_->iterateVec->set(x);
118 state_->iterateVec->axpy(alpha,*s);
120 ftrial = obj.
value(*state_->iterateVec,tol); ls_nfval++;
121 if (verbosity_ > 1) {
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);
138 state_->value = ftrial;
139 state_->searchSize = alpha;
140 x.
set(*state_->iterateVec);
144 if (state_->value <= fmin) {
145 fmin = state_->value;
151 y->set(*state_->gradientVec);
153 obj.
gradient(*state_->gradientVec,x,tol); state_->ngrad++;
154 y->plus(*state_->gradientVec);
157 lambda_ = (ys<=eps ? lambdaMax_ : std::max(lambdaMin_,std::min(ss/ys,lambdaMax_)));
158 state_->snorm = std::sqrt(ss);
161 state_->stepVec->set(state_->gradientVec->dual());
164 s->set(x); s->axpy(-one,*state_->stepVec);
165 proj_->project(*s,outStream); state_->nproj++;
167 state_->gnorm = s->norm();
170 if (verbosity_ > 0) writeOutput(outStream,writeHeader_);
173 state_->value = fmin;
179 std::ios_base::fmtflags osFlags(os.flags());
180 if (verbosity_ > 1) {
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";
219 std::ios_base::fmtflags osFlags(os.flags());
220 os << std::scientific << std::setprecision(6);
221 if ( state_->iter == 0 ) writeName(os);
222 if ( write_header ) writeHeader(os);
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;