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

Class to perform optimization using firefly algorithm [32], [33]. More...

#include <num_collect/opt/firefly_optimizer.h>

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

Public Types

using objective_function_type = ObjectiveFunction
 Type of the objective function.
using random_number_generator_type = std::mt19937
 Type of the random number generator.
using this_type = firefly_optimizer<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

 firefly_optimizer (const ObjectiveFunction &obj_fun=ObjectiveFunction())
 Construct.
auto absorption_coeff (variable_scalar_type value) -> this_type &
 Set the light absorption coefficient.
auto attractiveness_coeff (variable_scalar_type value) -> this_type &
 Set the coefficient of the attractiveness.
void change_objective_function (const objective_function_type &obj_fun)
 Change the objective function.
void configure_iteration_logger (logging::iterations::iteration_logger< firefly_optimizer< ObjectiveFunction > > &iteration_logger) const
 Configure an iteration logger.
auto evaluations () const noexcept -> index_type
 Get the number of function evaluations.
void init (const variable_type &lower, const variable_type &upper)
 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 max_evaluations (index_type value) -> this_type &
 Set the maximum number of function evaluations.
auto num_fireflies (index_type value) -> this_type &
 Set the number of fireflies.
auto opt_value () const -> const value_type &
 Get current optimal value.
auto opt_variable () const -> const variable_type &
 Get current optimal variable.
auto random_coeff (variable_scalar_type value) -> this_type &
 Set the coefficient of the random walk.
auto seed (random_number_generator_type::result_type value) -> this_type &
 Change the seed of the random number generator.
Public Member Functions inherited from num_collect::opt::optimizer_base< firefly_optimizer< 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< firefly_optimizer< 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< firefly_optimizer< ObjectiveFunction > >
 iteration_logger_mixin ()=default
 Constructor.
void configure_iteration_logger (num_collect::logging::iterations::iteration_logger< firefly_optimizer< ObjectiveFunction > > &iteration_logger) const
 Configure an iteration logger.
auto initialize_iteration_logger () -> num_collect::logging::iterations::iteration_logger< firefly_optimizer< ObjectiveFunction > > &
 Get the iteration logger.

Private Member Functions

auto evaluate_on (const variable_type &variable) -> value_type
 Evaluate a function value.

Static Private Member Functions

static auto correct_value_if_needed (value_type value) noexcept -> value_type
 Correct function values if needed.

Private Attributes

variable_scalar_type absorption_coeff_ {default_absorption_coeff}
 Light absorption coefficient.
variable_scalar_type attractiveness_coeff_ {default_attractiveness_coeff}
 Coefficient of the attractiveness.
index_type dim_ {0}
 Number of dimension.
index_type evaluations_ {0}
 Number of function evaluations.
std::uniform_real_distribution< variable_scalar_typeinitial_distribution_ {}
 Distribution for the initial variables. (Uniform distribution from 0 to 1.)
index_type iterations_ {0}
 Number of iterations.
variable_type lower_ {}
 Element-wise lower limit.
index_type max_evaluations_ {default_max_evaluations}
 Maximum number of function evaluations.
index_type num_fireflies_ {default_num_fireflies}
 Number of fireflies.
objective_function_type obj_fun_
 Objective function.
value_type opt_value_ {std::numeric_limits<value_type>::max()}
 Current optimal value.
variable_type opt_variable_ {}
 Current optimal variable.
variable_scalar_type random_coeff_ {default_random_coeff}
 Coefficient of the random walk.
random_number_generator_type random_number_generator_
 Random number generator.
std::normal_distribution< variable_scalar_typerandom_walk_distribution_ {}
 Distribution for random walk. (Standard normal distribution.)
variable_type upper_ {}
 Element-wise upper limit.
Eigen::VectorX< value_typevalues_
 Function values of the current variables.
util::vector< variable_typevariable_changes_
 Buffer of variable changes.
