Skip to content

adeeps1/PyRiemann-openBLAS

 
 

Repository files navigation

PyRiemann

Python implementation for EEG-based BCI based on Riemannian geometry, using OpenBLAS

This is a fork from Alexandre Barachant's pyRiemann toolbox and it is a work in progress.

Benchmarks and selected solutions

We have benchmark two main Python distributions (Canopy, Anaconda) and we have build our own Python toolchain, with numpy compiled against MKL and OpenBLAS. A canevas script to build the benchmark is available from this gist. Some results are plotted below for 500x500 covariance matrices, with the code available here. Nota bene, Anaconda is used in its vanilla version (the free one), it is possible to pay to obtain a version compiled against MKL.

Extensive testing shows that OpenBLAS is largely suitable for our computation and that it is much more easier to deploy than MKL. See also this benchmark.

We have tried to also several alternative solutions:

  • Python calling C functions with BLAS calls
  • Python linked with matrix classes written in C++, with BLAS calls
  • direct call to BLAS functions in Python
  • using numpy, either the one embeded in Canopy/Anaconda, or our own build with MKL or OpenBLAS The most efficient and easy to maintain solution is our own build with numpy build against OpenBLAS. In practice, it just requires to install OpenBLAS on the system and to download/build numpy and scipy as user.

Difference from pyRiemann toolbox

A specific class is designed for the covariance matrix and the intermediate computation are recorded. For example, when computing Fisher distance (aka AIRM), the eigenvalues needed for the computation are stored for further computation. It increases the memory load but save a lot of computation time when dealing with sucessive computation, such as in computation for Karcher mean. The intermediate variables were carefully selected and evaluated, to avoid inefficient and time-consuming unwanted memory allocation.

Covariance matrices have a dedicated class, which can be handle as a list and as numpy ndarray. This class also store some cached storage, for intermediate computation.

Below are some speed-up test comparison with direct numpy implementation, without cached storage. The most important facts are that:

  • for euclidean case, the overhead is the most visible and increase the computation cost. This effecti vanishes when increasing the dimension of the matrices
  • for Riemannian metric, there a clear effect for the small dimension problem, the speed up factor is around 1.25. For larger problem, it is less obvious.
  • For computing mean values, especially for small scale problem, the Riemannian cases shows a good speed-up (around 1.15) and the euclidean ones are not as efficient. The values obtained by the log-euclidean may be the result of good performances of the rewriting covariance class on top of a specific issue with the original code.

Dependencies

  • Numpy
  • Scipy
  • Scikit-learn
  • OpenBLAS
  • nose (for continuous integration)

Contributors:

  • Sylvain Chevallier
  • Romain Da Rocha
  • Rado Andrianjanahary

About

Rewriting pyriemann toolbox for optimized computation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.7%
  • Shell 1.3%