# neuropop
analysis tools for large-scale neural recordings
Copyright (C) 2023 Howard Hughes Medical Institute Janelia Research Campus, the labs of Carsen Stringer and Marius Pachitariu
**This code is licensed under GPL v3 (no redistribution without credit, and no redistribution in private repos, see [license](LICENSE) for more details).**
## references
[[1]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6642054/) Stringer, C.\*, Pachitariu, M.\*, Steinmetz, N., Carandini, M., & Harris, K. D. (2019). High-dimensional geometry of population responses in visual cortex. *Nature, 571*(7765), 361-365.
[[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/) Stringer, C.\*, Pachitariu, M.\*, Steinmetz, N., Reddy, C. B., Carandini, M., & Harris, K. D. (2019). Spontaneous behaviors drive multidimensional, brainwide activity. *Science, 364*(6437), eaav7893.
[[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1) Syeda, A., Zhong, L., Tung, R., Long, W., Pachitariu, M.\*, & Stringer, C.\* (2022). Facemap: a framework for modeling neural activity based on orofacial tracking. *bioRxiv*.
## [dimensionality.py](neuropop/dimensionality.py)
This module contains code for dimensionality estimation methods for neural data:
* Cross-validated PCA (described in [[1]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6642054/)) is for estimating the dimensionality of neural stimulus responses where each stimulus is shown at least twice. Divide your data into two repeats -- a matrix of 2 x stimuli x neurons, and input it into the function `cvPCA` to obtain the cross-validated eigenspectrum. Note that each repeat can be the average of several stimulus responses (e.g. 5-10 each). You can then use the `get_powerlaw` function to estimate the exponent of the decay of the eigenspectrum. If you use these functions please cite [[1]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6642054/).
<img src="figures/cvPCA.PNG" width="600" />
* Shared variance components analysis (described in [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/)) is for estimating the dimensionality of neural activity that is shared across neurons (excluding single neuron variability). This method divides the neurons in half and the timepoints in half into training and testing. Then it computes the principal components of the covariance between the two neural halves on the training timepoints, and then computing the variance of those components on the testing timepoints. Take your neural data as a matrix of neurons x time and input it into the function `SVCA` to obtain the variance of each component of the covariance matrix on the test set `scov` (this had a powerlaw decay of ~1.1 in [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/)). The function also returns the average variance of each component in each neural half `varcov`. If you use this function please cite [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/).
<img src="figures/SVCA.PNG" width="200" />
## [peer_prediction.py](neuropop/peer_prediction.py)
Prediction of one half of neurons from the other half of neurons, in order to estimate an upper bound for the amount of predictable variance in the neural population. If you use this function, please cite [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/).
## [linear_prediction.py](neuropop/linear_prediction.py)
This module contains code for ridge regression and regularized reduced rank regression, particularly for predicting from behavior to neural activity. The main function is `prediction_wrapper`, if `rank` is None then ridge regression is performed, otherwise reduced rank regression is performed. This function assumes you have pytorch with GPU support, otherwise set `device=torch.device('cpu')`. CCA is also implemented without GPU support. If you use these functions please cite [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/).
## [nn_prediction.py](neuropop/nn_prediction.py)
This module contains code for non-linear prediction of neural activity from behavior, as described in [[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1). The main function is `network_wrapper`, this function assumes you have pytorch with GPU support, otherwise set `device=torch.device('cpu')`, and it also assumes you have taken the principal components of the data `U`, e.g.:
```
# z-score neural activity
spks -= spks.mean(axis=1)[:, np.newaxis]
std = ((spks**2).mean(axis=1) ** 0.5)[:, np.newaxis]
std[std == 0] = 1
spks /= std
# compute principal components
from sklearn.decomposition import PCA
Y = PCA(n_components=128).fit_transform(spks.T)
U = spks @ Y
U /= (U**2).sum(axis=0) ** 0.5
# predict Y from behavior variables x (z-score x if using keypoints)
# tcam are camera/behavior timestamps, tneural are neural timestamps
varexp, varexp_neurons, spks_pred_test0, itest, model = network_wrapper(x, Y, tcam, tneural, U, spks, delay=-1, verbose=True)
```
If you use these functions please cite [[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1).
<img src="figures/nn_prediction.PNG" width="600" />
## [future_prediction.py](neuropop/future_prediction.py)
This contains functions for predicting behavioral or neural variables into the future using ridge regression with exponential basis functions (see Figure 1 in [[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1)). If you use these functions please cite [[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1).
## requirements
This package relies on the following excellent packages (recommended to cite these in your work as well if you use them):
* numpy
* scipy
* scikit-learn
* pytorch
Raw data
{
"_id": null,
"home_page": "https://github.com/MouseLand/neuropop",
"name": "neuropop",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Marius Pachitariu and Carsen Stringer",
"author_email": "stringerc@janelia.hhmi.org",
"download_url": "https://files.pythonhosted.org/packages/f3/7f/22b7aa12f7f44ef1c768dc3478380f19cfd2c45c3e3d27ee39d0f8809da2/neuropop-1.0.1.tar.gz",
"platform": null,
"description": "# neuropop\nanalysis tools for large-scale neural recordings\n\nCopyright (C) 2023 Howard Hughes Medical Institute Janelia Research Campus, the labs of Carsen Stringer and Marius Pachitariu\n\n**This code is licensed under GPL v3 (no redistribution without credit, and no redistribution in private repos, see [license](LICENSE) for more details).**\n\n## references\n\n[[1]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6642054/) Stringer, C.\\*, Pachitariu, M.\\*, Steinmetz, N., Carandini, M., & Harris, K. D. (2019). High-dimensional geometry of population responses in visual cortex. *Nature, 571*(7765), 361-365.\n\n[[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/) Stringer, C.\\*, Pachitariu, M.\\*, Steinmetz, N., Reddy, C. B., Carandini, M., & Harris, K. D. (2019). Spontaneous behaviors drive multidimensional, brainwide activity. *Science, 364*(6437), eaav7893.\n\n[[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1) Syeda, A., Zhong, L., Tung, R., Long, W., Pachitariu, M.\\*, & Stringer, C.\\* (2022). Facemap: a framework for modeling neural activity based on orofacial tracking. *bioRxiv*.\n\n\n## [dimensionality.py](neuropop/dimensionality.py)\n\nThis module contains code for dimensionality estimation methods for neural data:\n\n* Cross-validated PCA (described in [[1]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6642054/)) is for estimating the dimensionality of neural stimulus responses where each stimulus is shown at least twice. Divide your data into two repeats -- a matrix of 2 x stimuli x neurons, and input it into the function `cvPCA` to obtain the cross-validated eigenspectrum. Note that each repeat can be the average of several stimulus responses (e.g. 5-10 each). You can then use the `get_powerlaw` function to estimate the exponent of the decay of the eigenspectrum. If you use these functions please cite [[1]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6642054/).\n<img src=\"figures/cvPCA.PNG\" width=\"600\" />\n\n* Shared variance components analysis (described in [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/)) is for estimating the dimensionality of neural activity that is shared across neurons (excluding single neuron variability). This method divides the neurons in half and the timepoints in half into training and testing. Then it computes the principal components of the covariance between the two neural halves on the training timepoints, and then computing the variance of those components on the testing timepoints. Take your neural data as a matrix of neurons x time and input it into the function `SVCA` to obtain the variance of each component of the covariance matrix on the test set `scov` (this had a powerlaw decay of ~1.1 in [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/)). The function also returns the average variance of each component in each neural half `varcov`. If you use this function please cite [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/).\n<img src=\"figures/SVCA.PNG\" width=\"200\" />\n\n\n## [peer_prediction.py](neuropop/peer_prediction.py)\n\nPrediction of one half of neurons from the other half of neurons, in order to estimate an upper bound for the amount of predictable variance in the neural population. If you use this function, please cite [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/).\n\n## [linear_prediction.py](neuropop/linear_prediction.py)\n\nThis module contains code for ridge regression and regularized reduced rank regression, particularly for predicting from behavior to neural activity. The main function is `prediction_wrapper`, if `rank` is None then ridge regression is performed, otherwise reduced rank regression is performed. This function assumes you have pytorch with GPU support, otherwise set `device=torch.device('cpu')`. CCA is also implemented without GPU support. If you use these functions please cite [[2]](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6525101/).\n\n## [nn_prediction.py](neuropop/nn_prediction.py)\n\nThis module contains code for non-linear prediction of neural activity from behavior, as described in [[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1). The main function is `network_wrapper`, this function assumes you have pytorch with GPU support, otherwise set `device=torch.device('cpu')`, and it also assumes you have taken the principal components of the data `U`, e.g.:\n\n```\n# z-score neural activity\nspks -= spks.mean(axis=1)[:, np.newaxis]\nstd = ((spks**2).mean(axis=1) ** 0.5)[:, np.newaxis]\nstd[std == 0] = 1\nspks /= std\n\n# compute principal components\nfrom sklearn.decomposition import PCA\nY = PCA(n_components=128).fit_transform(spks.T)\nU = spks @ Y\nU /= (U**2).sum(axis=0) ** 0.5\n\n# predict Y from behavior variables x (z-score x if using keypoints)\n# tcam are camera/behavior timestamps, tneural are neural timestamps\nvarexp, varexp_neurons, spks_pred_test0, itest, model = network_wrapper(x, Y, tcam, tneural, U, spks, delay=-1, verbose=True)\n```\n\nIf you use these functions please cite [[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1).\n\n<img src=\"figures/nn_prediction.PNG\" width=\"600\" />\n\n## [future_prediction.py](neuropop/future_prediction.py)\n\nThis contains functions for predicting behavioral or neural variables into the future using ridge regression with exponential basis functions (see Figure 1 in [[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1)). If you use these functions please cite [[3]](https://www.biorxiv.org/content/10.1101/2022.11.03.515121v1).\n\n## requirements\n\nThis package relies on the following excellent packages (recommended to cite these in your work as well if you use them):\n* numpy\n* scipy\n* scikit-learn\n* pytorch\n",
"bugtrack_url": null,
"license": "",
"summary": "analysis tools for neural population recordings",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/MouseLand/neuropop"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f0e68edadf71005bdb82f57630f460cf6aaa63a1267de19d6dfcfd228dccf731",
"md5": "9319445859b71e9346f04f74b7a25b95",
"sha256": "34ec58ff109fdc4143b6218fb8f96f7a4016d18bbb059735a190d87e252ee042"
},
"downloads": -1,
"filename": "neuropop-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9319445859b71e9346f04f74b7a25b95",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 32734,
"upload_time": "2023-07-16T02:07:20",
"upload_time_iso_8601": "2023-07-16T02:07:20.582118Z",
"url": "https://files.pythonhosted.org/packages/f0/e6/8edadf71005bdb82f57630f460cf6aaa63a1267de19d6dfcfd228dccf731/neuropop-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f37f22b7aa12f7f44ef1c768dc3478380f19cfd2c45c3e3d27ee39d0f8809da2",
"md5": "305721e4d5a892b5c768ca6f4120b740",
"sha256": "66db0f82a6821a984a5f4806a0309b2f5aa06d120079afa30aa9fd3d2fe3d08c"
},
"downloads": -1,
"filename": "neuropop-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "305721e4d5a892b5c768ca6f4120b740",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 562133,
"upload_time": "2023-07-16T02:07:22",
"upload_time_iso_8601": "2023-07-16T02:07:22.152713Z",
"url": "https://files.pythonhosted.org/packages/f3/7f/22b7aa12f7f44ef1c768dc3478380f19cfd2c45c3e3d27ee39d0f8809da2/neuropop-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-16 02:07:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MouseLand",
"github_project": "neuropop",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "neuropop"
}