Skip to content

Commit

Permalink
Remove duplicate values before creating PIT Ensemble. (#173)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
drewoldag and eacharles authored May 2, 2023
1 parent e3c1e86 commit 2b1059f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/qp/metrics/pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2b1059f

Please sign in to comment.