10#ifndef ROL_TYPEU_LINESEARCHALGORITHM_DEF_H
11#define ROL_TYPEU_LINESEARCHALGORITHM_DEF_H
19template<
typename Real>
32 ParameterList& Llist = parlist.sublist(
"Step").sublist(
"Line Search");
33 ParameterList& Glist = parlist.sublist(
"General");
34 std::string condType = Llist.sublist(
"Curvature Condition").get(
"Type",
"Strong Wolfe Conditions");
41 lineSearchName_ = Llist.sublist(
"Line-Search Method").get(
"Type",
"Cubic Interpolation");
46 lineSearchName_ = Llist.sublist(
"Line-Search Method").get(
"User Defined Line Search Name",
"Unspecified User Defined Line Search");
48 if (
desc_ == nullPtr) {
49 ParameterList& dlist = Llist.sublist(
"Descent Method");
55 descentName_ = Llist.sublist(
"Descent Method").get(
"User Defined Descent Direction Name",
"Unspecified User Defined Descent Direction");
59template<
typename Real>
63 std::ostream &outStream) {
67 desc_->initialize(x,g);
79template<
typename Real>
83 std::ostream &outStream ) {
89 Ptr<Vector<Real>> gprev = g.
clone();
120 gprev->set(*
state_->gradientVec);
126 state_->iterateVec->set(x);
138template<
typename Real>
140 std::ios_base::fmtflags osFlags(os.flags());
142 os << std::string(109,
'-') << std::endl;
144 os <<
" status output definitions" << std::endl << std::endl;
145 os <<
" iter - Number of iterates (steps taken)" << std::endl;
146 os <<
" value - Objective function value" << std::endl;
147 os <<
" gnorm - Norm of the gradient" << std::endl;
148 os <<
" snorm - Norm of the step (update to optimization vector)" << std::endl;
149 os <<
" alpha - Line search step length" << std::endl;
150 os <<
" #fval - Cumulative number of times the objective function was evaluated" << std::endl;
151 os <<
" #grad - Cumulative number of times the gradient was computed" << std::endl;
152 os <<
" ls_#fval - Number of the times the objective function was evaluated during the line search" << std::endl;
153 os <<
" ls_#grad - Number of the times the gradient was evaluated during the line search" << std::endl;
155 os <<
" iterCG - Number of Krylov iterations used to compute search direction" << std::endl;
156 os <<
" flagCG - Krylov solver flag" << std::endl;
158 os << std::string(109,
'-') << std::endl;
162 os << std::setw(6) << std::left <<
"iter";
163 os << std::setw(15) << std::left <<
"value";
164 os << std::setw(15) << std::left <<
"gnorm";
165 os << std::setw(15) << std::left <<
"snorm";
166 os << std::setw(15) << std::left <<
"alpha";
167 os << std::setw(10) << std::left <<
"#fval";
168 os << std::setw(10) << std::left <<
"#grad";
169 os << std::setw(10) << std::left <<
"ls_#fval";
170 os << std::setw(10) << std::left <<
"ls_#grad";
172 os << std::setw(10) << std::left <<
"iterCG";
173 os << std::setw(10) << std::left <<
"flagCG";
179template<
typename Real>
181 std::ios_base::fmtflags osFlags(os.flags());
182 os << std::endl <<
desc_->printName();
189template<
typename Real>
191 std::ios_base::fmtflags osFlags(os.flags());
192 os << std::scientific << std::setprecision(6);
193 if (
state_->iter == 0 ) {
196 if ( print_header ) {
199 if (
state_->iter == 0 ) {
201 os << std::setw(6) << std::left <<
state_->iter;
202 os << std::setw(15) << std::left <<
state_->value;
203 os << std::setw(15) << std::left <<
state_->gnorm;
204 os << std::setw(15) << std::left <<
"---";
205 os << std::setw(15) << std::left <<
"---";
206 os << std::setw(10) << std::left <<
state_->nfval;
207 os << std::setw(10) << std::left <<
state_->ngrad;
208 os << std::setw(10) << std::left <<
"---";
209 os << std::setw(10) << std::left <<
"---";
211 os << std::setw(10) << std::left <<
"---";
212 os << std::setw(10) << std::left <<
"---";
218 os << std::setw(6) << std::left <<
state_->iter;
219 os << std::setw(15) << std::left <<
state_->value;
220 os << std::setw(15) << std::left <<
state_->gnorm;
221 os << std::setw(15) << std::left <<
state_->snorm;
222 os << std::setw(15) << std::left <<
state_->searchSize;
223 os << std::setw(10) << std::left <<
state_->nfval;
224 os << std::setw(10) << std::left <<
state_->ngrad;
225 os << std::setw(10) << std::left <<
ls_nfval_;
226 os << std::setw(10) << std::left <<
ls_ngrad_;
228 os << std::setw(10) << std::left <<
SPiter_;
229 os << std::setw(10) << std::left <<
SPflag_;
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Provides the interface to compute unconstrained optimization steps for line search.
Provides interface for and implements line searches.
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.
Algorithm()
Constructor, given a step and a status test.
const Ptr< CombinedStatusTest< Real > > status_
const Ptr< AlgorithmState< Real > > state_
Provides interface for and implements limited-memory secant operators.
Provides an interface to check status of optimization algorithms.
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeExitStatus(std::ostream &os) const
Ptr< DescentDirection_U< Real > > desc_
Unglobalized step object.
LineSearchAlgorithm(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr, const Ptr< DescentDirection_U< Real > > &descent=nullPtr, const Ptr< LineSearch_U< Real > > &lineSearch=nullPtr)
Constructor.
bool acceptLastAlpha_
For backwards compatibility. When max function evaluations are reached take last step.
void writeHeader(std::ostream &os) const override
Print iterate header.
Ptr< LineSearch_U< Real > > lineSearch_
Line-search object.
void writeName(std::ostream &os) const override
Print step name.
EDescentU edesc_
enum determines type of descent direction
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, std::ostream &outStream=std::cout) override
std::string lineSearchName_
ELineSearchU els_
enum determines type of line search
void initialize(const Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, std::ostream &outStream=std::cout)
void writeOutput(std::ostream &os, const bool print_header=false) const override
Print iterate status.
ECurvatureConditionU econd_
enum determines type of curvature condition
Defines the linear algebra or vector space interface.
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Ptr< LineSearch_U< Real > > LineSearchUFactory(ParameterList &parlist)
@ CURVATURECONDITION_U_WOLFE
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
std::string ECurvatureConditionUToString(ECurvatureConditionU ls)
ECurvatureConditionU StringToECurvatureConditionU(std::string s)
@ LINESEARCH_U_USERDEFINED
ELineSearchU StringToELineSearchU(std::string s)
EDescentU StringToEDescentU(std::string s)
Ptr< DescentDirection_U< Real > > DescentDirectionUFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)