Giter Site home page Giter Site logo

pyriemann / pyriemann Goto Github PK

View Code? Open in Web Editor NEW
606.0 32.0 164.0 1.31 MB

Machine learning for multivariate data through the Riemannian geometry of positive definite matrices in Python

Home Page: https://pyriemann.readthedocs.io

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
eeg brain-computer-interface python machine-learning riemannian-geometry statistics signal-processing time-series covariance-estimation covariance-matrix

pyriemann's Introduction

pyRiemann

Code PythonVersion PyPI version Build Status codecov Documentation Status DOI Downloads

pyRiemann is a Python machine learning package based on scikit-learn API. It provides a high-level interface for processing and classification of real (resp. complex)-valued multivariate data through the Riemannian geometry of symmetric (resp. Hermitian) positive definite (SPD) (resp. HPD) matrices.

pyRiemann aims at being a generic package for multivariate data analysis but has been designed around biosignals (like EEG, MEG or EMG) manipulation applied to brain-computer interface (BCI), estimating covariance matrices from multichannel time series, and classifying them using the Riemannian geometry of SPD matrices [1].

For BCI applications, studied paradigms are motor imagery [2] [3], event-related potentials (ERP) [4] and steady-state visually evoked potentials (SSVEP) [5]. Using extended labels, API allows transfer learning between sessions or subjects [6].

This code is BSD-licensed (3 clause).

Documentation

The documentation is available on http://pyriemann.readthedocs.io/en/latest/

Installation

Using PyPI

pip install pyriemann

or using pip+git for the latest version of the code:

pip install git+https://github.com/pyRiemann/pyRiemann

Using conda

The package is distributed via conda-forge. You could install it in your working environment, with the following command:

conda install -c conda-forge pyriemann

From sources

For the latest version, you can install the package from the sources using pip:

pip install .

or in editable mode to be able to modify the sources:

pip install -e .

How to use

Most of the functions mimic the scikit-learn API, and therefore can be directly used with sklearn. For example, for cross-validation classification of EEG signal using the MDM algorithm described in [2], it is easy as:

import pyriemann
from sklearn.model_selection import cross_val_score

# load your data
X = ... # EEG data, in format n_epochs x n_channels x n_times
y = ... # labels

# estimate covariance matrices
cov = pyriemann.estimation.Covariances().fit_transform(X)

# cross validation
mdm = pyriemann.classification.MDM()

accuracy = cross_val_score(mdm, cov, y)

print(accuracy.mean())

You can also pipeline methods using sklearn pipeline framework. For example, to classify EEG signal using a SVM classifier in the tangent space, described in [3]:

from pyriemann.estimation import Covariances
from pyriemann.tangentspace import TangentSpace

from sklearn.pipeline import make_pipeline
from sklearn.svm import SVC
from sklearn.model_selection import cross_val_score

# load your data
X = ... # EEG data, in format n_epochs x n_channels x n_times
y = ... # labels

# build your pipeline
covest = Covariances()
ts = TangentSpace()
svc = SVC(kernel='linear')
clf = make_pipeline(covest, ts, svc)

# cross validation
accuracy = cross_val_score(clf, X, y)

print(accuracy.mean())

Check out the example folder for more examples.

Contribution Guidelines

The package aims at adopting the scikit-learn and MNE-Python conventions as much as possible. See their contribution guidelines before contributing to the repository.

Testing

If you make a modification, run the test suite before submitting a pull request

pytest

How to cite

