def test_labels_frequency(self): annotations = [[1, 1, 2], [-1, 1, 2]] nclasses = 4 expected_result = [0., 0.6, 0.4, 0.0] result = voting.labels_frequency(annotations, nclasses) #self.assertAlmostEqual(expected_result, list(result)) #AlmostEqual not working on np.arrays but lists assert_array_almost_equal(expected_result, result) #Probably better
def test_label_frequency(self): annotations = [[1, 1, 2], [-1, 1, 2]] nclasses = 4 expected = np.array([0., 0.6, 0.4, 0.]) result = voting.labels_frequency(annotations, nclasses) assert_array_almost_equal(expected, result, 2)
def test_label_frequency(self): annotations = [[1, 1, 2], [-1, 1, 2]] nclasses = 4 expected = np.array([ 0. , 0.6, 0.4, 0. ]) result = voting.labels_frequency(annotations, nclasses) assert_array_almost_equal(expected, result, 2)
def test_labels_frequency(self): annotations = [[1, 2, MV, MV], [MV, MV, 3, 3], [MV, 1, 3, 1], [MV, MV, MV, MV]] nclasses = 5 expected = np.array([0., 3., 1., 3., 0.]) / 7. result = voting.labels_frequency(annotations, nclasses) np.testing.assert_almost_equal(result, expected)
def test_labels_frequency(): matrix = [ [1, 2, 2, -1], [2, 2, 2, 2], [1, 1, 3, 3], [1, 3, 3, 2], [-1, 2, 3, 1], [-1, -1, -1, 3], ] result = voting.labels_frequency(matrix, 4) assert np.all([res != None for res in result]) assert len(result) == 4 assert np.all( voting.labels_frequency([[-1, -1, -1, -1], [-1, -1, -1, -1]], 4) == np.zeros(4)) assert np.all([i >= 0 and i <= 1 for i in result]) assert isclose(np.sum(result), 1) or isclose( np.sum(result), 0, abs_tol=1e-12)
def test_labels_frequency(self): annotations = [ [ 1, 2, MV, MV], [MV, MV, 3, 3], [MV, 1, 3, 1], [MV, MV, MV, MV] ] nclasses = 5 expected = np.array([0., 3., 1., 3., 0.]) / 7. result = voting.labels_frequency(annotations, nclasses) np.testing.assert_almost_equal(result, expected)
def test_labels_freq(self): annotations=[[1, 1, 2], [-1, 1, 2]] nclasses=4 #annotations = [ # [1, 2, MV, MV], # [MV, MV, 3, 3], # [MV, 1, 3, 1], # [MV, MV, MV, MV], #] #nclasses = 5 #expected = [0, 3, 1, 3, 0] expected=[ 0. , 0.6, 0.4, 0. ] result = voting.labels_frequency(annotations, nclasses) self.assertAlmostEqual(result, expected,5)
def test_labels_freq(self): annotations = [[1, 1, 2], [-1, 1, 2]] nclasses = 4 #annotations = [ # [1, 2, MV, MV], # [MV, MV, 3, 3], # [MV, 1, 3, 1], # [MV, MV, MV, MV], #] #nclasses = 5 #expected = [0, 3, 1, 3, 0] expected = [0., 0.6, 0.4, 0.] result = voting.labels_frequency(annotations, nclasses) self.assertAlmostEqual(result, expected, 5)
def test_labels_frequency(self): result = voting.labels_frequency([[1, 1, 2], [-1, 1, 2]], 4) expected = np.asarray([0., 0.6, 0.4, 0.]) assert_array_almost_equal(result, expected)
def test_exception_all_missing(self): with self.assertRaises(PyannoValueError): result = voting.labels_frequency([[MV, MV, MV], [MV, MV, MV]], 4)
def test_labels_frequency(self): result = voting.labels_frequency([[1, 1, 2], [-1, 1, 2]], 4) expected = np.asarray([ 0. , 0.6, 0.4, 0. ]) assert_array_almost_equal(result, expected)
def test_exception_empty_list(self): with self.assertRaises(PyannoValueError): result = voting.labels_frequency([], 4)
def test_different_missing_value(self): annotations = np.array([[1, 1, 2], [MV, 1, 2]]) expected = [0.0, 0.6, 0.4, 0.0] result = voting.labels_frequency(annotations, 4, MV) print(result) np.testing.assert_array_almost_equal(expected, result)
def test_different_missing_value(self): annotations = np.array([[1, 1, 2], [MV, 1, 2]]) expected = [0., 0.6, 0.4, 0.] result = voting.labels_frequency(annotations, 4, MV) print(result) np.testing.assert_array_almost_equal(expected, result)