Exemplo n.º 1
0
 def test_shannon(self):
     """shannon should match hand-calculated values"""
     c = array([5])
     self.assertFloatEqual(shannon(c), 0)
     c = array([5,5])
     self.assertFloatEqual(shannon(c), 1)
     c = array([1,1,1,1,0])
     self.assertEqual(shannon(c), 2)
Exemplo n.º 2
0
 def test_heip_e(self):
     """heip e should match hand-calculated value"""
     c = array([1,2,3,1])
     h = shannon(c, base=e)
     expected = exp(h-1)/3
     self.assertEqual(heip_e(c), expected)