From 2b1059f0f607d61e534f5c3e2054ed2c12f43223 Mon Sep 17 00:00:00 2001 From: Drew Oldag <47493171+drewoldag@users.noreply.github.com> Date: Tue, 2 May 2023 11:17:49 -0700 Subject: [PATCH] Remove duplicate values before creating PIT Ensemble. (#173) * protect quantile prepresenation used in PIT * Moved the mask creation into an classmethod, and added a handful of unit tests. * This addressess errors related to duplicate values when evaluating the CDF of the PIT Ensemble. --------- Co-authored-by: Eric Charles --- src/qp/metrics/pit.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/qp/metrics/pit.py b/src/qp/metrics/pit.py index f355e87..a8c6694 100644 --- a/src/qp/metrics/pit.py +++ b/src/qp/metrics/pit.py @@ -51,8 +51,20 @@ def __init__(self, qp_ens, true_vals, eval_grid=DEFAULT_QUANTS): eval_grid = np.linspace(0, 1, n_pit) data_quants = np.quantile(self._pit_samps, eval_grid) - quant_mask = self._create_quant_mask(data_quants) - self._pit = qp.Ensemble(qp.quant, data=dict(quants=eval_grid[quant_mask], locs=np.atleast_2d(data_quants[quant_mask]))) + + # Remove duplicates values as well as values outside the range (0,1) + _, unique_indices = np.unique(data_quants, return_index=True) + unique_data_quants = data_quants[unique_indices] + unique_eval_grid = eval_grid[unique_indices] + quant_mask = self._create_quant_mask(unique_data_quants) + + self._pit = qp.Ensemble( + qp.quant, + data=dict( + quants=unique_eval_grid[quant_mask], + locs=np.atleast_2d(unique_data_quants[quant_mask]) + ) + ) @property def pit_samps(self):