Skip to main content

poisson_fit

Function poisson_fit 

Source
pub fn poisson_fit(
    model: &dyn FitModel,
    y_obs: &[f64],
    params: &mut ParameterSet,
    config: &PoissonConfig,
) -> Result<PoissonResult, FittingError>
Expand description

Fit params to the counts y_obs by minimizing half the Poisson deviance within the parameter bounds.

The model must provide an analytical Jacobian at every point the fit visits. A trial predicting a negative count, or zero where something was counted, is rejected; a bin predicted zero with no counts adds its slope to the gradient and nothing to the information. Each step is the Levenberg–Marquardt step (F + λI)⁻¹g in coordinates scaled to unit Fisher information, projected onto the box; λ is divided by 10 after a step that lowers the deviance, and multiplied by 10, to at least its starting 1e-3, before retrying one that does not (D. W. Marquardt, J. Soc. Indust. Appl. Math. 11, 431–441, 1963). A free parameter on its bound whose gradient points out of the box is held there for the step and left out of the convergence test.

The fit has converged when the Newton decrement ½ gᵀF⁺g over the parameters not held by a bound (on it, gradient pointing out), F = Jᵀ diag(1/μ) J the expected information, is below 1e-6: the quadratic model built from F predicts less than 1e-6 of further decrease. Where the deviance is quadratic near the minimum this puts the fit within about 0.0014 standard errors of it, and within 0.01 where the expected information overstates the curvature, as at one count per bin. Where it is not quadratic — weakly determined parameters on a curved or flat likelihood ridge, a minimum at infinity, or a parameter that adds counts to a bin predicted near zero — the fit can stop short of the minimum, or at another local minimum, and the error bars are not standard errors. A minimum where a bin’s prediction reaches zero inside the box is reported unconverged.

It stops unconverged when no step lowers the deviance, when the Jacobian is not finite, when the start predicts a negative count or zero where something was counted, or after config.max_iter steps. A trial whose prediction has a different length from y_obs is rejected.

§Errors

FittingError::EmptyData if y_obs is empty; FittingError::InvalidConfig if an observation is negative or not finite, a parameter value is not finite, a free parameter’s bounds are inverted, NaN or admit no finite value, or the model returns no analytical Jacobian; FittingError::LengthMismatch if the prediction or the Jacobian does not match y_obs and the free parameters; the model’s error if it fails at the start.