From 6f60db348cc5b7cad8607d2c0825714cf23e5629 Mon Sep 17 00:00:00 2001 From: Naoise Holohan Date: Tue, 12 Sep 2023 13:03:43 +0100 Subject: [PATCH] Fixing histogram2d test --- tests/tools/test_histogram2d.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/tools/test_histogram2d.py b/tests/tools/test_histogram2d.py index bd4efcc..393d15b 100644 --- a/tests/tools/test_histogram2d.py +++ b/tests/tools/test_histogram2d.py @@ -3,7 +3,7 @@ from diffprivlib.accountant import BudgetAccountant from diffprivlib.tools.histograms import histogram2d -from diffprivlib.utils import PrivacyLeakWarning, BudgetError +from diffprivlib.utils import PrivacyLeakWarning, BudgetError, check_random_state class TestHistogram2d(TestCase): @@ -60,9 +60,11 @@ def test_different_result(self): self.assertTrue((hist != dp_hist).any()) def test_density(self): + rng = check_random_state(1) + x = np.array([1, 2, 3, 4, 5]) y = np.array([5, 7, 1, 5, 9]) - dp_hist, _, _ = histogram2d(x, y, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True) + dp_hist, _, _ = histogram2d(x, y, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True, random_state=rng) # print(dp_hist.sum())