calculate_ks_statistic
- zdm.optical_numerics.calculate_ks_statistic(NFRB, AppMags, AppMagPriors, ObsMags, ObsPosteriors, PUobs, PUprior, plotfile=None, POxcut=None, plotlabel=None, abc=None, tag='')[source]
Compute a KS-like goodness-of-fit statistic between model prior and observed posteriors.
Builds cumulative magnitude distributions for both the model prior and the PATH posteriors, normalised by the number of FRBs, and returns the maximum absolute difference between them — analogous to the KS test statistic.
Optionally produces a plot comparing the two cumulative distributions.
- Parameters:
NFRB (int) – Number of FRBs used for normalisation.
AppMags (np.ndarray, shape (NMAG,)) – Apparent magnitude grid on which priors are defined.
AppMagPriors (list of np.ndarray, length NFRB) – Model prior p(m_r | DM_EG) on
AppMags, one array per FRB.ObsMags (list of np.ndarray, length NFRB) – Observed r-band magnitudes of PATH candidate galaxies, one per FRB.
ObsPosteriors (list of np.ndarray, length NFRB) – PATH posteriors P(O_i|x) for each candidate, one array per FRB.
PUobs (list of float) – Posterior P(U|x) for each FRB (not used directly in the statistic, kept for API consistency).
PUprior (list of float) – Prior P_U for each FRB (not used directly, kept for API consistency).
plotfile (str or None, optional) – If provided, save a CDF comparison plot to this path. Defaults to None.
POxcut (float or None, optional) – If not None, restrict to candidates with P(O|x) > POxcut and normalise both CDFs to unity (simulates the approach of selecting only confidently identified hosts). Defaults to None.
plotlabel (str or None, optional) – Text label placed in the centre-bottom of the plot. Defaults to None.
abc (str or None, optional) – Panel label (e.g.
'(a)') placed in the upper-left corner of the figure in figure-coordinate space. Defaults to None.tag (str, optional) – String prefix added to the legend labels
"Observed"and"Prior". Defaults to"".
- Returns:
stat – Maximum absolute difference between the observed and prior cumulative distributions. Smaller values indicate a better fit.
- Return type: