44 #ifndef ROL_LINESEARCHSTEP_H 45 #define ROL_LINESEARCHSTEP_H 138 template <
class Real>
145 Teuchos::RCP<NonlinearCG<Real> >
nlcg_;
148 Teuchos::RCP<Vector<Real> >
d_;
175 gs = d_->dot(g.
dual());
177 d_->axpy(-one,g.
dual());
182 gs -= d_->dot(g.
dual());
208 const Teuchos::RCP<
Secant<Real> > &secant = Teuchos::null,
209 const Teuchos::RCP<
Krylov<Real> > &krylov = Teuchos::null,
210 const Teuchos::RCP<NonlinearCG<Real> > &nlcg = Teuchos::null )
211 :
Step<Real>(), desc_(Teuchos::null), secant_(secant),
212 krylov_(krylov), nlcg_(nlcg), lineSearch_(lineSearch),
214 verbosity_(0), computeObj_(true), fval_(0), parlist_(parlist) {
216 Teuchos::ParameterList& Llist = parlist.sublist(
"Step").sublist(
"Line Search");
217 Teuchos::ParameterList& Glist = parlist.sublist(
"General");
219 acceptLastAlpha_ = Llist.get(
"Accept Last Alpha",
false);
220 verbosity_ = Glist.get(
"Print Verbosity",0);
221 computeObj_ = Glist.get(
"Recompute Objective Function",
true);
223 if (lineSearch_ == Teuchos::null) {
224 lineSearchName_ = Llist.sublist(
"Line-Search Method").get(
"Type",
"Cubic Interpolation");
226 lineSearch_ = LineSearchFactory<Real>(parlist);
229 lineSearchName_ = Llist.sublist(
"Line-Search Method").get(
"User Defined Line-Search Name",
230 "Unspecified User Defined Line-Search");
241 Teuchos::ParameterList& list
242 = parlist_.sublist(
"Step").sublist(
"Line Search").sublist(
"Descent Method");
267 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
268 ">>> (LineSearchStep::Initialize): Undefined descent type!");
294 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
295 ">>> (LineSearchStep::Initialize): Undefined descent type!");
298 desc_->initialize(x,s,g,obj,bnd,algo_state);
301 lineSearch_->initialize(x,s,g,obj,bnd);
322 Real zero(0), one(1);
324 desc_->compute(s,x,obj,bnd,algo_state);
328 const Teuchos::RCP<const StepState<Real> > desc_state = desc_->getStepState();
331 s.
set((desc_state->gradientVec)->dual());
338 fval_ = algo_state.
value;
339 step_state->nfval = 0; step_state->ngrad = 0;
340 lineSearch_->setData(algo_state.
gnorm,*(desc_state->gradientVec));
341 lineSearch_->run(step_state->searchSize,fval_,step_state->nfval,step_state->ngrad,gs,s,x,obj,bnd);
344 if(!acceptLastAlpha_) {
345 lineSearch_->setMaxitUpdate(step_state->searchSize,fval_,algo_state.
value);
349 s.
scale(step_state->searchSize);
353 s.
axpy(static_cast<Real>(-1),x);
372 algo_state.
nfval += step_state->nfval;
373 algo_state.
ngrad += step_state->ngrad;
374 desc_->update(x,s,obj,bnd,algo_state);
375 if ( !computeObj_ ) {
385 std::string head = desc_->printHeader();
386 head.erase(std::remove(head.end()-3,head.end(),
'\n'), head.end());
387 std::stringstream hist;
388 hist.write(head.c_str(),head.length());
389 hist << std::setw(10) << std::left <<
"ls_#fval";
390 hist << std::setw(10) << std::left <<
"ls_#grad";
400 std::string name = desc_->printName();
401 std::stringstream hist;
417 std::string desc = desc_->print(algo_state,
false);
418 desc.erase(std::remove(desc.end()-3,desc.end(),
'\n'), desc.end());
419 std::string name = desc_->printName();
420 size_t pos = desc.find(name);
421 if ( pos != std::string::npos ) {
422 desc.erase(pos, name.length());
425 std::stringstream hist;
426 if ( algo_state.
iter == 0 ) {
429 if ( print_header ) {
433 if ( algo_state.
iter == 0 ) {
437 hist << std::setw(10) << std::left << step_state->nfval;
438 hist << std::setw(10) << std::left << step_state->ngrad;
Provides the interface to evaluate objective functions.
virtual void scale(const Real alpha)=0
Compute where .
virtual void plus(const Vector &x)=0
Compute , where .
bool acceptLastAlpha_
For backwards compatibility. When max function evaluations are reached take last step.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
ELineSearch StringToELineSearch(std::string s)
Real GradDotStep(const Vector< Real > &g, const Vector< Real > &s, const Vector< Real > &x, BoundConstraint< Real > &bnd, Real eps=0)
Provides the interface to compute optimization steps with projected Newton's method using line search...
Provides the interface to compute optimization steps.
Teuchos::RCP< StepState< Real > > getState(void)
Contains definitions of custom data types in ROL.
Teuchos::ParameterList parlist_
void pruneInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=0)
Set variables to zero if they correspond to the -inactive set.
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful.
ELineSearch
Enumeration of line-search types.
bool usePreviousAlpha_
If true, use the previously accepted step length (if any) as the new initial step length...
Contains definitions for helper functions in ROL.
Defines the linear algebra or vector space interface.
Provides the interface to compute optimization steps with projected inexact ProjectedNewton's method ...
Provides the interface to compute optimization steps with projected secant method using line search...
virtual Real dot(const Vector &x) const =0
Compute where .
virtual void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0)
Set variables to zero if they correspond to the -active set.
void initialize(Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
Provides the interface to compute optimization steps with Newton's method globalized using line searc...
EDescent StringToEDescent(std::string s)
State for algorithm class. Will be used for restarts.
Provides the interface to compute optimization steps with line search.
Teuchos::RCP< Krylov< Real > > krylov_
Krylov solver object (used for inexact Newton)
bool isActivated(void)
Check if bounds are on.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
std::string ECurvatureConditionToString(ECurvatureCondition ls)
Provides interface for and implements line searches.
const Teuchos::RCP< const StepState< Real > > getStepState(void) const
Get state for step object.
std::string printHeader(void) const
Print iterate header.
LineSearchStep(Teuchos::ParameterList &parlist, const Teuchos::RCP< LineSearch< Real > > &lineSearch=Teuchos::null, const Teuchos::RCP< Secant< Real > > &secant=Teuchos::null, const Teuchos::RCP< Krylov< Real > > &krylov=Teuchos::null, const Teuchos::RCP< NonlinearCG< Real > > &nlcg=Teuchos::null)
Constructor.
Provides interface for and implements limited-memory secant operators.
Teuchos::RCP< LineSearch< Real > > lineSearch_
Line-search object.
ELineSearch els_
enum determines type of line search
Provides definitions for Krylov solvers.
Provides the interface to apply upper and lower bound constraints.
Teuchos::RCP< Step< Real > > desc_
Unglobalized step object.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step.
std::string print(AlgorithmState< Real > &algo_state, bool print_header=false) const
Print iterate status.
Provides the interface to compute optimization steps with nonlinear CG.
Provides the interface to compute optimization steps with projected inexact Newton's method using lin...
ECurvatureCondition
Enumeration of line-search curvature conditions.
Teuchos::RCP< NonlinearCG< Real > > nlcg_
Nonlinear CG object (used for nonlinear CG)
std::string printName(void) const
Print step name.
Teuchos::RCP< Vector< Real > > d_
virtual void set(const Vector &x)
Set where .
ECurvatureCondition StringToECurvatureCondition(std::string s)
Provides the interface to compute optimization steps with the gradient descent method globalized usin...
EDescent
Enumeration of descent direction types.
ECurvatureCondition econd_
enum determines type of curvature condition
Teuchos::RCP< Secant< Real > > secant_
Secant object (used for quasi-Newton)
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
std::string lineSearchName_
Provides the interface to compute optimization steps with a secant method.