math_audio_test_functions/functions/schaffer_n4.rs
1//! Schaffer N4 test function
2
3use ndarray::Array1;
4
5/// Schaffer N.4 function - multimodal, 2D only
6/// Global minimum: f(x) = 0.292579 at x = (0, ±1.25313) or (±1.25313, 0)
7/// Bounds: x_i in [-100, 100]
8pub fn schaffer_n4(x: &Array1<f64>) -> f64 {
9 let x1 = x[0];
10 let x2 = x[1];
11 0.5 + ((x1.powi(2) - x2.powi(2)).abs().sin().cos().powi(2) - 0.5)
12 / (1.0 + 0.001 * (x1.powi(2) + x2.powi(2))).powi(2)
13}