Skip to main content

math_audio_test_functions/functions/
trid.rs

1//! Trid test function
2
3use ndarray::Array1;
4
5/// Trid function - unimodal, bowl-shaped
6/// Global minimum for 2D: f(x) = -2 at x = (2, 2)
7/// Bounds: x_i in [-d^2, d^2] where d is dimension
8pub fn trid(x: &Array1<f64>) -> f64 {
9    let sum1 = x.iter().map(|&xi| (xi - 1.0).powi(2)).sum::<f64>();
10    let sum2 = x.windows(2).into_iter().map(|w| w[0] * w[1]).sum::<f64>();
11    sum1 - sum2
12}