예제 #1
0
 def test_self_convolve_dictionary(self):
     inp_dictionary = {1: 2, 3: 5, 4: 6}
     expected_result = {
         3: 8,
         5: 60,
         6: 72,
         7: 150,
         8: 360,
         9: 341,
         10: 450,
         11: 540,
         12: 216
     }
     result = common.self_convolve_dictionary(inp_dictionary, 3)
     test_util.assert_dictionary_almost_equal(self, expected_result, result)
 def test_discrete_laplace_privacy_loss_tail(
         self, parameter, sensitivity, sampling_prob, adjacency_type,
         expected_lower_x_truncation, expected_upper_x_truncation,
         expected_tail_probability_mass_function):
     pl = privacy_loss_mechanism.DiscreteLaplacePrivacyLoss(
         parameter,
         sensitivity=sensitivity,
         sampling_prob=sampling_prob,
         adjacency_type=adjacency_type)
     tail_pld = pl.privacy_loss_tail()
     self.assertAlmostEqual(expected_lower_x_truncation,
                            tail_pld.lower_x_truncation)
     self.assertAlmostEqual(expected_upper_x_truncation,
                            tail_pld.upper_x_truncation)
     test_util.assert_dictionary_almost_equal(
         self, expected_tail_probability_mass_function,
         tail_pld.tail_probability_mass_function)
 def test_discrete_gaussian_privacy_loss_tail(
         self, sigma, sensitivity, truncation_bound, sampling_prob,
         adjacency_type, expected_lower_x_truncation,
         expected_upper_x_truncation,
         expected_tail_probability_mass_function):
     pl = privacy_loss_mechanism.DiscreteGaussianPrivacyLoss(
         sigma,
         sensitivity=sensitivity,
         truncation_bound=truncation_bound,
         sampling_prob=sampling_prob,
         adjacency_type=adjacency_type)
     tail_pld = pl.privacy_loss_tail()
     self.assertAlmostEqual(expected_lower_x_truncation,
                            tail_pld.lower_x_truncation)
     self.assertAlmostEqual(expected_upper_x_truncation,
                            tail_pld.upper_x_truncation)
     test_util.assert_dictionary_almost_equal(
         self, expected_tail_probability_mass_function,
         tail_pld.tail_probability_mass_function)
 def test_gaussian_privacy_loss_tail(
         self, standard_deviation, sensitivity, sampling_prob,
         adjacency_type, expected_lower_x_truncation,
         expected_upper_x_truncation, pessimistic_estimate,
         expected_tail_probability_mass_function):
     pl = privacy_loss_mechanism.GaussianPrivacyLoss(
         standard_deviation,
         sensitivity=sensitivity,
         pessimistic_estimate=pessimistic_estimate,
         log_mass_truncation_bound=math.log(2) + stats.norm.logcdf(-1),
         sampling_prob=sampling_prob,
         adjacency_type=adjacency_type)
     tail_pld = pl.privacy_loss_tail()
     self.assertAlmostEqual(expected_lower_x_truncation,
                            tail_pld.lower_x_truncation)
     self.assertAlmostEqual(expected_upper_x_truncation,
                            tail_pld.upper_x_truncation)
     test_util.assert_dictionary_almost_equal(
         self, expected_tail_probability_mass_function,
         tail_pld.tail_probability_mass_function)
예제 #5
0
 def test_convolve_dictionary_with_truncation(self):
     dictionary1 = {1: 0.4, 2: 0.6}
     dictionary2 = {1: 0.7, 3: 0.3}
     expected_result = {3: 0.42, 4: 0.12}
     result = common.convolve_dictionary(dictionary1, dictionary2, 0.57)
     test_util.assert_dictionary_almost_equal(self, expected_result, result)
예제 #6
0
 def test_convolve_dictionary(self):
     dictionary1 = {1: 2, 3: 4}
     dictionary2 = {2: 3, 4: 6}
     expected_result = {3: 6, 5: 24, 7: 24}
     result = common.convolve_dictionary(dictionary1, dictionary2)
     test_util.assert_dictionary_almost_equal(self, expected_result, result)
예제 #7
0
 def test_list_to_dict_truncation(self, input_list, offset,
                                  tail_mass_truncation, expected_result):
     result = common.list_to_dictionary(
         input_list, offset, tail_mass_truncation=tail_mass_truncation)
     test_util.assert_dictionary_almost_equal(self, expected_result, result)
예제 #8
0
 def test_dictionary_almost_equal(self, dict1, dict2, expected_result):
     if expected_result:
         test_util.assert_dictionary_almost_equal(self, dict1, dict2)
     else:
         with self.assertRaises(AssertionError):
             test_util.assert_dictionary_almost_equal(self, dict1, dict2)