Skip to main content

math_audio_test_functions/functions/
vincent.rs

1//! Vincent test function
2
3use ndarray::Array1;
4
5/// Vincent function - high-dimensional multimodal
6/// Global minimum: f(x) = -N at x = (7.70628, 7.70628, ..., 7.70628)
7/// Bounds: x_i in [0.25, 10]
8pub fn vincent(x: &Array1<f64>) -> f64 {
9    -x.iter().map(|&xi| (10.0 * xi.ln()).sin()).sum::<f64>()
10}
11#[cfg(test)]
12mod tests {
13    use super::*;
14
15    #[test]
16    fn test_vincent_known_properties() {
17        // Test some properties of the Vincent function
18        use ndarray::Array1;
19
20        // Test the approximate known optimum
21        let x_approx = Array1::from(vec![7.70628, 7.70628]);
22        let f_approx = vincent(&x_approx);
23
24        // Should be approximately -2.0 for 2D
25        assert!(
26            f_approx < -1.9,
27            "Approximate optimum value not as expected: {}",
28            f_approx
29        );
30
31        // Test boundary behavior
32        let x_low = Array1::from(vec![0.25, 0.25]);
33        let f_low = vincent(&x_low);
34        assert!(
35            f_low.is_finite(),
36            "Function at lower bound should be finite"
37        );
38
39        let x_high = Array1::from(vec![10.0, 10.0]);
40        let f_high = vincent(&x_high);
41        assert!(
42            f_high.is_finite(),
43            "Function at upper bound should be finite"
44        );
45    }
46}