Ejemplo n.º 1
0
    def test_heip_e(self):
        # Calculate "by hand".
        arr = np.array([1, 2, 3, 1])
        h = shannon(arr, base=np.e)
        expected = (np.exp(h) - 1) / 3
        self.assertEqual(heip_e(arr), expected)

        # From Statistical Ecology: A Primer in Methods and Computing, page 94,
        # table 8.1.
        self.assertAlmostEqual(heip_e([500, 300, 200]), 0.90, places=2)
        self.assertAlmostEqual(heip_e([500, 299, 200, 1]), 0.61, places=2)
Ejemplo n.º 2
0
 def test_shannon(self):
     self.assertEqual(shannon(np.array([5])), 0)
     self.assertEqual(shannon(np.array([5, 5])), 1)
     self.assertEqual(shannon(np.array([1, 1, 1, 1, 0])), 2)