polarcbo.objectives.Rastrigin
- class polarcbo.objectives.Rastrigin(b=0.0, c=0.0)[source]
Bases:
objective
Rastrigin’s function
Rastrigin’s function is a multimodal function with a global minima at \((0,0)\). The function is originally defined on \(\mathbb{R}^2\) as
\[f(x,y) = (x^2 + y - 11)^2 + (x + y^2 - 7)^2.\]See Rastrigin’s function. For our case we employ a shifted version on \(\mathbb{R}^d\), where the global minimum is at \((b)\) and we additonally employ a offset \(c\),
\[\tilde{f}(x,y) = \frac{1}{n} \sum_{i=1}^n (x_i - b)^2 - 10 \cos(2 \pi (x_i - b)) + 10 + c.\]- Parameters:
b (float, optional) – The first parameter of the function. The default is 0.0.
c (float, optional) – The second parameter of the function. The default is 0.0.
Examples
>>> import numpy as np >>> from polarcbo.objectives import Rastrigin >>> x = np.array([[1,2], [3,4], [5,6]]) >>> f = Rastrigin() >>> f(x) array([ 68., 148., 1556.])
- __call__(x)[source]
Call method for classes that inherit from
objective
- Parameters:
x (array_like, shape (J, d)) – For a system of \(J\) particles, the i-th row of this array
x[i,:]
represents the position of the i-th particle.- Returns:
y – The value of the objective function at the positions
x
.- Return type:
array_like, shape (J,)