util::vector< variable_typevariables_
 Current variables. (Positions of fireflies.)
variable_type width_ {}
 Element-wise width.

Static Private Attributes

static constexpr auto default_absorption_coeff
 Default value of the light absorption coefficient.
static constexpr auto default_attractiveness_coeff
 Default value of the coefficient of the attractiveness.
static constexpr index_type default_max_evaluations = 10000
 Default maximum number of function evaluations.
static constexpr index_type default_num_fireflies = 200
 Default value of the number of fireflies.
static constexpr auto default_random_coeff
 Default value of the coefficient of the random walk.

Additional Inherited Members

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

Detailed Description

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

Class to perform optimization using firefly algorithm [32], [33].

Template Parameters
ObjectiveFunctionType of the objective function.

Definition at line 63 of file firefly_optimizer.h.

Member Typedef Documentation

◆ objective_function_type

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

Type of the objective function.

Definition at line 70 of file firefly_optimizer.h.

◆ random_number_generator_type

template<concepts::multi_variate_objective_function ObjectiveFunction>
using num_collect::opt::firefly_optimizer< ObjectiveFunction >::random_number_generator_type = std::mt19937

Type of the random number generator.

Definition at line 82 of file firefly_optimizer.h.

◆ this_type

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

This class.

Definition at line 67 of file firefly_optimizer.h.

◆ value_type

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

Type of function values.

Definition at line 79 of file firefly_optimizer.h.

◆ variable_scalar_type

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

Type of scalars in variables.

Definition at line 76 of file firefly_optimizer.h.

◆ variable_type

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

Type of variables.

Definition at line 73 of file firefly_optimizer.h.

Constructor & Destructor Documentation

◆ firefly_optimizer()

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

Construct.

Parameters
[in]obj_funObjective function.

Definition at line 89 of file firefly_optimizer.h.

Member Function Documentation

◆ absorption_coeff()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::absorption_coeff ( variable_scalar_type value) -> this_type&
inline

Set the light absorption coefficient.

Note
This value is \(\gamma\) in [32].
Parameters
[in]valueValue.
Returns
This object.

Definition at line 286 of file firefly_optimizer.h.

◆ attractiveness_coeff()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::attractiveness_coeff ( variable_scalar_type value) -> this_type&
inline

Set the coefficient of the attractiveness.

Note
This value is \(\beta 0\) in [32].
Parameters
[in]valueValue.
Returns
This object.

Definition at line 271 of file firefly_optimizer.h.

◆ change_objective_function()

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

Change the objective function.

Parameters
[in]obj_funObjective function.

Definition at line 98 of file firefly_optimizer.h.

◆ configure_iteration_logger()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::firefly_optimizer< ObjectiveFunction >::configure_iteration_logger ( logging::iterations::iteration_logger< firefly_optimizer< ObjectiveFunction > > & iteration_logger) const
inline

Configure an iteration logger.

Parameters
[in]iteration_loggerIteration logger.

Definition at line 212 of file firefly_optimizer.h.

◆ correct_value_if_needed()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::correct_value_if_needed ( value_type value) -> value_type
inlinestaticnodiscardprivatenoexcept

Correct function values if needed.

Parameters
[in]valueFunction value.
Returns
Corrected value.

Definition at line 358 of file firefly_optimizer.h.

◆ evaluate_on()

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

Evaluate a function value.

Parameters
[in]variableVariable.
Returns
Function value.

Definition at line 340 of file firefly_optimizer.h.

◆ evaluations()

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

Get the number of function evaluations.

Returns
Number of function evaluations.

Definition at line 246 of file firefly_optimizer.h.

◆ init()

template<concepts::multi_variate_objective_function ObjectiveFunction>
void num_collect::opt::firefly_optimizer< ObjectiveFunction >::init ( const variable_type & lower,
const variable_type & upper )
inline

Initialize the algorithm.

Parameters
[in]lowerLower limit.
[in]upperUpper limit.

