Add check to prevent small values of delta (#18)
* Add check to prevent small values of delta * Move check to discrete prv * Fix merge conflict Co-authored-by: Lukas Wutschitz <lukas.wutschitz@microsoft.com>
This commit is contained in:
Родитель
31dc86948a
Коммит
f4690b8956
|
@ -19,6 +19,10 @@ class DiscretePrivacyRandomVariable:
|
|||
return len(self.pmf)
|
||||
|
||||
def compute_epsilon(self, delta: float, delta_error: float, epsilon_error: float) -> Tuple[float, float, float]:
|
||||
if np.finfo(np.longdouble).eps*len(self.domain) > delta - delta_error:
|
||||
raise ValueError("Floating point errors will dominate for such small values of delta. "
|
||||
"Increase delta or reduce domain size.")
|
||||
|
||||
t = self.domain.ts()
|
||||
p = self.pmf
|
||||
d1 = np.flip(np.flip(p).cumsum())
|
||||
|
|
|
@ -31,6 +31,17 @@ class TestAccountant:
|
|||
assert delta_upper == pytest.approx(delta_exact, rel=1e-3)
|
||||
assert delta_lower == pytest.approx(delta_exact, rel=1e-3)
|
||||
|
||||
def test_throw_error_small_delta(self):
|
||||
with pytest.raises(ValueError):
|
||||
accountant = Accountant(
|
||||
noise_multiplier=4,
|
||||
sampling_probability=0.00038,
|
||||
delta=1.13e-18,
|
||||
eps_error=0.01,
|
||||
max_compositions=10000
|
||||
)
|
||||
accountant.compute_epsilon(1000)
|
||||
|
||||
def test_invariance_max_compositions(self):
|
||||
noise_multiplier = 0.9
|
||||
sampling_probability = 256/100000
|
||||
|
|
Загрузка…
Ссылка в новой задаче