numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver > Class Template Reference

Class of quasi-Newton method with Broyden-Fletcher-Goldfarb-Shanno (BFGS) formula. More...

#include <num_collect/opt/bfgs_optimizer.h>

+ Inheritance diagram for num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >:
+ Collaboration diagram for num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >:

Public Types

using base_type = descent_method_base<this_type, LineSearcher>
 Type of base class.
 
using hessian_solver_type = HessianSolver
 Type of solvers of linear equation of Hessian.
 
using hessian_type = typename hessian_solver_type::MatrixType
 Type of Hessian.
 
using objective_function_type
 Type of the objective function.
 
using this_type
 This class.
 
using value_type
 Type of function values.
 
using variable_scalar_type = typename variable_type::Scalar
 Type of scalars in variables.
 
using variable_type
 Type of variables.
 

Public Member Functions

 bfgs_optimizer (const objective_function_type &obj_fun=objective_function_type())
 Constructor.
 
auto calc_direction () -> variable_type
 Calculate search direction.
 
void configure_iteration_logger (logging::iterations::iteration_logger< this_type > &iteration_logger) const
 Configure an iteration logger.
 
auto evaluations () const noexcept -> index_type
 Get the number of function evaluations.
 
auto gradient () const -> const variable_type &
 Get gradient for current optimal variable.
 
auto gradient_norm () const -> value_type
 Calculate norm of gradient.
 
void init (const variable_type &init_variable)
 Initialize.
 
auto iterations () const noexcept -> index_type
 Get the number of iterations.
 
auto line_searcher () -> line_searcher_type &
 Access object to perform line search.
 
auto line_searcher () const -> const line_searcher_type &
 Access object to perform line search.
 
auto opt_value () const -> const value_type &
 Get current optimal value.
 
auto opt_variable () const -> const variable_type &
 Get current optimal variable.
 

Private Attributes

hessian_type approx_hessian_ {}
 Approximate Hessian.
 
variable_type diff_grad_ {}
 Difference of gradient.
 
variable_type diff_var_ {}
 Difference of variable.
 
bool has_first_iteration_done_ {false}
 Whether the first iteration has been done.
 
variable_type hessian_var_ {}
 approx_hessian_ * diff_var_
 
variable_type prev_grad_ {}
 Previous gradient.
 
variable_type prev_var_ {}
 Previous variable.
 
hessian_solver_type solver_ {}
 Solver of linear equation of Hessian.
 

Detailed Description

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
class num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >

Class of quasi-Newton method with Broyden-Fletcher-Goldfarb-Shanno (BFGS) formula.

Warning
This implementation assumes Eigen's dense vector types for variable types.
Template Parameters
ObjectiveFunctionType of the objective function.
LineSearcherType of class to perform line search.
HessianSolverType of solvers of linear equation of Hessian.

Definition at line 60 of file bfgs_optimizer.h.

Member Typedef Documentation

◆ base_type

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
using num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::base_type = descent_method_base<this_type, LineSearcher>

Type of base class.

Definition at line 70 of file bfgs_optimizer.h.

◆ hessian_solver_type

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
using num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::hessian_solver_type = HessianSolver

Type of solvers of linear equation of Hessian.

Definition at line 79 of file bfgs_optimizer.h.

◆ hessian_type

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
using num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::hessian_type = typename hessian_solver_type::MatrixType

Type of Hessian.

Definition at line 82 of file bfgs_optimizer.h.

◆ objective_function_type

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
using num_collect::opt::descent_method_base< Derived, LineSearcher >::objective_function_type

Type of the objective function.

Definition at line 42 of file descent_method_base.h.

◆ this_type

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
using num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::this_type
Initial value:
bfgs_optimizer(const objective_function_type &obj_fun=objective_function_type())
Constructor.

This class.

Definition at line 66 of file bfgs_optimizer.h.

◆ value_type

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
using num_collect::opt::descent_method_base< Derived, LineSearcher >::value_type

Type of function values.

Definition at line 49 of file descent_method_base.h.

◆ variable_scalar_type

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
using num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::variable_scalar_type = typename variable_type::Scalar

Type of scalars in variables.

Definition at line 76 of file bfgs_optimizer.h.

◆ variable_type

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
using num_collect::opt::descent_method_base< Derived, LineSearcher >::variable_type

Type of variables.

Definition at line 46 of file descent_method_base.h.

Constructor & Destructor Documentation

◆ bfgs_optimizer()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::bfgs_optimizer ( const objective_function_type & obj_fun = objective_function_type())
inlineexplicit

Constructor.

Parameters
[in]obj_funObjective function.

Definition at line 89 of file bfgs_optimizer.h.

Member Function Documentation

