def test_apply_single_many(self): expected_values = np.array([145.0590587, 354.4284063, 32.746848]) lower = 10.0 upper = 99.0 epsilon = 1.0 anonymizer = DiffPrivSumAnonymizer(epsilon, lower, upper) self.set_seed() values = anonymizer.apply(87.0, size=3) np.testing.assert_almost_equal(values, expected_values)
def test_apply_multiple(self): expected_values = np.array([145.0590587, 702.4284063]) lower = 10.0 upper = 99.0 epsilon = 1.0 anonymizer = DiffPrivSumAnonymizer(epsilon, lower, upper) self.set_seed() values = anonymizer.apply([87.0, 435.0]) np.testing.assert_almost_equal(values, expected_values)
def test_apply_single(self): expected_value = 145.05905871186388 lower = 10.0 upper = 99.0 epsilon = 1.0 anonymizer = DiffPrivSumAnonymizer(epsilon, lower, upper) self.set_seed() value = anonymizer.apply(87.0) np.testing.assert_almost_equal(value, expected_value)
def test_scale_getter(self): lower = 10.0 upper = 99.0 epsilon = 1.0 gs_value = np.max([np.abs(lower), np.abs(upper)]) scale = gs_value / epsilon anonymizer = DiffPrivSumAnonymizer(epsilon, lower, upper) self.assertEqual(anonymizer.scale, scale)
def test_global_sensitivity_getter(self): lower = 10.0 upper = 99.0 epsilon = 1.0 gs_value = np.max([np.abs(lower), np.abs(upper)]) anonymizer = DiffPrivSumAnonymizer(epsilon, lower, upper) np.testing.assert_almost_equal(anonymizer.global_sensitivity.value, gs_value)
def create_sum_anonymizer(cls, epsilon, lower, upper): """ Creates a sum anonymizer instance. Parameters ---------- epsilon : float The privacy budget. lower : float The lower bound of the data. upper : float The upper bound of the data. Returns ------- `DiffPrivSumAnonymizer` A sum anonymizer with the provided privacy budget. """ anonymizer = DiffPrivSumAnonymizer(epsilon, lower, upper) return anonymizer
def test_epsilon_getter(self): lower = 10.0 upper = 99.0 epsilon = 1.0 anonymizer = DiffPrivSumAnonymizer(epsilon, lower, upper) self.assertEqual(anonymizer.epsilon, epsilon)