Пример #1
0
    def source_competence(self):
        """
        Calculates the source of competence using the randomized reference classifier (RRC) method.

        The source of competence C_src at the validation point xk calculated using the probabilistic model based on
        the supports obtained by the base classifier and randomized reference classifier (RRC) model.
        The probabilistic modeling of the classifier competence is calculated using the ccprmod function.

        Returns
        ----------
        C_src : array of shape = [n_samples, n_classifiers]
                The competence source for each base classifier at each data point.
        """
        c_src = np.zeros((self.n_samples, self.n_classifiers))

        for clf_index in range(self.n_classifiers):
            # Get supports for all samples in DSEL
            supports = self._get_scores_dsel(clf_index)
            c_src[:, clf_index] = ccprmod(supports, self.DSEL_target)

        return c_src
Пример #2
0
def test_ccprmod_one_support():
    supports = [[0.0, 0.0, 1.0], [0.0, 1.0, 0.0]]
    idx_correct_label = [2, 1]
    assert np.isclose(ccprmod(supports, idx_correct_label), 1.0, atol=0.01).all()
Пример #3
0
def test_ccprmod_zero_support():
    supports = [[0.0, 0.0, 1.0], [0.0, 1.0, 0.0], [0.0, 0.8, 0.2]]
    idx_correct_label = [0, 2, 0]
    assert np.isclose(ccprmod(supports, idx_correct_label), 0.0, atol=0.01).all()
Пример #4
0
def test_valid_ccprmod_beta(B):
    supports = [0.3, 0.6, 0.1]
    idx_correct_label = [1]

    with pytest.raises((ValueError, TypeError)):
        ccprmod(supports, idx_correct_label, B)
Пример #5
0
def test_ccprmod_return_value(supports, idx_correct_label, expected):
        value = ccprmod(supports, idx_correct_label)
        assert np.isclose(value, expected, atol=0.001).all()