def test_zero(self): x = np.zeros((2, 3)) s1 = hoyer_sparseness(x) self.assertEqual(s1, 1.)
def test_is_0_on_flat(self): x = np.ones((1, 4)) self.assertAlmostEqual(hoyer_sparseness(x), 0.)
def test_is_1_on_spike(self): x = np.zeros((1, 4)) x[0, 2] = 10. self.assertEqual(hoyer_sparseness(x), 1.)
def test_is_in_0_1(self): x = np.random.random((5, 7)) s = hoyer_sparseness(x) assert(np.all(0 <= s <= 1))
def test_axis(self): x = np.array([[1, 1], [0, 0]]) s1 = hoyer_sparseness(x, axis=0) self.assertEqual(s1, 1.)
def test_is_in_0_1(self): x = np.random.random((5, 7)) s = hoyer_sparseness(x) assert (np.all(0 <= s <= 1))