| 405 | |
| 406 | |
| 407 | class TestDisagreements(unittest.TestCase): |
| 408 | |
| 409 | def test_vote_entropy(self): |
| 410 | for n_samples in range(1, 10): |
| 411 | for n_classes in range(1, 10): |
| 412 | for true_query_idx in range(n_samples): |
| 413 | # 1. fitted committee |
| 414 | vote_return = np.zeros( |
| 415 | shape=(n_samples, n_classes), dtype=np.int16) |
| 416 | vote_return[true_query_idx] = np.asarray( |
| 417 | range(n_classes), dtype=np.int16) |
| 418 | committee = mock.MockCommittee(classes_=np.asarray( |
| 419 | range(n_classes)), vote_return=vote_return) |
| 420 | vote_entr = modAL.disagreement.vote_entropy( |
| 421 | committee, np.random.rand(n_samples, n_classes) |
| 422 | ) |
| 423 | true_entropy = np.zeros(shape=(n_samples, )) |
| 424 | true_entropy[true_query_idx] = entropy( |
| 425 | np.ones(n_classes)/n_classes) |
| 426 | np.testing.assert_array_almost_equal( |
| 427 | vote_entr, true_entropy) |
| 428 | |
| 429 | # 2. unfitted committee |
| 430 | committee = mock.MockCommittee(fitted=False) |
| 431 | true_entropy = np.zeros(shape=(n_samples,)) |
| 432 | vote_entr = modAL.disagreement.vote_entropy( |
| 433 | committee, np.random.rand(n_samples, n_classes) |
| 434 | ) |
| 435 | np.testing.assert_almost_equal(vote_entr, true_entropy) |
| 436 | |
| 437 | def test_consensus_entropy(self): |
| 438 | for n_samples in range(1, 10): |
| 439 | for n_classes in range(2, 10): |
| 440 | for true_query_idx in range(n_samples): |
| 441 | # 1. fitted committee |
| 442 | proba = np.zeros(shape=(n_samples, n_classes)) |
| 443 | proba[:, 0] = 1.0 |
| 444 | proba[true_query_idx] = np.ones(n_classes)/n_classes |
| 445 | committee = mock.MockCommittee(predict_proba_return=proba) |
| 446 | consensus_entropy = modAL.disagreement.consensus_entropy( |
| 447 | committee, np.random.rand(n_samples, n_classes) |
| 448 | ) |
| 449 | true_entropy = np.zeros(shape=(n_samples,)) |
| 450 | true_entropy[true_query_idx] = entropy( |
| 451 | np.ones(n_classes) / n_classes) |
| 452 | np.testing.assert_array_almost_equal( |
| 453 | consensus_entropy, true_entropy) |
| 454 | |
| 455 | # 2. unfitted committee |
| 456 | committee = mock.MockCommittee(fitted=False) |
| 457 | true_entropy = np.zeros(shape=(n_samples,)) |
| 458 | consensus_entropy = modAL.disagreement.consensus_entropy( |
| 459 | committee, np.random.rand(n_samples, n_classes) |
| 460 | ) |
| 461 | np.testing.assert_almost_equal( |
| 462 | consensus_entropy, true_entropy) |
| 463 | |
| 464 | def test_KL_max_disagreement(self): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…