@software{pyriemann,
  author       = {Alexandre Barachant and
                  Quentin Barthélemy and
                  Jean-Rémi King and
                  Alexandre Gramfort and
                  Sylvain Chevallier and
                  Pedro L. C. Rodrigues and
                  Emanuele Olivetti and
                  Vladislav Goncharenko and
                  Gabriel Wagner vom Berg and
                  Ghiles Reguig and
                  Arthur Lebeurrier and
                  Erik Bjäreholt and
                  Maria Sayu Yamamoto and
                  Pierre Clisson and
                  Marie-Constance Corsi},
  title        = {pyRiemann/pyRiemann: v0.5},
  month        = june,
  year         = 2023,
  publisher    = {Zenodo},
  version      = {v0.5},
  doi          = {10.5281/zenodo.8059038},
  url          = {https://doi.org/10.5281/zenodo.8059038}
}

References

[1] M. Congedo, A. Barachant and R. Bhatia, "Riemannian geometry for EEG-based brain-computer interfaces; a primer and a review". Brain-Computer Interfaces, 4.3, pp. 155-174, 2017. link

[2] A. Barachant, S. Bonnet, M. Congedo and C. Jutten, "Multiclass Brain-Computer Interface Classification by Riemannian Geometry". IEEE Transactions on Biomedical Engineering, vol. 59, no. 4, pp. 920-928, 2012. link

[3] A. Barachant, S. Bonnet, M. Congedo and C. Jutten, "Classification of covariance matrices using a Riemannian-based kernel for BCI applications". Neurocomputing, 112, pp. 172-178, 2013. link

[4] A. Barachant and M. Congedo, "A Plug&Play P300 BCI Using Information Geometry". Research report, 2014. link

[5] EK. Kalunga, S. Chevallier, Q. Barthélemy, K. Djouani, E. Monacelli and Y. Hamam, "Online SSVEP-based BCI using Riemannian geometry". Neurocomputing, 191, pp. 55-68, 2014. link

[6] PLC. Rodrigues, C. Jutten and M. Congedo, "Riemannian Procrustes analysis: transfer learning for brain-computer interfaces". IEEE Transactions on Biomedical Engineering, vol. 66, no. 8, pp. 2390-2401, 2018. link

pyriemann's People

Contributors

agramfort avatar alexandrebarachant avatar ammarmian avatar apmellot avatar artim436 avatar brentgaisford avatar brunaafl avatar carraraig avatar computerscienceiscool avatar davestanley avatar emanuele avatar erikbjare avatar gabelstein avatar gcattan avatar ghilesreguig avatar hoechenberger avatar jliersch avatar jona-sassenhagen avatar kingjr avatar maxdolle avatar mccorsi avatar mesca avatar mhurte avatar msyamamoto avatar musicinmybrain avatar plcrodrigues avatar qbarthelemy avatar stevenmortier avatar stonebig avatar v-goncharenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyriemann's Issues

Q: regularize cospcovariances

Hey Alex!

Is there a way to easily regularize `CospCovariances'?

I'm trying to do

clf = make_pipeline(
    CospCovariances(fmin=4., fmax=45, fs=500.),
    SlidingEstimator(
        make_pipeline(TangentSpace(), SVC(kernel='linear'))
)

but get the usual non positive definite error

Thanks!

Kernel Matrix Representation

From this paper

Wang, Lei, et al. "Beyond covariance: Feature representation with nonlinear kernel matrices." Proceedings of the IEEE International Conference on Computer Vision. 2015.

we can replace covariance by a kernel matrix. In our case, we could apply a kernel function between any pair of channels to build the kernel matrix.

This could be an interesting functionality to implement. We could rely on scikit-learn kernel functions

This could be done as a stand-alone Transformer (i.e. KernelMatrixRepresentation) or by extending the parameter estimator of the covariance estimation.

The later solution is easier, just extending the dict in _check_est from utils.covariance with what the sklearn.metrics.pairwise.kernel_metrics returns. However, we must add a mechanism to pass parameters to the estimator (which is not possible currently)

This is an easy one. Any Help is welcome

Float numbers

I used to get deprecation errors because a lot of pyriemmann return floats.
Updating my packages results in
TypeError: 'float' object cannot be interpreted as an integer
Was the package developed in python 2? Should I replace all division with // ?

some places are
pyriemann/utils/tangentspace.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
T = numpy.empty((Nt, Ne * (Ne + 1) / 2))

pyriemann/utils/ajd.py", line 159, in ajd_pham
tmp2 = (tmp*g12 - g21)/np.max(omega - 1, 1e-9)

Q: projecting single time point on tangent space?

Hi,

I'm trying to play with your code.

I was wondering whether it would be in principle possible to project a single time point (Nchan x 1) on the tangent space. I was thinking of fitting TangentSpace on the complete epochs, but then assess a series of svm on each time point separately in the tangent space. Although I'm not sure this makes sense at all..

Thanks!

Q? CSP transform without cov

I'm trying to do a dimensionality reduction with CSP, but want to keep the time sample to then perform a search light eg.

make_pipeline(
    CSP(2),  # find spatial filters where covariance is most predictive
    Windower(size=50, step=50),  # chunk into time slices
    SearchLight(make_pipeline(Covariances(), TangentSpace(), Logistic()))  # for each slice decode from cov

Would it make sense? If so, is it possible to implement it with pyRiemann?

Thanks!

test fails with numpy 1.11

======================================================================
ERROR: Test inverse transform of Tangent Space without fit.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/builddir/build/BUILD/python-pyriemann-0.2.3/python2/tests/test_tangentspace.py", line 68, in test_TangentSpace_inversetransform_without_fit
    ts.inverse_transform(tsv)
  File "/builddir/build/BUILDROOT/python-pyriemann-0.2.3-4.fc24.noarch/usr/lib/python2.7/site-packages/pyriemann/tangentspace.py", line 178, in inverse_transform
    self._check_reference_points(X)
  File "/builddir/build/BUILDROOT/python-pyriemann-0.2.3-4.fc24.noarch/usr/lib/python2.7/site-packages/pyriemann/tangentspace.py", line 110, in _check_reference_points
    self.Cr = numpy.eye(self._check_data_dim(X))
  File "/usr/lib64/python2.7/site-packages/numpy/lib/twodim_base.py", line 233, in eye
    m = zeros((N, M), dtype=dtype)
TypeError: 'numpy.float64' object cannot be interpreted as an index
----------------------------------------------------------------------

Incorrect computation of the non-AIRM metrics

Maybe I'm confused on this, but we were going through the code and the tangent_space function in pyriemann.utils.tangentspace appears to be incorrect -- it returns log(Cm^-.5XCm^-.5), which is not right for the AIRM and only correct for log-euclid when Cm is I? Where are the unique tangent space projection functions found?

[ENH] Add example with benchark of different mean/distance metric for MDM

MDM works by default with Riemannian mean and distance, but different combination of metrics can be set

metric = dict(distance='euclid', mean='wasserstein')
mdm = MDM(metric=metric)

The choice of metric impact peformance and computational cost. An example with benchmark of different metric for the mean and distance needed.

Remove pandas as dependency

Can we please remove pandas from the requirements?

Using this in the wild requires using pandas which is not needed by the core utils AFAIK

Cannot use anaconda to install

Trying to set up a virtual environment to develop in across computers and when trying to use

$ conda install -n MyVenv pyriemann 

I get:

Fetching package metadata .......
Solving package specifications: .
PackageNotFoundError: Package not found: '' Package missing in current osx-64 channels: 
  - pyriemann

You can search for packages on anaconda.org with

    anaconda search -t conda pyriemann

This also occurs when trying to simply do

conda install pyriemann

Probabilistic output for MDM

Add proba for MDM algorithm for the predict_proba function.
can be done by applying a LR or an IR on the distances.

Make pyRiemann citable

I'm actually using your implementation of XDawn in one of my studies. I would like to include a proper citation to the source (for now I mention the URL). Github supports generating proper DOI's though, which are easier to cite.

Potato issue: Type Error!

I'm getting a strange issue with potato!

TypeError: 'numpy.float64' object does not support item assignment

image

Any ideas?

Python Compatibility Issues

I am trying to run the following code on Python 3.4, Spyder 2.3.8, Anaconda 4.0 but it gave me an issue
AttributeError: 'range' object has no attribute 'pop' .

So I moved to Python 2.7.12, Spyder 2.3.9, Anaconda 4.0 but the kernel keeps dying without any execution.

data = loadmat(filename,squeeze_me=True);
XX = data['X'] trials x channels x time samples
YY = data['y']
cov = pyriemann.estimation.Covariances(estimator = 'oas').fit_transform(XX)
cov = pyriemann.channelselection.ElectrodeSelection().fit(cov,YY)

How can I run the toolbox for Python 3.4?

ImportError: cannot import name softmax

Trying to import:

from pyriemann.clustering import potato

and run with

$ python foo.py

Running into this error:

$ python python/handoff.py

Traceback (most recent call last):
  File "python/handoff.py", line 2, in <module>
    from pyriemann.clustering import potato
  File "/Users/ajk/anaconda/lib/python2.7/site-packages/pyriemann-0.2.4-py2.7.egg/pyriemann/__init__.py", line 1, in <module>
    from . import classification
  File "/Users/ajk/anaconda/lib/python2.7/site-packages/pyriemann-0.2.4-py2.7.egg/pyriemann/classification.py", line 7, in <module>
    from sklearn.utils.extmath import softmax
ImportError: cannot import name softmax

I am running 2.7

$ python --version
Python 2.7.11 :: Anaconda 2.3.0 (x86_64)

cannot run MDM example

Hi Alexandre,

I was trying the cross-validation classification example code from the homepage on some toy EEG data (64 channels), but I keep running into the following error:

screen shot 2016-08-23 at 15 33 31

I tracked the error down to the mean_riemann method . logm(tmp) (line 61) is filled with NaNs.

My input data is in the following format (Ntrials, Nchannels, Nsamples) :

screen shot 2016-08-23 at 15 38 48

Let me know if you need more information.

Thanks!

distance metric

The current code support different metric for mean covariance estimation, but only the riemannian metric for the distance.

FIX: var naming convention?

Since there's going to be a bckward incompatibility with the attributes, you may also want to change some of the param names: i.e. underscore to separate words (e.g. applyfilters =>apply_filter), explicit naming (e.g. n => n_sample), no uppercase (e.g. Nx) etc.

WDYT?

Incorrect computation of the tangent space

In pyriemann.utils.tangentspace it appears the tangent space mapping is incorrect -- it only computes log(Cm^-.5XCm^-.5), which is not the full tangent mapping for the AIRM and is only true for log-euclid when Cm=I

TypeError: 'module' object is not callable

Hi, I just got in touch with pyRiemann. In the beginning, I wanna thanks for your work about pyRiemann based on the riemannian geometry. Recently, this problem was occurred when trying to use it.
screenshot from 2018-09-03 16-32-40
the related code as follows:

   # estimate covariances matrices
  cov = pyriemann.estimation(estimator='lwf').Covariances().fit_transform(data1)
  # cross validation
  mdm = pyriemann.classification.MDM()

 accuracy = cross_val_score(mdm, cov, y_vals_new)

 print(accuracy.mean())

I was adding “(estimator='lwf')" after this error was popped up.

      ValueError: Covariance matrices must be positive definite.

Do you have any clue about this issue? Thank you.
Best
Irving

couple of tests are failing under python3

======================================================================
ERROR: Test transform of channelselection.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_channelselection.py", line 20, in test_ElectrodeSelection_transform
    se.fit(covset, labels)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/channelselection.py", line 93, in fit
    sub.pop(idx)
AttributeError: 'range' object has no attribute 'pop'

======================================================================
ERROR: Test Fit of FgMDM
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_classification.py", line 67, in test_FgMDM_fit
    mdm.fit(covset,labels)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/classification.py", line 283, in fit
    cov = self._fgda.fit_transform(X, y)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 308, in fit_transform
    ts = self._fit_lda(X, y, sample_weight=sample_weight)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 240, in _fit_lda
    ts = self._ts.fit_transform(X, sample_weight=sample_weight)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 169, in fit_transform
    return tangent_space(X, self.reference_)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test prediction of FgMDM
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_classification.py", line 74, in test_FgMDM_predict
    mdm.fit(covset,labels)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/classification.py", line 283, in fit
    cov = self._fgda.fit_transform(X, y)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 308, in fit_transform
    ts = self._fit_lda(X, y, sample_weight=sample_weight)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 240, in _fit_lda
    ts = self._ts.fit_transform(X, sample_weight=sample_weight)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 169, in fit_transform
    return tangent_space(X, self.reference_)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test fit CospCovariances
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_estimation.py", line 47, in test_Cospcovariances
    cov.fit_transform(x)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/estimation.py", line 270, in fit_transform
    return self.transform(X)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/estimation.py", line 264, in transform
    fmin=self.fmin, fmax=self.fmax, fs=self.fs)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/covariance.py", line 123, in cospectrum
    fdata = numpy.zeros((number_windows, Ne, number_freqs), dtype=complex)
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test one way permutation test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_stats.py", line 18, in test_permutation_test
    p.test(covset,labels)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/stats.py", line 186, in test
    self.F_ = numpy.zeros(numpy.min([self.n_perms, Npe]))
TypeError: 'numpy.float64' object cannot be interpreted as an integer

======================================================================
ERROR: Test transform of Tangent Space.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_tangentspace.py", line 34, in test_TangentSpace_transform
    ts.transform(covset)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 146, in transform
    return tangent_space(X, Cr)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test transform of Tangent Space without fit.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_tangentspace.py", line 41, in test_TangentSpace_transform_without_fit
    ts.transform(covset)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 146, in transform
    return tangent_space(X, Cr)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test transform of Tangent Space with TSupdate.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_tangentspace.py", line 49, in test_TangentSpace_transform_with_ts_update
    ts.transform(covset)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 146, in transform
    return tangent_space(X, Cr)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test inverse transform of Tangent Space.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_tangentspace.py", line 57, in test_TangentSpace_inversetransform
    t = ts.transform(covset)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 146, in transform
    return tangent_space(X, Cr)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test inverse transform of Tangent Space without fit.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_tangentspace.py", line 66, in test_TangentSpace_inversetransform_without_fit
    tsv = np.random.randn(Nt, Ne)
  File "mtrand.pyx", line 1404, in mtrand.RandomState.randn (numpy/random/mtrand/mtrand.c:19843)
  File "mtrand.pyx", line 1534, in mtrand.RandomState.standard_normal (numpy/random/mtrand/mtrand.c:20368)
  File "mtrand.pyx", line 167, in mtrand.cont0_array (numpy/random/mtrand/mtrand.c:6127)
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test Fit of FGDA.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_tangentspace.py", line 81, in test_FGDA_fit
    ts.fit(covset, labels)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 271, in fit
    self._fit_lda(X, y, sample_weight=sample_weight)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 240, in _fit_lda
    ts = self._ts.fit_transform(X, sample_weight=sample_weight)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 169, in fit_transform
    return tangent_space(X, self.reference_)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test transform of FGDA.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_tangentspace.py", line 89, in test_FGDA_transform
    ts.fit(covset, labels)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 271, in fit
    self._fit_lda(X, y, sample_weight=sample_weight)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 240, in _fit_lda
    ts = self._ts.fit_transform(X, sample_weight=sample_weight)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/tangentspace.py", line 169, in fit_transform
    return tangent_space(X, self.reference_)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test eegtocov
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_utils_covariance.py", line 40, in test_covariances_cospectrum
    cov = cospectrum(x)
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/covariance.py", line 123, in cospectrum
    fdata = numpy.zeros((number_windows, Ne, number_freqs), dtype=complex)
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test tangent space projection
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_utils_tangent_space.py", line 18, in test_tangent_space
    T = tangent_space(C,np.eye(3))
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

======================================================================
ERROR: Test tangent space projection and retro-projection should be the same
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/brain/Projects/fedora/python-pyriemann/pyRiemann-0.2.4/tests/test_utils_tangent_space.py", line 28, in test_tangent_and_untangent_space
    T = tangent_space(C,np.eye(3))
  File "/home/brain/rpmbuild/BUILDROOT/python-pyriemann-0.2.4-1.fc27.x86_64/usr/lib/python3.6/site-packages/pyriemann/utils/tangentspace.py", line 20, in tangent_space
    T = numpy.empty((Nt, Ne * (Ne + 1) / 2))
TypeError: 'float' object cannot be interpreted as an integer

ValueError: array must not contain infs or NaNs

If I follow the 1st example mentioned in the description under "how to use it" I get the following error. The dataset has 578 trials, 306 channels, 375 time points.

Error:

"array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs

Code:

import pyriemann
from sklearn.cross_validation import cross_val_score

load your data
X = ... # your EEG data, in format Ntrials x Nchannels X Nsamples
y = ... # the labels

estimate covariances matrices
cov = pyriemann.estimation.Covariances().fit_transform(X)

cross validation
mdm = pyriemann.classification.MDM()

accuracy = cross_val_score(mdm,cov,y)

print(accuracy.mean())

Covariance matrices must be positive definite. Add regularization to avoid this error

Hi,

Over all, thanks for your lib !

In this simple example

from pyriemann.estimation import Covariances
from pyriemann.utils.mean import mean_riemann
cov = Covariances().fit_transform(X_train)
mean_riemann(cov)

I get an error

Covariance matrices must be positive definite. Add regularization to avoid this error.

X_train is correct format with shape (trials, channels, n_samples)

Maybe I'm sailing in the wrong direction but I investigated a bit and I got NaN values after the logm function at line 61 in mean_riemann function (utils/mean.py)

J += sample_weight[index] * logm(tmp)

The first iterations for gradient descent until k=3 are going well, but NaN values appear at the third iteration.

Thanks for your help !

ENH: Metric for the distance in MDM

We should be able to specify the metric for the distance in MDM.
The metric for the distance and the mean can be different.

The argument metric should be used like this :
if it is a string, use the same metric for mean and distance.
otherwise, we can pass a dict like metric = dict(mean = 'logeuclid', distance = 'riemann')

Cannot pip install with Python 3.6

I tried to install pyRiemann in a Python 3.6 virtual environment by running:
pip install pyriemann
But the installation failed and the following error was printed:

Could not find a version that satisfies the requirement pyreimman (from versions: )
No matching distribution found for pyreimman

I first thought that maybe the package is only Python 2 compatible. But I installed the package from source. The package imports with no errors. Also, I ran the tests in the Python 3 venv and all of them passed.

clustering.Kmeans works with sklearn 1.6.1 but not 1.7

Hi alexandrebarachant,

First of all, I would like to thank you guys for the great library that you are building and making it open to the research community. I just want to report a bug related to the version of scikit-learn package. The Kmeans fit and fit_predict worked well on 1.6.1 but not 1.7. I got this error message:

/lib/python2.7/site-packages/sklearn/lda.py:4: DeprecationWarning: lda.LDA has been moved to discriminant_analysis.LinearDiscriminantAnalysis in 0.17 and will be removed in 0.19
"in 0.17 and will be removed in 0.19", DeprecationWarning)
Traceback (most recent call last):
File "main.py", line 429, in
cluster_covariances(params['covars'].reshape((-1, 3, 3)), n_clusters=7, means=params['means'].reshape((-1, 3)), viz=True)
File "main.py", line 70, in cluster_covariances
km.fit(covars)
File "
/lib/python2.7/site-packages/pyriemann-0.2.3-py2.7.egg/pyriemann/clustering.py", line 155, in fit
tol=self.tol)
File "/lib/python2.7/site-packages/pyriemann-0.2.3-py2.7.egg/pyriemann/clustering.py", line 20, in _fit_single
X, n_clusters, init, random_state=random_state)
File "
/lib/python2.7/site-packages/sklearn/cluster/k_means_.py", line 620, in _init_centroids
x_squared_norms = row_norms(X, squared=True)
File "~/lib/python2.7/site-packages/sklearn/utils/extmath.py", line 69, in row_norms
norms = np.einsum('ij,ij->i', X, X)
ValueError: operand has more dimensions than subscripts given in einstein sum, but no '...' ellipsis provided to broadcast the extra dimensions.

Process finished with exit code 1

[ENH] [Easy] Add t-sne dataset visualization

t-SNE is practical to vizualize a dataset.
it can be done by providing pairwise distance matrix to tsne :

from pyriemann.stats import pairwise_distance
from pyriemann.estimation import Covariances
from sklearn.manifold import TSNE

# Estimate covariance matrices
covs = Covariances().transform(X)

# compute pairewise distance matrix
pair_dist = pairwise_distance(covs, metric='riemann')

# t-SNE projection
tsne = TSNE(metric='precomputed', perplexity=50, learning_rate=200,
            early_exaggeration=4, random_state=666)

out = tsne.fit_transform(pair_dist)

plt.scatter(out[:, 0], out[:, 1])

the process is a bit cumbersome and could be encapsulated in a single function.

Geting Nan Inf errors for the TangentSpace(metric='riemann') transform

Sorry to bother you, I have one question which I don't know the answer.
First I would like to say it is great to see you apply Information Geometry to some real world problems and get amazing results, I am also using Information Geometry in my research, but applied to the field of entropy.

I am trying a simple example of pyRiemann, first I pass the data through covariance

cov_data_ = pyRiemannCovariances(epochs_data_)

then calculate tangent space

ts = pyRiemannTangentSpace(metric='riemann')
data_ = ts.fit_transform(cov_data_)

however, it give me a ValueError, saying array must not contain infs or NaNs.
I checked the matrix of cov_data_ and epochs_data_, there is no Inf or Nan.
I am wondering what are the conditions for my data in order for this to work?
Does this mean one or more of the covariance matrix have zero det, but what is
wrong with the original data so it have zero det.In other word, what is the condition
for my data so that the covariance matrix have zero det?
For example, if my data is

array([[[1, 4],
        [2, 5],
        [3, 6]],

       [[3, 4],
        [1, 2],
        [3, 6]]])

it will give me the same infs or NaNs error.
Thanks in advance.

Implement ALE mean

Implement ALE men described in :

Approximate Joint Diagonalization and Geometric Mean of Symmetric Positive Definite Matrices
Marco Congedo , Bijan Afsari, Alexandre Barachant, Maher Moakher

Py3k

Are you planning on Python 3 support?

http://pythonhosted.org/pyriemann site not working properly.

Webpage is not working properly. API reference page is showing 404 not found error on clicking on any function. example gallery is showing 404 not found. Please resolve the issue. Unable to use the package without going through the reference material.

Fix Data generation in test suite

in the test suite, the generation of covariance matrices is flawed and can create non-SPD matrice, causing the test to fail.

  • possible fix : add test data

About Covariances

thank you for this respository!

X is my experiment data(trial * channel * sample)

cov = Covariances().fit_transform(X)
mdm = pyriemann.classification.MDM()
# cross validation
accuracy = cross_val_score(mdm, cov, y)

raise "ValueError:Covariance matrices must be positive definite. Add regularization to avoid this error"
so i try
cov = Covariances().fit_transform(X) + 0.001*np.eye(X.shape[1])
it's OK
do you think the first ValueError is the result of calculation process?
what about adding some reminder about this?

problem with ptest.print()

I've been using pyRiemann for several days and it's working very well - very impressive. I did have an issue with the ptest.print() function - maybe I am not initializing something correctly. Anyway, here's a demo:

capture

for me, it produces this output:

capture2

Thanks Alex,
Jonathan Miller.

Set threshold of Potato in real time

Would be very nice if a user could change their threshold values because this seems to be both device dependent and and environment dependent. I picture having a little slider or something or dynamically working with the user to tune a proper value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.