Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 322996754
  • Loading branch information
tensorflower-gardener committed Jul 24, 2020
1 parent 267ea7f commit f318fbb
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from absl.testing import absltest
import numpy as np
from tensorflow_privacy.privacy.membership_inference_attack.data_structures import AttackInputData
from tensorflow_privacy.privacy.membership_inference_attack.data_structures import RocCurve


class AttackInputDataTest(absltest.TestCase):
Expand Down Expand Up @@ -61,5 +62,40 @@ def test_validator(self):
AttackInputData().validate)


class RocCurveTest(absltest.TestCase):

def test_auc_random_classifier(self):
roc = RocCurve(
tpr=np.array([0.0, 0.5, 1.0]),
fpr=np.array([1.0, 0.5, 0.0]),
thresholds=np.array([0, 1, 2]))

self.assertEqual(roc.get_auc(), 0.5)

def test_auc_perfect_classifier(self):
roc = RocCurve(
tpr=np.array([0.0, 1.0, 1.0]),
fpr=np.array([1.0, 1.0, 0.0]),
thresholds=np.array([0, 1, 2]))

self.assertEqual(roc.get_auc(), 1.0)

def test_attacker_advantage_random_classifier(self):
roc = RocCurve(
tpr=np.array([0.0, 0.5, 1.0]),
fpr=np.array([1.0, 0.5, 0.0]),
thresholds=np.array([0, 1, 2]))

self.assertEqual(roc.get_attacker_advantage(), 0.0)

def test_attacker_advantage_perfect_classifier(self):
roc = RocCurve(
tpr=np.array([0.0, 1.0, 1.0]),
fpr=np.array([1.0, 1.0, 0.0]),
thresholds=np.array([0, 1, 2]))

self.assertEqual(roc.get_auc(), 1.0)


if __name__ == '__main__':
absltest.main()

0 comments on commit f318fbb

Please sign in to comment.