def test_gaussian_mechanism_respects_random_state(self): lm0 = noisers.GaussianMechanism( lambda x: np.array([1., 2., 3.]), 1., 2., .1, random_state=np.random.RandomState(seed=123)) result0 = lm0(5.) lm1 = noisers.GaussianMechanism( lambda x: np.array([1., 2., 3.]), 1., 2., .1, random_state=np.random.RandomState(seed=123)) result1 = lm1(5.) self.assertEqual(list(result0), list(result1)) result2 = lm1(5.) self.assertNotEqual(list(result1), list(result2))
def test_gaussian_mechanism_adds_expected_noise(self): rs = FakeGaussianRandomState(np.array([2., 4., 6.])) lm = noisers.GaussianMechanism(lambda x: np.array([1., 2., 3.]), 1., 2., .1, random_state=rs) result = lm(5.) np.testing.assert_array_equal(result, np.array([3., 6., 9.]))
def __init__(self, epsilon, delta, num_queries=1, random_state=None): """Instantiates a GaussianEstimateNoiser object. Args: epsilon: The differential privacy level. delta: The differential privacy level. num_queries: The number of queries for which the noiser is used. Note that the constructed noiser will be (epsilon, delta)-differentially private when answering (no more than) num_queries queries. random_state: Optional instance of numpy.random.RandomState that is used to seed the random number generator. """ # Note that any cardinality estimator will have sensitivity (delta_f) of 1. self._noiser = noisers.GaussianMechanism(lambda x: x, 1.0, epsilon, delta, num_queries=num_queries, random_state=random_state)
def test_gaussian_mechanism_works_with_scipy_stats_normal(self): lm = noisers.GaussianMechanism(lambda x: np.array([1., 2., 3.]), 1., 2., .1) result = lm(5.) self.assertLen(result, 3)