Thalamo-Cortical Neural Mass Modelling in Python
A Python implementation of an extended conductance-based thalamo-cortical neural mass model (TCM), designed for computational psychiatry, neuropharmacology, and generative modelling applications.
This package provides:
- A biologically grounded thalamo-cortical neural mass model
- Laplace-domain transfer function computation
- Jacobian and delay handling
- Compatibility with Variational Laplace / Thermodynamic VL
- A clean Python interface for model inversion and simulation
Developed within the Computational Psychiatry & Neuropharmacological Systems (CPNS) Lab. https://cpnslab.com
This model implements an extended canonical thalamo-cortical neural mass architecture inspired by Dynamic Causal Modelling (DCM), predictive coding, and conductance-based population models.
Populations per cortical source:
- Spiny Stellate (L4)
- Superficial Pyramidal (L2/3)
- Superficial Interneurons
- Deep Pyramidal (L5)
- Deep Interneurons
- Thalamic Projection Pyramidal (L6)
- Reticular Thalamus
- Thalamic Relay Cells
Conductances modelled:
- AMPA
- NMDA
- GABA-A
- GABA-B
- Optional M-channel
- Optional H-channel
The implementation supports:
- Linearisation around fixed points
- Laplace-domain spectral predictions
- Cross-spectral density reconstruction
- Delay-aware dynamics
- Parameter estimation via Variational Laplace
Clone the repository:
git clone https://github.com/yourusername/tcm_py.git
cd tcm_pyCreate a virtual environment (recommended):
python -m venv venv
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtMinimal dependencies typically include:
- numpy
- scipy
- matplotlib
tcm_py/
│
├── tcm/
│ ├── tc_hilge2.py
│ ├── single_source_dynamics.py
│ ├── compute_delays.py
│ ├── compute_jacobian.py
│ ├── laplace_transfer_function.py
│
├── inference/
│ ├── fit_variational_laplace_thermo.py
│ ├── fixed_point_solver.py
│
├── examples/
│ ├── test.py
│
├── requirements.txt
└── README.md
from tcm.tc_hilge2 import tc_hilge2
import numpy as np
P = {...}
M = {...}
x = np.zeros(M["n_states"])
u = np.zeros(M["n_inputs"])
dx = tc_hilge2(x, u, P, M)from tcm.laplace_transfer_function import laplace_transfer_function
import numpy as np
w = np.linspace(1, 100, 128)
G = laplace_transfer_function(P, M, w)from inference.fit_variational_laplace_thermo import fit_variational_laplace_thermo
m, V, diagnostics = fit_variational_laplace_thermo(
y,
forward_model,
m0,
S0
)This package is built around generative modelling principles:
Forward model:
y = f(θ) + ε
Variational Laplace approximation:
Gaussian posterior over parameters
Thermodynamic integration:
Robust free energy estimation
The design supports:
- Spectral DCM-style inversion
- Pharmacological perturbation modelling
- Synaptic parameter estimation
- E/I balance inference
- Precision modulation analysis
The model linearises around a steady-state operating point.
If you see:
This typically means:
- Parameter scaling needs adjustment
- Initial state guess is poor
- Conductance values are too extreme
Check:
- Leak conductance (GL)
- Synaptic gains
- External input scaling
This framework is suitable for:
- EEG/MEG spectral modelling
- Dynamic Causal Modelling
- Computational psychiatry
- Neuropharmacology
- Active inference agents (TCM as world model)
- Generative modelling research
Planned extensions:
- Multi-source connectivity matrices
- Empirical Bayes group inversion
- Polyphonic Variational Laplace integration
- Mixture noise models
- Julia interoperability
- GPU acceleration
If you use this code in academic work, please cite and link.
Pull requests welcome.
Please:
- Add docstrings
- Include minimal working examples
- Avoid breaking API without version bump
MIT License