◆ calc_direction()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::calc_direction ( ) -> variable_type
inlinenodiscard

Calculate search direction.

Returns
Search direction.

Definition at line 117 of file bfgs_optimizer.h.

◆ configure_iteration_logger()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
void num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::configure_iteration_logger ( logging::iterations::iteration_logger< this_type > & iteration_logger) const
inline

Configure an iteration logger.

Parameters
[in]iteration_loggerIteration logger.

Definition at line 139 of file bfgs_optimizer.h.

◆ evaluations()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::descent_method_base< Derived, LineSearcher >::evaluations ( ) const -> index_type
inlinenodiscardnoexcept

Get the number of function evaluations.

Returns
Number of function evaluations.

Definition at line 127 of file descent_method_base.h.

◆ gradient()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::descent_method_base< Derived, LineSearcher >::gradient ( ) const -> const variable_type&
inlinenodiscard

Get gradient for current optimal variable.

Returns
Gradient for current optimal variable.

Definition at line 136 of file descent_method_base.h.

◆ gradient_norm()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::descent_method_base< Derived, LineSearcher >::gradient_norm ( ) const -> value_type
inlinenodiscard

Calculate norm of gradient.

Returns
Norm of gradient.

Definition at line 145 of file descent_method_base.h.

◆ init()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
void num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::init ( const variable_type & init_variable)
inline

Initialize.

Parameters
[in]init_variableInitial variable.

Definition at line 107 of file bfgs_optimizer.h.

◆ iterations()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::descent_method_base< Derived, LineSearcher >::iterations ( ) const -> index_type
inlinenodiscardnoexcept

Get the number of iterations.

Returns
Number of iterations.

Definition at line 120 of file descent_method_base.h.

◆ line_searcher() [1/2]

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::descent_method_base< Derived, LineSearcher >::line_searcher ( ) -> line_searcher_type&
inlinenodiscard

Access object to perform line search.

Returns
Object to perform line search.

Definition at line 90 of file descent_method_base.h.

◆ line_searcher() [2/2]

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::descent_method_base< Derived, LineSearcher >::line_searcher ( ) const -> const line_searcher_type&
inlinenodiscard

Access object to perform line search.

Returns
Object to perform line search.

Definition at line 99 of file descent_method_base.h.

◆ opt_value()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::descent_method_base< Derived, LineSearcher >::opt_value ( ) const -> const value_type&
inlinenodiscard

Get current optimal value.

Returns
Current optimal value.

Definition at line 113 of file descent_method_base.h.

◆ opt_variable()

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
auto num_collect::opt::descent_method_base< Derived, LineSearcher >::opt_variable ( ) const -> const variable_type&
inlinenodiscard

Get current optimal variable.

Returns
Current optimal variable.

Definition at line 106 of file descent_method_base.h.

Member Data Documentation

◆ approx_hessian_

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
hessian_type num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::approx_hessian_ {}
private

Approximate Hessian.

Definition at line 154 of file bfgs_optimizer.h.

◆ diff_grad_

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
variable_type num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::diff_grad_ {}
private

Difference of gradient.

Definition at line 166 of file bfgs_optimizer.h.

◆ diff_var_

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
variable_type num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::diff_var_ {}
private

Difference of variable.

Definition at line 163 of file bfgs_optimizer.h.

◆ has_first_iteration_done_

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
bool num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::has_first_iteration_done_ {false}
private

Whether the first iteration has been done.

Definition at line 172 of file bfgs_optimizer.h.

◆ hessian_var_

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
variable_type num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::hessian_var_ {}
private

approx_hessian_ * diff_var_

Definition at line 169 of file bfgs_optimizer.h.

◆ prev_grad_

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
variable_type num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::prev_grad_ {}
private

Previous gradient.

Definition at line 160 of file bfgs_optimizer.h.

◆ prev_var_

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
variable_type num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::prev_var_ {}
private

Previous variable.

Definition at line 157 of file bfgs_optimizer.h.

◆ solver_

template<concepts::multi_variate_differentiable_objective_function ObjectiveFunction, concepts::line_searcher LineSearcher = backtracking_line_searcher<ObjectiveFunction>, base::concepts::eigen_solver_of< Eigen::MatrixX< typename ObjectiveFunction::value_type >, typename ObjectiveFunction::variable_type > HessianSolver = Eigen::LLT<Eigen::MatrixX<typename ObjectiveFunction::value_type>>>
hessian_solver_type num_collect::opt::bfgs_optimizer< ObjectiveFunction, LineSearcher, HessianSolver >::solver_ {}
private

Solver of linear equation of Hessian.

Definition at line 175 of file bfgs_optimizer.h.


The documentation for this class was generated from the following file: