Skip to content

Commit

Permalink
corrections.py: add sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalch committed Oct 16, 2023
1 parent 154557a commit 00f2958
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions deel/puncc/api/corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def bonferroni(alpha: float, nvars: int) -> float:
:returns: corrected coverage level.
:rtype: float.
"""
# Sanity checks
if alpha <= 0 or alpha >= 1:
raise ValueError("alpha must be in (0,1)")

if nvars <= 0:
raise ValueError("nvars must be a positive integer")

return alpha / nvars


Expand All @@ -50,12 +57,14 @@ def weighted_bonferroni(alpha: float, weights: np.ndarray) -> np.ndarray:
:returns: array of corrected featurewise coverage levels.
:rtype: np.ndarray.
"""
# Sanity checks
if alpha <= 0 or alpha >= 1:
raise ValueError("alpha must be in (0,1)")

# Positivity check
positiveness_condition = np.all(weights > 0)
if not positiveness_condition:
error = "weights must be positive"
raise RuntimeError(error)
raise RuntimeError("weights must be positive")

# Normalization check
norm_condition = np.isclose(np.sum(weights) - 1, 0, atol=1e-14)
Expand Down

0 comments on commit 00f2958

Please sign in to comment.