10#ifndef ROL_TYPEU_LINESEARCHALGORITHM_DEF_H
11#define ROL_TYPEU_LINESEARCHALGORITHM_DEF_H
19template<
typename Real>
24 :
Algorithm<Real>(), desc_(descent), lineSearch_(lineSearch),
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");
52 desc_ = DescentDirectionUFactory<Real>(parlist,secant);
55 descentName_ = Llist.sublist(
"Descent Method").get(
"User Defined Descent Direction Name",
"Unspecified User Defined Descent Direction");
59template<
typename Real>
63 std::ostream &outStream) {
66 lineSearch_->initialize(x,g);
67 desc_->initialize(x,g);
69 Real ftol = std::sqrt(ROL_EPSILON<Real>());
71 state_->value = obj.
value(x,ftol);
73 obj.
gradient(*state_->gradientVec,x,ftol);
75 state_->gnorm = state_->gradientVec->norm();
76 state_->snorm = ROL_INF<Real>();
79template<
typename Real>
83 std::ostream &outStream ) {
86 Real ftrial(0), gs(0), tol(std::sqrt(ROL_EPSILON<Real>()));
87 initialize(x,g,obj,outStream);
88 state_->searchSize = one;
89 Ptr<Vector<Real>> gprev = g.
clone();
92 if (verbosity_ > 0) writeOutput(outStream,
true);
94 while (status_->check(*state_)) {
96 desc_->compute(*state_->stepVec,state_->snorm,gs,SPiter_,SPflag_,x,
97 *state_->gradientVec,obj);
100 ftrial = state_->value;
101 ls_nfval_ = 0; ls_ngrad_ = 0;
102 lineSearch_->run(state_->searchSize,ftrial,ls_nfval_,ls_ngrad_,gs,*state_->stepVec,x,obj);
105 if(!acceptLastAlpha_) {
106 lineSearch_->setMaxitUpdate(state_->searchSize,ftrial,state_->value);
110 state_->stepVec->scale(state_->searchSize);
111 state_->snorm *= state_->searchSize;
114 x.
plus(*state_->stepVec);
118 state_->value = obj.
value(x,tol);
120 gprev->set(*state_->gradientVec);
121 obj.
gradient(*state_->gradientVec,x,tol);
123 state_->gnorm = state_->gradientVec->norm();
126 state_->iterateVec->set(x);
127 state_->nfval += ls_nfval_;
128 state_->ngrad += ls_ngrad_;
129 desc_->update(x,*state_->stepVec,*gprev,*state_->gradientVec,state_->snorm,state_->iter);
133 if (verbosity_ > 0) writeOutput(outStream,printHeader_);
138template<
typename Real>
140 std::ios_base::fmtflags osFlags(os.flags());
141 if (verbosity_ > 1) {
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();
184 os <<
"Line Search: " << lineSearchName_;
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_;
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.
Provides interface for and implements limited-memory secant operators.
Provides an interface to check status of optimization algorithms.
Provides an interface to run unconstrained optimization algorithms.
const Ptr< CombinedStatusTest< Real > > status_
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
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
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.
@ CURVATURECONDITION_U_WOLFE
std::string ECurvatureConditionUToString(ECurvatureConditionU ls)
ECurvatureConditionU StringToECurvatureConditionU(std::string s)
@ LINESEARCH_U_USERDEFINED
ELineSearchU StringToELineSearchU(std::string s)
EDescentU StringToEDescentU(std::string s)