Example #1
0
 def test_values(self):
     # information gain is np.log2(len(histogram)) - entropy(histogram)
     # histogram with zeros
     self.assertTrue(_information_gain([0, 0, 0]) == np.log2(3))
     # uniform histogram
     self.assertTrue(_information_gain([1, 1, 1]) == 0)
     # use the examples of the TestErrorHistogramHelperFunction test above
     # A)
     hist = [0, 4]
     self.assertTrue(_information_gain(hist) == np.log2(2))
     # B)
     hist = [0, 0, 4, 0]
     self.assertTrue(_information_gain(hist) == np.log2(4))
     # C)
     hist = [4, 0, 0, 0]
     self.assertTrue(_information_gain(hist) == np.log2(4))
     # D)
     hist = [0, 0, 3, 1]
     self.assertTrue(np.allclose(_information_gain(hist), 1.18872187554))
     # E)
     hist = [
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 8, 0,
         0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
     ]
     self.assertTrue(_information_gain(hist) == 4.4)
Example #2
0
 def test_values(self):
     # information gain is np.log2(len(histogram)) - entropy(histogram)
     # histogram with zeros
     self.assertTrue(_information_gain([0, 0, 0]) == np.log2(3))
     # uniform histogram
     self.assertTrue(_information_gain([1, 1, 1]) == 0)
     # use the examples of the TestErrorHistogramHelperFunction test above
     # A)
     hist = [0, 4]
     self.assertTrue(_information_gain(hist) == np.log2(2))
     # B)
     hist = [0, 0, 4, 0]
     self.assertTrue(_information_gain(hist) == np.log2(4))
     # C)
     hist = [4, 0, 0, 0]
     self.assertTrue(_information_gain(hist) == np.log2(4))
     # D)
     hist = [0, 0, 3, 1]
     self.assertTrue(np.allclose(_information_gain(hist), 1.18872187554))
     # E)
     hist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
             8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
     self.assertTrue(_information_gain(hist) == 4.4)
Example #3
0
 def test_types(self):
     bins = _histogram_bins(4)
     hist = _error_histogram(DETECTIONS, ANNOTATIONS, bins)
     ig = _information_gain(hist)
     self.assertIsInstance(ig, float)
Example #4
0
 def test_types(self):
     bins = _histogram_bins(4)
     hist = _error_histogram(DETECTIONS, ANNOTATIONS, bins)
     ig = _information_gain(hist)
     self.assertIsInstance(ig, float)