How to use the diffprivlib.utils.global_seed function in diffprivlib

To help you get started, we’ve selected a few diffprivlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / differential-privacy-library / tests / models / test_KMeans.py View on Github external
def test_simple(self):
        global_seed(3141592653)
        clf = KMeans(5, [(0, 1)], 3)

        X = np.zeros(1000) + 0.1
        X[:666] = 0.5
        X[:333] = 0.9
        X = X.reshape(-1, 1)

        clf.fit(X)
        centers = clf.cluster_centers_

        self.assertTrue(np.isclose(centers, 0.1, atol=0.05).any())
        self.assertTrue(np.isclose(centers, 0.5, atol=0.05).any())
        self.assertTrue(np.isclose(centers, 0.9, atol=0.05).any())
github IBM / differential-privacy-library / tests / mechanisms / test_GeometricTruncated.py View on Github external
def setup_method(self, method):
        if method.__name__ .endswith("prob"):
            global_seed(314159)

        self.mech = GeometricTruncated()
github IBM / differential-privacy-library / tests / tools / test_histogram.py View on Github external
def test_different_result(self):
        global_seed(3141592653)
        a = np.array([1, 2, 3, 4, 5])
        hist, _ = np.histogram(a, bins=3, range=(0, 10))
        dp_hist, _ = histogram(a, epsilon=0.1, bins=3, range=(0, 10))

        # print("Non-private histogram: %s" % hist)
        # print("Private histogram: %s" % dp_hist)
        self.assertTrue((hist != dp_hist).any())
github IBM / differential-privacy-library / tests / mechanisms / test_LaplaceBoundedNoise.py View on Github external
def setup_method(self, method):
        if method.__name__ .endswith("prob"):
            global_seed(314159)

        self.mech = LaplaceBoundedNoise()
github IBM / differential-privacy-library / tests / tools / test_histogramdd.py View on Github external
def test_density_2d(self):
        global_seed(3141592653)
        a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]).T
        dp_hist, _ = histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True)

        # print(dp_hist.sum())

        self.assertAlmostEqual(dp_hist.sum(), 1.0 * (3 / 10) ** 2)
github IBM / differential-privacy-library / tests / mechanisms / test_Geometric.py View on Github external
def setup_method(self, method):
        if method.__name__ .endswith("prob"):
            global_seed(314159)

        self.mech = Geometric()
github IBM / differential-privacy-library / tests / mechanisms / test_LaplaceBoundedDomain.py View on Github external
def setup_method(self, method):
        if method.__name__ .endswith("prob"):
            global_seed(314159)

        self.mech = LaplaceBoundedDomain()
github IBM / differential-privacy-library / tests / mechanisms / test_GeometricFolded.py View on Github external
def setup_method(self, method):
        if method.__name__ .endswith("prob"):
            global_seed(314159)

        self.mech = GeometricFolded()
github IBM / differential-privacy-library / tests / mechanisms / test_Exponential.py View on Github external
def setup_method(self, method):
        if method.__name__ .endswith("prob"):
            global_seed(314159)

        self.mech = Exponential()
github IBM / differential-privacy-library / tests / mechanisms / test_ExponentialHierarchical.py View on Github external
def setup_method(self, method):
        if method.__name__ .endswith("prob"):
            global_seed(314159)

        self.mech = ExponentialHierarchical()