nemos


Namenemos JSON
Version 0.1.6 PyPI version JSON
download
home_pageNone
SummaryNEural MOdelS, a statistical modeling framework for neuroscience.
upload_time2024-08-14 11:17:01
maintainerNone
docs_urlNone
authornemos authors
requires_python>=3.9
licenseMIT License Copyright (c) 2023 nemos authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords neuroscience poisson-glm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # <div style="text-align: center;"> <img src="docs/assets/NeMoS_Logo_CMYK_Full.svg" width="75%"> </div>

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/flatironinstitute/nemos/blob/main/LICENSE)
![Python version](https://img.shields.io/badge/python-3.9%7C3.10%7C3.11-blue.svg)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
![PyPI - Version](https://img.shields.io/pypi/v/nemos)
[![codecov](https://codecov.io/gh/flatironinstitute/nemos/graph/badge.svg?token=vvtrcTFNeu)](https://codecov.io/gh/flatironinstitute/nemos)
[![Documentation Status](https://readthedocs.org/projects/nemos/badge/?version=latest)](https://nemos.readthedocs.io/en/latest/?badge=latest)
[![nemos CI](https://github.com/flatironinstitute/nemos/actions/workflows/ci.yml/badge.svg)](https://github.com/flatironinstitute/nemos/actions/workflows/ci.yml)


NeMoS (Neural ModelS) is a statistical modeling framework optimized for systems neuroscience and powered by [JAX](https://jax.readthedocs.io/en/latest/). 
It streamlines the process of creating and selecting models, through a collection of easy-to-use methods for feature design.

The core of NeMoS includes GPU-accelerated, well-tested implementations of standard statistical models, currently 
focusing on the Generalized Linear Model (GLM). 

We provide a **Poisson GLM** for analyzing spike counts, and a **Gamma GLM** for calcium or voltage imaging traces.

The package is under active development and more methods will be added in the future.

For those looking to get a better grasp of the Generalized Linear Model, we recommend checking out the 
Neuromatch Academy's lesson [here](https://compneuro.neuromatch.io/tutorials/W1D3_GeneralizedLinearModels/student/W1D3_Tutorial1.htmls) and Jonathan Pillow's tutorial 
from Cosyne 2018 [here](https://www.youtube.com/watch?v=NFeGW5ljUoI&t=424s).

## Overview

At his core, NeMoS consists of two primary modules: the `basis` and the `glm` module.

The `basis` module focuses on designing model features (inputs) for the GLM. It includes a suite of composable feature 
constructors that accept time-series data as inputs. These inputs can be any observed variables, such as presented 
stimuli, head direction, position, or spike counts. 

The basis objects can perform two types of transformations on the inputs:

1. **Non-linear Mapping:** This process transforms the input data through a non-linear function, 
   allowing it to capture complex, non-linear relationships between inputs and neuronal firing rates. 
   Importantly, this transformation preserves the properties that makes GLM easy to fit and guarantee a 
   single optimal solution (e.g. convexity).

2. **Convolution:** This applies a convolution of the input data with a bank of filters, designed to 
   capture linear temporal effects. This transformation is particularly useful when analyzing data with 
   inherent time dependencies or when the temporal dynamics of the input are significant.

Both transformations produce a vector of features `X` that changes over time, with a shape 
of `(n_time_points, n_features)`.

On the other hand, the `glm` module maps the feature to spike counts. It is used to learn the GLM weights, 
evaluating the model performance, and explore its behavior on new input.

## Examples

Here's a brief demonstration of how the `basis` and `glm` modules work together within NeMoS.

### Poisson GLM for features analysis

<img src="docs/assets/glm_features_scheme.svg" width="100%">

In this example, we'll construct a time-series of features using the basis objects, applying a non-linear mapping
(default behavior):

#### Feature Representation

```python
import nemos as nmo

# Instantiate the basis
basis_1 = nmo.basis.MSplineBasis(n_basis_funcs=5)
basis_2 = nmo.basis.CyclicBSplineBasis(n_basis_funcs=6)
basis_3 = nmo.basis.MSplineBasis(n_basis_funcs=7)

basis = basis_1 * basis_2 + basis_3

# Generate the design matrix starting from some raw 
# input time series, i.e. LFP phase, position, etc.
X = basis.compute_features(input_1, input_2, input_3)
```

#### GLM

```python

# Fit the model mapping X to the spike count
# time-series y
glm = nmo.glm.GLM().fit(X, y)

# Inspect the learned coefficients
print(glm.coef_, glm.intercept_)

# compute the rate
firing_rate = glm.predict(X)

# compute log-likelihood
ll = glm.score(X, y)
```

### Poisson GLM for neural population

<img src="docs/assets/glm_population_scheme.svg" width="84%">

This second example demonstrates feature construction by convolving the simultaneously recorded population spike counts with a bank of filters, utilizing the basis in `conv` mode.
The figure above show the GLM scheme for a single neuron, however in NeMoS you can fit jointly the whole population with the [`PopulationGLM`](https://nemos.readthedocs.io/en/latest/generated/api_guide/plot_04_population_glm/) object.

#### Feature Representation

```python
import nemos as nmo

# assume that the population spike counts time-series is stored 
# in a 2D array spike_counts of shape (n_samples, n_neurons).

# generate 5 basis functions of 100 time-bins, 
# and convolve the counts with the basis.
X = nmo.basis.RaisedCosineBasisLog(5, mode="conv", window_size=100
    ).compute_features(spike_counts)
```
#### Population GLM

```python
# fit a GLM to the first neuron counts time-series
glm = nmo.glm.PopulationGLM().fit(X, spike_counts)

# compute the rate
firing_rate = glm.predict(X)

# compute log-likelihood
ll = glm.score(X, spike_counts)
```

For a deeper dive, see our [Quickstart](https://nemos.readthedocs.io/en/latest/quickstart/)  guide and consider using [pynapple](https://github.com/pynapple-org/pynapple) for data exploration and preprocessing. When initializing the GLM object, you may optionally specify an [observation
model](https://nemos.readthedocs.io/en/latest/reference/nemos/observation_models/) and a [regularizer](https://nemos.readthedocs.io/en/latest/reference/nemos/regularizer/).

> **Note: Multi-epoch Convolution**
>
> If your data is formatted as a `pynapple` time-series, the convolution performed by the basis objects will be 
> executed epoch-by-epoch, avoiding the risk of introducing artifacts from gaps in your time-series.


## Installation
Run the following `pip` command in your virtual environment.

**For macOS/Linux users:**
 ```bash
 pip install nemos
 ```

**For Windows users:**
 ```
 python -m pip install nemos
 ```

For more details, including specifics for GPU users and developers, refer to NeMoS [docs](https://nemos.readthedocs.io/en/latest/installation/).


## Disclaimer

Please note that this package is currently under development. While you can
download and test the functionalities that are already present, please be aware
that syntax and functionality may change before our preliminary release.

## Getting help and getting in touch

We communicate via several channels on Github:

- To report a bug, open an
  [issue](https://github.com/flatironinstitute/nemos/issues).
- To ask usage questions, discuss broad issues, or show off what you’ve made
  with NeMoS, go to
  [Discussions](https://github.com/flatironinstitute/nemos/discussions).
- To send suggestions for extensions or enhancements, please post in the
  [ideas](https://github.com/flatironinstitute/nemos/discussions/categories/ideas)
  section of discussions first. We’ll discuss it there and, if we decide to
  pursue it, open an issue to track progress.
- To contribute to the project, see the [contributing
  guide](CONTRIBUTING.md).

In all cases, we request that you respect our [code of
conduct](CODE_OF_CONDUCT.md).


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "nemos",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "neuroscience, Poisson-GLM",
    "author": "nemos authors",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/df/96/b61440750aa93620f902d68ad1d33f136fcc4bdfa1edfa5bdaadee62600d/nemos-0.1.6.tar.gz",
    "platform": null,
    "description": "# <div style=\"text-align: center;\"> <img src=\"docs/assets/NeMoS_Logo_CMYK_Full.svg\" width=\"75%\"> </div>\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/flatironinstitute/nemos/blob/main/LICENSE)\n![Python version](https://img.shields.io/badge/python-3.9%7C3.10%7C3.11-blue.svg)\n[![Project Status: Active \u2013 The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n![PyPI - Version](https://img.shields.io/pypi/v/nemos)\n[![codecov](https://codecov.io/gh/flatironinstitute/nemos/graph/badge.svg?token=vvtrcTFNeu)](https://codecov.io/gh/flatironinstitute/nemos)\n[![Documentation Status](https://readthedocs.org/projects/nemos/badge/?version=latest)](https://nemos.readthedocs.io/en/latest/?badge=latest)\n[![nemos CI](https://github.com/flatironinstitute/nemos/actions/workflows/ci.yml/badge.svg)](https://github.com/flatironinstitute/nemos/actions/workflows/ci.yml)\n\n\nNeMoS (Neural ModelS) is a statistical modeling framework optimized for systems neuroscience and powered by [JAX](https://jax.readthedocs.io/en/latest/). \nIt streamlines the process of creating and selecting models, through a collection of easy-to-use methods for feature design.\n\nThe core of NeMoS includes GPU-accelerated, well-tested implementations of standard statistical models, currently \nfocusing on the Generalized Linear Model (GLM). \n\nWe provide a **Poisson GLM** for analyzing spike counts, and a **Gamma GLM** for calcium or voltage imaging traces.\n\nThe package is under active development and more methods will be added in the future.\n\nFor those looking to get a better grasp of the Generalized Linear Model, we recommend checking out the \nNeuromatch Academy's lesson [here](https://compneuro.neuromatch.io/tutorials/W1D3_GeneralizedLinearModels/student/W1D3_Tutorial1.htmls) and Jonathan Pillow's tutorial \nfrom Cosyne 2018 [here](https://www.youtube.com/watch?v=NFeGW5ljUoI&t=424s).\n\n## Overview\n\nAt his core, NeMoS consists of two primary modules: the `basis` and the `glm` module.\n\nThe `basis` module focuses on designing model features (inputs) for the GLM. It includes a suite of composable feature \nconstructors that accept time-series data as inputs. These inputs can be any observed variables, such as presented \nstimuli, head direction, position, or spike counts. \n\nThe basis objects can perform two types of transformations on the inputs:\n\n1. **Non-linear Mapping:** This process transforms the input data through a non-linear function, \n   allowing it to capture complex, non-linear relationships between inputs and neuronal firing rates. \n   Importantly, this transformation preserves the properties that makes GLM easy to fit and guarantee a \n   single optimal solution (e.g. convexity).\n\n2. **Convolution:** This applies a convolution of the input data with a bank of filters, designed to \n   capture linear temporal effects. This transformation is particularly useful when analyzing data with \n   inherent time dependencies or when the temporal dynamics of the input are significant.\n\nBoth transformations produce a vector of features `X` that changes over time, with a shape \nof `(n_time_points, n_features)`.\n\nOn the other hand, the `glm` module maps the feature to spike counts. It is used to learn the GLM weights, \nevaluating the model performance, and explore its behavior on new input.\n\n## Examples\n\nHere's a brief demonstration of how the `basis` and `glm` modules work together within NeMoS.\n\n### Poisson GLM for features analysis\n\n<img src=\"docs/assets/glm_features_scheme.svg\" width=\"100%\">\n\nIn this example, we'll construct a time-series of features using the basis objects, applying a non-linear mapping\n(default behavior):\n\n#### Feature Representation\n\n```python\nimport nemos as nmo\n\n# Instantiate the basis\nbasis_1 = nmo.basis.MSplineBasis(n_basis_funcs=5)\nbasis_2 = nmo.basis.CyclicBSplineBasis(n_basis_funcs=6)\nbasis_3 = nmo.basis.MSplineBasis(n_basis_funcs=7)\n\nbasis = basis_1 * basis_2 + basis_3\n\n# Generate the design matrix starting from some raw \n# input time series, i.e. LFP phase, position, etc.\nX = basis.compute_features(input_1, input_2, input_3)\n```\n\n#### GLM\n\n```python\n\n# Fit the model mapping X to the spike count\n# time-series y\nglm = nmo.glm.GLM().fit(X, y)\n\n# Inspect the learned coefficients\nprint(glm.coef_, glm.intercept_)\n\n# compute the rate\nfiring_rate = glm.predict(X)\n\n# compute log-likelihood\nll = glm.score(X, y)\n```\n\n### Poisson GLM for neural population\n\n<img src=\"docs/assets/glm_population_scheme.svg\" width=\"84%\">\n\nThis second example demonstrates feature construction by convolving the simultaneously recorded population spike counts with a bank of filters, utilizing the basis in `conv` mode.\nThe figure above show the GLM scheme for a single neuron, however in NeMoS you can fit jointly the whole population with the [`PopulationGLM`](https://nemos.readthedocs.io/en/latest/generated/api_guide/plot_04_population_glm/) object.\n\n#### Feature Representation\n\n```python\nimport nemos as nmo\n\n# assume that the population spike counts time-series is stored \n# in a 2D array spike_counts of shape (n_samples, n_neurons).\n\n# generate 5 basis functions of 100 time-bins, \n# and convolve the counts with the basis.\nX = nmo.basis.RaisedCosineBasisLog(5, mode=\"conv\", window_size=100\n    ).compute_features(spike_counts)\n```\n#### Population GLM\n\n```python\n# fit a GLM to the first neuron counts time-series\nglm = nmo.glm.PopulationGLM().fit(X, spike_counts)\n\n# compute the rate\nfiring_rate = glm.predict(X)\n\n# compute log-likelihood\nll = glm.score(X, spike_counts)\n```\n\nFor a deeper dive, see our [Quickstart](https://nemos.readthedocs.io/en/latest/quickstart/)  guide and consider using [pynapple](https://github.com/pynapple-org/pynapple) for data exploration and preprocessing. When initializing the GLM object, you may optionally specify an [observation\nmodel](https://nemos.readthedocs.io/en/latest/reference/nemos/observation_models/) and a [regularizer](https://nemos.readthedocs.io/en/latest/reference/nemos/regularizer/).\n\n> **Note: Multi-epoch Convolution**\n>\n> If your data is formatted as a `pynapple` time-series, the convolution performed by the basis objects will be \n> executed epoch-by-epoch, avoiding the risk of introducing artifacts from gaps in your time-series.\n\n\n## Installation\nRun the following `pip` command in your virtual environment.\n\n**For macOS/Linux users:**\n ```bash\n pip install nemos\n ```\n\n**For Windows users:**\n ```\n python -m pip install nemos\n ```\n\nFor more details, including specifics for GPU users and developers, refer to NeMoS [docs](https://nemos.readthedocs.io/en/latest/installation/).\n\n\n## Disclaimer\n\nPlease note that this package is currently under development. While you can\ndownload and test the functionalities that are already present, please be aware\nthat syntax and functionality may change before our preliminary release.\n\n## Getting help and getting in touch\n\nWe communicate via several channels on Github:\n\n- To report a bug, open an\n  [issue](https://github.com/flatironinstitute/nemos/issues).\n- To ask usage questions, discuss broad issues, or show off what you\u2019ve made\n  with NeMoS, go to\n  [Discussions](https://github.com/flatironinstitute/nemos/discussions).\n- To send suggestions for extensions or enhancements, please post in the\n  [ideas](https://github.com/flatironinstitute/nemos/discussions/categories/ideas)\n  section of discussions first. We\u2019ll discuss it there and, if we decide to\n  pursue it, open an issue to track progress.\n- To contribute to the project, see the [contributing\n  guide](CONTRIBUTING.md).\n\nIn all cases, we request that you respect our [code of\nconduct](CODE_OF_CONDUCT.md).\n\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 nemos authors  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "NEural MOdelS, a statistical modeling framework for neuroscience.",
    "version": "0.1.6",
    "project_urls": null,
    "split_keywords": [
        "neuroscience",
        " poisson-glm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d592a888b9b2271c6f8b95abf28f9269ffcc79de337e926507b7433aeb8c9ebe",
                "md5": "d667a4128cd32b80681978fef3f6dd03",
                "sha256": "a493eeb464538a0ac4daa95b67b4269b605dadbd51fdcf9592c0206df0291246"
            },
            "downloads": -1,
            "filename": "nemos-0.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d667a4128cd32b80681978fef3f6dd03",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 80329,
            "upload_time": "2024-08-14T11:17:00",
            "upload_time_iso_8601": "2024-08-14T11:17:00.091869Z",
            "url": "https://files.pythonhosted.org/packages/d5/92/a888b9b2271c6f8b95abf28f9269ffcc79de337e926507b7433aeb8c9ebe/nemos-0.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "df96b61440750aa93620f902d68ad1d33f136fcc4bdfa1edfa5bdaadee62600d",
                "md5": "558603584cdaeca9f2c1aaf3a21e0eaa",
                "sha256": "3b84f371c8c44c45280e15b0895dd7ccca7c9f6ec4815a89b6ff921ee2385df8"
            },
            "downloads": -1,
            "filename": "nemos-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "558603584cdaeca9f2c1aaf3a21e0eaa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 1415921,
            "upload_time": "2024-08-14T11:17:01",
            "upload_time_iso_8601": "2024-08-14T11:17:01.514464Z",
            "url": "https://files.pythonhosted.org/packages/df/96/b61440750aa93620f902d68ad1d33f136fcc4bdfa1edfa5bdaadee62600d/nemos-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-14 11:17:01",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nemos"
}
        
Elapsed time: 0.27769s