porcupy.functions
Functions
|
Sphere function for optimization benchmarking. |
|
Rosenbrock function for optimization benchmarking. |
Schwefel 2.22 function for optimization benchmarking. |
|
|
Schwefel 1.2 function for optimization benchmarking. |
Schwefel 2.21 function for optimization benchmarking. |
|
|
Step function for optimization benchmarking. |
|
Quartic function with noise for optimization benchmarking. |
|
Rastrigin function for optimization benchmarking. |
|
Ackley function for optimization benchmarking. |
|
Griewank function for optimization benchmarking. |
|
Schwefel function for optimization benchmarking. |
|
Michalewicz function for optimization benchmarking. |
|
Get a benchmark function by name. |
|
Get the recommended bounds for a benchmark function. |
|
Get the global optimum for a benchmark function. |
Module Contents
- porcupy.functions.sphere(x)[source]
Sphere function for optimization benchmarking.
The sphere function is a simple, unimodal function defined as f(x) = sum(x_i^2). Its global minimum is 0 at x = [0, 0, …, 0].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.rosenbrock(x)[source]
Rosenbrock function for optimization benchmarking.
The Rosenbrock function is a non-convex function defined as f(x) = sum(100 * (x_{i+1} - x_i^2)^2 + (1 - x_i)^2). Its global minimum is 0 at x = [1, 1, …, 1].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.schwefel_2_22(x)[source]
Schwefel 2.22 function for optimization benchmarking.
This is a unimodal function defined as f(x) = sum(|x_i|) + prod(|x_i|). Its global minimum is 0 at x = [0, 0, …, 0].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.schwefel_1_2(x)[source]
Schwefel 1.2 function for optimization benchmarking.
This is a unimodal function defined as f(x) = sum(sum(x_j)^2) for j=1 to i, i=1 to n. Its global minimum is 0 at x = [0, 0, …, 0].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.schwefel_2_21(x)[source]
Schwefel 2.21 function for optimization benchmarking.
This is a unimodal function defined as f(x) = max(|x_i|). Its global minimum is 0 at x = [0, 0, …, 0].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.step(x)[source]
Step function for optimization benchmarking.
This is a discontinuous function defined as f(x) = sum(floor(x_i + 0.5)^2). Its global minimum is 0 at x in [-0.5, 0.5]^n.
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.quartic(x)[source]
Quartic function with noise for optimization benchmarking.
This is a function defined as f(x) = sum(i * x_i^4) + random[0, 1). Its global minimum is close to 0 at x = [0, 0, …, 0].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.rastrigin(x)[source]
Rastrigin function for optimization benchmarking.
The Rastrigin function is a multimodal function defined as f(x) = 10 * dim + sum(x_i^2 - 10 * cos(2 * pi * x_i)). Its global minimum is 0 at x = [0, 0, …, 0].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.ackley(x)[source]
Ackley function for optimization benchmarking.
The Ackley function is a multimodal function defined as f(x) = -20 * exp(-0.2 * sqrt(sum(x_i^2) / n)) - exp(sum(cos(2 * pi * x_i)) / n) + 20 + e. Its global minimum is 0 at x = [0, 0, …, 0].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.griewank(x)[source]
Griewank function for optimization benchmarking.
The Griewank function is a multimodal function defined as f(x) = 1 + sum(x_i^2 / 4000) - prod(cos(x_i / sqrt(i))). Its global minimum is 0 at x = [0, 0, …, 0].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.schwefel(x)[source]
Schwefel function for optimization benchmarking.
The Schwefel function is a multimodal function defined as f(x) = 418.9829 * n - sum(x_i * sin(sqrt(|x_i|))). Its global minimum is 0 at x = [420.9687, …, 420.9687].
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.michalewicz(x)[source]
Michalewicz function for optimization benchmarking.
The Michalewicz function is a multimodal function with steep ridges and valleys. It has n! local minima, and the global minimum value depends on the dimension.
- Parameters:
x (ndarray) – Input vector (1D array) of shape (dim,).
- Returns:
The computed function value.
- Return type:
- porcupy.functions.get_function_by_name(name: str) Callable[source]
Get a benchmark function by name.
- Parameters:
name (str) – Name of the function.
- Returns:
The benchmark function.
- Return type:
callable
- Raises:
ValueError – If the function name is not recognized.
- porcupy.functions.get_function_bounds(name: str, dimensions: int) Tuple[numpy.ndarray, numpy.ndarray][source]
Get the recommended bounds for a benchmark function.
- Parameters:
- Returns:
A tuple (lb, ub) containing the lower and upper bounds.
- Return type:
- Raises:
ValueError – If the function name is not recognized.
- porcupy.functions.get_function_optimum(name: str, dimensions: int) Tuple[numpy.ndarray, float][source]
Get the global optimum for a benchmark function.
- Parameters:
- Returns:
A tuple (x_opt, f_opt) containing the optimal position and value.
- Return type:
- Raises:
ValueError – If the function name is not recognized.