Example #1
0
def test_exponential_func():
    n_classes = 2
    result1 = exponential_func(n_classes, np.array([0.2]))
    assert result1 < 0.0

    result2 = exponential_func(n_classes, np.array([0.8]))
    assert result2 > 0.0

    assert result2 > result1

    result3 = exponential_func(n_classes, np.array([1.0]))
    result4 = exponential_func(n_classes, np.array([0.9]))
    assert result3 > result4 > result2 > result1
Example #2
0
    def source_competence(self):
        """The source of competence C_src at the validation point :math:`\mathbf{x}_{k}` is a product of two factors:
        The absolute value of  the competence and the sign. The value of the source competence is inverse proportional
        to the normalized entropy of its supports vector.The sign of competence is simply determined by
        correct/incorrect classification of the instance :math:`\mathbf{x}_{k}`.

        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):
            supports = self.dsel_scores[:, clf_index, :]
            support_correct = supports[np.arange(self.n_samples),
                                       self.DSEL_target]

            C_src[:, clf_index] = exponential_func(self.n_classes,
                                                   support_correct)
        return C_src
Example #3
0
    def source_competence(self):
        """The source of competence C_src at the validation point xk is a product of two factors: The absolute value of
        the competence and the sign. The value of the source competence is inverse proportional
        to the normalized entropy of its supports vector.The sign of competence is simply determined by
        correct/incorrect classification of the instance xk.

        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):
            supports = self._get_scores_dsel(clf_index)
            support_correct = [
                supports[sample_idx, i]
                for sample_idx, i in enumerate(self.DSEL_target)
            ]
            support_correct = np.array(support_correct)
            C_src[:, clf_index] = exponential_func(self.n_classes,
                                                   support_correct)
        return C_src
Example #4
0
def test_exponential_func_two_class(supports_correct, expected):
    n_classes = 2
    result = exponential_func(n_classes, supports_correct)
    assert np.isclose(result, expected, atol=0.01).all()
Example #5
0
def test_exponential_func_multi_class_batch():
    supports_correct = np.array([0.33, 0.0, 1.0])
    expected = [-0.01, -1.0, 1.0]
    n_classes = 3
    result = exponential_func(n_classes, supports_correct)
    assert np.allclose(result, expected, atol=0.01)