torchcell.losses.distributional.pit_ks
- pit_ks(pit: Tensor) Tensor[source]
Kolmogorov-Smirnov distance between the PIT distribution and
Uniform(0,1).One scalar for the whole PIT histogram – the sup-norm gap between the empirical CDF of the pooled PIT values and the uniform CDF that perfect calibration implies:
\[D = \sup_{u\in[0,1]} \big| F_N(u) - u \big| = \max_{i=1..N} \max\!\Big(\tfrac{i}{N} - p_{(i)},\; p_{(i)} - \tfrac{i-1}{N}\Big),\]with \(p_{(1)}\le\dots\le p_{(N)}\) the sorted PIT values.
0is perfect; larger is worse, in either direction (it is a distance, so it does not say WHICH way – readcoverage()or the histogram shape for that).Comparable WITHIN a head, not ACROSS distributional modes. A calibrated
quantilehead on the defaulttau in [0.05, 0.95]grid parks ~5% of its PIT mass exactly at0and ~5% exactly at1(see_quantile_pit()), which alone forces \(D \approx 0.05\) even when the head is perfect. A parametric head has no such floor. Comparingpit_ksbetween a quantile arm and a Gaussian arm therefore measures the grid, not the model. Usecoverage()for cross-mode comparison – it evaluates the CDF at interior points where no mode has a structural artifact – and usepit_ksto track one head across epochs or hyperparameters.- Parameters:
pit – PIT values, any shape (all entries are pooled and flattened).
- Returns:
Scalar KS distance in
[0, 1].