def test_geometric_mechanism_respects_random_state(self): lm0 = noisers.GeometricMechanism( lambda x: np.array([1., 2., 3.]), 1., 2., random_state=np.random.RandomState(seed=125)) result0 = lm0(5.) lm1 = noisers.GeometricMechanism( lambda x: np.array([1., 2., 3.]), 1., 2., random_state=np.random.RandomState(seed=125)) result1 = lm1(5.) self.assertAlmostEqual(list(result0), list(result1)) result2 = lm1(5.) self.assertNotEqual(list(result1), list(result2))
def test_geometric_mechanism_adds_expected_noise(self): rs = FakeGeometricRandomState(np.array([[3., 6., 13.], [1., 2., 7.]])) lm = noisers.GeometricMechanism(lambda x: np.array([1., 2., 3.]), 1., 2., random_state=rs) result = lm(5.) np.testing.assert_array_equal(result, np.array([3., 6., 9.]))
def __init__(self, epsilon, random_state=None): """Instantiates a GeometricEstimateNoiser object. Args: epsilon: The differential privacy level. 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.GeometricMechanism(lambda x: x, 1.0, epsilon, random_state)
def test_geometric_mechanism_works_with_scipy_stats_geom(self): lm = noisers.GeometricMechanism(lambda x: np.array([1., 2., 3.]), 1., 2.) result = lm(5.) self.assertLen(result, 3)