44#ifndef ROL_TYPEU_LINESEARCHALGORITHM_DEF_H
45#define ROL_TYPEU_LINESEARCHALGORITHM_DEF_H
53template<
typename Real>
66 ParameterList& Llist = parlist.sublist(
"Step").sublist(
"Line Search");
67 ParameterList& Glist = parlist.sublist(
"General");
74 lineSearchName_ = Llist.sublist(
"Line-Search Method").get(
"Type",
"Cubic Interpolation");
79 lineSearchName_ = Llist.sublist(
"Line-Search Method").get(
"User Defined Line Search Name",
"Unspecified User Defined Line Search");
81 if (
desc_ == nullPtr) {
82 ParameterList& dlist = Llist.sublist(
"Descent Method");
88 descentName_ = Llist.sublist(
"Descent Method").get(
"User Defined Descent Direction Name",
"Unspecified User Defined Descent Direction");
92template<
typename Real>
96 std::ostream &outStream) {
100 desc_->initialize(x,g);
112template<
typename Real>
116 std::ostream &outStream ) {
122 Ptr<Vector<Real>> gprev = g.
clone();
130 *
state_->gradientVec,obj);
153 gprev->set(*
state_->gradientVec);
159 state_->iterateVec->set(x);
171template<
typename Real>
173 std::stringstream hist;
175 hist << std::string(109,
'-') << std::endl;
177 hist <<
" status output definitions" << std::endl << std::endl;
178 hist <<
" iter - Number of iterates (steps taken)" << std::endl;
179 hist <<
" value - Objective function value" << std::endl;
180 hist <<
" gnorm - Norm of the gradient" << std::endl;
181 hist <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
182 hist <<
" alpha - Line search step length" << std::endl;
183 hist <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
184 hist <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
185 hist <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
186 hist <<
" ls_#grad - Number of the times the gradient was evaluated during the line search" << std::endl;
188 hist <<
" iterCG - Number of Krylov iterations used to compute search direction" << std::endl;
189 hist <<
" flagCG - Krylov solver flag" << std::endl;
191 hist << std::string(109,
'-') << std::endl;
195 hist << std::setw(6) << std::left <<
"iter";
196 hist << std::setw(15) << std::left <<
"value";
197 hist << std::setw(15) << std::left <<
"gnorm";
198 hist << std::setw(15) << std::left <<
"snorm";
199 hist << std::setw(15) << std::left <<
"alpha";
200 hist << std::setw(10) << std::left <<
"#fval";
201 hist << std::setw(10) << std::left <<
"#grad";
202 hist << std::setw(10) << std::left <<
"ls_#fval";
203 hist << std::setw(10) << std::left <<
"ls_#grad";
205 hist << std::setw(10) << std::left <<
"iterCG";
206 hist << std::setw(10) << std::left <<
"flagCG";
212template<
typename Real>
214 std::stringstream hist;
215 hist << std::endl <<
desc_->printName();
222template<
typename Real>
224 std::stringstream hist;
225 hist << std::scientific << std::setprecision(6);
226 if (
state_->iter == 0 ) {
229 if ( print_header ) {
232 if (
state_->iter == 0 ) {
234 hist << std::setw(6) << std::left <<
state_->iter;
235 hist << std::setw(15) << std::left <<
state_->value;
236 hist << std::setw(15) << std::left <<
state_->gnorm;
237 hist << std::setw(15) << std::left <<
"---";
238 hist << std::setw(15) << std::left <<
"---";
239 hist << std::setw(10) << std::left <<
state_->nfval;
240 hist << std::setw(10) << std::left <<
state_->ngrad;
241 hist << std::setw(10) << std::left <<
"---";
242 hist << std::setw(10) << std::left <<
"---";
244 hist << std::setw(10) << std::left <<
"---";
245 hist << std::setw(10) << std::left <<
"---";
251 hist << std::setw(6) << std::left <<
state_->iter;
252 hist << std::setw(15) << std::left <<
state_->value;
253 hist << std::setw(15) << std::left <<
state_->gnorm;
254 hist << std::setw(15) << std::left <<
state_->snorm;
255 hist << std::setw(15) << std::left <<
state_->searchSize;
256 hist << std::setw(10) << std::left <<
state_->nfval;
257 hist << std::setw(10) << std::left <<
state_->ngrad;
258 hist << std::setw(10) << std::left <<
ls_nfval_;
259 hist << std::setw(10) << std::left <<
ls_ngrad_;
261 hist << std::setw(10) << std::left <<
SPiter_;
262 hist << std::setw(10) << std::left <<
SPflag_;
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
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.
Algorithm()
Constructor, given a step and a status test.
const Ptr< CombinedStatusTest< Real > > status_
const Ptr< AlgorithmState< Real > > state_
void writeHeader(std::ostream &os) const override
Print iterate header.
void writeName(std::ostream &os) const override
Print step name.
ELineSearchU els_
enum determines type of line search
ECurvatureConditionU econd_
enum determines type of curvature condition
Ptr< LineSearch_U< Real > > lineSearch_
Line-search object.
EDescentU edesc_
enum determines type of descent direction
Ptr< DescentDirection_U< Real > > desc_
Unglobalized step object.
void writeOutput(std::ostream &os, bool print_header=false) const override
Print iterate status.
std::string lineSearchName_
bool acceptLastAlpha_
For backwards compatibility. When max function evaluations are reached take last step.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void plus(const Vector &x)=0
Compute , where .
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeExitStatus(std::ostream &os) const
LineSearchAlgorithm(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr, const Ptr< DescentDirection_U< Real > > &descent=nullPtr, const Ptr< LineSearch_U< Real > > &lineSearch=nullPtr)
Constructor.
void writeHeader(std::ostream &os) const override
Print iterate header.
void writeName(std::ostream &os) const override
Print step name.
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, std::ostream &outStream=std::cout) override
void writeOutput(std::ostream &os, bool print_header=false) const override
Print iterate status.
void initialize(const Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, std::ostream &outStream=std::cout)
@ LINESEARCH_U_USERDEFINED
@ CURVATURECONDITION_U_WOLFE
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Ptr< LineSearch_U< Real > > LineSearchUFactory(ParameterList &parlist)
std::string ECurvatureConditionUToString(ECurvatureConditionU ls)
ECurvatureConditionU StringToECurvatureConditionU(std::string s)
ELineSearchU StringToELineSearchU(std::string s)
EDescentU StringToEDescentU(std::string s)
Ptr< DescentDirection_U< Real > > DescentDirectionUFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)