def test_get_private_average_error(self):
        nonprivate_points = [[1, 2, 1], [0.4, 0.2, 0.8], [3, 0, 3]]
        average_privacy_param = AveragePrivacyParam(epsilon=7,
                                                    delta=1e-2,
                                                    sensitivity=4.3)

        with self.assertRaises(ValueError):
            central_privacy_utils.get_private_average(nonprivate_points,
                                                      0,
                                                      average_privacy_param,
                                                      dim=3)
        with self.assertRaises(ValueError):
            central_privacy_utils.get_private_average(nonprivate_points,
                                                      -2,
                                                      average_privacy_param,
                                                      dim=3)
Пример #2
0
    def test_get_private_average_error(self):
        nonprivate_points = [[1, 2, 1], [0.4, 0.2, 0.8], [3, 0, 3]]
        clustering_param = test_utils.get_test_clustering_param(
            epsilon=10,
            delta=1e-2,
            frac_sum=0.7,
            frac_group_count=0.3,
            radius=4.3)

        with self.assertRaises(ValueError):
            central_privacy_utils.get_private_average(nonprivate_points,
                                                      0,
                                                      clustering_param,
                                                      dim=3)
        with self.assertRaises(ValueError):
            central_privacy_utils.get_private_average(nonprivate_points,
                                                      -2,
                                                      clustering_param,
                                                      dim=3)
 def test_get_private_average_infinite_eps(self):
     nonprivate_points = [[1, 2, 1], [0.2, 0.1, 0.8], [3, 0, 3]]
     private_count = 3
     expected_center = [1.4, 0.7, 1.6]
     average_privacy_param = AveragePrivacyParam(epsilon=np.inf,
                                                 delta=1e-2,
                                                 sensitivity=4.3)
     self.assertSequenceAlmostEqual(
         central_privacy_utils.get_private_average(nonprivate_points,
                                                   private_count,
                                                   average_privacy_param,
                                                   dim=3), expected_center)
    def test_get_private_average(self, nonprivate_points, expected_center,
                                 mock_normal_fn):
        private_count = 4
        average_privacy_param = AveragePrivacyParam(epsilon=7,
                                                    delta=1e-2,
                                                    sensitivity=4.3)

        result = central_privacy_utils.get_private_average(
            nonprivate_points, private_count, average_privacy_param, dim=3)
        self.assertSequenceAlmostEqual(result, expected_center)
        mock_normal_fn.assert_called_once()
        self.assertEqual(mock_normal_fn.call_args[1]['size'], 3)
        self.assertAlmostEqual(mock_normal_fn.call_args[1]['scale'],
                               1.927768,
                               delta=1e-5)
Пример #5
0
 def test_get_private_average_infinite_eps(self):
     nonprivate_points = [[1, 2, 1], [0.2, 0.1, 0.8], [3, 0, 3]]
     private_count = 3
     expected_center = [1.4, 0.7, 1.6]
     clustering_param = test_utils.get_test_clustering_param(
         epsilon=np.inf,
         delta=1e-2,
         frac_sum=0.7,
         frac_group_count=0.3,
         radius=4.3)
     self.assertSequenceAlmostEqual(
         central_privacy_utils.get_private_average(nonprivate_points,
                                                   private_count,
                                                   clustering_param,
                                                   dim=3), expected_center)
Пример #6
0
    def get_private_average(self) -> np.ndarray:
        """Returns and saves private average of the points in the node.

    Requires that self.private_count >= 1.
    """
        # Reuse old results if they've been computed in the past.
        if self.private_average is not None:
            return self.private_average

        privacy_param = self.clustering_param.privacy_param
        if privacy_param.privacy_model != clustering_params.PrivacyModel.CENTRAL:
            raise NotImplementedError(
                f"Currently unsupported privacy model: {privacy_param.privacy_model}"
            )
        self.private_average = central_privacy_utils.get_private_average(
            self.nonprivate_points, self.private_count, self.clustering_param,
            self.sim_hash.dim)
        return self.private_average
Пример #7
0
    def test_get_private_average(self, nonprivate_points, expected_center,
                                 mock_normal_fn):
        private_count = 4
        clustering_param = test_utils.get_test_clustering_param(
            epsilon=10,
            delta=1e-2,
            frac_sum=0.7,
            frac_group_count=0.3,
            radius=4.3)

        result = central_privacy_utils.get_private_average(nonprivate_points,
                                                           private_count,
                                                           clustering_param,
                                                           dim=3)
        self.assertSequenceAlmostEqual(result, expected_center)
        mock_normal_fn.assert_called_once()
        self.assertEqual(mock_normal_fn.call_args[1]['size'], 3)
        self.assertAlmostEqual(mock_normal_fn.call_args[1]['scale'],
                               1.927768,
                               delta=1e-5)