| 1530 | |
| 1531 | |
| 1532 | class TestCommitteeRegressor(unittest.TestCase): |
| 1533 | |
| 1534 | def test_predict(self): |
| 1535 | for n_members in range(1, 10): |
| 1536 | for n_instances in range(1, 100): |
| 1537 | vote = np.random.rand(n_instances, n_members) |
| 1538 | # assembling the Committee |
| 1539 | learner_list = [mock.MockActiveLearner(predict_return=vote[:, member_idx]) |
| 1540 | for member_idx in range(n_members)] |
| 1541 | committee = modAL.models.learners.CommitteeRegressor( |
| 1542 | learner_list=learner_list) |
| 1543 | np.testing.assert_array_almost_equal( |
| 1544 | committee.predict(np.random.rand( |
| 1545 | n_instances).reshape(-1, 1), return_std=False), |
| 1546 | np.mean(vote, axis=1) |
| 1547 | ) |
| 1548 | np.testing.assert_array_almost_equal( |
| 1549 | committee.predict(np.random.rand( |
| 1550 | n_instances).reshape(-1, 1), return_std=True), |
| 1551 | (np.mean(vote, axis=1), np.std(vote, axis=1)) |
| 1552 | ) |
| 1553 | |
| 1554 | def test_vote(self): |
| 1555 | for n_members in range(1, 10): |
| 1556 | for n_instances in range(1, 100): |
| 1557 | vote_output = np.random.rand(n_instances, n_members) |
| 1558 | # assembling the Committee |
| 1559 | learner_list = [mock.MockActiveLearner(predict_return=vote_output[:, member_idx]) |
| 1560 | for member_idx in range(n_members)] |
| 1561 | committee = modAL.models.learners.CommitteeRegressor( |
| 1562 | learner_list=learner_list) |
| 1563 | np.testing.assert_array_almost_equal( |
| 1564 | committee.vote(np.random.rand(n_instances).reshape(-1, 1)), |
| 1565 | vote_output |
| 1566 | ) |
| 1567 | |
| 1568 | def test_on_transformed(self): |
| 1569 | n_samples = 10 |
| 1570 | n_features = 5 |
| 1571 | query_strategies = [ |
| 1572 | # TODO remove, added just to make sure on_transformed doesn't break anything |
| 1573 | # but it has no influence on this strategy, nothing special tested here |
| 1574 | mock.MockFunction(return_val=[np.random.randint(0, n_samples)]) |
| 1575 | |
| 1576 | # add further strategies which work with instance representations |
| 1577 | # no further ones as of 25.09.2020 |
| 1578 | ] |
| 1579 | X_pool = np.random.rand(n_samples, n_features) |
| 1580 | |
| 1581 | # use pandas data frame as X_pool, which will be transformed back to numpy with sklearn pipeline |
| 1582 | X_pool = pd.DataFrame(X_pool) |
| 1583 | |
| 1584 | y_pool = np.random.rand(n_samples) |
| 1585 | train_idx = np.random.choice(range(n_samples), size=2, replace=False) |
| 1586 | |
| 1587 | learner_list = [modAL.models.learners.ActiveLearner( |
| 1588 | estimator=make_pipeline( |
| 1589 | FunctionTransformer(func=pd.DataFrame.to_numpy), |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…