48template <concepts::
objective_function ObjectiveFunction>
56template <concepts::single_variate_
objective_function ObjectiveFunction>
70 using value_type =
typename objective_function_type::value_type;
112 const auto num_samples_size_t =
114 samples_.resize(num_samples_size_t);
115 values_.resize(num_samples_size_t);
117 value_type min_val = std::numeric_limits<value_type>::max();
119 for (std::size_t i = 0; i < num_samples_size_t; ++i) {
130 if (value < min_val) {
160 iteration_logger.template append<index_type>(
162 iteration_logger.template append<index_type>(
164 iteration_logger.template append<value_type>(
218 "Number of samples must be at least two.");
231 "Maximum number of iterations must be a positive integer.");
Class to write logs of iterations.
Class of tags of logs without memory management.
auto logger() const noexcept -> const num_collect::logging::logger &
Access to the logger.
optimizer_base(logging::log_tag_view tag)
void iterate()
Iterate the algorithm once.
void configure_iteration_logger(logging::iterations::iteration_logger< sampling_optimizer< ObjectiveFunction > > &iteration_logger) const
Configure an iteration logger.
objective_function_type obj_fun_
Objective function.
index_type max_iterations_
Maximum number of iterations.
std::size_t ind_opt_sample_
Index of the minimum sampling point.
auto upper() const -> const variable_type &
Get the current upper limit.
sampling_optimizer(const objective_function_type &obj_fun=objective_function_type())
Constructor.
index_type iterations_
Number of iterations.
sampling_optimizer< ObjectiveFunction > this_type
This class.
variable_type upper_
Upper limit.
auto iterations() const noexcept -> index_type
Get the number of iterations.
auto opt_value() const -> const value_type &
Get current optimal value.
auto evaluations() const noexcept -> index_type
Get the number of function evaluations.
index_type evaluations_
Number of function evaluations.
void change_objective_function(const objective_function_type &obj_fun)
Change the objective function.
auto lower() const -> const variable_type &
Get the current lower limit.
static constexpr index_type default_max_iterations
Default maximum number of iterations.
variable_type lower_
Lower limit.
typename objective_function_type::variable_type variable_type
Type of variables.
index_type num_samples_
Number of sampling points.
auto max_iterations(index_type value) -> sampling_optimizer &
Set the maximum number of iterations.
std::vector< value_type > values_
List of function values.
auto num_samples(index_type value) -> sampling_optimizer &
Set the number of samples.
auto is_stop_criteria_satisfied() const -> bool
Determine if stopping criteria of the algorithm are satisfied.
typename objective_function_type::value_type value_type
Type of function values.
ObjectiveFunction objective_function_type
Type of the objective function.
std::vector< variable_type > samples_
List of sampling points.
static constexpr index_type default_num_samples
Default number of sampling points.
auto opt_variable() const -> const variable_type &
Get current optimal variable.
void init(const variable_type &lower, const variable_type &upper)
Initialize the algorithm.
Class to perform optimization using samples of objective functions.
Definition of exceptions.
Definition of index_type type.
Definition of iteration_logger class.
Definition of log_tag_view class.
Definition of macros for logging.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of optimization algorithms.
constexpr auto sampling_optimizer_tag
Tag of golden_section_search.
auto safe_cast(const From &value) -> To
Cast safely.
Definition of objective_function concept.
Definition of optimizer_base class.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of safe_cast function.
Definition of single_variate_objective_function concept.