Exemplo n.º 1
0
    def test_budget_scopes(self):
        budget_accountant = NaiveBudgetAccountant(total_epsilon=1,
                                                  total_delta=1e-6)

        with budget_accountant.scope(weight=0.4):
            budget1 = budget_accountant.request_budget(
                mechanism_type=MechanismType.LAPLACE)
            budget2 = budget_accountant.request_budget(
                mechanism_type=MechanismType.LAPLACE, weight=3)

        with budget_accountant.scope(weight=0.6):
            budget3 = budget_accountant.request_budget(
                mechanism_type=MechanismType.LAPLACE)
            budget4 = budget_accountant.request_budget(
                mechanism_type=MechanismType.LAPLACE, weight=4)

        budget_accountant.compute_budgets()

        self.assertEqual(budget1.eps, 0.4 * (1 / 4))
        self.assertEqual(budget2.eps, 0.4 * (3 / 4))
        self.assertEqual(budget3.eps, 0.6 * (1 / 5))
        self.assertEqual(budget4.eps, 0.6 * (4 / 5))
Exemplo n.º 2
0
    def test_budget_scopes_no_parentscope(self):
        budget_accountant = NaiveBudgetAccountant(total_epsilon=1,
                                                  total_delta=1e-6)

        # Allocated in the top-level scope with no weight specified
        budget1 = budget_accountant.request_budget(
            mechanism_type=MechanismType.LAPLACE)

        with budget_accountant.scope(weight=0.5):
            budget2 = budget_accountant.request_budget(
                mechanism_type=MechanismType.LAPLACE)

        budget_accountant.compute_budgets()

        self.assertEqual(budget1.eps, 1.0 / (1.0 + 0.5))
        self.assertEqual(budget2.eps, 0.5 / (1.0 + 0.5))