Benchmarks package
This package contains a set of optimization functions to demonstrate the algorithms ability to deal with multiple modes.
Submodules
star_pso.benchmarks.composite_functions module
- star_pso.benchmarks.composite_functions.BASIC_FUNCTIONS: dict = {'f_ackley': CPUDispatcher(<function f_ackley>), 'f_griewank': CPUDispatcher(<function f_griewank>), 'f_rastrigin': CPUDispatcher(<function f_rastrigin>), 'f_sphere': CPUDispatcher(<function f_sphere>), 'f_weierstrass': CPUDispatcher(<function f_weierstrass>)}
Define a dictionary with all the basic functions:
Ackley
Sphere
Griewank
Rastrigin
Weierstrass
- class star_pso.benchmarks.composite_functions.CompositeFunction(n_dim: int = 2, n_func: int | list = 4, x_min: float = -5.0, x_max: float = 5.0)[source]
Bases:
TestFunctionGenerates a Composite Function using a weighted average of basic functions, as defined in the ‘BASIC_FUNCTIONS’ dictionary.
- static compute_weights(x_pos: ndarray[Any, dtype[_ScalarType_co]], sigma: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
Calculates a set of weights (one for each function).
- Parameters:
x_pos – (ndarray) the position that we are evaluating the functions.
sigma – (ndarray) are used to control each function’s range. a small value gives a narrow range for the function.
- Returns:
a (ndarray) of normalized weights.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]], i_bias: float = 0.0, f_bias: float = 0.0) float | ndarray[Any, dtype[_ScalarType_co]][source]
Describes the general framework for the construction of multimodal composition functions with several global optima.
- Parameters:
x_pos – the current position(s) of the function.
i_bias – function value bias for each basic function.
f_bias – function value bias for the composition function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
- star_pso.benchmarks.composite_functions.f_ackley(x_pos: ndarray[Any, dtype[_ScalarType_co]], alpha: float = 20.0, beta: float = 0.2) ndarray[Any, dtype[_ScalarType_co]][source]
Computes the Ackley function at x_pos, with default alpha and beta parameters.
- star_pso.benchmarks.composite_functions.f_griewank(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
Computes the Griewank function at x_pos.
- star_pso.benchmarks.composite_functions.f_rastrigin(x_pos: ndarray[Any, dtype[_ScalarType_co]], kappa: float = 10.0) ndarray[Any, dtype[_ScalarType_co]][source]
Computes the Rastrigin function at x_pos, with default kappa parameter.
star_pso.benchmarks.equal_maxima module
- class star_pso.benchmarks.equal_maxima.EqualMaxima(x_min: float = 0.0, x_max: float = 1.0)[source]
Bases:
TestFunctionThis function was originally proposed in:
K. Deb, “Genetic algorithms in multimodal function optimization (master thesis and tcga report no. 89002),” Ph.D. dissertation, Tuscaloosa: University of Alabama, The Clearinghouse for Genetic Algorithms, 1989.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This is 1D function. There are 5 global optima.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
star_pso.benchmarks.five_uneven_peak_trap module
- class star_pso.benchmarks.five_uneven_peak_trap.FiveUnevenPeakTrap(x_min: float = 0.0, x_max: float = 30.0)[source]
Bases:
TestFunctionThis function was originally proposed in:
J.-P. Li, M. E. Balazs, G. T. Parks, and P. J. Clarkson, “A species conserving genetic algorithm for multimodal function optimization” Evolutionary Computation, vol. 10, no. 3, pp. 207–234, 2002.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This is 1D function. There are two global and one local optima.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
star_pso.benchmarks.gaussian_mixture module
- class star_pso.benchmarks.gaussian_mixture.GaussianMixture(x_min: float = -15.0, x_max: float = 15.0)[source]
Bases:
TestFunctionThis function provides a 2D Gaussian mixture model.
The equations are given by the Multivariate Normal Distribution, with four modes (2 global and 2 local):
\[f(x) = \sum_{i=1}^{4} \mathcal{N}(\mu_i, \Sigma_i)\]with mean vectors:
\[ \begin{align}\begin{aligned}\mu_1 = [-0.0, -1.0]\\\mu_2 = [-4.0, -6.0]\\\mu_3 = [-5.0, +1.0]\\\mu_4 = [5.0, -10.0]\end{aligned}\end{align} \]and covariances:
\[ \begin{align}\begin{aligned}\Sigma_1 = [ [ 1.0, 0.1 ], [ 0.1, 1.0 ] ]\\\Sigma_2 = [ [ 1.0, 0.1 ], [ 0.1, 1.0 ] ]\\\Sigma_3 = [ [ 1.2, 0.3 ], [ 0.3, 1.2 ] ]\\\Sigma_4 = [ [ 1.2, 0.3 ], [ 0.3, 1.2 ] ]\end{aligned}\end{align} \]- MVN = (<scipy.stats._multivariate.multivariate_normal_frozen object>, <scipy.stats._multivariate.multivariate_normal_frozen object>, <scipy.stats._multivariate.multivariate_normal_frozen object>, <scipy.stats._multivariate.multivariate_normal_frozen object>)
Set up four multivariate normal distributions.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This is 2D function with is 2 global and 2 local optima.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
star_pso.benchmarks.himmelblau module
- class star_pso.benchmarks.himmelblau.Himmelblau(x_min: float = -6.0, x_max: float = 6.0)[source]
Bases:
TestFunctionThis function was originally proposed in:
K. Deb, “Genetic algorithms in multimodal function optimization (master thesis and tcga report no. 89002)”, Ph.D. dissertation, Tuscaloosa: University of Alabama, The Clearinghouse for Genetic Algorithms, 1989.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This is 2D function with is 4 global optima.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
star_pso.benchmarks.rastrigin module
- class star_pso.benchmarks.rastrigin.Rastrigin(n_dim: int = 2, x_min: float = 0.0, x_max: float = 1.0)[source]
Bases:
TestFunctionThis function was originally proposed in:
A. Saha and K. Deb, “A bi-criterion approach to multimodal optimization: self-adaptive approach”, in Proceedings of the 8th international conference on Simulated evolution and learning, ser. SEAL-10. Berlin, Heidelberg: Springer-Verlag, 2010, pp. 95–104.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This is a multidimensional function with ‘M’ global optimal values.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
star_pso.benchmarks.shubert module
- class star_pso.benchmarks.shubert.Shubert(n_dim: int = 2, x_min: float = -10.0, x_max: float = 10.0)[source]
Bases:
TestFunctionThis function was originally proposed in:
Z. Michalewicz, Genetic Algorithms + Data Structures = Evolution Programs. New York: Springer-Verlag, New York, 1996.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This is a multidimensional function with ‘n_dim * 3^n_dim’ global optimal values.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
star_pso.benchmarks.vincent module
- class star_pso.benchmarks.vincent.Vincent(n_dim: int = 2, x_min: float = 0.25, x_max: float = 10.0)[source]
Bases:
TestFunctionThis function was originally proposed in:
O. Shir and T. Back, “Niche radius adaptation in the cms-es niching algorithm”, in Parallel Problem-Solving from Nature - PPSN IX, 9th International Conference (LNCS 4193). Reykjavík, Iceland: Springer, 2006, pp. 142 – 151.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This is a nD function with 6^n_dim global optimal values.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
star_pso.benchmarks.six_hump_camel_back module
- class star_pso.benchmarks.six_hump_camel_back.SixHumpCamelBack(x_min: list | ndarray[Any, dtype[_ScalarType_co]] | None = None, x_max: list | ndarray[Any, dtype[_ScalarType_co]] | None = None)[source]
Bases:
TestFunctionThis function was originally proposed in:
Z. Michalewicz, Genetic Algorithms + Data Structures = Evolution Programs. New York: Springer-Verlag, New York, 1996.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) float | ndarray[Any, dtype[_ScalarType_co]][source]
This is a 2D function with 2 global and 2 local optima.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
star_pso.benchmarks.test_function module
- class star_pso.benchmarks.test_function.TestFunction(name: str, n_dim: int, x_min: float | ndarray[Any, dtype[_ScalarType_co]], x_max: float | ndarray[Any, dtype[_ScalarType_co]])[source]
Bases:
object- Description:
All benchmark test functions should inherit from this class. Here is provided the interface for all the test problems.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This method will implement the objective function to be optimized.
- Returns:
None.
- property n_dim: int
Accessor (getter) of the test function dimensions.
- Returns:
(int) number of dimensions.
- property name: str
Accessor (getter) of the test function name.
- Returns:
string name of the test function.
- rng: Generator = Generator(PCG64) at 0x7C2F38931C40
Random number generator for the whole class.
- sample_random_positions(n_pos: int = 100, method: str = 'random') ndarray[Any, dtype[_ScalarType_co]][source]
Generate an initial set of uniformly random sampled positions within the lower / upper bounds of the test problem.
- Parameters:
n_pos – (int) number of random positions to create.
method – (str) method to use for sampling (“random”, “latin-hc”).
- Returns:
a uniformly sampled set of random positions.
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – a list of Particles to search the global optimum.
epsilon – (float) accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.
- classmethod set_seed(new_seed=None) None[source]
Sets a new seed for the random number generator.
- Parameters:
new_seed – New seed value (default=None).
- Returns:
None.
- property x_max: float | ndarray[Any, dtype[_ScalarType_co]]
Accessor (getter) of the upper bounds of the test function.
- Returns:
numpy array with maximum values.
- property x_min: float | ndarray[Any, dtype[_ScalarType_co]]
Accessor (getter) of the lower bounds of the test function.
- Returns:
numpy array with minimum values.
star_pso.benchmarks.uneven_decreasing_maxima module
- class star_pso.benchmarks.uneven_decreasing_maxima.UnevenDecreasingMaxima(x_min: float = 0.0, x_max: float = 1.0)[source]
Bases:
TestFunctionThis function was originally proposed in:
K. Deb, “Genetic algorithms in multimodal function optimization (master thesis and tcga report no. 89002)”, Ph.D. dissertation, Tuscaloosa: University of Alabama, The Clearinghouse for Genetic Algorithms, 1989.
- func(x_pos: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]
This is 1D function. There is 1 global and 4 local optima.
- Parameters:
x_pos – the current position(s) of the function.
- Returns:
the function value(s).
- search_for_optima(population: list[Particle], epsilon: float = 0.0001) tuple[int, int][source]
Searches the input population for the global optimum values of the specific test function, using default (problem specific) parameters.
- Parameters:
population – the population to search the global optimum.
epsilon – accuracy level of the global optimal solution.
- Returns:
a tuple with the number of global optima found and the total number that exist.