DiSMEC++
|
Backtracking line search using the armijo rule. More...
#include <line_search.h>
Public Member Functions | |
BacktrackingLineSearch () | |
double | get_initial_step () const |
void | set_initial_step (double s) |
sets the initial step multiplied. Throws std::invalid_argument if s is not positive. More... | |
double | get_alpha () const |
void | set_alpha (double a) |
sets the alpha parameter. Throws std::invalid_argument if a is not in (0, 1) More... | |
double | get_eta () const |
void | set_eta (double e) |
sets the eta parameter. Throws std::invalid_argument if e is not in (0, 1) More... | |
long | get_max_steps () const |
void | set_max_steps (long n) |
sets the eta parameter. Throws std::invalid_argument if n is not positive More... | |
sLineSearchResult | search (const std::function< double(double)> &projected_objective, double gTs, double f_init) const |
Public Member Functions inherited from dismec::HyperParameterBase | |
HyperParameterBase ()=default | |
virtual | ~HyperParameterBase ()=default |
HyperParameterBase (const HyperParameterBase &)=default | |
HyperParameterBase (HyperParameterBase &&)=default | |
HyperParameterBase & | operator= (HyperParameterBase &&)=default |
HyperParameterBase & | operator= (const HyperParameterBase &)=default |
void | set_hyper_parameter (const std::string &name, long value) |
void | set_hyper_parameter (const std::string &name, double value) |
hyper_param_t | get_hyper_parameter (const std::string &name) const |
std::vector< std::string > | get_hyper_parameter_names () const |
Returns a vector that lists all hyper parameter names. More... | |
Private Attributes | |
double | m_StepSize = 1.0 |
double | m_Alpha = 0.5 |
double | m_Eta = 0.01 |
long | m_MaxSteps = 20 |
Additional Inherited Members | |
Public Types inherited from dismec::HyperParameterBase | |
using | hyper_param_t = std::variant< long, double > |
Protected Member Functions inherited from dismec::HyperParameterBase | |
template<class U , class S > | |
void | declare_hyper_parameter (std::string name, U S::*pointer) |
template<class U , class S > | |
void | declare_hyper_parameter (std::string name, U(S::*getter)() const, void(S::*setter)(U)) |
Declares an constrained hyper-parameter with explicit getter and setter function. More... | |
template<class T , class S > | |
void | declare_sub_object (const std::string &name, T S::*object) |
Declares a sub-object that also contains hyper-parameters. More... | |
Backtracking line search using the armijo rule.
The algorithm starts with a step size of initial_step
(default: 1) times the direction vector. If the reduction of function value is not at least eta
(default 0.01) times the expected reduction according to the gradient (i.e. the linear approximation) a step that is smaller by a factor of alpha
(default 0.5) is tried. This is repeated until the maximum number of steps has been reached (default: 20). If no adequate point is found then, a step of 0
is returned.
This class gets supplied with a "projected objective", i.e. an objective function g: R->R that is related to the original as follows: g(a) = f(x_0 + a d)
where d
is the search direction and x_0
is the starting point.
Definition at line 35 of file line_search.h.
BacktrackingLineSearch::BacktrackingLineSearch | ( | ) |
Definition at line 13 of file line_search.cpp.
References dismec::HyperParameterBase::declare_hyper_parameter(), get_alpha(), get_eta(), get_initial_step(), get_max_steps(), set_alpha(), set_eta(), set_initial_step(), and set_max_steps().
|
inline |
Definition at line 44 of file line_search.h.
References m_Alpha.
Referenced by BacktrackingLineSearch().
|
inline |
Definition at line 48 of file line_search.h.
References m_Eta.
Referenced by BacktrackingLineSearch().
|
inline |
Definition at line 40 of file line_search.h.
References m_StepSize.
Referenced by BacktrackingLineSearch().
|
inline |
Definition at line 52 of file line_search.h.
References m_MaxSteps.
Referenced by BacktrackingLineSearch().
sLineSearchResult BacktrackingLineSearch::search | ( | const std::function< double(double)> & | projected_objective, |
double | gTs, | ||
double | f_init | ||
) | const |
projected_objective | A function that when called with parameter \( \alpha \) , will return the value of the objective along the search direction \(d\) given by \( g(\alpha) = f(x_0 + \alpha d) \). |
gTs | Gradient at 0, i.e. \( \left. \frac{\partial g}{\partial \alpha}\right|_{\alpha=0}\). |
f_init | \( g(0) = f(x_0) \). |
Definition at line 20 of file line_search.cpp.
References m_Alpha, m_Eta, m_MaxSteps, and m_StepSize.
Referenced by dismec::solvers::NewtonWithLineSearch::run().
void BacktrackingLineSearch::set_alpha | ( | double | a | ) |
sets the alpha parameter. Throws std::invalid_argument
if a
is not in (0, 1)
Definition at line 56 of file line_search.cpp.
References m_Alpha.
Referenced by BacktrackingLineSearch(), and TEST_CASE().
void BacktrackingLineSearch::set_eta | ( | double | e | ) |
sets the eta parameter. Throws std::invalid_argument
if e
is not in (0, 1)
Definition at line 66 of file line_search.cpp.
References m_Eta.
Referenced by BacktrackingLineSearch().
void BacktrackingLineSearch::set_initial_step | ( | double | s | ) |
sets the initial step multiplied. Throws std::invalid_argument
if s
is not positive.
Definition at line 42 of file line_search.cpp.
References m_StepSize.
Referenced by BacktrackingLineSearch().
void BacktrackingLineSearch::set_max_steps | ( | long | n | ) |
sets the eta parameter. Throws std::invalid_argument
if n
is not positive
Definition at line 49 of file line_search.cpp.
References m_MaxSteps.
Referenced by BacktrackingLineSearch().
|
private |
Definition at line 68 of file line_search.h.
Referenced by get_alpha(), search(), and set_alpha().
|
private |
Definition at line 70 of file line_search.h.
|
private |
Definition at line 72 of file line_search.h.
Referenced by get_max_steps(), search(), and set_max_steps().
|
private |
Definition at line 65 of file line_search.h.
Referenced by get_initial_step(), search(), and set_initial_step().