How to use the pyriemann.utils.distance.distance function in pyriemann

To help you get started, we’ve selected a few pyriemann examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexandrebarachant / pyRiemann / tests / test_utils_distance.py View on Github external
def test_distance_generic_logeuclid():
    """Test logeuclid distance for generic function"""
    A = 2*np.eye(3)
    B = 2*np.eye(3)
    assert_equal(distance(A, B, metric='logeuclid'), distance_logeuclid(A, B))
github alexandrebarachant / pyRiemann / tests / test_utils_distance.py View on Github external
def test_distance_generic_logdet():
    """Test logdet distance for generic function"""
    A = 2*np.eye(3)
    B = 2*np.eye(3)
    assert_equal(distance(A, B, metric='logdet'), distance_logdet(A, B))
github alexandrebarachant / pyRiemann / pyriemann / stats.py View on Github external
def _score_ttest(self, X, y):
        """Get the score"""
        mdm = self.mdm.fit(X, y)
        covmeans = numpy.array(mdm.covmeans_)

        # estimates distances between means
        n_classes = len(covmeans)
        pairs = pairwise_distance(covmeans, metric=mdm.metric_dist)
        mean_dist = numpy.triu(pairs).sum()
        mean_dist /= (n_classes * (n_classes - 1)) / 2.0

        dist = 0
        for ix, classe in enumerate(mdm.classes_):
            di = (distance(
                X[y == classe], covmeans[ix], metric=mdm.metric_dist)
                  **2).mean()
            dist += (di / numpy.sum(y == classe))
        score = mean_dist / numpy.sqrt(dist)
        return score
github alexandrebarachant / pyRiemann / pyriemann / stats.py View on Github external
mdm = self.mdm.fit(X, y)
        covmeans = numpy.array(mdm.covmeans_)

        # estimates between classes variability
        n_classes = len(covmeans)
        between = 0
        for ix, classe in enumerate(mdm.classes_):
            di = distance(
                covmeans[ix], self.global_mean, metric=mdm.metric_dist)**2
            between += numpy.sum(y == classe) * di
        between /= (n_classes - 1)

        # estimates within class variability
        within = 0
        for ix, classe in enumerate(mdm.classes_):
            within += (distance(
                X[y == classe], covmeans[ix], metric=mdm.metric_dist)
                       **2).sum()
        within /= (len(y) - n_classes)

        score = between / within
        return score
github alexandrebarachant / pyRiemann / pyriemann / stats.py View on Github external
def _score_ftest(self, X, y):
        """Get the score"""
        mdm = self.mdm.fit(X, y)
        covmeans = numpy.array(mdm.covmeans_)

        # estimates between classes variability
        n_classes = len(covmeans)
        between = 0
        for ix, classe in enumerate(mdm.classes_):
            di = distance(
                covmeans[ix], self.global_mean, metric=mdm.metric_dist)**2
            between += numpy.sum(y == classe) * di
        between /= (n_classes - 1)

        # estimates within class variability
        within = 0
        for ix, classe in enumerate(mdm.classes_):
            within += (distance(
                X[y == classe], covmeans[ix], metric=mdm.metric_dist)
                       **2).sum()
        within /= (len(y) - n_classes)

        score = between / within
        return score
github alexandrebarachant / pyRiemann / pyriemann / classification.py View on Github external
def _predict_distances(self, covtest):
        """Helper to predict the distance. equivalent to transform."""
        Nc = len(self.covmeans_)

        if self.n_jobs == 1:
            dist = [distance(covtest, self.covmeans_[m], self.metric_dist)
                    for m in range(Nc)]
        else:
            dist = Parallel(n_jobs=self.n_jobs)(delayed(distance)(
                covtest, self.covmeans_[m], self.metric_dist)
                for m in range(Nc))

        dist = numpy.concatenate(dist, axis=1)
        return dist
github alexandrebarachant / pyRiemann / pyriemann / classification.py View on Github external
def _predict_distances(self, covtest):
        """Helper to predict the distance. equivalent to transform."""
        Nc = len(self.covmeans_)

        if self.n_jobs == 1:
            dist = [distance(covtest, self.covmeans_[m], self.metric_dist)
                    for m in range(Nc)]
        else:
            dist = Parallel(n_jobs=self.n_jobs)(delayed(distance)(
                covtest, self.covmeans_[m], self.metric_dist)
                for m in range(Nc))

        dist = numpy.concatenate(dist, axis=1)
        return dist