Esempio n. 1
0
def test_select_random_classifier():
    competences = np.random.rand(100)
    expected = np.where(competences > 0.25)[0]
    probabilistic_test = Probabilistic(create_pool_all_agree(1, 100))
    probabilistic_test.n_classes = 4
    indices = probabilistic_test.select(competences)
    assert np.array_equal(indices, expected)
Esempio n. 2
0
def test_not_predict_proba():
    X = X_dsel_ex1
    y = y_dsel_ex1
    clf1 = Perceptron()
    clf1.fit(X, y)
    with pytest.raises(ValueError):
        Probabilistic([clf1, clf1])
Esempio n. 3
0
def test_select_threshold():
    competences = np.random.rand(100)
    expected = np.where(competences > 0.5)[0]

    probabilistic_test = Probabilistic(create_pool_all_agree(1, 100))
    probabilistic_test.selection_threshold = 0.5
    indices = probabilistic_test.select(competences)
    assert np.array_equal(indices, expected)
Esempio n. 4
0
def test_estimate_competence_ones():
    query = np.atleast_2d([1, 1])
    probabilistic_test = Probabilistic(create_pool_classifiers())
    probabilistic_test.distances = distances_ex1[0, 0:3]
    probabilistic_test.neighbors = [0, 2, 1]
    probabilistic_test.DFP_mask = np.ones(probabilistic_test.n_classifiers)
    probabilistic_test.C_src = np.ones((3, 3))
    competence = probabilistic_test.estimate_competence(query)
    assert (competence == 1.0).all()
Esempio n. 5
0
def test_estimate_competence():

    query = np.atleast_2d([1, 1])
    probabilistic_test = Probabilistic(create_pool_classifiers())
    probabilistic_test.distances = [0.5, 1.0, 2.0]
    probabilistic_test.neighbors = [0, 1, 2]
    probabilistic_test.DFP_mask = np.ones(probabilistic_test.n_classifiers)

    probabilistic_test.C_src = np.array([[0.5, 0.2, 0.8], [1.0, 1.0, 1.0],
                                         [1.0, 0.6, 0.3]])

    competence = probabilistic_test.estimate_competence(query)
    assert np.allclose(competence, [0.665, 0.458, 0.855], atol=0.01)
Esempio n. 6
0
def test_estimate_competence_batch():
    n_samples = 10
    query = np.ones((n_samples, 2))
    probabilistic_test = Probabilistic(create_pool_classifiers())
    probabilistic_test.distances = np.tile([0.5, 1.0, 2.0], (n_samples, 1))
    probabilistic_test.neighbors = np.tile([0, 1, 2], (n_samples, 1))
    probabilistic_test.DFP_mask = np.ones(
        (n_samples, probabilistic_test.n_classifiers))

    probabilistic_test.C_src = np.array([[0.5, 0.2, 0.8], [1.0, 1.0, 1.0],
                                         [1.0, 0.6, 0.3]])
    expected = np.tile([0.665, 0.458, 0.855], (n_samples, 1))
    competence = probabilistic_test.estimate_competence(query)
    assert np.allclose(competence, expected, atol=0.01)
Esempio n. 7
0
def test_select_all_ones():
    competences = np.ones(100)
    probabilistic_test = Probabilistic(create_pool_all_agree(1, 100))
    probabilistic_test.n_classes = 2
    indices = probabilistic_test.select(competences)
    assert indices == list(range(100))
Esempio n. 8
0
def test_select_all_zeros():
    competences = np.zeros(100)
    probabilistic_test = Probabilistic(create_pool_all_agree(1, 100))
    probabilistic_test.n_classes = 2
    selected_matrix = probabilistic_test.select(competences)
    assert selected_matrix.all()