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

Class of downhill simplex method [20]. More...

#include <num_collect/opt/downhill_simplex.h>

Inheritance diagram for num_collect::opt::downhill_simplex< ObjectiveFunction >:
Collaboration diagram for num_collect::opt::downhill_simplex< ObjectiveFunction >:

Public Types

using objective_function_type = ObjectiveFunction
 Type of the objective function.
enum class  process_type : std::uint8_t {
  none , reflection , reflection_and_expansion , contraction ,
  multiple_contraction
}
 Type of processes. More...
using this_type = downhill_simplex<ObjectiveFunction>
 This class.
using value_type = typename objective_function_type::value_type
 Type of function values.
using variable_scalar_type = typename variable_type::Scalar
 Type of scalars in variables.
using variable_type = typename objective_function_type::variable_type
 Type of variables.

Public Member Functions

 downhill_simplex (const objective_function_type &obj_fun=objective_function_type())
 Constructor.
void change_objective_function (const objective_function_type &obj_fun)
 Change the objective function.
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.
void init (const variable_type &init_var, const variable_scalar_type &width=default_width)
 Initialize the algorithm.
auto is_stop_criteria_satisfied () const -> bool
 Determine if stopping criteria of the algorithm are satisfied.
void iterate ()
 Iterate the algorithm once.
auto iterations () const noexcept -> index_type
 Get the number of iterations.
auto last_process () const noexcept -> process_type
 Get last process.
auto last_process_name () const noexcept -> std::string_view
 Get the name of the last process.
auto opt_value () const -> const value_type &
 Get current optimal value.
auto opt_variable () const -> const variable_type &
 Get current optimal variable.
auto simplex_size () const -> variable_scalar_type
 Get the size of simplex.
auto tol_simplex_size (const variable_scalar_type &value) -> downhill_simplex &
 Set tolerance of size of simplex.
Public Member Functions inherited from num_collect::opt::optimizer_base< downhill_simplex< ObjectiveFunction > >
 optimizer_base (logging::log_tag_view tag)
 Constructor.
auto evaluations () const noexcept -> index_type
 Get the number of function evaluations.
auto iterations () const noexcept -> index_type
 Get the number of iterations.
auto opt_value () const
 Get current optimal value.
auto opt_variable () const
 Get current optimal variable.
Public Member Functions inherited from num_collect::base::iterative_solver_base< downhill_simplex< ObjectiveFunction > >
 iterative_solver_base (logging::log_tag_view tag)
 Constructor.
auto is_stop_criteria_satisfied () const -> bool
 Determine if stopping criteria of the algorithm are satisfied.
void iterate ()
 Iterate the algorithm once.
void solve ()
 Solve the problem.
Public Member Functions inherited from num_collect::logging::logging_mixin
 logging_mixin (log_tag_view tag)
 Constructor.
template<typename Child>
void configure_child_algorithm_logger_if_exists (Child &child)
 Configure a logger of a child algorithm if exists.
auto logger () const noexcept -> const num_collect::logging::logger &
 Access to the logger.
auto logger () noexcept -> num_collect::logging::logger &
 Access to the logger.
Public Member Functions inherited from num_collect::logging::iterations::iteration_logger_mixin< downhill_simplex< ObjectiveFunction > >
 iteration_logger_mixin ()=default
 Constructor.
void configure_iteration_logger (num_collect::logging::iterations::iteration_logger< downhill_simplex< ObjectiveFunction > > &iteration_logger) const
 Configure an iteration logger.
auto initialize_iteration_logger () -> num_collect::logging::iterations::iteration_logger< downhill_simplex< ObjectiveFunction > > &
 Get the iteration logger.

Static Public Member Functions

static auto process_name (process_type process) -> std::string_view
 Convert type of process to string.

Static Public Attributes

static const auto default_width
 Default width of simplex.

Private Member Functions

auto calc_face_center () const -> variable_type
 Calculate center of the face composed from points other than highest point.
void contract (const variable_type &face_center)
 Contract the highest point to the opposite face.
auto evaluate_on (const variable_type &variable)
 Evaluate function value.
void expand (const variable_type &face_center)
 Expand the simplex.
void multi_contract ()
 Contract all points other than the lowest point toward the lowest point.
void reflect (const variable_type &face_center)
 Reflect the highest point.
