Beispiel #1
0
 def test_anonymize_median_multiple(self):
     expected_values = np.array([87.5864551, 437.701297])
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_median([87.0, 435.0])
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #2
0
 def test_anonymize_median_single_many(self):
     expected_values = np.array([87.5864551, 89.701297, 86.4519884])
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_median(87.0, size=3)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #3
0
 def test_anonymize_median_single(self):
     expected_value = 87.58645513850368
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_median(87.0)
     np.testing.assert_almost_equal(anonymized, expected_value)
Beispiel #4
0
 def test_anonymize_proportion_multiple(self):
     expected_values = np.array([87.0586455, 435.2701297])
     n = 10.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_proportion([87.0, 435.0], n)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #5
0
 def test_anonymize_proportion_single_many(self):
     expected_values = np.array([87.0586455, 87.2701297, 86.9451988])
     n = 10.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_proportion(87.0, n, size=3)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #6
0
 def test_anonymize_proportion_single(self):
     expected_value = 87.05864551385037
     n = 10.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_proportion(87.0, n)
     np.testing.assert_almost_equal(anonymized, expected_value)
Beispiel #7
0
 def test_anonymize_sum_multiple(self):
     expected_values = np.array([145.0590587, 702.4284063])
     lower = 10.0
     upper = 99.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_sum([87.0, 435.0], lower, upper)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #8
0
 def test_anonymize_sum_single_many(self):
     expected_values = np.array([145.0590587, 354.4284063, 32.746848])
     lower = 10.0
     upper = 99.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_sum(87.0, lower, upper, size=3)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #9
0
 def test_anonymize_sum_single(self):
     expected_value = 145.05905871186388
     lower = 10.0
     upper = 99.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_sum(87.0, lower, upper)
     np.testing.assert_almost_equal(anonymized, expected_value)
Beispiel #10
0
 def test_anonymize_variance_single(self):
     expected_value = 133.45311152087612
     lower = 10.0
     upper = 99.0
     n = 100.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_variance(87.0, lower, upper, n)
     np.testing.assert_almost_equal(anonymized, expected_value)
Beispiel #11
0
 def test_anonymize_mean_multiple(self):
     expected_values = np.array([87.5219451, 437.4041544])
     lower = 10.0
     upper = 99.0
     n = 100.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_mean([87.0, 435.0], lower, upper, n)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #12
0
 def test_anonymize_mean_single_many(self):
     expected_values = np.array([87.5219451, 89.4041544, 86.5122696])
     lower = 10.0
     upper = 99.0
     n = 100.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_mean(87.0, lower, upper, n, size=3)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #13
0
 def test_anonymize_mean_single(self):
     expected_value = 87.52194507326827
     lower = 10.0
     upper = 99.0
     n = 100.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_mean(87.0, lower, upper, n)
     np.testing.assert_almost_equal(anonymized, expected_value)
Beispiel #14
0
 def test_anonymize_variance_multiple(self):
     expected_values = np.array([133.4531115, 648.969738])
     lower = 10.0
     upper = 99.0
     n = 100.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_variance([87.0, 435.0], lower, upper,
                                                n)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #15
0
 def test_anonymize_variance_single_many(self):
     expected_values = np.array([133.4531115, 300.969738, 43.5919983])
     lower = 10.0
     upper = 99.0
     n = 100.0
     epsilon = 1.0
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.set_seed()
     anonymized = anonymizer.anonymize_variance(87.0,
                                                lower,
                                                upper,
                                                n,
                                                size=3)
     np.testing.assert_almost_equal(anonymized, expected_values)
Beispiel #16
0
 def test_epsilon_getter(self):
     epsilon = 0.1
     anonymizer = DiffPrivLaplaceMechanism(epsilon)
     self.assertEqual(anonymizer.epsilon, epsilon)