MCPcopy Create free account
hub / github.com/modAL-python/modAL / TestUtils

Class TestUtils

tests/core_tests.py:49–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48
49class TestUtils(unittest.TestCase):
50
51 def test_check_class_labels(self):
52 for n_labels in range(1, 10):
53 for n_learners in range(1, 10):
54 # 1. test fitted estimators
55 labels = np.random.randint(10, size=n_labels)
56 different_labels = np.random.randint(
57 10, 20, size=np.random.randint(1, 10))
58 learner_list_1 = [mock.MockEstimator(
59 classes_=labels) for _ in range(n_learners)]
60 learner_list_2 = [mock.MockEstimator(
61 classes_=different_labels) for _ in range(np.random.randint(1, 5))]
62 shuffled_learners = random.sample(
63 learner_list_1 + learner_list_2, len(learner_list_1 + learner_list_2))
64 self.assertTrue(
65 modAL.utils.validation.check_class_labels(*learner_list_1))
66 self.assertFalse(
67 modAL.utils.validation.check_class_labels(*shuffled_learners))
68
69 # 2. test unfitted estimators
70 unfitted_learner_list = [mock.MockEstimator(
71 classes_=labels) for _ in range(n_learners)]
72 idx = np.random.randint(0, n_learners)
73 unfitted_learner_list.insert(
74 idx, mock.MockEstimator(fitted=False))
75 self.assertRaises(
76 NotFittedError, modAL.utils.validation.check_class_labels, *unfitted_learner_list)
77
78 def test_check_class_proba(self):
79 for n_labels in range(2, 20):
80 # when all classes are known:
81 proba = np.random.rand(100, n_labels)
82 class_labels = list(range(n_labels))
83 np.testing.assert_almost_equal(
84 modAL.utils.check_class_proba(
85 proba, known_labels=class_labels, all_labels=class_labels),
86 proba
87 )
88 for unknown_idx in range(n_labels):
89 all_labels = list(range(n_labels))
90 known_labels = deepcopy(all_labels)
91 known_labels.remove(unknown_idx)
92 aug_proba = np.insert(
93 proba[:, known_labels], unknown_idx, np.zeros(len(proba)), axis=1)
94 np.testing.assert_almost_equal(
95 modAL.utils.check_class_proba(
96 proba[:, known_labels], known_labels=known_labels, all_labels=all_labels),
97 aug_proba
98 )
99
100 def test_linear_combination(self):
101
102 def dummy_function(X_in):
103 return np.ones(shape=(len(X_in), 1))
104
105 for n_samples in range(2, 10):
106 for n_features in range(1, 10):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…