From 31bb7c9382789a0860e12d5f802fd9fc4e196238 Mon Sep 17 00:00:00 2001 From: shivamlalakiya Date: Tue, 18 Aug 2026 16:34:22 -0500 Subject: [PATCH] Fix the non-smoothed online p-value: wrong index and an unassigned name p_values_online_classification's smoothing=False arms have two independent bugs, both in the code added for online (Mondrian) p-values: - base.py:3055 indexed all_alphas[q] (a calibration score) instead of all_alphas[start+q] (the test score), so the non-Mondrian path returned the rank of the wrong object. The p-value moved in the wrong direction as the test label became less conforming. - base.py:3093 and :3100 assigned p_values_bin, but :3107 reads bin_p_values, which every other accumulate block in the file uses. Both Mondrian smoothing=False branches raised UnboundLocalError unconditionally through predict_p_online, predict_set_online, and evaluate(online=True). Fixes #52 --- src/crepes/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/crepes/base.py b/src/crepes/base.py index 5a301b9..e7e3562 100644 --- a/src/crepes/base.py +++ b/src/crepes/base.py @@ -3052,7 +3052,7 @@ class names for q in range(len(alphas))]) else: p_values = np.array( - [np.sum(all_alphas[:start+q+1] >= all_alphas[q])/ \ + [np.sum(all_alphas[:start+q+1] >= all_alphas[start+q])/ \ (start + q + 1) for q in range(len(alphas))]) else: bin_values, bin_indexes = np.unique(all_bins, return_inverse=True) @@ -3090,14 +3090,14 @@ class names bin_alphas = alphas[bin_indexes[start:] == b] bin_start = len(bin_all_alphas) - len(bin_alphas) if all_classes: - p_values_bin = np.array([[ + bin_p_values = np.array([[ (np.sum(bin_all_alphas[ :bin_start+q] >= bin_alphas[q,c]) + 1) \ / (bin_start + q + 1) for c in range(bin_alphas.shape[1])] for q in range(len(bin_alphas))]) else: - p_values_bin = np.array([ + bin_p_values = np.array([ (np.sum(bin_all_alphas[ :bin_start+q] >= \ bin_all_alphas[bin_start+q]) + 1) \