Fit and evaluate models of sensory encoding and decoding.
Project description
NEMS
The Neural Encoding Model System (NEMS) is helpful for fitting a mathematical model to time series data, plotting the model predictions, and comparing the predictive accuracy of multiple models. We use it to develop and test computational models of how sound is encoded in the brains of behaving mammals, but it will work with many different types of timeseries data.
Note: this is a refactor of a former version of NEMS that is now archived at github.com/LBHB/NEMS0. This refactor is still very much a work in progress, and is likely to contain bugs, missing documentation, and a lot of TODOs..
Examples
Build a standard linear-nonlinear spectrotemporal receptive field (LN-STRF) model.
from nems import Model
from nems.layers import FiniteImpulseResponse, DoubleExponential
model = Model()
model.add_layers(
FiniteImpulseResponse(shape=(15, 18)), # 15 taps, 18 spectral channels
DoubleExponential(shape=(1,)) # static nonlinearity, 1 output
)
Or use the customizable keyword system for faster scripting and prototyping.
from nems import Model
same_model = Model.from_keywords('fir.15x18-dexp.1')
Fit the model to (fake) evoked neural activity (in this case, in response to a sound represented by a spectrogram).
import numpy as np
spectrogram = np.random.rand(1000, 18) # 1000 time bins, 18 channels
response = np.random.rand(1000, 1) # 1 neural response
fitted_model = model.fit(spectrogram, response)
Predict the response to a different stimulus.
test_spectrogram = np.random.rand(1000, 18)
prediction = fitted_model.predict(test_spectrogram)
Score the prediction
from nems.metrics import correlation
print(correlation(prediction, response))
# OR
# Still TODO
print(model.score(spectrogram, response, metric='correlation'))
Installation instructions
Recommended: Intall from source.
NEMS is still under rapid development, so this is the best way to ensure you're using the most up-to-date version.
- Download source code
git clone https://github.com/lbhb/nems
- Create a new virtual environment using your preferred environment manager (examples for
condabelow).
conda create -n nems-env python=3.9 pip # manually
# OR (don't do both)
conda env create -f NEMS/environment.yml # or with .yml
- Install in editable mode with optional development tools.
pip install -e NEMS[dev]
- Run tests to ensure proper installation. We recommend repeating this step after making changes to the source code.
pytest NEMS
Alternative: PyPI (pip)
Create a new environment using your preferred environment manager, then use pip install.
conda create -n nems-env python=3.9 pip
pip install PyNEMS
Alternative: Conda
Coming soon.
Note: the mkl library for numpy does not play well with tensorflow.
If using conda to install dependencies manually, and you want to use the tensorflow backend, use conda-forge for numpy (which uses openblas instead of mkl):
conda install -c conda-forge numpy
(See: https://github.com/conda-forge/numpy-feedstock/issues/84)
Upcoming features/updates
Roughly in order of priority:
- Add more Layers from nems0.
-
- Get wc.g and stategain working in TensorFlow.
- Add core pre-processing and scoring from nems0.
- Set up readthedocs.
- Demo data.
- Other core features (like jackknifed fits, cross-validation, etc.).
- Enable Travis build (.travis.yml is already there, but not yet tested).
- Publish through conda install and pip install (and update readme accordingly).
- Backwards-compatibility tools for loading nems0 models.
- Try Numba for Layer.evaluate and cost functions.
- Implement Jax back-end.
- ... (see issues tracker).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PyNEMS-0.0.1.tar.gz.
File metadata
- Download URL: PyNEMS-0.0.1.tar.gz
- Upload date:
- Size: 131.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e14dd11d5d129d545c5f7856fcd3d696a22303b249ae098a8bbbf1d259f5ae0
|
|
| MD5 |
5167a29abbbb350e5716c935ce90b91a
|
|
| BLAKE2b-256 |
5c9e0583247ebfbf8152788c2ded518aa179cbac968a8363375405e6a3cd0960
|
File details
Details for the file PyNEMS-0.0.1-py3-none-any.whl.
File metadata
- Download URL: PyNEMS-0.0.1-py3-none-any.whl
- Upload date:
- Size: 141.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbde6764da8a81cc43801d4ae9b52dc7626cecfa2d2a269422a29ef0d8f200a1
|
|
| MD5 |
70ee3a9d76400cbaa5ad348103f814e8
|
|
| BLAKE2b-256 |
2f82182f88ccf7ea76ccf00ee76679f1924e7fbbb07f893581cf62b5eda1c556
|