def test_count_single_with_condition(self): data = np.array([0.1, -0.1, 0.1, 0.1] * 10) expected_value = np.count_nonzero(data >= 0) def condition(data): return data >= 0.0 self.set_seed() value = DiffPrivStatistics.count(data, self.epsilon, condition=condition) self.assertAlmostEqual(value, expected_value, self.decimal_places)
def test_count_multiple_with_condition(self): data = np.array([[0.1, -0.1, 0.1, 0.1] * 10] * 3) expected_values = np.count_nonzero(data >= 0, axis=1) def condition(data): return data >= 0.0 self.set_seed() value = DiffPrivStatistics.count( data, self.epsilon, condition=condition, axis=1 ) np.testing.assert_almost_equal(value, expected_values, self.decimal_places)
def test_count_multiple(self): data = np.array([[True, False, True, True] * 10] * 3) expected_values = np.count_nonzero(data, axis=1) self.set_seed() value = DiffPrivStatistics.count(data, self.epsilon, axis=1) np.testing.assert_almost_equal(value, expected_values, self.decimal_places)
def test_count_single(self): data = np.array([True, False, True, True] * 10) expected_value = np.count_nonzero(data) self.set_seed() value = DiffPrivStatistics.count(data, self.epsilon) self.assertAlmostEqual(value, expected_value, self.decimal_places)