Example #1
0
    def test_simulated_venn_diagram_reach_by_spend_without_active_pub(self):
        pdfs = [
            PublisherData([(1, 0.01), (2, 0.02), (1, 0.04), (3, 0.05)],
                          "pdf1"),
            PublisherData([(2, 0.03), (4, 0.06)], "pdf2"),
            PublisherData([(2, 0.01), (3, 0.03), (4, 0.05)], "pdf3"),
        ]
        data_set = DataSet(pdfs, "test")
        params = SystemParameters(
            [0.4, 0.5, 0.4],
            LiquidLegionsParameters(),
            FakeRandomGenerator(),
        )
        privacy_tracker = PrivacyTracker()
        halo = HaloSimulator(data_set, params, privacy_tracker)

        spends = [0, 0, 0]
        budget = PrivacyBudget(0.2, 0.4)
        privacy_budget_split = 0.5
        max_freq = 1

        reach_points = halo.simulated_venn_diagram_reach_by_spend(
            spends, budget, privacy_budget_split, max_freq)

        expected_reach_points = []

        self.assertEqual(expected_reach_points, reach_points)
        self.assertEqual(halo.privacy_tracker.privacy_consumption.epsilon, 0)
        self.assertEqual(halo.privacy_tracker.privacy_consumption.delta, 0)
        self.assertEqual(len(halo.privacy_tracker._noising_events), 0)
Example #2
0
 def test_simulated_reach_by_spend_with_negative_noise(
         self, mock_estimate_cardinality):
     mock_estimate_cardinality.return_value = [10, 5, -1, 0, -1]
     reach_point = self.halo.simulated_reach_by_spend([1.0, 1.0],
                                                      PrivacyBudget(
                                                          1.0, 0.0), 0.5, 5)
     self.assertTrue(all([reach_point.reach(i + 1) >= 0 for i in range(5)]))
Example #3
0
 def test_simulated_reach_by_spend_with_privacy(self,
                                                mock_laplace_mechanism):
     mock_laplace_mechanism.return_value = FakeLaplaceMechanism()
     reach_point = self.halo.simulated_reach_by_spend([0.04, 0.04],
                                                      PrivacyBudget(
                                                          1.0, 0.0), 0.5, 3)
     self.assertTrue(reach_point.reach(1) >= 0)
Example #4
0
 def test_simulated_reach_by_spend_no_privacy(self):
     reach_point = self.halo.simulated_reach_by_spend([0.04, 0.04],
                                                      PrivacyBudget(
                                                          100.0, 0.0), 0.5,
                                                      3)
     self.assertEqual(reach_point.reach(1), 2)
     self.assertEqual(reach_point.reach(2), 1)
     self.assertEqual(reach_point.reach(3), 0)
Example #5
0
 def test_simulated_reach_by_spend_reach_is_too_high(
         self, mock_estimate_cardinality):
     mock_estimate_cardinality.return_value = [20, 1, -1, 0, -1]
     reach_point = self.halo.simulated_reach_by_spend([0.06, 0.06],
                                                      PrivacyBudget(
                                                          1.0, 0.0), 0.5, 3)
     self.assertEqual(reach_point.reach(1), 5)
     self.assertEqual(reach_point.reach(2), 0)
     self.assertEqual(reach_point.reach(3), 0)