Selection methods#
-
namespace selection#
Selection operators for the single-objective algorithm.
class Roulette#
#include <algorithm/soga_selection.hpp>
-
class Roulette : public gapp::selection::Selection#
Roulette selection operator for the single-objective algorithm.
The probability of selecting a candidate from the population is proportional to it’s fitness value. The operator assumes maximization, so candidates with higher fitness values will have a higher probability of being selected.
\[ p_i = \frac{f_i}{\sum_i f_i} \]This operator is a modified version of the standard roulette-selection method, so it also works if there are negative fitness values in the population, but all of the fitness must be finite for the operator to work correctly.
class Tournament#
#include <algorithm/soga_selection.hpp>
-
class Tournament : public gapp::selection::Selection#
Tournament selection operator for the single-objective algorithm.
When performing a selection, the operator selects a set number of candidate solutions randomly from the population using a uniform distribution, and then the best one is selected from these. The number of candidates initially picked is controlled by the
size
parameter of the operator.The operator assumes fitness maximization, and works with arbitrary fitness values, including infinite fitness values.
Public Functions
-
inline explicit constexpr Tournament(Positive<size_t> size = 2) noexcept#
Create a tournament selection operator.
- Parameters:
size – The tournament size to use. Must be at least 1.
-
inline constexpr void size(Positive<size_t> size) noexcept#
Set the number of candidates that will be picked for a tournament.
If the tourney size is 1, the selection operator is equivalent to randomly selecting a candidate from a uniform distribution.
- Parameters:
size – The size of the tournaments during tournament selection. Must be at least 1.
-
inline constexpr size_t size() const noexcept#
- Returns:
The tournament size used.
-
inline explicit constexpr Tournament(Positive<size_t> size = 2) noexcept#
class Rank#
#include <algorithm/soga_selection.hpp>
-
class Rank : public gapp::selection::Selection#
Rank selection operator for the single-objective algorithm.
The individuals of the population are assigned selection weights between a minimum and maximum value based on their rank in the population relative to other individuals, assuming fitness maximization. The selection probabilities are then determined based on these weights.
The operator works with arbitrary fitness values, infinite values are also allowed to be present in the fitness matrix of the population.
Public Functions
- explicit Rank(
- NonNegative<double> min_weight = 0.1,
- NonNegative<double> max_weight = 1.1,
Create a rank selection operator using the specified weight limits.
- Parameters:
min_weight – The selection weight assigned to the worst individual of the population. Must be in the closed interval [0.0,
max_weight
].max_weight – The selection weight assigned to the best individual of the population. Must be greater than
min_weight
.
- void weights(
- NonNegative<double> min_weight,
- NonNegative<double> max_weight,
Sets the minimum and maximum selection weights used.
- Parameters:
min_weight – The selection weight assigned to the worst individual of the population. Must be in the closed interval [0.0,
max_weight
].max_weight – The selection weight assigned to the best individual of the population. Must be greater than
min_weight
.
-
inline std::pair<double, double> weights() const noexcept#
- Returns:
The minimum and maximum selection weights used.
-
inline double min_weight() const noexcept#
- Returns:
The minimum selection weight used.
-
inline double max_weight() const noexcept#
- Returns:
The maximum selection weight used.
class Sigma#
#include <algorithm/soga_selection.hpp>
-
class Sigma : public gapp::selection::Selection#
Sigma scaling selection operator for the single-objective algorithm.
The fitness values of the population are scaled based on the mean and the standard deviation of the fitness values in the population, and the probability of selecting a candidate will be proportional to its scaled fitness value. The operator has a parameter (scale, or S) that controls how the values are scaled. Smaller values of the parameter will emphasize the differences between the fitness values of the candidates.
\[ f_i' = \frac{ f_i - f_{\textrm{mean}} }{ S\ f_{\textrm{sd}} } \]The operator assumes fitness maximization, and all of the fitness values of the population must be finite.
Public Functions
-
inline explicit Sigma(Positive<double> scale = 3.0) noexcept#
Create a sigma scaling selection operator.
- Parameters:
scale – The scaling parameter to use. Must be greater than 0.
-
inline void scale(Positive<double> scale) noexcept#
Set the scaling parameter used.
The value of this parameter determines how the fitness values are scaled. Smaller values of the parameter will emphasize the differences between the candidates, meaning that even candidates with small differences in their fitnesses can have large differences in their selection probabilities. Larger values will lead to the candidates having a more equal probability of being selected regardless of the differences in fitnesses.
- Parameters:
scale – The scaling parameter to use. Must be greater than 0.
-
inline double scale() const noexcept#
- Returns:
The scaling parameter used.
-
inline explicit Sigma(Positive<double> scale = 3.0) noexcept#
class Boltzmann#
#include <algorithm/soga_selection.hpp>
-
class Boltzmann : public gapp::selection::Selection#
Boltzmann selection operator forthe single-objective algorithm.
The fitness values of the candidates are scaled based on the overall fitness values of the population, and the probability of selecting a candidate will be proportional to its scaled fitness value. How the fitness values are scaled changes over time in a run (from generation to generation) based on a temperature function. In the early generations this temperature value will be high, leading to the candidates having close to equal probabilities of being selected. The temperature value will decrease over the generations, and in the later generations even small differences in the fitness values of the candidates will lead to large differences in their selection probabilities.
\[ p_i = \frac{ e^{\frac{f_i}{T(t)}} }{ \sum_i e^{\frac{f_i}{T(t)}} } \]The operator assumes fitness maximization, and all of the fitness values of the population must be finite.
Public Types
-
using TemperatureFunction = std::function<double(size_t, size_t)>#
The general callable type that can be used as a temperature function. The function should return the temperature in the given generation, with its signature being:
\t double f(size_t current_generation, size_t max_generation)
Public Functions
-
explicit Boltzmann(TemperatureFunction f = boltzmannDefaultTemp) noexcept#
Create a Boltzmann selection operator.
- Parameters:
f – The temperature function to use. Can’t be a nullptr.
-
using TemperatureFunction = std::function<double(size_t, size_t)>#