From 954a9834315313474501c0c83a2869dc527dbe34 Mon Sep 17 00:00:00 2001 From: Solosneros <24623119+Solosneros@users.noreply.github.com> Date: Fri, 6 Oct 2023 07:15:33 +0300 Subject: [PATCH 1/2] fix: determine points for mean computation based on inputs --- .../abstract_privacy_random_variable.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/prv_accountant/privacy_random_variables/abstract_privacy_random_variable.py b/prv_accountant/privacy_random_variables/abstract_privacy_random_variable.py index c64f503..90cf6b0 100644 --- a/prv_accountant/privacy_random_variables/abstract_privacy_random_variable.py +++ b/prv_accountant/privacy_random_variables/abstract_privacy_random_variable.py @@ -49,7 +49,11 @@ def __init__(self, prv, t_min: float, t_max: float) -> None: self.remaining_mass = self.prv.cdf(t_max) - self.prv.cdf(t_min) def mean(self) -> float: - points = [self.t_min, -1e-1, -1e-2, -1e-3, -1e-4, -1e-5, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, self.t_max] + # determine points based on t_min and t_max + lower_exponent = int(np.log10(np.abs(self.t_min))) + upper_exponent = int(np.log10(self.t_max)) + points = np.concatenate([[self.t_min], -np.logspace(start=lower_exponent, stop=-5, num=10), [0], + np.logspace(start=upper_exponent, stop=-5, num=10)[::-1], [self.t_max]]) m = 0.0 for L, R in zip(points[:-1], points[1:]): I, err = integrate.quad(self.cdf, L, R, limit=500) From c36388bf44487824e43dea4b4ce51de42495b804 Mon Sep 17 00:00:00 2001 From: Solosneros <24623119+Solosneros@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:39:55 +0300 Subject: [PATCH 2/2] style: create upper log space simpler --- .../abstract_privacy_random_variable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prv_accountant/privacy_random_variables/abstract_privacy_random_variable.py b/prv_accountant/privacy_random_variables/abstract_privacy_random_variable.py index 90cf6b0..7614977 100644 --- a/prv_accountant/privacy_random_variables/abstract_privacy_random_variable.py +++ b/prv_accountant/privacy_random_variables/abstract_privacy_random_variable.py @@ -53,7 +53,7 @@ def mean(self) -> float: lower_exponent = int(np.log10(np.abs(self.t_min))) upper_exponent = int(np.log10(self.t_max)) points = np.concatenate([[self.t_min], -np.logspace(start=lower_exponent, stop=-5, num=10), [0], - np.logspace(start=upper_exponent, stop=-5, num=10)[::-1], [self.t_max]]) + np.logspace(start=-5, stop=upper_exponent, num=10), [self.t_max]]) m = 0.0 for L, R in zip(points[:-1], points[1:]): I, err = integrate.quad(self.cdf, L, R, limit=500)