def test_compute_dp_sum(self): params = dp_computations.MeanVarParams( eps=0.5, delta=1e-10, min_value=2, max_value=3, max_partitions_contributed=1, max_contributions_per_partition=1, noise_kind=NoiseKind.LAPLACE) l0_sensitivity = params.l0_sensitivity() linf_sensitivity = params.max_contributions_per_partition * max( params.min_value, params.max_value) # Laplace Mechanism l1_sensitivity = dp_computations.compute_l1_sensitivity( l0_sensitivity, linf_sensitivity) results = [ dp_computations.compute_dp_sum(sum=10, dp_params=params) for _ in range(N_ITERATIONS) ] self._test_laplace_noise(results, 10, params.eps, l1_sensitivity) # Gaussian Mechanism params.noise_kind = NoiseKind.GAUSSIAN l2_sensitivity = dp_computations.compute_l2_sensitivity( l0_sensitivity, linf_sensitivity) results = [ dp_computations.compute_dp_sum(sum=10, dp_params=params) for _ in range(N_ITERATIONS) ] self._test_gaussian_noise(results, 10, params.eps, params.delta, l2_sensitivity)
def test_compute_dp_sum(self, bound_per_partition): min_value = max_value = min_sum_per_partition = max_sum_per_partition = None if bound_per_partition: min_sum_per_partition, max_sum_per_partition = 2, 3 else: min_value, max_value = 2, 3 params = dp_computations.ScalarNoiseParams( eps=0.5, delta=1e-10, min_value=min_value, max_value=max_value, min_sum_per_partition=min_sum_per_partition, max_sum_per_partition=max_sum_per_partition, max_partitions_contributed=1, max_contributions_per_partition=1, noise_kind=NoiseKind.LAPLACE) l0_sensitivity = params.l0_sensitivity() if bound_per_partition: linf_sensitivity = params.max_contributions_per_partition * max( params.min_sum_per_partition, params.max_sum_per_partition) else: # bound per contribution linf_sensitivity = params.max_contributions_per_partition * max( params.min_value, params.max_value) # Laplace Mechanism l1_sensitivity = dp_computations.compute_l1_sensitivity( l0_sensitivity, linf_sensitivity) results = [ dp_computations.compute_dp_sum(sum=10, dp_params=params) for _ in range(N_ITERATIONS) ] self._test_laplace_noise(results=results, num_trials=N_ITERATIONS, expected_mean=10, eps=params.eps, l1_sensitivity=l1_sensitivity) # Gaussian Mechanism params.noise_kind = NoiseKind.GAUSSIAN l2_sensitivity = dp_computations.compute_l2_sensitivity( l0_sensitivity, linf_sensitivity) results = [ dp_computations.compute_dp_sum(sum=10, dp_params=params) for _ in range(N_ITERATIONS) ] self._test_gaussian_noise(results=results, expected_mean=10, num_trials=N_ITERATIONS, eps=params.eps, delta=params.delta, l2_sensitivity=l2_sensitivity)
def test_compute_dp_sum_min_max_zero(self): params = dp_computations.ScalarNoiseParams( eps=0.5, delta=1e-10, min_value=0, max_value=0, min_sum_per_partition=None, max_sum_per_partition=None, max_partitions_contributed=1, max_contributions_per_partition=1, noise_kind=NoiseKind.LAPLACE) self.assertEqual(0, dp_computations.compute_dp_sum(10, params))
def compute_metrics(self) -> float: return dp_computations.compute_dp_sum(self._sum, self._params.mean_var_params)
def compute_metrics(self, sum_: AccumulatorType) -> dict: return { 'sum': dp_computations.compute_dp_sum(sum_, self._params.scalar_noise_params) }
def compute_metrics(self, sum: AccumulatorType) -> dict: return { 'sum': dp_computations.compute_dp_sum(sum, self._params.mean_var_params) }