示例#1
0
 def rowUncertainty(self):
     """Returns the uncertainty (Shannon's entropy) for each row in profile
     
     Entropy is returned in BITS (not in NATS).
     """
     if not self.Data:
         return array([])
     try:
         return row_uncertainty(self.Data)
     except ValueError:
         raise ProfileError,\
         "Profile has to be two dimensional to calculate rowUncertainty"
示例#2
0
 def test_row_uncertainty(self):
     """row_uncertainty: should handle pos/neg/zero/empty arrays as expected
     """
     #normal valid array
     b = transpose(array([[.25,.2,.45,.25,1],[.25,.2,.45,0,0],\
         [.25,.3,.05,.75,0],[.25,.3,.05,0,0]]))
     self.assertFloatEqual(row_uncertainty(b),[2,1.97,1.47,0.81,0],1e-3)
     #one-dimensional array
     self.assertRaises(ValueError, row_uncertainty,\
         array([.25,.25,.25,.25]))
     #zeros
     self.assertEqual(row_uncertainty(array([[0,0]])),array([0]))
     #empty 2D array
     self.assertEqual(row_uncertainty(array([[]])),array([0]))
     self.assertEqual(row_uncertainty(array([[],[]])),array([0,0]))
     #negative number
     self.assertNotEqual(row_uncertainty(array([[-2]])),\
         row_uncertainty(array([[-2]])))