Function rastrigin

Source
pub fn rastrigin<T>(param: &[T]) -> T
where T: Float + FromPrimitive + Sum,
Expand description

Rastrigin test function.

Defined as

$$ f(x_1,\,x_2,\,\ldots,\,x_d) = a\cdot d + \sum_{i=1}^{d} \left[ x_i^2 - a\cos(2\pi x_i) \right] $$

where $x_i \in [-5.12,\,5.12]$ and $a = 10$.

The global minimum is at $f(x_1,\,x_2,\,\ldots,\,x_d) = f(0,\,0,\,\ldots,\,0) = 0$.

See rastrigin_a for a variant where the parameter a can be chosen freely.