38template <concepts::differentiable_
objective_function ObjectiveFunction>
57 using value_type =
typename objective_function_type::value_type;
59 static_assert(std::is_same_v<typename variable_type::Scalar, value_type>,
60 "This class assumes that scalars in Eigen::Matrix class is same as "
70 : obj_fun_(obj_fun) {}
78 variable_ = init_variable;
79 obj_fun_.evaluate_on(variable_);
92 const value_type prev_value = obj_fun_.value();
94 armijo_coeff_ * obj_fun_.gradient().dot(direction);
99 variable_ = prev_var + step_ * direction;
100 obj_fun_.evaluate_on(variable_);
102 if (obj_fun_.value() <= prev_value + step_ * step_coeff) {
105 step_ *= step_scale_;
145 return obj_fun_.value();
154 return obj_fun_.gradient();
182 "Coefficient in Armijo rule must be in the range (0, 1).");
183 armijo_coeff_ = value;
196 "Ratio to scale step sizes must be in the range (0, 1).");
209 static inline const auto init_step =
static_cast<value_type>(1.0);
215 static inline const auto default_armijo_coeff =
222 static inline const auto default_step_scale =
static_cast<value_type>(0.5);
Class of exception on failure in algorithm.
auto armijo_coeff(value_type value) -> backtracking_line_searcher &
Set the coefficient in Armijo rule.
auto obj_fun() const -> const objective_function_type &
Access objective function.
auto gradient() const -> const variable_type &
Get gradient for current optimal variable.
typename objective_function_type::variable_type variable_type
Type of variables.
auto step_scale(value_type value) -> backtracking_line_searcher &
Set the ratio to scale step sizes.
auto obj_fun() -> objective_function_type &
Access objective function.
void search(const variable_type &direction)
Search step size.
auto opt_value() const -> const value_type &
Get current optimal value.
auto evaluations() const -> index_type
Get the number of function evaluations.
backtracking_line_searcher(const objective_function_type &obj_fun=objective_function_type())
Constructor.
objective_function_type obj_fun_
Objective function.
typename objective_function_type::value_type value_type
Type of function values.
void init(const variable_type &init_variable)
Initialize.
auto last_step() const -> value_type
Get last step size.
auto opt_variable() const -> const variable_type &
Get current optimal variable.
ObjectiveFunction objective_function_type
Type of the objective function.
Class to perform backtracking line search.
Concept of multi-variate first-order differentiable objective functions in optimization.
Definition of differentiable_objective_function concept.
Definition of exceptions.
Definition of index_type type.
Definition of macros for logging.
#define NUM_COLLECT_LOG_AND_THROW(EXCEPTION_TYPE,...)
Write an error log and throw an exception for an error.
Definition of multi_variate_differentiable_objective_function concept.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of optimization algorithms.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.