Skip to content

Commit

Permalink
Updated binom_test to binomtest in randomized_smoothing.py
Browse files Browse the repository at this point in the history
Signed-off-by: Prem Kiran Laknaboina <[email protected]>
  • Loading branch information
Ashuradhipathi committed Nov 2, 2024
1 parent 87fd213 commit 8274360
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def predict(self, x: np.ndarray, batch_size: int = 128, verbose: bool = False, *
:type is_abstain: `boolean`
:return: Array of predictions of shape `(nb_inputs, nb_classes)`.
"""
from scipy.stats import binom_test
from scipy.stats import binomtest

Check warning on line 88 in art/estimators/certification/randomized_smoothing/randomized_smoothing.py

View check run for this annotation

Codecov / codecov/patch

art/estimators/certification/randomized_smoothing/randomized_smoothing.py#L88

Added line #L88 was not covered by tests

is_abstain = kwargs.get("is_abstain")
if is_abstain is not None and not isinstance(is_abstain, bool): # pragma: no cover
Expand All @@ -100,12 +100,15 @@ def predict(self, x: np.ndarray, batch_size: int = 128, verbose: bool = False, *
# get class counts
counts_pred = self._prediction_counts(x_i, batch_size=batch_size)
top = counts_pred.argsort()[::-1]
count1 = np.max(counts_pred)
count2 = counts_pred[top[1]]
# Conersion to int
count1 = int(np.max(counts_pred))
count2 = int(counts_pred[top[1]])

Check warning on line 105 in art/estimators/certification/randomized_smoothing/randomized_smoothing.py

View check run for this annotation

Codecov / codecov/patch

art/estimators/certification/randomized_smoothing/randomized_smoothing.py#L104-L105

Added lines #L104 - L105 were not covered by tests

# predict or abstain
smooth_prediction = np.zeros(counts_pred.shape)
if (not is_abstain) or (binom_test(count1, count1 + count2, p=0.5) <= self.alpha):
#Get p value from BinomTestResult object
p_value = binomtest(count1, count1 + count2, p=0.5).pvalue

Check warning on line 110 in art/estimators/certification/randomized_smoothing/randomized_smoothing.py

View check run for this annotation

Codecov / codecov/patch

art/estimators/certification/randomized_smoothing/randomized_smoothing.py#L110

Added line #L110 was not covered by tests
if (not is_abstain) or (p_value <= self.alpha):
smooth_prediction[np.argmax(counts_pred)] = 1
elif is_abstain:
n_abstained += 1
Expand Down

0 comments on commit 8274360

Please sign in to comment.