Skip to content

Commit c5a3633

Browse files
hbmcmahantensorflower-gardener
authored andcommitted
Fix sample weight generation in membership_inference_attack_test.
* Replace `rng.randn` with `rng.rand` for sample weights in MIA test helpers to ensure non-negative sample weights required by `RandomForestClassifier`'s bootstrap sampling logic. PiperOrigin-RevId: 971422996
1 parent e5d2dea commit c5a3633

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎tensorflow_privacy/privacy/privacy_tests/membership_inference_attack/membership_inference_attack_test.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def get_multilabel_test_input_with_sample_weights(n_train, n_test):
8383
logits_test=rng.randn(n_test, num_classes) + 0.2,
8484
labels_train=get_multihot_labels_for_test(n_train, num_classes),
8585
labels_test=get_multihot_labels_for_test(n_test, num_classes),
86-
sample_weight_train=rng.randn(n_train, 1),
87-
sample_weight_test=rng.randn(n_test, 1))
86+
sample_weight_train=rng.rand(n_train, 1),
87+
sample_weight_test=rng.rand(n_test, 1),
88+
)
8889

8990

9091
def get_test_input_logits_only(n_train, n_test):
@@ -101,8 +102,9 @@ def get_test_input_logits_only_with_sample_weights(n_train, n_test):
101102
return AttackInputData(
102103
logits_train=rng.randn(n_train, 5) + 0.2,
103104
logits_test=rng.randn(n_test, 5) + 0.2,
104-
sample_weight_train=rng.randn(n_train, 1),
105-
sample_weight_test=rng.randn(n_test, 1))
105+
sample_weight_train=rng.rand(n_train, 1),
106+
sample_weight_test=rng.rand(n_test, 1),
107+
)
106108

107109

108110
class MockTrainedAttacker(object):

0 commit comments

Comments
 (0)