Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schaefer-Strimmer shrinkage covariance estimator #59

Merged
merged 55 commits into from Sep 3, 2021

Conversation

sylvchev
Copy link
Member

A PR to merge the code of Schaefer-Strimmer covariance estimator [1]. This shrinkage estimator is not implemented in scikit-learn, but is useful to estimate covariance matrices from a limited number of samples.
There is a python implementation already available, see https://github.com/rmcgibbo/covar/, but it relies on Cython and thus does not seem to fit well with the pyRiemann scope. The code of this PR is in pure Python.

[1] Schafer, J., and K. Strimmer. 2005. A shrinkage approach to large-scale covariance estimation and implications for functional genomics. Statist. Appl. Genet. Mol. Biol. 4:32.
http://doi.org/10.2202/1544-6115.1175

Sylvain Chevallier added 27 commits April 13, 2016 11:26
… initialized on one of the point of the set, generating zero-divide error.
@codecov-io
Copy link

codecov-io commented Aug 18, 2017

Codecov Report

Merging #59 into master will increase coverage by 0.54%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #59      +/-   ##
==========================================
+ Coverage   98.09%   98.63%   +0.54%     
==========================================
  Files          18       18              
  Lines        1311     1322      +11     
==========================================
+ Hits         1286     1304      +18     
+ Misses         25       18       -7
Impacted Files Coverage Δ
pyriemann/utils/covariance.py 100% <100%> (ø) ⬆️
pyriemann/stats.py 99.37% <0%> (+4.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22ee36d...b6a73a3. Read the comment docs.

@alexandrebarachant
Copy link
Collaborator

Very nice !

In practice, do you observe a difference in performances ?

It would be great if you can add an example with the 3 different shrinkage estimator.
i think the physionet motor imagery dataset in MNE is a good candidate

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
@agramfort
Copy link
Member

agramfort commented Aug 19, 2021 via email

Sylvain Chevallier and others added 2 commits August 19, 2021 14:21
Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
@qbarthelemy
Copy link
Member

Code ok for me! Good job Sylvain!

pyriemann/utils/covariance.py Outdated Show resolved Hide resolved
pyriemann/utils/covariance.py Outdated Show resolved Hide resolved
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
@agramfort agramfort merged commit 3ac67b7 into pyRiemann:master Sep 3, 2021
@agramfort
Copy link
Member

Thx @sylvchev

@qbarthelemy qbarthelemy mentioned this pull request Sep 6, 2021
agramfort added a commit that referenced this pull request Sep 20, 2021
* rewriting base file to get ride of numpy matrices.

* last modification to rewrite into full numpy integration

* rewriting mean with dotted notation and getting rid of numpy matrices

* continuing to rewrite the geodesic

* rewriting of the spatial filters

* small style correction in channelselection

* updating the use of numpy for all higher packages

* last rewriting of pyriemann file

* adding slack  notification

* finishing to update numpy ref and removing numpy matrices

* covering all functions of classification: TSclassifier, kNN

* PEP8 conformation for test clustering

* PEP 8 normalisation

* fixing last bugs for testing

* update test

* adding test for Potato

* end of modification of test units and coverage improvment.

* modifying and adapting travis file.

* updating travis file and correcting error in testing wasserstein mean

* adding pandas in the requierement for Travis

* ajout de la generation de matrice SPD

* Correcting the Karcher mean implementation if the gradient descent is initialized on one of the point of the set, generating zero-divide error.

* adding ALM to mean computation

* adding ref for the parametrized geodesic

* update avant merge

* uncomplete merge

* merge with upstream

* use fixture and parametrize for tests, avoid code redundancy, systematic test of dist and metric

* correct tangent fit bug

Co-authored-by: kjersbry <noreply@github.com>
Co-authored-by: sylvchev <noreply@github.com>

* add tsupdate check

* reduce complexity of the test to make them faster

* add flake8 to tests and examples, correct style in tests

* switch to triangular inequality to avoid random failure

* update coverage

* remove redundant tests, add coverage

* correct flake8

* correct F401,F811 import errors with fixtures

* correct w value

* remove assert_array_equal and correct variable names

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>

* add is_spsd and get_labels fixture

* adding test for Schaefer estimator

* update test for spatial filters

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>

* correct var name for inverse transform

* use get_labels fixture

* correct flake8

* add is_psd and is_semi_psd

* add independence test for fit/transform

* correct zeros -> empty

* Schaefer-Strimmer shrinkage covariance estimator (#59)

* rewriting base file to get ride of numpy matrices.

* last modification to rewrite into full numpy integration

* rewriting mean with dotted notation and getting rid of numpy matrices

* continuing to rewrite the geodesic

* rewriting of the spatial filters

* small style correction in channelselection

* updating the use of numpy for all higher packages

* last rewriting of pyriemann file

* adding slack  notification

* finishing to update numpy ref and removing numpy matrices

* covering all functions of classification: TSclassifier, kNN

* PEP8 conformation for test clustering

* PEP 8 normalisation

* fixing last bugs for testing

* update test

* adding test for Potato

* end of modification of test units and coverage improvment.

* modifying and adapting travis file.

* updating travis file and correcting error in testing wasserstein mean

* adding pandas in the requierement for Travis

* ajout de la generation de matrice SPD

* Correcting the Karcher mean implementation if the gradient descent is initialized on one of the point of the set, generating zero-divide error.

* adding ALM to mean computation

* adding ref for the parametrized geodesic

* update avant merge

* adding computation and test of Schaefer-Strimmer covariance estimator

* replacing loops with algebra

* adding an example

* correcting plots

* uncomplete merge

* pep8

* update test for tangent space

* correct docstring and bug

* converting notebook into py file

* correct style

* rewrite plots, reduce computation time

* update link and rename variables

* correct style

* correct plot layout

* adding Schaefer-Strimmer in whatsnew

* update test, docstring and docs from suggestions

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>

* improve tests for covariance

* keep the same color for each estimator across figures

* correct example text

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>

* raise error for covariance_EP and initialize RandomState in example

* correct import order

* Apply suggestions from code review

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>

* sort import, correct spd

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>

* switch zeros to np.empty

Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>

* add doc

* rebase on master

* correct tangent fit bug

Co-authored-by: kjersbry <noreply@github.com>
Co-authored-by: sylvchev <noreply@github.com>

* add tsupdate check

* reduce complexity of the test to make them faster

* add flake8 to tests and examples, correct style in tests

* switch to triangular inequality to avoid random failure

* update coverage

* remove redundant tests, add coverage

* correct flake8

* correct F401,F811 import errors with fixtures

* correct w value

* add is_spsd and get_labels fixture

* remove assert_array_equal and correct variable names

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>

* adding test for Schaefer estimator

* correct var name for inverse transform

* update test for spatial filters

Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>

* use get_labels fixture

* correct flake8

* add is_psd and is_semi_psd

* add independence test for fit/transform

* correct zeros -> empty

* define is_spd/is_spsd fixtures

* clean code

* updating whats new

Co-authored-by: kjersbry <noreply@github.com>
Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
@sylvchev sylvchev deleted the cov-schaefer branch September 21, 2021 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants