2424import numpy as np
2525import scipy
2626
27- from art .utils import check_and_transform_label_format , is_probability
27+ from art .utils import check_and_transform_label_format , is_probability_array
2828
2929if TYPE_CHECKING :
3030 from art .estimators .classification .classifier import Classifier
@@ -77,14 +77,15 @@ def PDTP( # pylint: disable=C0103
7777 iter_results = []
7878 # get probabilities from original model
7979 pred = target_estimator .predict (x )
80- if not is_probability (pred ):
80+ if not is_probability_array (pred ):
8181 try :
8282 pred = scipy .special .softmax (pred , axis = 1 )
8383 except Exception as exc : # pragma: no cover
8484 raise ValueError ("PDTP metric only supports classifiers that output logits or probabilities." ) from exc
8585 # divide into 100 bins and return center of bin
8686 bins = np .array (np .arange (0.0 , 1.01 , 0.01 ).round (decimals = 2 ))
8787 pred_bin_indexes = np .digitize (pred , bins )
88+ pred_bin_indexes [pred_bin_indexes == 101 ] = 100
8889 pred_bin = bins [pred_bin_indexes ] - 0.005
8990
9091 if not indexes :
@@ -102,10 +103,11 @@ def PDTP( # pylint: disable=C0103
102103 extra_estimator .fit (alt_x , alt_y )
103104 # get probabilities from new model
104105 alt_pred = extra_estimator .predict (x )
105- if not is_probability (alt_pred ):
106+ if not is_probability_array (alt_pred ):
106107 alt_pred = scipy .special .softmax (alt_pred , axis = 1 )
107108 # divide into 100 bins and return center of bin
108109 alt_pred_bin_indexes = np .digitize (alt_pred , bins )
110+ alt_pred_bin_indexes [alt_pred_bin_indexes == 101 ] = 100
109111 alt_pred_bin = bins [alt_pred_bin_indexes ] - 0.005
110112 ratio_1 = pred_bin / alt_pred_bin
111113 ratio_2 = alt_pred_bin / pred_bin
0 commit comments