Skip to main content

ForwardModel

Trait ForwardModel 

Source
pub trait ForwardModel {
    // Required methods
    fn predict(&self, params: &[f64]) -> Result<Vec<f64>, FittingError>;
    fn n_data(&self) -> usize;
    fn n_params(&self) -> usize;

    // Provided method
    fn jacobian(
        &self,
        _params: &[f64],
        _free_param_indices: &[usize],
        _y_current: &[f64],
    ) -> Option<Vec<Vec<f64>>> { ... }
}
Expand description

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.).

Required Methods§

Source

fn predict(&self, params: &[f64]) -> Result<Vec<f64>, FittingError>

Predict model output for the given parameter vector.

Returns a vector of predicted values (transmission, counts, etc.) with length equal to the number of data points.

Source

fn n_data(&self) -> usize

Number of data points in the model output.

Source

fn n_params(&self) -> usize

Number of parameters (total, including fixed).

Provided Methods§

Source

fn jacobian( &self, _params: &[f64], _free_param_indices: &[usize], _y_current: &[f64], ) -> Option<Vec<Vec<f64>>>

Analytical Jacobian (column-major layout).

Returns a Vec of column vectors: result[j] is the j-th column (partial derivatives of all data points w.r.t. the j-th free parameter), so result[j][i] = ∂predict[i] / ∂params[free_param_indices[j]].

Only the columns corresponding to free_param_indices are needed. Returns None to signal “use finite differences” (the default).

y_current is the output of predict(params), provided so implementations can avoid redundant computation.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§