pyfli.solver.mle_fitter#
Extend the base fitter with Poisson and chi-square maximum-likelihood estimators.
This module belongs to pyfli.solver and is part of PyFLI least-squares, maximum-
likelihood, CPU, GPU, binned, and global FLI fitting routines. Public API includes
classes MLEFLIFitter.
Module Attributes
Objectives of |
Classes
|
Extend the base FLI fitter with Poisson, Pearson, and Neyman objective functions. |
- MLE_WEIGHTINGS = ('poisson', 'pearson', 'neyman', 'none')#
Objectives of
MLEFLIFitter.fit_with_estimator()("poisson"is the default).
- class MLEFLIFitter(freq, decay_px, irf_px, white_noise=0.1, guess_plugin=moment_based_guess, custom_funcs=None, shift_method='zero_pad', fit_indices=None, excitation='bin_start', gate_width=None)[source]#
Bases:
BaseFLIFitterExtend the base FLI fitter with Poisson, Pearson, and Neyman objective functions. It supports MLE-style fitting, Fisher-information (Poisson) and robust sandwich (chi-square) parameter uncertainties, and likelihood-based model comparison.
- Parameters:
- pearson_chi_square(params, model_type)[source]#
Pearson’s Chi-square: Weighted by the MODEL [1/y_model].
- neyman_chi_square(params, model_type)[source]#
Neyman’s Chi-square: Weighted by the DATA [1/y_data].
- unweighted_sum_of_squares(params, model_type)[source]#
Unweighted sum of squared residuals (every gate counts equally).
- fit_with_estimator(estimator_type='poisson', model_type='bi-exponential', p0=None, bounds=None, weighting=None, **kwargs)[source]#
Main interface for MLE/Chi-square fitting, with the same argument order as
pyfli.solver.base_fitter.BaseFLIFitter.fit_with_estimator():(estimator_type, model_type, p0, bounds, ...).- Parameters:
estimator_type (
str) – Objective name ("poisson","pearson"or"neyman"); used when weighting is not given. Unknown names fall back to"poisson".model_type (
str) –"mono-exponential"or"bi-exponential".p0 (
Any) – Initial parameters and bounds (seeresolve_params_and_bounds()).bounds (
Any) – Initial parameters and bounds (seeresolve_params_and_bounds()).weighting (
str | None) –Objective to minimize (see
MLE_WEIGHTINGS); overrides estimator_type:"poisson"(default): Poisson deviance – the maximum-likelihood estimator for photon counts; the consistent, least-biased choice."pearson":sum (d - mu)^2 / muminimized directly. Because the weights move with the model, it is biased towards larger model values (for decays, longer lifetimes) at low counts."neyman":sum (d - mu)^2 / max(d, 1); biased towards low counts (shorter lifetimes) at low counts."none": unweighted sum of squares.
**kwargs (
Any) –max_iter(ormaxiter, default 2000) optimizer iterations,maxfun(default 50000),ftolandgtol.
- Return type:
- parameter_errors(popt, model_type, weighting='poisson', bounds=None)[source]#
One-standard-deviation uncertainties of parameters fitted with weighting.
"poisson"uses the inverse Fisher information(J^T diag(1/mu) J)^-1of the Poisson likelihood at popt, i.e. the asymptotic covariance (and Cramer-Rao bound) of the MLE."pearson","neyman"and"none"use the heteroscedasticity-robust sandwich ofcalculate_uncertainties()on the weighted Jacobian and residuals.- Parameters:
popt (
np.ndarray) – Fitted parameter vector (before tau ordering).model_type (
str) –"mono-exponential"or"bi-exponential".weighting (
str) – Objective the parameters were fitted with (seeMLE_WEIGHTINGS).bounds (
tuple[np.ndarray,np.ndarray] | None) –(low, high)bounds of the fit. Parameters pinned by them (low == high) get 0; parameters sitting on an active bound get NaN, because the asymptotic normal approximation does not hold there. The remaining uncertainties are computed with those parameters held fixed.
- Returns:
Standard error of each parameter.
- Return type:
np.ndarray