Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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())
def setup_method(self, method):
if method.__name__ .endswith("prob"):
global_seed(314159)
self.mech = GeometricTruncated()
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())
def setup_method(self, method):
if method.__name__ .endswith("prob"):
global_seed(314159)
self.mech = LaplaceBoundedNoise()
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)
def setup_method(self, method):
if method.__name__ .endswith("prob"):
global_seed(314159)
self.mech = Geometric()
def setup_method(self, method):
if method.__name__ .endswith("prob"):
global_seed(314159)
self.mech = LaplaceBoundedDomain()
def setup_method(self, method):
if method.__name__ .endswith("prob"):
global_seed(314159)
self.mech = GeometricFolded()
def setup_method(self, method):
if method.__name__ .endswith("prob"):
global_seed(314159)
self.mech = Exponential()
def setup_method(self, method):
if method.__name__ .endswith("prob"):
global_seed(314159)
self.mech = ExponentialHierarchical()