| 566 | |
| 567 | |
| 568 | class TestUncertainties(unittest.TestCase): |
| 569 | |
| 570 | def test_classifier_uncertainty(self): |
| 571 | test_cases = (Test(p * np.ones(shape=(k, l)), (1 - p) * np.ones(shape=(k, ))) |
| 572 | for k in range(1, 100) for l in range(1, 10) for p in np.linspace(0, 1, 11)) |
| 573 | for case in test_cases: |
| 574 | # testing _proba_uncertainty |
| 575 | np.testing.assert_almost_equal( |
| 576 | modAL.uncertainty._proba_uncertainty(case.input), |
| 577 | case.output |
| 578 | ) |
| 579 | |
| 580 | # fitted estimator |
| 581 | fitted_estimator = mock.MockEstimator( |
| 582 | predict_proba_return=case.input) |
| 583 | np.testing.assert_almost_equal( |
| 584 | modAL.uncertainty.classifier_uncertainty( |
| 585 | fitted_estimator, np.random.rand(10)), |
| 586 | case.output |
| 587 | ) |
| 588 | |
| 589 | # not fitted estimator |
| 590 | not_fitted_estimator = mock.MockEstimator(fitted=False) |
| 591 | np.testing.assert_almost_equal( |
| 592 | modAL.uncertainty.classifier_uncertainty( |
| 593 | not_fitted_estimator, case.input), |
| 594 | np.ones(shape=(len(case.output))) |
| 595 | ) |
| 596 | |
| 597 | def test_classifier_margin(self): |
| 598 | test_cases_1 = (Test(p * np.ones(shape=(k, l)), np.zeros(shape=(k,))) |
| 599 | for k in range(1, 100) for l in range(1, 10) for p in np.linspace(0, 1, 11)) |
| 600 | test_cases_2 = (Test(p * np.tile(np.asarray(range(k))+1.0, l).reshape(l, k), |
| 601 | p * np.ones(shape=(l, ))*int(k != 1)) |
| 602 | for k in range(1, 10) for l in range(1, 100) for p in np.linspace(0, 1, 11)) |
| 603 | for case in chain(test_cases_1, test_cases_2): |
| 604 | # _proba_margin |
| 605 | np.testing.assert_almost_equal( |
| 606 | modAL.uncertainty._proba_margin(case.input), |
| 607 | case.output |
| 608 | ) |
| 609 | |
| 610 | # fitted estimator |
| 611 | fitted_estimator = mock.MockEstimator( |
| 612 | predict_proba_return=case.input) |
| 613 | np.testing.assert_almost_equal( |
| 614 | modAL.uncertainty.classifier_margin( |
| 615 | fitted_estimator, np.random.rand(10)), |
| 616 | case.output |
| 617 | ) |
| 618 | |
| 619 | # not fitted estimator |
| 620 | not_fitted_estimator = mock.MockEstimator(fitted=False) |
| 621 | np.testing.assert_almost_equal( |
| 622 | modAL.uncertainty.classifier_margin( |
| 623 | not_fitted_estimator, case.input), |
| 624 | np.zeros(shape=(len(case.output))) |
| 625 | ) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…