Definition at line 108 of file firefly_optimizer.h.

◆ is_stop_criteria_satisfied()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< 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 205 of file firefly_optimizer.h.

◆ iterate()

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

Iterate the algorithm once.

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

Definition at line 143 of file firefly_optimizer.h.

◆ iterations()

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

Get the number of iterations.

Returns
Number of iterations.

Definition at line 239 of file firefly_optimizer.h.

◆ max_evaluations()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::max_evaluations ( index_type value) -> this_type&
inline

Set the maximum number of function evaluations.

Parameters
[in]valueValue.
Returns
This object.

Definition at line 314 of file firefly_optimizer.h.

◆ num_fireflies()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::num_fireflies ( index_type value) -> this_type&
inline

Set the number of fireflies.

Parameters
[in]valueValue.
Returns
This object.

Definition at line 256 of file firefly_optimizer.h.

◆ opt_value()

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

Get current optimal value.

Returns
Current optimal value.

Definition at line 232 of file firefly_optimizer.h.

◆ opt_variable()

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

Get current optimal variable.

Returns
Current optimal variable.

Definition at line 225 of file firefly_optimizer.h.

◆ random_coeff()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::random_coeff ( variable_scalar_type value) -> this_type&
inline

Set the coefficient of the random walk.

Note
This value is \(\alpha\) in [32].
Parameters
[in]valueValue.
Returns
This object.

Definition at line 301 of file firefly_optimizer.h.

◆ seed()

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::seed ( random_number_generator_type::result_type value) -> this_type&
inline

Change the seed of the random number generator.

Parameters
[in]valueValue.
Returns
This.

Definition at line 328 of file firefly_optimizer.h.

Member Data Documentation

◆ absorption_coeff_

template<concepts::multi_variate_objective_function ObjectiveFunction>
variable_scalar_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::absorption_coeff_ {default_absorption_coeff}
private

Light absorption coefficient.

Note
This value is \(\gamma\) in [32].

Definition at line 408 of file firefly_optimizer.h.

◆ attractiveness_coeff_

template<concepts::multi_variate_objective_function ObjectiveFunction>
variable_scalar_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::attractiveness_coeff_ {default_attractiveness_coeff}
private

Coefficient of the attractiveness.

Note
This value is \(\beta 0\) in [32].

Definition at line 397 of file firefly_optimizer.h.

◆ default_absorption_coeff

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::default_absorption_coeff
staticconstexprprivate
Initial value:
=
static_cast<variable_scalar_type>(300)
typename variable_type::Scalar variable_scalar_type
Type of scalars in variables.

Default value of the light absorption coefficient.

Definition at line 400 of file firefly_optimizer.h.

◆ default_attractiveness_coeff

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::default_attractiveness_coeff
staticconstexprprivate
Initial value:
=
static_cast<variable_scalar_type>(1)

Default value of the coefficient of the attractiveness.

Definition at line 389 of file firefly_optimizer.h.

◆ default_max_evaluations

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::default_max_evaluations = 10000
staticconstexprprivate

Default maximum number of function evaluations.

Definition at line 454 of file firefly_optimizer.h.

◆ default_num_fireflies

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::default_num_fireflies = 200
staticconstexprprivate

Default value of the number of fireflies.

Definition at line 383 of file firefly_optimizer.h.

◆ default_random_coeff

template<concepts::multi_variate_objective_function ObjectiveFunction>
auto num_collect::opt::firefly_optimizer< ObjectiveFunction >::default_random_coeff
staticconstexprprivate
Initial value:
=
static_cast<variable_scalar_type>(0.1)

Default value of the coefficient of the random walk.

Definition at line 411 of file firefly_optimizer.h.

◆ dim_

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

Number of dimension.

Definition at line 380 of file firefly_optimizer.h.

◆ evaluations_

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

Number of function evaluations.

Definition at line 451 of file firefly_optimizer.h.

