예제 #1
0
def test_select_random_classifier():
    competences = np.random.rand(1, 100)
    expected = (competences > 0.25)
    probabilistic_test = BaseProbabilistic()
    probabilistic_test.n_classes_ = 4
    indices = probabilistic_test.select(competences)
    assert np.array_equal(indices, expected)
예제 #2
0
def test_select_threshold():
    competences = np.random.rand(1, 100)
    expected = (competences > 0.5)

    probabilistic_test = BaseProbabilistic()
    probabilistic_test.selection_threshold = 0.5
    indices = probabilistic_test.select(competences)
    assert np.array_equal(indices, expected)
예제 #3
0
def test_estimate_competence_ones():
    query = np.atleast_2d([1, 1])
    probabilistic_test = BaseProbabilistic(create_pool_classifiers())
    probabilistic_test.k_ = 7

    distances = distances_ex1[0, 0:3].reshape(1, -1)
    neighbors = np.array([[0, 2, 1]])
    probabilistic_test.C_src_ = np.ones((3, 3))
    competence = probabilistic_test.estimate_competence(
        query, neighbors, distances)
    assert (competence == 1.0).all()
예제 #4
0
def test_estimate_competence_ones(example_estimate_competence):
    distances = example_estimate_competence[3]
    query = np.atleast_2d([1, 1])
    probabilistic_test = BaseProbabilistic()
    probabilistic_test.k_ = 7

    distances = distances[0, 0:3].reshape(1, -1)
    neighbors = np.array([[0, 2, 1]])
    probabilistic_test.C_src_ = np.ones((3, 3))
    competence = probabilistic_test.estimate_competence(neighbors,
                                                        distances)
    assert (competence == 1.0).all()
예제 #5
0
def test_estimate_competence_zeros(example_estimate_competence):
    distances = example_estimate_competence[3]
    query = np.atleast_2d([1, 1])
    probabilistic_test = BaseProbabilistic()
    probabilistic_test.k_ = 7

    distances = distances[0, 0:3].reshape(1, -1)
    neighbors = np.array([[0, 2, 1]])
    probabilistic_test.C_src_ = np.zeros((3, 3))
    competence = probabilistic_test.estimate_competence(
        competence_region=neighbors,
        distances=distances)
    assert np.sum(competence) == 0.0
예제 #6
0
def test_estimate_competence_batch():
    n_samples = 10
    query = np.ones((n_samples, 2))
    probabilistic_test = BaseProbabilistic()
    probabilistic_test.k_ = 7
    distances = np.tile([0.5, 1.0, 2.0], (n_samples, 1))
    neighbors = np.tile([0, 1, 2], (n_samples, 1))

    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(
        competence_region=neighbors,
        distances=distances)
    assert np.allclose(competence, expected, atol=0.01)
예제 #7
0
def test_not_predict_proba(create_X_y):
    X, y = create_X_y

    clf1 = Perceptron()
    clf1.fit(X, y)
    with pytest.raises(ValueError):
        BaseProbabilistic([clf1, clf1]).fit(X, y)
예제 #8
0
def test_not_predict_proba():
    X = X_dsel_ex1
    y = y_dsel_ex1
    clf1 = Perceptron()
    clf1.fit(X, y)
    with pytest.raises(ValueError):
        BaseProbabilistic([clf1, clf1]).fit(X, y)
예제 #9
0
def test_potential_function():
    dists = np.array([1.0, 0.5, 2, 0.33])
    value = BaseProbabilistic.potential_func(dists)
    assert np.allclose(value, [0.3679, 0.7788, 0.0183, 0.8968], atol=0.001)
예제 #10
0
def test_potential_function_zeros():
    dists = np.zeros(10)
    value = BaseProbabilistic.potential_func(dists)
    assert np.array_equal(value, np.ones(10))
예제 #11
0
def test_select_all_zeros():
    competences = np.zeros(100)
    probabilistic_test = BaseProbabilistic()
    probabilistic_test.n_classes_ = 2
    selected_matrix = probabilistic_test.select(competences)
    assert selected_matrix.all()
예제 #12
0
def test_knne_not_allowed(create_X_y):
    X, y = create_X_y

    with pytest.raises(ValueError):
        BaseProbabilistic(knn_classifier='knne').fit(X, y)
예제 #13
0
def test_potential_function_batch():
    dists = np.tile([1.0, 0.5, 2, 0.33], (10, 1))
    value = BaseProbabilistic.potential_func(dists)
    expected = np.tile([0.3679, 0.7788, 0.0183, 0.8968], (10, 1))
    assert np.allclose(value, expected, atol=0.001)
예제 #14
0
def test_select_all_ones():
    competences = np.ones(100)
    probabilistic_test = BaseProbabilistic(create_pool_all_agree(1, 100))
    probabilistic_test.n_classes_ = 2
    selected_matrix = probabilistic_test.select(competences)
    assert selected_matrix.all()