nemos


Namenemos JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryNEural MOdelS, a statistical modeling framework for neuroscience.
upload_time2024-04-16 21:11:18
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.
            # nemos 

[![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: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![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). 

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://www.youtube.com/watch?v=NFeGW5ljUoI&t=424s) 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/9b/aa/d408281897b4ae1f7942a1556102e8520cbba1a1d0ea6cc1690e8f7af873/nemos-0.1.2.tar.gz",
    "platform": null,
    "description": "# nemos \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: WIP \u2013 Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)\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\n`nemos` (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\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://www.youtube.com/watch?v=NFeGW5ljUoI&t=424s) 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.2",
    "project_urls": null,
    "split_keywords": [
        "neuroscience",
        " poisson-glm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c50e637b7d286081e7c80224ff4893c7a635a17ef9b15f2b257754513ee6479",
                "md5": "d6c66bc3f1c4e53aa6faeedb0afa6e14",
                "sha256": "544b7c467d105111a76671b34b34a1d5abeb2fda3c3af163ccb95f486f8646c4"
            },
            "downloads": -1,
            "filename": "nemos-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d6c66bc3f1c4e53aa6faeedb0afa6e14",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 65076,
            "upload_time": "2024-04-16T21:11:15",
            "upload_time_iso_8601": "2024-04-16T21:11:15.789530Z",
            "url": "https://files.pythonhosted.org/packages/9c/50/e637b7d286081e7c80224ff4893c7a635a17ef9b15f2b257754513ee6479/nemos-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9baad408281897b4ae1f7942a1556102e8520cbba1a1d0ea6cc1690e8f7af873",
                "md5": "bcbd3b87cd52bcdcf10b0023196df160",
                "sha256": "839a053aab6f23e43ff20528199a84d7e419a30563aa941f62b91d1e91879227"
            },
            "downloads": -1,
            "filename": "nemos-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "bcbd3b87cd52bcdcf10b0023196df160",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 1266567,
            "upload_time": "2024-04-16T21:11:18",
            "upload_time_iso_8601": "2024-04-16T21:11:18.142631Z",
            "url": "https://files.pythonhosted.org/packages/9b/aa/d408281897b4ae1f7942a1556102e8520cbba1a1d0ea6cc1690e8f7af873/nemos-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-16 21:11:18",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nemos"
}
        
Elapsed time: 0.24696s