void reorder ()
 Reorder function values.

Private Attributes

index_type dim_ {0}
 Number of dimension.
index_type evaluations_ {0}
 Number of function evaluations.
index_type iterations_ {0}
 Number of iterations.
index_type max_iterations_ {default_max_iterations}
 Maximum number of iterations.
objective_function_type obj_fun_
 Objective function.
std::vector< variable_type, Eigen::aligned_allocator< variable_type > > points_ {}
 Points.
process_type process_ {process_type::none}
 Last process.
variable_scalar_type tol_simplex_size_ {default_tol_simplex_size}
 Tolerance of size of simplex.
std::vector< std::size_t > value_order_ {}
 Order of function values (ascending order).
std::vector< value_typevalues_ {}
 Function values.

Static Private Attributes

static constexpr index_type default_max_iterations = 1000
 Default maximum number of iterations.
static const auto default_tol_simplex_size
 Default tolerance of size of simplex.
static const auto half = static_cast<variable_scalar_type>(0.5)
 Half.
static const auto twice = static_cast<variable_scalar_type>(2.0)
 Two.

Additional Inherited Members

Protected Member Functions inherited from num_collect::base::iterative_solver_base< downhill_simplex< ObjectiveFunction > >
auto derived () noexcept -> downhill_simplex< ObjectiveFunction > &
 Access derived object.

Detailed Description

template<concepts::multi_variate_objective_function ObjectiveFunction>
class num_collect::opt::downhill_simplex< ObjectiveFunction >

Class of downhill simplex method [20].

Template Parameters
ObjectiveFunctionType of the objective function.

Definition at line 59 of file downhill_simplex.h.

Member Typedef Documentation

◆ objective_function_type

template<concepts::multi_variate_objective_function ObjectiveFunction>
using num_collect::opt::downhill_simplex< ObjectiveFunction >::objective_function_type = ObjectiveFunction

Type of the objective function.

Definition at line 66 of file downhill_simplex.h.

◆ this_type

template<concepts::multi_variate_objective_function ObjectiveFunction>
using num_collect::opt::downhill_simplex< ObjectiveFunction >::this_type = downhill_simplex<ObjectiveFunction>

This class.

Definition at line 63 of file downhill_simplex.h.

◆ value_type

template<concepts::multi_variate_objective_function ObjectiveFunction>
using num_collect::opt::downhill_simplex< ObjectiveFunction >::value_type = typename objective_function_type::value_type

Type of function values.

Definition at line 75 of file downhill_simplex.h.

◆ variable_scalar_type

template<concepts::multi_variate_objective_function ObjectiveFunction>
using num_collect::opt::downhill_simplex< ObjectiveFunction >::variable_scalar_type = typename variable_type::Scalar

Type of scalars in variables.

Definition at line 72 of file downhill_simplex.h.

◆ variable_type

template<concepts::multi_variate_objective_function ObjectiveFunction>
using num_collect::opt::downhill_simplex< ObjectiveFunction >::variable_type = typename objective_function_type::variable_type

Type of variables.

Definition at line 69 of file downhill_simplex.h.

Member Enumeration Documentation

◆ process_type

template<concepts::multi_variate_objective_function ObjectiveFunction>
enum class num_collect::opt::downhill_simplex< ObjectiveFunction >::process_type : std::uint8_t
strong

Type of processes.

Enumerator
none 

None.

reflection 

Reflection.

reflection_and_expansion 

Reflection and expansion.

contraction 

Contraction.

multiple_contraction 

Multiple contraction.

Definition at line 78 of file downhill_simplex.h.

Constructor & Destructor Documentation

◆ downhill_simplex()

template<concepts::multi_variate_objective_function ObjectiveFunction>
num_collect::opt::downhill_simplex< ObjectiveFunction >::downhill_simplex ( const objective_function_type & obj_fun = objective_function_type())
inlineexplicit

Constructor.

Parameters
[in]obj_funObjective function.

Definition at line 115 of file downhill_simplex.h.

Member Function Documentation

◆ calc_face_center()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::calc_face_center ( ) const -> variable_type
inlinenodiscardprivate

Calculate center of the face composed from points other than highest point.

Returns
Center.

Definition at line 322 of file downhill_simplex.h.

