57template <concepts::
objective_function ObjectiveFunction>
66template <concepts::multi_variate_
objective_function ObjectiveFunction>
68 :
public optimizer_base<annealing_downhill_simplex<ObjectiveFunction>> {
85 using value_type =
typename objective_function_type::value_type;
106 -> std::string_view {
113 return "reflection and expansion";
115 return "contraction";
117 return "multiple contraction";
119 return "invalid process";
151 dim_ = init_var.size();
156 opt_value_ = std::numeric_limits<value_type>::max();
172 for (std::size_t i = 0; i < util::safe_cast<std::size_t>(
dim_ + 1);
186 const auto second_max_ind =
231 iteration_logger.template append<index_type>(
233 iteration_logger.template append<index_type>(
235 iteration_logger.template append<value_type>(
237 iteration_logger.template append<variable_scalar_type>(
239 iteration_logger.template append<variable_scalar_type>(
243 .template append<std::string_view>(
245 ->width(process_width);
319 auto seed(random_number_generator_type::result_type value)
333 this->
logger(),
"Highest temperature must be a positive number.");
347 "Maximum number of iterations in each trial must be a positive "
361 "Maximum number of iterations must be a positive number.");
380 const auto& value =
obj_fun_.value();
392 for (std::size_t i = 0; i <
values_.size(); ++i) {
396 [
this](std::size_t i, std::size_t j) {
409 for (std::size_t i = 0; i < util::safe_cast<std::size_t>(
dim_); ++i) {
473 for (std::size_t i = 1; i <= util::safe_cast<std::size_t>(
dim_); ++i) {
491 log(
static_cast<value_type>(random_number_generator_type::max()) /
503 std::vector<variable_type, Eigen::aligned_allocator<variable_type>>
535 std::random_device()()};
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.
auto iterations() const noexcept -> index_type
Get the number of iterations.
auto is_stop_criteria_satisfied() const -> bool
Determine if stopping criteria of the algorithm are satisfied.
auto max_iterations_per_trial(index_type value) -> annealing_downhill_simplex &
Set the maximum number of iterations in each trial.
process_type
Type of processes.
@ reflection_and_expansion
Reflection and expansion.
@ contraction
Contraction.
@ multiple_contraction
Multiple contraction.
std::vector< std::size_t > value_order_
Order of function values (ascending order).
annealing_downhill_simplex< ObjectiveFunction > this_type
This class.
void change_objective_function(const objective_function_type &obj_fun)
Change the objective function.
static const auto half
Half.
value_type highest_temperature_
Highest temperature.
void reorder()
Reorder function values.
void contract(const variable_type &face_center)
Contract the highest point to the opposite face.
static const auto default_highest_temperature
Default value of the highest temperature.
auto highest_temperature(value_type value) -> annealing_downhill_simplex &
Set the highest temperature.
auto simplex_size() const -> variable_scalar_type
Get the size of simplex.
index_type max_iterations_
Maximum number of iterations.
objective_function_type obj_fun_
Objective function.
auto evaluations() const noexcept -> index_type
Get the number of function evaluations.
process_type process_
Last process.
annealing_downhill_simplex(const objective_function_type &obj_fun=objective_function_type())
Constructor.
typename objective_function_type::value_type value_type
Type of function values.
auto calc_face_center() const -> variable_type
Calculate center of the face composed from points other than highest point.
std::mt19937 random_number_generator_type
Type of the random number generator.
index_type dim_
Number of dimension.
static const auto default_width
Default width of simplex.
void configure_iteration_logger(logging::iterations::iteration_logger< this_type > &iteration_logger) const
Configure an iteration logger.
static const auto twice
Two.
auto last_process_name() const noexcept -> std::string_view
Get the name of the last process.
auto opt_variable() const -> const variable_type &
Get current optimal variable.
variable_type opt_variable_
Current optimal variable.
void expand(const variable_type &face_center)
Expand the simplex.
index_type evaluations_
Number of function evaluations.
void iterate()
Iterate the algorithm once.
auto opt_value() const -> const value_type &
Get current optimal value.
auto max_iterations(index_type value) -> annealing_downhill_simplex &
Set the maximum number of iterations.
auto last_process() const noexcept -> process_type
Get last process.
typename variable_type::Scalar variable_scalar_type
Type of scalars in variables.
index_type iterations_in_current_trial_
Number of iterations in the current trial.
random_number_generator_type random_number_generator_
Generator of random numbers.
void init(const variable_type &init_var, const variable_scalar_type &width=default_width)
Initialize the algorithm.
value_type opt_value_
Current optimal value.
static auto process_name(process_type process) -> std::string_view
Convert type of process to string.
void reflect(const variable_type &face_center)
Reflect the highest point.
index_type iterations_
Number of iterations.
std::vector< value_type > values_
Function values.
value_type temperature_
Current temperature.
ObjectiveFunction objective_function_type
Type of the objective function.
static constexpr index_type default_max_iterations_per_trial
Default value of the maximum number of iterations in each trial.
void multi_contract()
Contract all points other than the lowest point toward the lowest point.
static constexpr index_type default_max_iterations
Default maximum number of iterations.
std::vector< variable_type, Eigen::aligned_allocator< variable_type > > points_
Points.
auto seed(random_number_generator_type::result_type value) -> annealing_downhill_simplex &
Change the seed of the random number generator.
auto evaluate_on(const variable_type &variable)
Evaluate function value.
index_type max_iterations_per_trial_
Maximum number of iterations in each trial.
typename objective_function_type::variable_type variable_type
Type of variables.
auto generate_fluctuation() -> value_type
Generate a thermal fluctuation.
auto temperature() const noexcept -> value_type
Get the current temperature.
std::vector< value_type > fluctuated_values_
Function values with thermal fluctuation.
Class of downhill simplex method with simulated annealing press2007.
optimizer_base(logging::log_tag_view tag)
Definition of exceptions.
Definition of index_type type.
Definition of iteration_logger class.
Definition of log_tag_view class.
Definition of macros for logging.
Definition of multi_variate_objective_function concept.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of optimization algorithms.
constexpr auto annealing_downhill_simplex_tag
Tag of annealing_downhill_simplex.
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.