tsdive.eval.conformal_p_values
¶
conformal_p_values(
calibration: Iterable[float],
stream: Iterable[float],
*,
online: bool = True,
) -> np.ndarray
Conformal p-value of each stream score against its pool, in stream order.
For stream position t the pool is calibration plus
stream[:t] when online is true, and calibration alone
otherwise. The p-value is
(count(pool > x_t) + count(pool == x_t) + 1) / (len(pool) + 1):
ties count against the new score, so the value is conservative and
the function is deterministic, with no randomised tie-breaking.
Under exchangeability of the calibration and stream scores each
p_t is stochastically no smaller than a uniform variable on
(0, 1], and with online=True the p_t are independent,
which is the property power_martingale and mixture_martingale
need. Raises ValueError when calibration is empty or either
input holds a non-finite value.
Examples:
>>> from tsdive.eval import conformal_p_values
>>> p = conformal_p_values([1.0, 2.0, 3.0, 4.0], [2.5, 5.0, 6.0])
>>> p.round(3).tolist()
[0.6, 0.167, 0.143]