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
57
58
59
60
61
62
63
64
65
66
67
68
use crate::;
use Array1;
/// Runs Differential Evolution optimization on a function.
///
/// This is a convenience function that mirrors SciPy's `differential_evolution` API.
/// It creates a DE optimizer with the given bounds and configuration, then runs
/// the optimization to find the global minimum.
///
/// # Arguments
///
/// * `func` - The objective function to minimize, mapping `&Array1<f64>` to `f64`
/// * `bounds` - Vector of (lower, upper) bound pairs for each dimension
/// * `config` - DE configuration (use `DEConfigBuilder` to construct)
///
/// # Returns
///
/// Returns `Ok(DEReport)` containing the optimization result on success.
///
/// # Errors
///
/// Returns `DEError::InvalidBounds` if any bound pair has upper < lower.
///
/// # Example
///
/// ```rust
/// use math_audio_differential_evolution::{differential_evolution, DEConfigBuilder};
///
/// let config = DEConfigBuilder::new()
/// .maxiter(50)
/// .seed(42)
/// .build()
/// .expect("invalid config");
///
/// let result = differential_evolution(
/// &|x| x[0].powi(2) + x[1].powi(2),
/// &[(-5.0, 5.0), (-5.0, 5.0)],
/// config,
/// ).expect("optimization failed");
///
/// assert!(result.fun < 0.01);
/// ```