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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: AGPL-3.0-or-later
//! Optimization algorithms for parameter fitting and model calibration
//!
//! This module provides both gradient-free and gradient-based optimization
//! methods suitable for scientific computing and machine learning.
//!
//! # Algorithms
//!
//! ## Optimization
//!
//! - **Nelder-Mead**: Simplex method for gradient-free local optimization
//! - **Multi-start Nelder-Mead**: Global optimization with LHS initial guesses
//! - **BFGS**: Quasi-Newton method with gradient information
//!
//! ## Root-Finding
//!
//! - **Bisection**: Reliable but slow O(n) convergence (CPU)
//! - **Batched Bisection GPU**: Parallel bisection for many problems (GPU)
//! - **Newton-Raphson**: Fast O(n²) convergence with derivatives
//! - **Brent's Method**: Best of both worlds - reliable and fast
//! - **Secant Method**: Newton-like without analytical derivatives
//!
//! ## Diagnostics & Utilities
//!
//! - **Evaluation Cache**: Record all evaluations for surrogate training
//! - **Convergence Diagnostics**: Detect stagnation, oscillation, divergence
//! - **Adaptive Penalty**: Data-driven penalty for constrained optimization
//!
//! # Cross-Domain Applications
//!
//! - **Physics**: Nuclear EOS parameter fitting, force-field calibration
//! - **ML**: Hyperparameter tuning, architecture search
//! - **Graphics**: Camera calibration, rendering parameter optimization
//! - **Audio**: Filter design, codec parameter tuning
//!
//! # Examples
//!
//! ```
//! use barracuda::optimize::{nelder_mead, multi_start_nelder_mead};
//!
//! // Local optimization
//! let rosenbrock = |x: &[f64]| {
//! let (a, b) = (1.0, 100.0);
//! (a - x[0]).powi(2) + b * (x[1] - x[0].powi(2)).powi(2)
//! };
//!
//! let x0 = vec![0.0, 0.0];
//! let bounds = vec![(-5.0, 5.0), (-5.0, 5.0)];
//!
//! let (x_best, f_best, n_evals) = nelder_mead(
//! rosenbrock,
//! &x0,
//! &bounds,
//! 1000,
//! 1e-8,
//! )?;
//!
//! // Global optimization with evaluation recording
//! let (best, cache, _) = multi_start_nelder_mead(
//! rosenbrock,
//! &bounds,
//! 16, // n_starts (like SparsitySampler npts=16)
//! 1000, // max_iter per start
//! 1e-8, // tolerance
//! 42, // seed
//! )?;
//!
//! // Use cache for surrogate training
//! let (x_data, y_data) = cache.training_data();
//! # Ok::<(), barracuda::error::BarracudaError>(())
//! ```
// EVOLVED: GPU batched root-finding (Feb 16, 2026)
// EVOLVED: GPU-resident optimizer (Feb 14, 2026)
pub use ;
pub use ;
pub use ;
pub use bisect;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use nelder_mead;
pub use ; // GPU-resident optimizer
pub use ;
pub use ;
pub use ;