◆ change_objective_function()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::change_objective_function ( const objective_function_type & obj_fun)
inline

Change the objective function.

Parameters
[in]obj_funObjective function.

Definition at line 126 of file downhill_simplex.h.

◆ configure_iteration_logger()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::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 203 of file downhill_simplex.h.

◆ contract()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::contract ( const variable_type & face_center)
inlineprivate

Contract the highest point to the opposite face.

Parameters
[in]face_centerCenter of the face composed from points other than highest point.

Definition at line 369 of file downhill_simplex.h.

◆ evaluate_on()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::evaluate_on ( const variable_type & variable)
inlinenodiscardprivate

Evaluate function value.

Parameters
[in]variableVariable.
Returns
Function value.

Definition at line 300 of file downhill_simplex.h.

◆ evaluations()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::evaluations ( ) const -> index_type
inlinenodiscardnoexcept

Get the number of function evaluations.

Returns
Number of function evaluations.

Definition at line 245 of file downhill_simplex.h.

◆ expand()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::expand ( const variable_type & face_center)
inlineprivate

Expand the simplex.

Parameters
[in]face_centerCenter of the face composed from points other than highest point.

Definition at line 356 of file downhill_simplex.h.

◆ init()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::init ( const variable_type & init_var,
const variable_scalar_type & width = default_width )
inline

Initialize the algorithm.

Parameters
[in]init_varAn initial variable.
[in]widthWidth of the initial simplex.

Definition at line 136 of file downhill_simplex.h.

◆ is_stop_criteria_satisfied()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::is_stop_criteria_satisfied ( ) const -> bool
inlinenodiscard

Determine if stopping criteria of the algorithm are satisfied.

Returns
If stopping criteria of the algorithm are satisfied.

Definition at line 195 of file downhill_simplex.h.

◆ iterate()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::iterate ( )
inline

Iterate the algorithm once.

Warning
Any required initializations (with init functions) are assumed to have been done.

Definition at line 169 of file downhill_simplex.h.

◆ iterations()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::iterations ( ) const -> index_type
inlinenodiscardnoexcept

Get the number of iterations.

Returns
Number of iterations.

Definition at line 238 of file downhill_simplex.h.

◆ last_process()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::last_process ( ) const -> process_type
inlinenodiscardnoexcept

Get last process.

Returns
Last process.

Definition at line 254 of file downhill_simplex.h.

◆ last_process_name()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::last_process_name ( ) const -> std::string_view
inlinenodiscardnoexcept

Get the name of the last process.

Returns
Last process.

Definition at line 263 of file downhill_simplex.h.

◆ multi_contract()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::multi_contract ( )
inlineprivate

Contract all points other than the lowest point toward the lowest point.

Definition at line 380 of file downhill_simplex.h.

◆ opt_value()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::opt_value ( ) const -> const value_type&
inlinenodiscard

Get current optimal value.

Returns
Current optimal value.

Definition at line 231 of file downhill_simplex.h.

◆ opt_variable()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::opt_variable ( ) const -> const variable_type&
inlinenodiscard

Get current optimal variable.

Returns
Current optimal variable.

Definition at line 224 of file downhill_simplex.h.

◆ process_name()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::process_name ( process_type process) -> std::string_view
inlinestaticnodiscard

Convert type of process to string.

Parameters
[in]processType of process.
Returns
Name of process.

Definition at line 92 of file downhill_simplex.h.

◆ reflect()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::reflect ( const variable_type & face_center)
inlineprivate

Reflect the highest point.

Parameters
[in]face_centerCenter of the face composed from points other than highest point.

Definition at line 343 of file downhill_simplex.h.

◆ reorder()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::downhill_simplex< ObjectiveFunction >::reorder ( )
inlineprivate

Reorder function values.

Definition at line 309 of file downhill_simplex.h.

◆ simplex_size()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::simplex_size ( ) const -> variable_scalar_type
inlinenodiscard

Get the size of simplex.

Returns
Size of simplex.

Definition at line 272 of file downhill_simplex.h.

◆ tol_simplex_size()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::downhill_simplex< ObjectiveFunction >::tol_simplex_size ( const variable_scalar_type & value) -> downhill_simplex&
inline

Set tolerance of size of simplex.

Parameters
[in]valueValue.
Returns
This object.

Definition at line 287 of file downhill_simplex.h.

Member Data Documentation

◆ default_max_iterations

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::downhill_simplex< ObjectiveFunction >::default_max_iterations = 1000
staticconstexprprivate

Default maximum number of iterations.

Definition at line 423 of file downhill_simplex.h.

◆ default_tol_simplex_size

template<concepts::multi_variate_objective_function ObjectiveFunction>
const auto num_collect::opt::downhill_simplex< ObjectiveFunction >::default_tol_simplex_size
inlinestaticprivate
Initial value:
=
static_cast<variable_scalar_type>(1e-4)
typename variable_type::Scalar variable_scalar_type
Type of scalars in variables.

Default tolerance of size of simplex.

Definition at line 416 of file downhill_simplex.h.

◆ default_width

template<concepts::multi_variate_objective_function ObjectiveFunction>
const auto num_collect::opt::downhill_simplex< ObjectiveFunction >::default_width
inlinestatic
Initial value:
=
static_cast<variable_scalar_type>(0.1)
typename variable_type::Scalar variable_scalar_type
Type of scalars in variables.

Default width of simplex.

Definition at line 278 of file downhill_simplex.h.

◆ dim_

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::downhill_simplex< ObjectiveFunction >::dim_ {0}
private

Number of dimension.

Definition at line 394 of file downhill_simplex.h.

◆ evaluations_

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::downhill_simplex< ObjectiveFunction >::evaluations_ {0}
private

Number of function evaluations.

Definition at line 413 of file downhill_simplex.h.

◆ half

template<concepts::multi_variate_objective_function ObjectiveFunction>
const auto num_collect::opt::downhill_simplex< ObjectiveFunction >::half = static_cast<variable_scalar_type>(0.5)
inlinestaticprivate

Half.

Definition at line 335 of file downhill_simplex.h.

◆ iterations_

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::downhill_simplex< ObjectiveFunction >::iterations_ {0}
private

Number of iterations.

Definition at line 410 of file downhill_simplex.h.

◆ max_iterations_

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::downhill_simplex< ObjectiveFunction >::max_iterations_ {default_max_iterations}
private

Maximum number of iterations.

Definition at line 426 of file downhill_simplex.h.

◆ obj_fun_

template<concepts::multi_variate_objective_function ObjectiveFunction>
objective_function_type num_collect::opt::downhill_simplex< ObjectiveFunction >::obj_fun_
private

Objective function.

Definition at line 391 of file downhill_simplex.h.

◆ points_

template<concepts::multi_variate_objective_function ObjectiveFunction>
std::vector<variable_type, Eigen::aligned_allocator<variable_type> > num_collect::opt::downhill_simplex< ObjectiveFunction >::points_ {}
private

Points.

Definition at line 398 of file downhill_simplex.h.

◆ process_

template<concepts::multi_variate_objective_function ObjectiveFunction>
process_type num_collect::opt::downhill_simplex< ObjectiveFunction >::process_ {process_type::none}
private

Last process.

Definition at line 407 of file downhill_simplex.h.

◆ tol_simplex_size_

template<concepts::multi_variate_objective_function ObjectiveFunction>
variable_scalar_type num_collect::opt::downhill_simplex< ObjectiveFunction >::tol_simplex_size_ {default_tol_simplex_size}
private

Tolerance of size of simplex.

Definition at line 420 of file downhill_simplex.h.

◆ twice

template<concepts::multi_variate_objective_function ObjectiveFunction>
const auto num_collect::opt::downhill_simplex< ObjectiveFunction >::twice = static_cast<variable_scalar_type>(2.0)
inlinestaticprivate

Two.

Definition at line 332 of file downhill_simplex.h.

◆ value_order_

template<concepts::multi_variate_objective_function ObjectiveFunction>
std::vector<std::size_t> num_collect::opt::downhill_simplex< ObjectiveFunction >::value_order_ {}
private

Order of function values (ascending order).

Definition at line 404 of file downhill_simplex.h.

◆ values_

template<concepts::multi_variate_objective_function ObjectiveFunction>
std::vector<value_type> num_collect::opt::downhill_simplex< ObjectiveFunction >::values_ {}
private

Function values.

Definition at line 401 of file downhill_simplex.h.


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