pyfli.cm_stats.deviance#

Poisson deviance statistics: per-gate terms, the summed and reduced deviance, and its expectation (and variance) under the model for photon counts.

Functions

deviance_dof(model, n_params[, weights, axis])

Expected deviance minus fitted parameters, sum_k w_k E[d_k] - n_params: the reduced-deviance denominator.

expected_poisson_deviance(model)

Expected Poisson deviance E[2 * (mu - d + d * ln(d / mu))] of a gate with expected count mu (element-wise), for d ~ Poisson(mu): about 2 mu ln(1/mu) for mu -> 0, peaks near 1.15 at mu ~ 1 and tends to 1 + 1/(6 mu) for large mu (poisson_deviance_moments()).

poisson_deviance(model, data[, axis])

Poisson deviance: poisson_deviance_terms() summed along axis (gates with d <= 0 contribute 2 * (mu - d) by default).

poisson_deviance_moment_table([mu_min, ...])

(ln mu, E[d], Var[d]) of the per-gate deviance on a log grid of mu, exact by summation.

poisson_deviance_moments(model)

Exact (E[d], Var[d]) of the per-gate deviance for d ~ Poisson(mu), element-wise: tabulated below mu = 1e3 (0 at mu = 0), then E = 1 + 1/(6 mu) + 1/(6 mu^2) and Var = 2 + 2/(3 mu) + 4/(3 mu^2).

poisson_deviance_terms(model, data[, floor, ...])

Per-gate Poisson deviance 2 (mu - d + d ln(d / mu)) with mu floored at floor.

reduced_poisson_deviance(model, data, n_params)

(D, D_reduced): the Poisson deviance along axis and the deviance divided by its expectation under the model minus the number of fitted parameters, D / max(sum E[D_k] - n_params, 1), which averages 1 for a correct model.

poisson_deviance_terms(model, data, floor=1e-12, nonpositive='zero', data_floor=1e-9)[source]#

Per-gate Poisson deviance 2 (mu - d + d ln(d / mu)) with mu floored at floor.

nonpositive sets the d ln(d / mu) term of gates with d <= 0: "zero" (0), "nan" (scipy xlogy: 0 for d = 0, NaN for d < 0) or "floor" (d ln(max(d, data_floor) / mu) on every gate).

Parameters:
Return type:

Any

poisson_deviance(model, data, axis=-1, **kwargs)[source]#

Poisson deviance: poisson_deviance_terms() summed along axis (gates with d <= 0 contribute 2 * (mu - d) by default). For counts drawn from the model, deviance / (sum E[D_k] - p) averages 1 (see reduced_poisson_deviance()).

Parameters:
Return type:

Any

poisson_deviance_moment_table(mu_min=MU_MIN, mu_max=MU_SWITCH, n_grid=N_GRID)[source]#

(ln mu, E[d], Var[d]) of the per-gate deviance on a log grid of mu, exact by summation.

Parameters:
Return type:

tuple[ndarray, ndarray, ndarray]

poisson_deviance_moments(model)[source]#

Exact (E[d], Var[d]) of the per-gate deviance for d ~ Poisson(mu), element-wise: tabulated below mu = 1e3 (0 at mu = 0), then E = 1 + 1/(6 mu) + 1/(6 mu^2) and Var = 2 + 2/(3 mu) + 4/(3 mu^2).

Parameters:

model (Any)

Return type:

tuple[Any, Any]

expected_poisson_deviance(model)[source]#

Expected Poisson deviance E[2 * (mu - d + d * ln(d / mu))] of a gate with expected count mu (element-wise), for d ~ Poisson(mu): about 2 mu ln(1/mu) for mu -> 0, peaks near 1.15 at mu ~ 1 and tends to 1 + 1/(6 mu) for large mu (poisson_deviance_moments()).

Parameters:

model (Any)

Return type:

Any

deviance_dof(model, n_params, weights=None, axis=-1)[source]#

Expected deviance minus fitted parameters, sum_k w_k E[d_k] - n_params: the reduced-deviance denominator.

Parameters:
Return type:

Any

reduced_poisson_deviance(model, data, n_params, axis=-1)[source]#

(D, D_reduced): the Poisson deviance along axis and the deviance divided by its expectation under the model minus the number of fitted parameters, D / max(sum E[D_k] - n_params, 1), which averages 1 for a correct model.

Parameters:
Return type:

tuple[Any, Any]