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

Class to perform optimization using samples of objective functions. More...

#include <num_collect/opt/sampling_optimizer.h>

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

Public Types

using objective_function_type = ObjectiveFunction
 Type of the objective function.
using this_type = sampling_optimizer<ObjectiveFunction>
 This class.
using value_type = typename objective_function_type::value_type
 Type of function values.
using variable_type = typename objective_function_type::variable_type
 Type of variables.

Public Member Functions

 sampling_optimizer (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< sampling_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 lower () const -> const variable_type &
 Get the current lower limit.
auto max_iterations (index_type value) -> sampling_optimizer &
 Set the maximum number of iterations.
auto num_samples (index_type value) -> sampling_optimizer &
 Set the number of samples.
auto opt_value () const -> const value_type &
 Get current optimal value.
auto opt_variable () const -> const variable_type &
 Get current optimal variable.
auto upper () const -> const variable_type &
 Get the current upper limit.
Public Member Functions inherited from num_collect::opt::optimizer_base< sampling_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< sampling_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< sampling_optimizer< ObjectiveFunction > >
 iteration_logger_mixin ()=default
 Constructor.
void configure_iteration_logger (num_collect::logging::iterations::iteration_logger< sampling_optimizer< ObjectiveFunction > > &iteration_logger) const
 Configure an iteration logger.
auto initialize_iteration_logger () -> num_collect::logging::iterations::iteration_logger< sampling_optimizer< ObjectiveFunction > > &
 Get the iteration logger.

Private Attributes

index_type evaluations_ {0}
 Number of function evaluations.
std::size_t ind_opt_sample_ {0}
 Index of the minimum sampling point.
index_type iterations_ {0}
 Number of iterations.
variable_type lower_ {static_cast<variable_type>(0)}
 Lower limit.
index_type max_iterations_ {default_max_iterations}
 Maximum number of iterations.
index_type num_samples_ {default_num_samples}
 Number of sampling points.
objective_function_type obj_fun_
 Objective function.
std::vector< variable_typesamples_ {}
 List of sampling points.
variable_type upper_ {static_cast<variable_type>(1)}
 Upper limit.
std::vector< value_typevalues_ {}
 List of function values.

Static Private Attributes

static constexpr index_type default_max_iterations = 3
 Default maximum number of iterations.
static constexpr index_type default_num_samples = 21
 Default number of sampling points.

Additional Inherited Members

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

Detailed Description

template<concepts::single_variate_objective_function ObjectiveFunction>
class num_collect::opt::sampling_optimizer< ObjectiveFunction >

Class to perform optimization using samples of objective functions.

Template Parameters
ObjectiveFunctionType of the objective function.

Definition at line 57 of file sampling_optimizer.h.

Member Typedef Documentation

◆ objective_function_type

template<concepts::single_variate_objective_function ObjectiveFunction>
using num_collect::opt::sampling_optimizer< ObjectiveFunction >::objective_function_type = ObjectiveFunction

Type of the objective function.

Definition at line 64 of file sampling_optimizer.h.

◆ this_type

template<concepts::single_variate_objective_function ObjectiveFunction>
using num_collect::opt::sampling_optimizer< ObjectiveFunction >::this_type = sampling_optimizer<ObjectiveFunction>

This class.

Definition at line 61 of file sampling_optimizer.h.

◆ value_type

template<concepts::single_variate_objective_function ObjectiveFunction>
using num_collect::opt::sampling_optimizer< ObjectiveFunction >::value_type = typename objective_function_type::value_type

Type of function values.

Definition at line 70 of file sampling_optimizer.h.

◆ variable_type

template<concepts::single_variate_objective_function ObjectiveFunction>
using num_collect::opt::sampling_optimizer< ObjectiveFunction >::variable_type = typename objective_function_type::variable_type

Type of variables.

Definition at line 67 of file sampling_optimizer.h.

Constructor & Destructor Documentation

◆ sampling_optimizer()

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

Constructor.

Parameters
[in]obj_funObjective function.

Definition at line 77 of file sampling_optimizer.h.

Member Function Documentation

◆ change_objective_function()

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

Change the objective function.

Parameters
[in]obj_funObjective function.

Definition at line 88 of file sampling_optimizer.h.

◆ configure_iteration_logger()

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

Configure an iteration logger.

Parameters
[in]iteration_loggerIteration logger.

Definition at line 158 of file sampling_optimizer.h.

◆ evaluations()

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

Get the number of function evaluations.

Returns
Number of function evaluations.

Definition at line 206 of file sampling_optimizer.h.

◆ init()

template<concepts::single_variate_objective_function ObjectiveFunction>
void num_collect::opt::sampling_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 98 of file sampling_optimizer.h.

◆ is_stop_criteria_satisfied()

template<concepts::single_variate_objective_function ObjectiveFunction>
auto num_collect::opt::sampling_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 151 of file sampling_optimizer.h.

◆ iterate()

template<concepts::single_variate_objective_function ObjectiveFunction>
void num_collect::opt::sampling_optimizer< ObjectiveFunction >::iterate ( )
inline

Iterate the algorithm once.

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

Definition at line 111 of file sampling_optimizer.h.

◆ iterations()

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

Get the number of iterations.

Returns
Number of iterations.

Definition at line 199 of file sampling_optimizer.h.

◆ lower()

template<concepts::single_variate_objective_function ObjectiveFunction>
auto num_collect::opt::sampling_optimizer< ObjectiveFunction >::lower ( ) const -> const variable_type&
inlinenodiscard

Get the current lower limit.

Returns
Lower limit.

Definition at line 194 of file sampling_optimizer.h.

◆ max_iterations()

template<concepts::single_variate_objective_function ObjectiveFunction>
auto num_collect::opt::sampling_optimizer< ObjectiveFunction >::max_iterations ( index_type value) -> sampling_optimizer&
inline

Set the maximum number of iterations.

Parameters
[in]valueValue.
Returns
This.

Definition at line 229 of file sampling_optimizer.h.

◆ num_samples()

template<concepts::single_variate_objective_function ObjectiveFunction>
auto num_collect::opt::sampling_optimizer< ObjectiveFunction >::num_samples ( index_type value) -> sampling_optimizer&
inline

Set the number of samples.

Parameters
[in]valueValue.
Returns
This.

Definition at line 216 of file sampling_optimizer.h.

◆ opt_value()

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

Get current optimal value.

Returns
Current optimal value.

Definition at line 178 of file sampling_optimizer.h.

◆ opt_variable()

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

Get current optimal variable.

Returns
Current optimal variable.

Definition at line 171 of file sampling_optimizer.h.

◆ upper()

template<concepts::single_variate_objective_function ObjectiveFunction>
auto num_collect::opt::sampling_optimizer< ObjectiveFunction >::upper ( ) const -> const variable_type&
inlinenodiscard

Get the current upper limit.

Returns
Upper limit.

Definition at line 187 of file sampling_optimizer.h.

Member Data Documentation

◆ default_max_iterations

template<concepts::single_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::default_max_iterations = 3
staticconstexprprivate

Default maximum number of iterations.

Definition at line 262 of file sampling_optimizer.h.

◆ default_num_samples

template<concepts::single_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::default_num_samples = 21
staticconstexprprivate

Default number of sampling points.

Definition at line 256 of file sampling_optimizer.h.

◆ evaluations_

template<concepts::single_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::evaluations_ {0}
private

Number of function evaluations.

Definition at line 271 of file sampling_optimizer.h.

◆ ind_opt_sample_

template<concepts::single_variate_objective_function ObjectiveFunction>
std::size_t num_collect::opt::sampling_optimizer< ObjectiveFunction >::ind_opt_sample_ {0}
private

Index of the minimum sampling point.

Definition at line 253 of file sampling_optimizer.h.

◆ iterations_

template<concepts::single_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::iterations_ {0}
private

Number of iterations.

Definition at line 268 of file sampling_optimizer.h.

◆ lower_

template<concepts::single_variate_objective_function ObjectiveFunction>
variable_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::lower_ {static_cast<variable_type>(0)}
private

Lower limit.

Definition at line 241 of file sampling_optimizer.h.

◆ max_iterations_

template<concepts::single_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::max_iterations_ {default_max_iterations}
private

Maximum number of iterations.

Definition at line 265 of file sampling_optimizer.h.

◆ num_samples_

template<concepts::single_variate_objective_function ObjectiveFunction>
index_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::num_samples_ {default_num_samples}
private

Number of sampling points.

Definition at line 259 of file sampling_optimizer.h.

◆ obj_fun_

template<concepts::single_variate_objective_function ObjectiveFunction>
objective_function_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::obj_fun_
private

Objective function.

Definition at line 238 of file sampling_optimizer.h.

◆ samples_

template<concepts::single_variate_objective_function ObjectiveFunction>
std::vector<variable_type> num_collect::opt::sampling_optimizer< ObjectiveFunction >::samples_ {}
private

List of sampling points.

Definition at line 247 of file sampling_optimizer.h.

◆ upper_

template<concepts::single_variate_objective_function ObjectiveFunction>
variable_type num_collect::opt::sampling_optimizer< ObjectiveFunction >::upper_ {static_cast<variable_type>(1)}
private

Upper limit.

Definition at line 244 of file sampling_optimizer.h.

◆ values_

template<concepts::single_variate_objective_function ObjectiveFunction>
std::vector<value_type> num_collect::opt::sampling_optimizer< ObjectiveFunction >::values_ {}
private

List of function values.

Definition at line 250 of file sampling_optimizer.h.


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