braincoder 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. braincoder-0.7.1/LICENSE +22 -0
  2. braincoder-0.7.1/MANIFEST.in +9 -0
  3. braincoder-0.7.1/PKG-INFO +136 -0
  4. braincoder-0.7.1/README.md +91 -0
  5. braincoder-0.7.1/braincoder/__init__.py +27 -0
  6. braincoder-0.7.1/braincoder/barstimuli.py +569 -0
  7. braincoder-0.7.1/braincoder/data/szinte2024/dm_gazecenter.npz +0 -0
  8. braincoder-0.7.1/braincoder/data/szinte2024/gauss_parameters.tsv +2366 -0
  9. braincoder-0.7.1/braincoder/data/szinte2024/grid_coordinates.tsv +3601 -0
  10. braincoder-0.7.1/braincoder/data/szinte2024/mask-v1_bold.tsv.gz +0 -0
  11. braincoder-0.7.1/braincoder/hrf.py +272 -0
  12. braincoder-0.7.1/braincoder/models/__init__.py +21 -0
  13. braincoder-0.7.1/braincoder/models/base.py +1004 -0
  14. braincoder-0.7.1/braincoder/models/linear.py +100 -0
  15. braincoder-0.7.1/braincoder/models/prf_1d.py +369 -0
  16. braincoder-0.7.1/braincoder/models/prf_2d.py +824 -0
  17. braincoder-0.7.1/braincoder/noise.py +614 -0
  18. braincoder-0.7.1/braincoder/optimize/__init__.py +22 -0
  19. braincoder-0.7.1/braincoder/optimize/bayesian_fitter.py +467 -0
  20. braincoder-0.7.1/braincoder/optimize/gp_prior.py +361 -0
  21. braincoder-0.7.1/braincoder/optimize/parameter_fitter.py +666 -0
  22. braincoder-0.7.1/braincoder/optimize/residual_fitter.py +563 -0
  23. braincoder-0.7.1/braincoder/optimize/stimulus_fitter.py +656 -0
  24. braincoder-0.7.1/braincoder/optimize/weight_fitter.py +112 -0
  25. braincoder-0.7.1/braincoder/stimuli.py +224 -0
  26. braincoder-0.7.1/braincoder/utils/__init__.py +4 -0
  27. braincoder-0.7.1/braincoder/utils/backend.py +533 -0
  28. braincoder-0.7.1/braincoder/utils/calibration.py +186 -0
  29. braincoder-0.7.1/braincoder/utils/cortex.py +141 -0
  30. braincoder-0.7.1/braincoder/utils/data.py +252 -0
  31. braincoder-0.7.1/braincoder/utils/formatting.py +63 -0
  32. braincoder-0.7.1/braincoder/utils/math.py +131 -0
  33. braincoder-0.7.1/braincoder/utils/mcmc.py +114 -0
  34. braincoder-0.7.1/braincoder/utils/stats.py +267 -0
  35. braincoder-0.7.1/braincoder/utils/visualize.py +26 -0
  36. braincoder-0.7.1/braincoder.egg-info/PKG-INFO +136 -0
  37. braincoder-0.7.1/braincoder.egg-info/SOURCES.txt +83 -0
  38. braincoder-0.7.1/braincoder.egg-info/dependency_links.txt +1 -0
  39. braincoder-0.7.1/braincoder.egg-info/requires.txt +30 -0
  40. braincoder-0.7.1/braincoder.egg-info/top_level.txt +1 -0
  41. braincoder-0.7.1/docs/Makefile +20 -0
  42. braincoder-0.7.1/docs/_static/favicon.png +0 -0
  43. braincoder-0.7.1/docs/_static/logo.png +0 -0
  44. braincoder-0.7.1/docs/_static/logo_dark.png +0 -0
  45. braincoder-0.7.1/docs/api_reference.rst +72 -0
  46. braincoder-0.7.1/docs/bibliography.rst +12 -0
  47. braincoder-0.7.1/docs/concepts.rst +89 -0
  48. braincoder-0.7.1/docs/conf.py +81 -0
  49. braincoder-0.7.1/docs/fisher_information.rst +153 -0
  50. braincoder-0.7.1/docs/index.rst +99 -0
  51. braincoder-0.7.1/docs/installation.rst +80 -0
  52. braincoder-0.7.1/docs/make.bat +35 -0
  53. braincoder-0.7.1/docs/migration.rst +82 -0
  54. braincoder-0.7.1/docs/noise_models.rst +242 -0
  55. braincoder-0.7.1/docs/tutorial/index.rst +28 -0
  56. braincoder-0.7.1/docs/tutorial/lesson1.rst +120 -0
  57. braincoder-0.7.1/docs/tutorial/lesson2.rst +105 -0
  58. braincoder-0.7.1/docs/tutorial/lesson3.rst +176 -0
  59. braincoder-0.7.1/docs/tutorial/lesson4.rst +88 -0
  60. braincoder-0.7.1/docs/tutorial/lesson5.rst +199 -0
  61. braincoder-0.7.1/docs/tutorial/lesson6.rst +190 -0
  62. braincoder-0.7.1/docs/tutorial/lesson7.rst +8 -0
  63. braincoder-0.7.1/pyproject.toml +70 -0
  64. braincoder-0.7.1/setup.cfg +4 -0
  65. braincoder-0.7.1/setup.py +7 -0
  66. braincoder-0.7.1/tests/helpers.py +33 -0
  67. braincoder-0.7.1/tests/test_backend_multibackend.py +377 -0
  68. braincoder-0.7.1/tests/test_fisher_information.py +197 -0
  69. braincoder-0.7.1/tests/test_gp_prior.py +361 -0
  70. braincoder-0.7.1/tests/test_hrf.py +135 -0
  71. braincoder-0.7.1/tests/test_hrf_parameter_transforms.py +26 -0
  72. braincoder-0.7.1/tests/test_models.py +372 -0
  73. braincoder-0.7.1/tests/test_models_extended.py +609 -0
  74. braincoder-0.7.1/tests/test_noise_models.py +319 -0
  75. braincoder-0.7.1/tests/test_parameter_fitter_memory.py +72 -0
  76. braincoder-0.7.1/tests/test_parameter_fitter_noise_model.py +130 -0
  77. braincoder-0.7.1/tests/test_residual_fitter_geodesic.py +281 -0
  78. braincoder-0.7.1/tests/test_residual_fitter_robustness.py +324 -0
  79. braincoder-0.7.1/tests/test_rf_normalization.py +53 -0
  80. braincoder-0.7.1/tests/test_safe_cholesky.py +175 -0
  81. braincoder-0.7.1/tests/test_silent_failures.py +247 -0
  82. braincoder-0.7.1/tests/test_stateless.py +162 -0
  83. braincoder-0.7.1/tests/test_stimuli.py +357 -0
  84. braincoder-0.7.1/tests/test_subtract_wt_baseline.py +315 -0
  85. braincoder-0.7.1/tests/test_utils.py +351 -0
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tomas Knapen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,9 @@
1
+ include LICENSE
2
+ include README.md
3
+ recursive-include braincoder/data *
4
+
5
+ recursive-include tests *
6
+ recursive-exclude * __pycache__
7
+ recursive-exclude * *.py[co]
8
+
9
+ recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: braincoder
3
+ Version: 0.7.1
4
+ Summary: Fit encoding models to fMRI data and invert them for Bayesian decoding
5
+ Author: Maike Renkert, Christian C. Ruff, Tomas H. Knapen
6
+ Author-email: Gilles de Hollander <gilles.de.hollander@gmail.com>
7
+ License-Expression: MIT
8
+ Project-URL: Documentation, https://braincoder-devs.github.io/
9
+ Project-URL: Source, https://github.com/Gilles86/braincoder
10
+ Project-URL: Changelog, https://github.com/Gilles86/braincoder/blob/main/CHANGELOG.md
11
+ Keywords: fMRI,encoding models,population receptive field,pRF,Bayesian decoding,neuroimaging
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: numpy
20
+ Requires-Dist: keras>=3.0
21
+ Requires-Dist: matplotlib
22
+ Requires-Dist: seaborn
23
+ Requires-Dist: pandas
24
+ Requires-Dist: pandas_flavor
25
+ Requires-Dist: scipy
26
+ Requires-Dist: scikit-learn
27
+ Requires-Dist: tqdm
28
+ Requires-Dist: patsy
29
+ Provides-Extra: tensorflow
30
+ Requires-Dist: tensorflow>=2.16; extra == "tensorflow"
31
+ Provides-Extra: jax
32
+ Requires-Dist: jax; extra == "jax"
33
+ Provides-Extra: torch
34
+ Requires-Dist: torch; extra == "torch"
35
+ Provides-Extra: test
36
+ Requires-Dist: pytest; extra == "test"
37
+ Provides-Extra: docs
38
+ Requires-Dist: sphinx; extra == "docs"
39
+ Requires-Dist: sphinx-gallery; extra == "docs"
40
+ Requires-Dist: sphinxcontrib-bibtex; extra == "docs"
41
+ Requires-Dist: furo; extra == "docs"
42
+ Requires-Dist: myst-parser; extra == "docs"
43
+ Requires-Dist: ipython; extra == "docs"
44
+ Dynamic: license-file
45
+
46
+ <p align="center">
47
+ <picture>
48
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Gilles86/braincoder/main/docs/_static/logo_dark.png">
49
+ <img src="https://raw.githubusercontent.com/Gilles86/braincoder/main/docs/_static/logo.png" alt="BrainCoder: neural encoding/decoding models" width="360">
50
+ </picture>
51
+ </p>
52
+
53
+ # Braincoder
54
+
55
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10778413.svg)](https://doi.org/10.5281/zenodo.10778413)
56
+
57
+ **Braincoder** is a package to fit encoding models to neural data (for now fMRI) and
58
+ to then *invert* those models to decode stimulus information from neural data. It
59
+ wraps stimulus handling, model definition, HRF convolution, and optimization into a
60
+ single [Keras 3](https://keras.io)-based toolkit that runs on TensorFlow, JAX, or PyTorch.
61
+
62
+ ## Highlights
63
+
64
+ - **Composable models.** Pick from ready-made encoding models (Gaussian PRF, HRF-aware, linear) or subclass `EncodingModel` to implement your own.
65
+ - **End-to-end workflow.** Utilities for simulation, fitting, and decoding stay in pandas/tensor-friendly formats.
66
+ - **Backend-agnostic.** Runs on TensorFlow, JAX, or PyTorch via Keras 3.
67
+
68
+ ## Links
69
+
70
+ - Source code: https://github.com/Gilles86/braincoder
71
+ - Documentation: https://braincoder-devs.github.io/
72
+
73
+ ## Installation
74
+
75
+ ```bash
76
+ pip install "braincoder[tensorflow]" # or [jax], or [torch]
77
+ ```
78
+
79
+ Pin the version in your project's environment, e.g. `braincoder[tensorflow]==0.7.1`, so that its results stay reproducible.
80
+
81
+ For development, use conda/mamba. Clone the repo, then create the environment:
82
+
83
+ ```bash
84
+ git clone https://github.com/Gilles86/braincoder.git
85
+ cd braincoder
86
+ conda env create -f environment.yml
87
+ conda activate braincoder
88
+ ```
89
+
90
+ This installs braincoder in editable mode (`pip install -e .`) along with a TensorFlow backend and dev tools. See the [installation docs](https://braincoder-devs.github.io/installation.html) for other backends (JAX, PyTorch) and pip-only setups.
91
+
92
+ ## Quick start
93
+
94
+ ```python
95
+ import numpy as np
96
+ import pandas as pd
97
+ from braincoder.models import GaussianPRF
98
+
99
+ paradigm = pd.DataFrame({"x": np.linspace(-5, 5, 100)},
100
+ index=pd.Index(np.arange(100), name="time"))
101
+ parameters = pd.DataFrame({"mu": [0.0, 1.0], "sd": [1.0, 2.0], "amplitude": [1.0, 1.0], "baseline": [0.0, 0.0]},
102
+ index=pd.Index(["v1", "v2"], name="voxel"))
103
+
104
+ model = GaussianPRF()
105
+ predicted = model.predict(paradigm=paradigm, parameters=parameters)
106
+ ```
107
+
108
+ See the [tutorials](https://braincoder-devs.github.io/tutorial/index.html) for full fitting and decoding pipelines.
109
+
110
+ ## Using an AI coding assistant
111
+
112
+ The [braincoder skill for Claude Code](https://github.com/Gilles86/gilles-claude-skills/tree/main/skills/braincoder) gives an assistant a step-by-step manual for new projects, the common silent errors, and measured runtimes. It is also readable on its own. Install it with:
113
+
114
+ ```bash
115
+ git clone https://github.com/Gilles86/gilles-claude-skills.git
116
+ ln -s "$PWD/gilles-claude-skills/skills/braincoder" ~/.claude/skills/braincoder
117
+ ```
118
+
119
+ ## Related software
120
+
121
+ [prfmodel](https://popylar-org.github.io/prfmodel/) is a Python package for population receptive field modelling, also built on Keras 3. It covers further pRF models, such as CSS, delayed normalization and connective fields.
122
+
123
+ ## How to cite
124
+
125
+ de Hollander, G., Renkert, M., Ruff, C. C., & Knapen, T. H. (2024). *Braincoder: A package for fitting encoding models to neural data and decoding stimulus features*. Zenodo. DOI: [10.5281/zenodo.10778413](https://doi.org/10.5281/zenodo.10778413).
126
+
127
+ ```bibtex
128
+ @software{deHollander2024braincoder,
129
+ author = {Gilles de Hollander and Maike Renkert and Christian C. Ruff and Tomas H. Knapen},
130
+ title = {braincoder: A package for fitting encoding models to neural data and decoding stimulus features},
131
+ year = {2024},
132
+ publisher = {Zenodo},
133
+ doi = {10.5281/zenodo.10778413},
134
+ url = {https://github.com/Gilles86/braincoder}
135
+ }
136
+ ```
@@ -0,0 +1,91 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Gilles86/braincoder/main/docs/_static/logo_dark.png">
4
+ <img src="https://raw.githubusercontent.com/Gilles86/braincoder/main/docs/_static/logo.png" alt="BrainCoder: neural encoding/decoding models" width="360">
5
+ </picture>
6
+ </p>
7
+
8
+ # Braincoder
9
+
10
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10778413.svg)](https://doi.org/10.5281/zenodo.10778413)
11
+
12
+ **Braincoder** is a package to fit encoding models to neural data (for now fMRI) and
13
+ to then *invert* those models to decode stimulus information from neural data. It
14
+ wraps stimulus handling, model definition, HRF convolution, and optimization into a
15
+ single [Keras 3](https://keras.io)-based toolkit that runs on TensorFlow, JAX, or PyTorch.
16
+
17
+ ## Highlights
18
+
19
+ - **Composable models.** Pick from ready-made encoding models (Gaussian PRF, HRF-aware, linear) or subclass `EncodingModel` to implement your own.
20
+ - **End-to-end workflow.** Utilities for simulation, fitting, and decoding stay in pandas/tensor-friendly formats.
21
+ - **Backend-agnostic.** Runs on TensorFlow, JAX, or PyTorch via Keras 3.
22
+
23
+ ## Links
24
+
25
+ - Source code: https://github.com/Gilles86/braincoder
26
+ - Documentation: https://braincoder-devs.github.io/
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install "braincoder[tensorflow]" # or [jax], or [torch]
32
+ ```
33
+
34
+ Pin the version in your project's environment, e.g. `braincoder[tensorflow]==0.7.1`, so that its results stay reproducible.
35
+
36
+ For development, use conda/mamba. Clone the repo, then create the environment:
37
+
38
+ ```bash
39
+ git clone https://github.com/Gilles86/braincoder.git
40
+ cd braincoder
41
+ conda env create -f environment.yml
42
+ conda activate braincoder
43
+ ```
44
+
45
+ This installs braincoder in editable mode (`pip install -e .`) along with a TensorFlow backend and dev tools. See the [installation docs](https://braincoder-devs.github.io/installation.html) for other backends (JAX, PyTorch) and pip-only setups.
46
+
47
+ ## Quick start
48
+
49
+ ```python
50
+ import numpy as np
51
+ import pandas as pd
52
+ from braincoder.models import GaussianPRF
53
+
54
+ paradigm = pd.DataFrame({"x": np.linspace(-5, 5, 100)},
55
+ index=pd.Index(np.arange(100), name="time"))
56
+ parameters = pd.DataFrame({"mu": [0.0, 1.0], "sd": [1.0, 2.0], "amplitude": [1.0, 1.0], "baseline": [0.0, 0.0]},
57
+ index=pd.Index(["v1", "v2"], name="voxel"))
58
+
59
+ model = GaussianPRF()
60
+ predicted = model.predict(paradigm=paradigm, parameters=parameters)
61
+ ```
62
+
63
+ See the [tutorials](https://braincoder-devs.github.io/tutorial/index.html) for full fitting and decoding pipelines.
64
+
65
+ ## Using an AI coding assistant
66
+
67
+ The [braincoder skill for Claude Code](https://github.com/Gilles86/gilles-claude-skills/tree/main/skills/braincoder) gives an assistant a step-by-step manual for new projects, the common silent errors, and measured runtimes. It is also readable on its own. Install it with:
68
+
69
+ ```bash
70
+ git clone https://github.com/Gilles86/gilles-claude-skills.git
71
+ ln -s "$PWD/gilles-claude-skills/skills/braincoder" ~/.claude/skills/braincoder
72
+ ```
73
+
74
+ ## Related software
75
+
76
+ [prfmodel](https://popylar-org.github.io/prfmodel/) is a Python package for population receptive field modelling, also built on Keras 3. It covers further pRF models, such as CSS, delayed normalization and connective fields.
77
+
78
+ ## How to cite
79
+
80
+ de Hollander, G., Renkert, M., Ruff, C. C., & Knapen, T. H. (2024). *Braincoder: A package for fitting encoding models to neural data and decoding stimulus features*. Zenodo. DOI: [10.5281/zenodo.10778413](https://doi.org/10.5281/zenodo.10778413).
81
+
82
+ ```bibtex
83
+ @software{deHollander2024braincoder,
84
+ author = {Gilles de Hollander and Maike Renkert and Christian C. Ruff and Tomas H. Knapen},
85
+ title = {braincoder: A package for fitting encoding models to neural data and decoding stimulus features},
86
+ year = {2024},
87
+ publisher = {Zenodo},
88
+ doi = {10.5281/zenodo.10778413},
89
+ url = {https://github.com/Gilles86/braincoder}
90
+ }
91
+ ```
@@ -0,0 +1,27 @@
1
+ """Top-level package for braincoder."""
2
+
3
+ __author__ = """Gilles de Hollander"""
4
+ __email__ = 'gilles.de.hollander@gmail.com'
5
+ __version__ = '0.7.1'
6
+
7
+ from .models import (
8
+ EncodingModel, EncodingRegressionModel, HRFEncodingModel,
9
+ GaussianPRF, RegressionGaussianPRF, VonMisesPRF, AxialVonMisesPRF, LogGaussianPRF,
10
+ GaussianPRFWithHRF, LogGaussianPRFWithHRF, AlphaGaussianPRF,
11
+ RegressionAlphaGaussianPRF, GaussianPRFOnGaussianSignal,
12
+ GaussianPointPRF2D, GaussianMixturePRF2D, GaussianPRF2D,
13
+ GaussianPRF2DAngle, GaussianPRF2DWithHRF, GaussianPRF2DAngleWithHRF,
14
+ DifferenceOfGaussiansPRF2D, DifferenceOfGaussiansPRF2DWithHRF,
15
+ DivisiveNormalizationGaussianPRF2D, DivisiveNormalizationGaussianPRF2DWithHRF,
16
+ DiscreteModel, LinearModel, LinearModelWithBaseline, LinearModelWithBaselineHRF,
17
+ )
18
+ from .optimize import WeightFitter, ParameterFitter, ResidualFitter
19
+ from . import noise
20
+ from .noise import LowRankNoise
21
+ try:
22
+ from .optimize import (
23
+ StimulusFitter, CustomStimulusFitter,
24
+ SzinteStimulus, SzinteStimulus2, make_aperture_stimuli,
25
+ )
26
+ except ImportError:
27
+ pass