mtdr
Model-based targeted dimensionality reduction (mTDR) for neural population data, in Python.
mTDR fits trial-by-neuron-by-time activity as a sum of low-rank, time-varying
regression coefficient matrices, one per task variable, and chooses each matrix's rank
by AIC. It handles neurons that were not recorded simultaneously through a per-trial
observation mask. The package provides the estimator mtdr.MTDR (fixed ranks or an AIC
rank search; predict, score, project, decode), data utilities, plots (mtdr.plot,
optional matplotlib) and a ground-truth simulator (mtdr.simulate).
Documentation: https://jyanar.github.io/mtdr/
Installation
pip install mtdr # the core
pip install "mtdr[plot,xarray]" # with the optional extras
The core needs only NumPy and SciPy (Python >= 3.11). The extras are optional:
plot: matplotlib, formtdr.plot;xarray: xarray and pandas, forMTDR.to_xarrayandRankSearchHistory.to_frame.
A worked example is on the documentation's Getting started page.
Credit
mTDR is the method of
- M. C. Aoi, V. Mante & J. W. Pillow (2020). Prefrontal cortex exhibits multidimensional dynamic encoding during decision-making. Nature Neuroscience 23, 1410–1420. https://doi.org/10.1038/s41593-020-0696-5
- M. C. Aoi & J. W. Pillow (2018). Model-based targeted dimensionality reduction for neuronal population data. Advances in Neural Information Processing Systems 31.
This package is a Python port of the authors' MATLAB demo,
pillowlab/mTDRdemo. It is not affiliated
with or endorsed by the authors; the method and the reference implementation are
theirs. If you use it, please cite the papers above as well as this software (see
CITATION.cff).
How this port was developed and checked
The port was planned, implemented, and reviewed over multiple rounds with the help
of Claude Fable 5.1, Opus 5.5, and GPT 6 Astra. The general approach I took was to
implement the algorithm from the 2018 and 2020 papers while also reproducing the
output of the published MATLAB code. The scripts in
tests/fixtures/matlab/
run the MATLAB reference on its two demos and on simulated datasets up to the scale
of the 2020 paper, and save what it computes. Run with MATLAB's starting points and
settings, mtdr reproduces the reference's quantities (rank paths, LLs, coefficient
estimates, etc) within numerical tolerance. Run with the package's own defaults, which
take a slightly different optimization path, each fit must reach a likelihood at least
as good as MATLAB's.
Where the port deliberately departs from the MATLAB code (some defaults, a few fixed
bugs, SciPy's optimizers in place of minFunc), each difference and, where available,
a compatibility option is listed in
docs/differences-from-matlab.md. The model and
its estimation are described in docs/model.md,
with technical appendices for the equations cited by the code.
Development
pip install -e ".[dev]" # the test, lint and docs tools
pre-commit install
ruff check . && ruff format --check .
mypy
pytest --cov=mtdr
mkdocs serve
License
MIT (see LICENSE).
Metadata
Release files for mtdr 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mtdr-0.1.0.tar.gz | 5.5 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mtdr-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.7 MB
Release files / mtdr-0.1.0.tar.gz
| Download URL | mtdr-0.1.0.tar.gz |
|---|---|
| Size | 5.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
da0b497408f80262a3e94eca6d8055550c5e0072a2bdc21dc5d6c9f17cc18a9a
|
|
BLAKE2b-256 checksum How to use checksums |
c577a35fb897f23e01111ce8fd4e6a315bc8ef6915bbe07d18d2ccc109626236
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency logRelease files / mtdr-0.1.0-py3-none-any.whl
| Download URL | mtdr-0.1.0-py3-none-any.whl |
|---|---|
| Size | 134.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a936bb7cda6fba723e81f4221ce60c891687deb45fbe48359f50e0bd308134d6
|
|
BLAKE2b-256 checksum How to use checksums |
20f8c47f1aabdfbfbec2f4cdda1d276edbacc3ba17e123a0f520a243b6684cf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency log