pub fn poisson_fit(
model: &dyn FitModel,
y_obs: &[f64],
priors: &[Prior],
params: &mut ParameterSet,
config: &PoissonConfig,
) -> Result<PoissonResult, FittingError>Expand description
Fit params to the counts y_obs by minimizing half the Poisson
deviance plus ½(θₚ − mₚ)ᵀCₚ⁻¹(θₚ − mₚ) for each of the priors, 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, with λ 1e-3 at first and
then that which keeps the step within a trust radius (J. J. Moré, Lect.
Notes Math. 630, 105–116, 1978): twice the length of a step that
delivers over three quarters of the decrease predicted for it as taken if
that is longer, a quarter of the length of one that delivers under a
quarter or does not lower the objective, which is then retried. 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 + Σₚ Cₚ⁻¹ the expected information, each Cₚ⁻¹ on
its prior’s parameters, 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.
The fit has also converged when none of its trial steps lowers the
objective and the decrement of each parameter with the others held,
½gⱼ²/Fⱼⱼ, is below 1e-6, provided those steps tested that since the fit
last moved beyond the rounding of the objective and of the predicted
counts, ε·(n·|objective| + Σ|yᵢ − μᵢ|) over n counts: the last
rejected one predicted to lower the objective beyond that rounding was
evaluated and, as taken after rounding and the bounds, still predicted so,
and none rejected after it was refused or impossible. Along
a weakly determined direction a slope error, or a curvature the expected
information leaves out, can keep ½ gᵀF⁺g large where no decrease is
left.
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 objective otherwise, when the
Jacobian
weighted by its bins is not finite or its decomposition fails, when the
objective is not finite at the start, as for a negative count or zero where
something was counted, or after config.max_iter steps;
PoissonResult::stop says which. 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, a prior is not on free
parameters, two priors are on one parameter, a prior’s mean is not finite
or a measured sd not finite and positive, 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.