pub trait FitModel {
// Required method
fn evaluate(&self, params: &[f64]) -> Result<Vec<f64>, FittingError>;
// Provided method
fn analytical_jacobian(
&self,
_params: &[f64],
_free_param_indices: &[usize],
_y_current: &[f64],
) -> Option<FlatMatrix> { ... }
}Expand description
A model function that can be fitted.
Given parameter values (all params including fixed), computes the model prediction at each data point.
Required Methods§
Sourcefn evaluate(&self, params: &[f64]) -> Result<Vec<f64>, FittingError>
fn evaluate(&self, params: &[f64]) -> Result<Vec<f64>, FittingError>
Evaluate the model for the given parameters.
On success, returns a vector of model predictions with the same
length as the data being fitted. On failure, returns a
FittingError indicating that the model could not be evaluated
(e.g. a broadening or physics error).
Optimizer semantics: during Levenberg-Marquardt trial steps,
an Err is treated as a failed step (increase λ / backtrack).
At the initial point or post-convergence, Err is propagated.
Provided Methods§
Sourcefn analytical_jacobian(
&self,
_params: &[f64],
_free_param_indices: &[usize],
_y_current: &[f64],
) -> Option<FlatMatrix>
fn analytical_jacobian( &self, _params: &[f64], _free_param_indices: &[usize], _y_current: &[f64], ) -> Option<FlatMatrix>
Optionally provide an analytical Jacobian.
free_param_indices: indices (into params) of the free parameters,
in the same order as the Jacobian columns.
y_current: current model output, i.e. self.evaluate(params).
Provided so implementations can compute J analytically from T without
an extra evaluate call.
Returns Some(J) where J.get(i, j) = ∂model[i]/∂params[free_param_indices[j]].
The matrix has y_current.len() rows and free_param_indices.len() columns.
Return None to fall back to finite-difference Jacobian (the default).
Implementations on Foreign Types§
Source§impl<M: FitModel + ?Sized> FitModel for &M
Blanket implementation: shared references to any FitModel also implement
FitModel, forwarding all calls to the underlying implementation.
impl<M: FitModel + ?Sized> FitModel for &M
Blanket implementation: shared references to any FitModel also implement
FitModel, forwarding all calls to the underlying implementation.
This enables NormalizedTransmissionModel<&dyn FitModel> to work when the
inner model is borrowed (e.g. in fit_spectrum where the inner model is a
local variable wrapped conditionally).