def test_values(self): # first bin maps the ±0.5 interval error, the second the 0 bins = _histogram_bins(2) ann = np.asarray([0, 1, 2, 3]) # A) identical detections map to the 0 error bin hist = _error_histogram(np.asarray([0, 1, 2, 3]), ann, bins) self.assertTrue(np.allclose(hist, [0, 4])) # bins maps the ±0.5, -0.25, 0, 0.25 interval errors bins = _histogram_bins(4) # B) identical detections map to the 0 error bin hist = _error_histogram(ann, ann, bins) self.assertTrue(np.allclose(hist, [0, 0, 4, 0])) # C) offbeat detections map to the ±0.5 error bin hist = _error_histogram(np.asarray([0.5, 1.5, 2.5, 3.5]), ann, bins) self.assertTrue(np.allclose(hist, [4, 0, 0, 0])) # D) smaller deviations mapping to the 0 and 0.125 error bins hist = _error_histogram(np.asarray([0.125, 0.875, 2.1, 3]), ann, bins) self.assertTrue(np.allclose(hist, [0, 0, 3, 1])) # E) default annotations and detections with 40 bins bins = _histogram_bins(40) hist = _error_histogram(DETECTIONS, ANNOTATIONS, bins) self.assertTrue( np.allclose(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 ]))
def test_values(self): # first bin maps the ±0.5 interval error, the second the 0 bins = _histogram_bins(2) ann = np.asarray([0, 1, 2, 3]) # A) identical detections map to the 0 error bin hist = _error_histogram(np.asarray([0, 1, 2, 3]), ann, bins) self.assertTrue(np.allclose(hist, [0, 4])) # bins maps the ±0.5, -0.25, 0, 0.25 interval errors bins = _histogram_bins(4) # B) identical detections map to the 0 error bin hist = _error_histogram(ann, ann, bins) self.assertTrue(np.allclose(hist, [0, 0, 4, 0])) # C) offbeat detections map to the ±0.5 error bin hist = _error_histogram(np.asarray([0.5, 1.5, 2.5, 3.5]), ann, bins) self.assertTrue(np.allclose(hist, [4, 0, 0, 0])) # D) smaller deviations mapping to the 0 and 0.125 error bins hist = _error_histogram(np.asarray([0.125, 0.875, 2.1, 3]), ann, bins) self.assertTrue(np.allclose(hist, [0, 0, 3, 1])) # E) default annotations and detections with 40 bins bins = _histogram_bins(40) hist = _error_histogram(DETECTIONS, ANNOTATIONS, bins) self.assertTrue(np.allclose(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]))
def test_values(self): # test some well defined situations bins = _histogram_bins(2) # the bins must be 0.5 wide and centered around 0 self.assertTrue(np.allclose(bins, [-0.75, -0.25, 0.25, 0.75])) bins = _histogram_bins(4) # the bins must be 0.25 wide and centered around 0 self.assertTrue(np.allclose(bins, [-0.625, -0.375, -0.125, 0.125, 0.375, 0.625]))
def test_values(self): # test some well defined situations bins = _histogram_bins(2) # the bins must be 0.5 wide and centered around 0 self.assertTrue(np.allclose(bins, [-0.75, -0.25, 0.25, 0.75])) bins = _histogram_bins(4) # the bins must be 0.25 wide and centered around 0 self.assertTrue( np.allclose(bins, [-0.625, -0.375, -0.125, 0.125, 0.375, 0.625]))
def test_errors(self): # bins must be even and greater or equal than 2 with self.assertRaises(ValueError): _histogram_bins(1) with self.assertRaises(ValueError): _histogram_bins(2.1) with self.assertRaises(ValueError): _histogram_bins(5)
def test_types(self): bins = _histogram_bins(4) hist = _error_histogram(DETECTIONS, ANNOTATIONS, bins) ig = _information_gain(hist) self.assertIsInstance(ig, float)
def test_types(self): bins = _histogram_bins(4) hist = _error_histogram(DETECTIONS, ANNOTATIONS, bins) self.assertIsInstance(hist, np.ndarray) self.assertTrue(hist.dtype == np.float)
def test_types(self): bins = _histogram_bins(40) self.assertIsInstance(bins, np.ndarray) self.assertTrue(bins.dtype == np.float)