fastsrm


Namefastsrm JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/hugorichard/FastSRM
SummaryFast Shared Response Model
upload_time2023-09-08 16:17:07
maintainer
docs_urlNone
authorHugo RICHARD
requires_python>=3
licenseMIT
keywords component analysis fmri
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastSRM

[![CircleCI](https://circleci.com/gh/hugorichard/FastSRM.svg?style=svg)](https://circleci.com/gh/hugorichard/FastSRM)

Implementation of FastSRM algorithms.


The model of probabilistic SRM is given by:

<img src="https://latex.codecogs.com/svg.image?\mathbf{x}_i&space;=&space;W_i&space;\mathbf{s}&space;&plus;&space;\mathbf{n}_i" title="\mathbf{x}_i = W_i \mathbf{s} + \mathbf{n}_i" />

where 
* <img src="https://latex.codecogs.com/svg.image?\mathbf{x}_i&space;\in&space;\mathbb{R}^v" title="\mathbf{x}_i \in \mathbb{R}^v" /> is the data of subject <img src="https://latex.codecogs.com/svg.image?i&space;" title="i " />
* <img src="https://latex.codecogs.com/svg.image?W_i&space;\in&space;\mathbb{R}^{v&space;\times&space;k}&space;" title="W_i \in \mathbb{R}^{v \times k} " /> is the basis of subject <img src="https://latex.codecogs.com/svg.image?i&space;" title="i " />
* <img src="https://latex.codecogs.com/svg.image?\mathbf{s}&space;\in&space;\mathbb{R}^k" title="\mathbf{s} \in \mathbb{R}^k" /> is the shared response (or sources) assumed to be sampled from a centered Gaussian with covariance <img src="https://latex.codecogs.com/svg.image?\Sigma&space;\in&space;\mathbb{R}^{k&space;\times&space;k}" title="\Sigma \in \mathbb{R}^{k \times k}" />
* <img src="https://latex.codecogs.com/svg.image?\mathbf{n}_i&space;\in&space;\mathbb{R}^v" title="\mathbf{n}_i \in \mathbb{R}^v" /> is  the noise in subject <img src="https://latex.codecogs.com/svg.image?i&space;" title="i " /> assumed to be sampled from a centered Gaussian with covariance <img src="https://latex.codecogs.com/svg.image?\sigma_i&space;I" title="\sigma_i I" /> where <img src="https://latex.codecogs.com/svg.image?I&space;\in&space;\mathbb{R}^{v,&space;v}" title="I \in \mathbb{R}^{v, v}" /> is the identity matrix. We call <img src="https://latex.codecogs.com/svg.image?\sigma_i" title="\sigma_i" /> the noise variance of subject <img src="https://latex.codecogs.com/svg.image?i&space;" title="i " />.

In practice we observe n samples of <img src="https://latex.codecogs.com/svg.image?\mathbf{x}_i" title="\mathbf{x}_i" />. When the number of samples is much lower than the number of features v, the SRM model can be fitted efficiently. This is what this repository provides. We also assume that the covariance of the shared response is diagonal to obtain identifiability.

Install
---------
Clone the repository

`git clone https://github.com/hugorichard/FastSRM`

In the cloned directory execute

`pip install -e .`

Requirements:

```
scipy>=0.18.0
numpy>=1.12
scikit-learn>=0.23
joblib>=1.1.0
matplotlib>=2.0.0
pytest>=6.2.5
```

To run the experiments on identifiability, brainiak (https://github.com/brainiak/brainiak) and nilearn (https://nilearn.github.io/stable/index.html) are necessary.

Usage
--------
In many neuroscience datasets, the samples are split into sessions. Therefore, for each subject we will have several sessions that can be time-wise concatenated to obtain all samples.
In `IdentifiableFastSRM` 


```python
# Input data X: neuroimaging data 
# X is a np array of shape (n_subjects, n_sessions)
# X[i, j] is a path to a np array of shape (n_voxels, n_timeframes)
from fastsrm.identifiable_srm import IdentifiableFastSRM
srm = IdentifiableFastSRM(n_components=5, temp_dir="./", n_jobs=5)
S = srm.fit_transform(X) # Shared response: np array of shape (n_components, n_timeframes)
W = srm.basis_list # Shared response: np array of shape (n_components, n_timeframes)
Sigma = srm.source_covariance # (Diagonal) Covariance of the shared response: np array of shape (n_components,)
sigmas = srm.noise_variance # Variance of the noise: np array of shape (n_subjects)

```

Run experiments
---------------

## Synthetic experiment

1. In the `experiments` folder run 
`ipython synthetic.py`

2. Go in the `plotting` folder and run
`ipython plot_synthetic_gradients.py`

The figure is now available in the `figures` folder under the name
`synthetic_gradient.pdf`


## Timesegment matching experiment

1. Go in the experiments folder and download the sherlock dataset by running:
`ipython get_sherlock.py`

2. Go in the `experiments` folder and run 
`bash timesegment.bash` if you have access to a cluster with slurm otherwise run `bash timesegment_local.bash`

4. Go in the `plotting` folder and run
`ipython plot_timesegment.py`

The figure is now available in the `figures` folder under the name
`timesegment_matching_sherlock.pdf`


## Identifiability experiment

1. Go in the experiments folder and download the sherlock dataset by running:
`ipython get_sherlock.py`

2. Download and install Brainiak (see https://github.com/brainiak/brainiak) 

3. Go in the `experiments` folder and run 
`bash identifiability.bash` if you have access to a cluster with slurm otherwise run `bash identifiability_local.bash`

4. Go in the `plotting` folder and run
`ipython plot_identifiability.py`

The figure is now available in the `figures` folder under the name
`identifiability.pdf`

Documentation
--------------

https://hugorichard.github.io/FastSRM/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hugorichard/FastSRM",
    "name": "fastsrm",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "Component analysis,fMRI",
    "author": "Hugo RICHARD",
    "author_email": "hugo.richard@inria.fr",
    "download_url": "https://files.pythonhosted.org/packages/49/19/4a76d71f31c980a4dc971d10a9f24c00553d34ff5b5f5257c7aff18432bf/fastsrm-0.0.5.tar.gz",
    "platform": null,
    "description": "# FastSRM\n\n[![CircleCI](https://circleci.com/gh/hugorichard/FastSRM.svg?style=svg)](https://circleci.com/gh/hugorichard/FastSRM)\n\nImplementation of FastSRM algorithms.\n\n\nThe model of probabilistic SRM is given by:\n\n<img src=\"https://latex.codecogs.com/svg.image?\\mathbf{x}_i&space;=&space;W_i&space;\\mathbf{s}&space;&plus;&space;\\mathbf{n}_i\" title=\"\\mathbf{x}_i = W_i \\mathbf{s} + \\mathbf{n}_i\" />\n\nwhere \n* <img src=\"https://latex.codecogs.com/svg.image?\\mathbf{x}_i&space;\\in&space;\\mathbb{R}^v\" title=\"\\mathbf{x}_i \\in \\mathbb{R}^v\" /> is the data of subject <img src=\"https://latex.codecogs.com/svg.image?i&space;\" title=\"i \" />\n* <img src=\"https://latex.codecogs.com/svg.image?W_i&space;\\in&space;\\mathbb{R}^{v&space;\\times&space;k}&space;\" title=\"W_i \\in \\mathbb{R}^{v \\times k} \" /> is the basis of subject <img src=\"https://latex.codecogs.com/svg.image?i&space;\" title=\"i \" />\n* <img src=\"https://latex.codecogs.com/svg.image?\\mathbf{s}&space;\\in&space;\\mathbb{R}^k\" title=\"\\mathbf{s} \\in \\mathbb{R}^k\" /> is the shared response (or sources) assumed to be sampled from a centered Gaussian with covariance <img src=\"https://latex.codecogs.com/svg.image?\\Sigma&space;\\in&space;\\mathbb{R}^{k&space;\\times&space;k}\" title=\"\\Sigma \\in \\mathbb{R}^{k \\times k}\" />\n* <img src=\"https://latex.codecogs.com/svg.image?\\mathbf{n}_i&space;\\in&space;\\mathbb{R}^v\" title=\"\\mathbf{n}_i \\in \\mathbb{R}^v\" /> is  the noise in subject <img src=\"https://latex.codecogs.com/svg.image?i&space;\" title=\"i \" /> assumed to be sampled from a centered Gaussian with covariance <img src=\"https://latex.codecogs.com/svg.image?\\sigma_i&space;I\" title=\"\\sigma_i I\" /> where <img src=\"https://latex.codecogs.com/svg.image?I&space;\\in&space;\\mathbb{R}^{v,&space;v}\" title=\"I \\in \\mathbb{R}^{v, v}\" /> is the identity matrix. We call <img src=\"https://latex.codecogs.com/svg.image?\\sigma_i\" title=\"\\sigma_i\" /> the noise variance of subject <img src=\"https://latex.codecogs.com/svg.image?i&space;\" title=\"i \" />.\n\nIn practice we observe n samples of <img src=\"https://latex.codecogs.com/svg.image?\\mathbf{x}_i\" title=\"\\mathbf{x}_i\" />. When the number of samples is much lower than the number of features v, the SRM model can be fitted efficiently. This is what this repository provides. We also assume that the covariance of the shared response is diagonal to obtain identifiability.\n\nInstall\n---------\nClone the repository\n\n`git clone https://github.com/hugorichard/FastSRM`\n\nIn the cloned directory execute\n\n`pip install -e .`\n\nRequirements:\n\n```\nscipy>=0.18.0\nnumpy>=1.12\nscikit-learn>=0.23\njoblib>=1.1.0\nmatplotlib>=2.0.0\npytest>=6.2.5\n```\n\nTo run the experiments on identifiability, brainiak (https://github.com/brainiak/brainiak) and nilearn (https://nilearn.github.io/stable/index.html) are necessary.\n\nUsage\n--------\nIn many neuroscience datasets, the samples are split into sessions. Therefore, for each subject we will have several sessions that can be time-wise concatenated to obtain all samples.\nIn `IdentifiableFastSRM` \n\n\n```python\n# Input data X: neuroimaging data \n# X is a np array of shape (n_subjects, n_sessions)\n# X[i, j] is a path to a np array of shape (n_voxels, n_timeframes)\nfrom fastsrm.identifiable_srm import IdentifiableFastSRM\nsrm = IdentifiableFastSRM(n_components=5, temp_dir=\"./\", n_jobs=5)\nS = srm.fit_transform(X) # Shared response: np array of shape (n_components, n_timeframes)\nW = srm.basis_list # Shared response: np array of shape (n_components, n_timeframes)\nSigma = srm.source_covariance # (Diagonal) Covariance of the shared response: np array of shape (n_components,)\nsigmas = srm.noise_variance # Variance of the noise: np array of shape (n_subjects)\n\n```\n\nRun experiments\n---------------\n\n## Synthetic experiment\n\n1. In the `experiments` folder run \n`ipython synthetic.py`\n\n2. Go in the `plotting` folder and run\n`ipython plot_synthetic_gradients.py`\n\nThe figure is now available in the `figures` folder under the name\n`synthetic_gradient.pdf`\n\n\n## Timesegment matching experiment\n\n1. Go in the experiments folder and download the sherlock dataset by running:\n`ipython get_sherlock.py`\n\n2. Go in the `experiments` folder and run \n`bash timesegment.bash` if you have access to a cluster with slurm otherwise run `bash timesegment_local.bash`\n\n4. Go in the `plotting` folder and run\n`ipython plot_timesegment.py`\n\nThe figure is now available in the `figures` folder under the name\n`timesegment_matching_sherlock.pdf`\n\n\n## Identifiability experiment\n\n1. Go in the experiments folder and download the sherlock dataset by running:\n`ipython get_sherlock.py`\n\n2. Download and install Brainiak (see https://github.com/brainiak/brainiak) \n\n3. Go in the `experiments` folder and run \n`bash identifiability.bash` if you have access to a cluster with slurm otherwise run `bash identifiability_local.bash`\n\n4. Go in the `plotting` folder and run\n`ipython plot_identifiability.py`\n\nThe figure is now available in the `figures` folder under the name\n`identifiability.pdf`\n\nDocumentation\n--------------\n\nhttps://hugorichard.github.io/FastSRM/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Fast Shared Response Model",
    "version": "0.0.5",
    "project_urls": {
        "Download": "https://github.com/hugorichard/FastSRM/archive/v_004.tar.gz",
        "Homepage": "https://github.com/hugorichard/FastSRM"
    },
    "split_keywords": [
        "component analysis",
        "fmri"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1673877693c830f912699f59677d78cc29dbfe48e9cabff941f56040dd820984",
                "md5": "0981dfeb981bef313cc769b52038b712",
                "sha256": "9f883acde8ac94421486a4b6a739b89a77330f0a063cf4a46221eae3f4e013d4"
            },
            "downloads": -1,
            "filename": "fastsrm-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0981dfeb981bef313cc769b52038b712",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 19338,
            "upload_time": "2023-09-08T16:17:04",
            "upload_time_iso_8601": "2023-09-08T16:17:04.543849Z",
            "url": "https://files.pythonhosted.org/packages/16/73/877693c830f912699f59677d78cc29dbfe48e9cabff941f56040dd820984/fastsrm-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49194a76d71f31c980a4dc971d10a9f24c00553d34ff5b5f5257c7aff18432bf",
                "md5": "fd9fd8079c43cf06f717165f7a0810c2",
                "sha256": "ca50d7222fd8328ace3c616084c2e1aa7e25668ec6b2fcbcc46567e5b81ec01d"
            },
            "downloads": -1,
            "filename": "fastsrm-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "fd9fd8079c43cf06f717165f7a0810c2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 9760221,
            "upload_time": "2023-09-08T16:17:07",
            "upload_time_iso_8601": "2023-09-08T16:17:07.494608Z",
            "url": "https://files.pythonhosted.org/packages/49/19/4a76d71f31c980a4dc971d10a9f24c00553d34ff5b5f5257c7aff18432bf/fastsrm-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-08 16:17:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hugorichard",
    "github_project": "FastSRM",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [],
    "lcname": "fastsrm"
}
        
Elapsed time: 0.12005s