Skip to main content

Code for performing Representational Similarity Analysis on MNE-Python data structures.

Project description

Representational Similarity Analysis

unit_tests build_docs

This is a Python package for performing representational similarity analysis (RSA) using MNE-Python data structures. The RSA is computed using a “searchlight” approach.

Read more on RSA in the paper that introduced the technique:

Nikolaus Kriegeskorte, Marieke Mur and Peter Bandettini (2008). Representational similarity analysis - connecting the branches of systems neuroscience. Frontiers in Systems Neuroscience, 2(4). https://doi.org/10.3389/neuro.06.004.2008

https://raw.githubusercontent.com/wmvanvliet/mne-rsa/master/doc/rsa.png

Installation

Here is how to install the package as a user:

pip install mne-rsa

Use cases

This is what the package can do for you:

  • Compute DSMs on arbitrary data

  • Compute DSMs in a searchlight across:

    • vertices/voxels and samples (source level)

    • sensors and samples (sensor level)

    • vertices/voxels only (source level)

    • sensors only (sensor level)

    • samples only (source and sensor level)

  • Use cross-validated distance metrics when computing DSMs

  • And of course: compute RSA between DSMs

Supported metrics for comparing DSMs:

  • Spearman correlation (the default)

  • Pearson correlation

  • Kendall’s Tau-A

  • Linear regression (when comparing multiple DSMs at once)

  • Partial correlation (when comparing multiple DSMs at once)

Juicy bits of the API

def compute_dsm(model, pca=False, metric='correlation', **kwargs)

def rsa_stcs(stcs, model_dsm, src, y=None,
             spatial_radius=0.04, temporal_radius=0.1,
             stc_dsm_metric='correlation', stc_dsm_params=None,
             rsa_metric='spearman',
             n_jobs=1, verbose=False)

def rsa_evokeds(evokeds, model_dsm, y=None, noise_cov=None,
                spatial_radius=0.04, temporal_radius=0.1,
                evoked_dsm_metric='correlation', evoked_dsm_params=None,
                rsa_metric='spearman',
                n_jobs=1, verbose=False)

def rsa_epochs(epochs, model_dsm, y=None, noise_cov=None,
               spatial_radius=0.04, temporal_radius=0.1,
               epochs_dsm_metric='correlation', epochs_dsm_params=None,
               rsa_metric='spearman',
               n_jobs=1, verbose=False)

def rsa_nifti(image, model_dsm, src, y=None,
              spatial_radius=0.01,
              image_dsm_metric='correlation', image_dsm_params=None,
              rsa_metric='spearman',
              n_jobs=1, verbose=False)

Example usage

Basic example on the EEG “kiloword” data:

import mne
import rsa
data_path = mne.datasets.kiloword.data_path(verbose=True)
epochs = mne.read_epochs(data_path + '/kword_metadata-epo.fif')
# Compute the model DSM using all word properties
dsm_model = rsa.compute_dsm(epochs.metadata.iloc[:, 1:].values)
evoked_rsa = rsa.rsa_epochs(epochs, dsm_model,
                            spatial_radius=0.04, temporal_radius=0.01,
                            verbose=True)

Documentation

For quick guides on how to do specific things, see the examples.

Finally, there is the API reference documentation.

Integration with other packages

I mainly wrote this package to perform RSA analysis on MEG data. Hence, integration functions with MNE-Python are provided. There is also some integration with nipy for fMRI.

Performance

This package aims to be fast and memory efficient. An important design feature is that under the hood, everything operates on generators. The searchlight routines produce a generator of DSMs which are consumed by a generator of RSA values. Parallel processing is also supported, so you can use all of your CPU cores.

Development

Here is how to set up the package as a developer:

git clone git@github.com:wmvanvliet/mne-rsa.git
cd mne-rsa
python setup.py develop --user

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mne-rsa-0.5.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

mne_rsa-0.5-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file mne-rsa-0.5.tar.gz.

File metadata

  • Download URL: mne-rsa-0.5.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/3.10.1 keyring/23.4.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for mne-rsa-0.5.tar.gz
Algorithm Hash digest
SHA256 ca2dc9c2cc18354809181b1687a47ce1867f6c80deff2be632cfff60df50d9dd
MD5 da345e5fa7f014171e9840d91281161a
BLAKE2b-256 d4026621af218f8bbda999bfe134aa6c8791a5c2dd519f33a6e35eb2e4fcb74b

See more details on using hashes here.

File details

Details for the file mne_rsa-0.5-py3-none-any.whl.

File metadata

  • Download URL: mne_rsa-0.5-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/3.10.1 keyring/23.4.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for mne_rsa-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 365c8ad73e13df519072faab58aff9805491359ed29b09c73a50497c07a7abe9
MD5 7c1354a78c6e55794dc5e409bf008892
BLAKE2b-256 b5ada75c23e688767eab77079c71c651a2a1976c23bb49e98e4dbc7f8ee5d524

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page