◆ initial_distribution_

template<concepts::multi_variate_objective_function ObjectiveFunction>
std::uniform_real_distribution<variable_scalar_type> num_collect::opt::firefly_optimizer< ObjectiveFunction >::initial_distribution_ {}
private

Distribution for the initial variables. (Uniform distribution from 0 to 1.)

Definition at line 436 of file firefly_optimizer.h.

◆ iterations_

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

Number of iterations.

Definition at line 448 of file firefly_optimizer.h.

◆ lower_

template<concepts::multi_variate_objective_function ObjectiveFunction>
variable_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::lower_ {}
private

Element-wise lower limit.

Definition at line 371 of file firefly_optimizer.h.

◆ max_evaluations_

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::max_evaluations_ {default_max_evaluations}
private

Maximum number of function evaluations.

Definition at line 457 of file firefly_optimizer.h.

◆ num_fireflies_

template<concepts::multi_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::num_fireflies_ {default_num_fireflies}
private

Number of fireflies.

Definition at line 386 of file firefly_optimizer.h.

◆ obj_fun_

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

Objective function.

Definition at line 368 of file firefly_optimizer.h.

◆ opt_value_

template<concepts::multi_variate_objective_function ObjectiveFunction>
value_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::opt_value_ {std::numeric_limits<value_type>::max()}
private

Current optimal value.

Definition at line 445 of file firefly_optimizer.h.

◆ opt_variable_

template<concepts::multi_variate_objective_function ObjectiveFunction>
variable_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::opt_variable_ {}
private

Current optimal variable.

Definition at line 442 of file firefly_optimizer.h.

◆ random_coeff_

template<concepts::multi_variate_objective_function ObjectiveFunction>
variable_scalar_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::random_coeff_ {default_random_coeff}
private

Coefficient of the random walk.

Note
This value is \(\alpha\) in [32].

Definition at line 419 of file firefly_optimizer.h.

◆ random_number_generator_

template<concepts::multi_variate_objective_function ObjectiveFunction>
random_number_generator_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::random_number_generator_
private
Initial value:
{
std::random_device()()}

Random number generator.

Definition at line 431 of file firefly_optimizer.h.

◆ random_walk_distribution_

template<concepts::multi_variate_objective_function ObjectiveFunction>
std::normal_distribution<variable_scalar_type> num_collect::opt::firefly_optimizer< ObjectiveFunction >::random_walk_distribution_ {}
private

Distribution for random walk. (Standard normal distribution.)

Definition at line 439 of file firefly_optimizer.h.

◆ upper_

template<concepts::multi_variate_objective_function ObjectiveFunction>
variable_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::upper_ {}
private

Element-wise upper limit.

Definition at line 374 of file firefly_optimizer.h.

◆ values_

template<concepts::multi_variate_objective_function ObjectiveFunction>
Eigen::VectorX<value_type> num_collect::opt::firefly_optimizer< ObjectiveFunction >::values_
private

Function values of the current variables.

Definition at line 428 of file firefly_optimizer.h.

◆ variable_changes_

template<concepts::multi_variate_objective_function ObjectiveFunction>
util::vector<variable_type> num_collect::opt::firefly_optimizer< ObjectiveFunction >::variable_changes_
private

Buffer of variable changes.

Definition at line 425 of file firefly_optimizer.h.

◆ variables_

template<concepts::multi_variate_objective_function ObjectiveFunction>
util::vector<variable_type> num_collect::opt::firefly_optimizer< ObjectiveFunction >::variables_
private

Current variables. (Positions of fireflies.)

Definition at line 422 of file firefly_optimizer.h.

◆ width_

template<concepts::multi_variate_objective_function ObjectiveFunction>
variable_type num_collect::opt::firefly_optimizer< ObjectiveFunction >::width_ {}
private

Element-wise width.

Definition at line 377 of file firefly_optimizer.h.


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