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
//! Solver-agnostic forward model trait.
//!
//! Unlike [`FitModel`](crate::lm::FitModel), which is LM-specific (evaluates
//! residuals + Jacobian in chi-squared space), `ForwardModel` exposes the
//! raw model prediction and parameter Jacobian. Each solver wraps this to
//! compute its own objective and gradient:
//!
//! - **LM**: residuals = `(data - predict) / σ`, J_lm = `-jacobian / σ`
//! - **KL**: gradient = `Σ (1 - data/predict) · jacobian`
//!
//! This makes new model extensions (background, temperature, etc.) work with
//! both solvers automatically — implement `ForwardModel` once, both solvers
//! benefit.
use crateFittingError;
/// Solver-agnostic forward model.
///
/// Implementations provide the model prediction and (optionally) its
/// analytical Jacobian. Solvers wrap this trait to compute solver-specific
/// objectives (chi-squared, Poisson NLL, etc.).