1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Ackley N3 test function
use ndarray::Array1;
/// Ackley N.3 function - variant of Ackley function
/// Global minimum: f(x) ≈ -195.6 at complex optimum
/// Bounds: x_i in [-32, 32]
pub fn ackley_n3(x: &Array1<f64>) -> f64 {
let x1 = x[0];
let x2 = x[1];
-200.0 * (-0.02 * (x1.powi(2) + x2.powi(2)).sqrt()).exp()
+ 5.0 * ((3.0 * x1).cos() + (3.0 * x2).sin()).exp()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_ackley_n3_known_properties() {
// Test some properties of the Ackley N.3 function
use ndarray::Array1;
// Test that function is finite at various points
let test_points = vec![
vec![0.0, 0.0],
vec![1.0, -1.0],
vec![-5.0, 5.0],
vec![32.0, -32.0],
];
for point in test_points {
let x = Array1::from(point.clone());
let f = ackley_n3(&x);
assert!(
f.is_finite(),
"Function should be finite at {:?}: {}",
point,
f
);
// Ackley N.3 should produce negative values in its optimal region
if point[0].abs() < 10.0 && point[1].abs() < 10.0 {
// Near origin, should have potential for good values
}
}
// Test boundary behavior
let x_boundary = Array1::from(vec![32.0, 32.0]);
let f_boundary = ackley_n3(&x_boundary);
assert!(
f_boundary.is_finite(),
"Function at boundary should be finite"
);
}
}