Author: Alexander D. Shaw
Lab: Computational Psychiatry & Neuropharmacological Systems (CPNS), University of Exeter
Website: https://cpnslab.com
This repository contains a research-grade MATLAB toolkit for Variational Laplace (VL) inference in nonlinear dynamical systems, with a particular focus on thermodynamic integration, low-rank and heteroscedastic noise models, hierarchical (PEB-style) inference, generalised coordinates, and active / polyphonic extensions.
The codebase reflects an experimental and methodological platform rather than a single “library-style” package. Many files represent alternative formulations, ablation studies, and exploratory variants used in ongoing research on Dynamic Causal Modelling (DCM), thalamo-cortical neural mass models, computational psychiatry, and neuro-inspired AI / active inference.
At its core, this repository implements and extends Variational Laplace as a practical inference scheme for models of the form:
[ y = f(m, u, M) + e, \quad e \sim \mathcal{N}(0, \Sigma(\theta)) ]
where:
- ( m ) are latent parameters or states
- ( f(\cdot) ) is a nonlinear forward / generative model
- ( \Sigma ) may be structured, low-rank, heteroscedastic, or learned online
Key research directions represented here:
-
Thermodynamic Variational Laplace (TherMO-VL)
Annealed free energy optimisation using temperature schedules to improve convergence and reduce local minima. -
Low-rank & structured noise models
Efficient covariance representations for high-dimensional observations and spectral data. -
Generalised Coordinates (VL-GC)
State-space inference in generalised coordinates of motion for dynamic systems and DCM-style models. -
Hierarchical & Empirical Bayes (PEB / ARD)
Group-level shrinkage, automatic relevance determination, and parameter field inference. -
Active / Expected Free Energy variants
Extensions toward control, policy selection, and closed-loop inference. -
Polyphonic Inference
Multi-voice, non-dominating posterior representations for multimodal and non-Gaussian posteriors. -
Riemannian & geometric updates
Metric-aware natural gradient style updates for improved optimisation stability.
-
fitVariationalLaplace.m
Baseline Variational Laplace implementation. -
fitVariationalLaplaceThermo.m
Thermodynamic / annealed VL with temperature scheduling. -
fitVariationalLaplaceThermoFE.m
Free-energy–driven variant with explicit FE tracking. -
fitVariationalLaplaceThermoStable.m
Stability-enhanced version with safeguarded updates. -
fitVariationalLaplaceThermoStruct.m
Structured covariance and model-aware noise updates.
fitVariationalLaplaceThermo_GC.mfitVariationalLaplaceThermo_GClam.mdcm_vl_gc.m,dcm_vl_gc_time.m
VL in generalised coordinates for state-space and DCM-style inference.
See:
VL_in_GeneralisedCoordinates.pdfVL_in_GC_new.pdf
fitHierarchicalVL.mWrapper_AlogLikeDCM_fitHierarchicalVL.m
Group-level parameter field inference with automatic relevance determination:
demo_peb_ard.mpeb_ard_novar.mpeb_ard_predict.mpeb_plot_betas.mpeb_plot_beta_densities.mpeb_plot_lambda.m
Includes examples, cross-validation, and shrinkage visualisation tools.
-
fitVL_LowRankNoise.m,fitVL_LowRankNoise2.m
Low-rank and structured observation noise models. -
fitVariationalLaplaceThermoRadialPrecision.m
Radial / precision-field updates. -
fitLogLikelihoodLM.m,fitLogLikelihoodLMFE.m
Likelihood-based fitting and free-energy variants.
Located in polyphonic/
-
fitVariationalLaplaceThermoPolyphonic.m
Multi-voice VL where several coupled Gaussian posteriors coexist and are softly aligned by predictive agreement rather than collapsed into a single mode. -
plotPolyphonicPosterior.m
Visualisation of multimodal and non-unimodal posterior structure.
This is experimental and intended for research into pluralistic inference and non-dominating integration.
-
fitVariationalLaplaceThermo_active.m
Extension toward expected free energy minimisation and action selection. -
fitDEM_ThermoVL.m
DEM-style state and parameter inference under thermodynamic VL.
Located in riemannian/
fitVariationalLaplaceThermo_Riemannian.mdefaultMetricDiagonalH.m
Metric-aware update rules inspired by natural gradients and information geometry.
-
aFitDCM.m
Wrapper for fitting DCM / neural mass models using ThermoVL backends. -
condFIM.m
Conditional Fisher Information Matrix utilities. -
propose_deltaF_ranked.m
Model comparison and ranked free-energy perturbations. -
dip/
Hybrid optimisation and MOGA-based parameter search for dynamical inversion problems.
Located in:
dem_test/test_fun/
Includes toy systems, nonlinear oscillators, bi-exponential delays, sigmoid shifts, and hierarchical test cases for validating inference behaviour.
-
thermoVL_equations.pdf
Formal derivation of thermodynamic VL and annealed free energy updates. -
Extending_Variational_Laplace_for_Hierarchical_Model_Fitting__Innovations_in_fitVLLowRankNoise_3.pdf
Low-rank noise, hierarchical inference, and empirical Bayes extensions.
Write a MATLAB function:
function yhat = f(m, M, U)
% m : parameter vector
% M : model structure
% U : inputs
% yhat : predicted observations
endm0 = prior_mean;
S0 = prior_covariance;OPT.Tschedule = linspace(2.0, 1.0, 16);
OUT = fitVariationalLaplaceThermo(y, @f, m0, S0, OPT);- Posterior means / covariances:
OUT.m,OUT.S - Free energy trajectory:
OUT.F - Predictions:
OUT.yhat
This toolkit underpins ongoing work in:
- Computational psychiatry (M/EEG, pharmacological modelling, synaptic inference)
- Thalamo-cortical and neural mass modelling
- Predictive coding and active inference
- Free energy methods for adaptive and neuro-inspired AI
- Hierarchical Bayesian modelling in clinical and translational neuroscience
Several components directly support work described in:
Shaw, A.D. Polyphonic Intelligence: Constraint-Based Emergence, Pluralistic Inference, and Non-Dominating Integration
and related manuscripts on thermodynamic variational inference, predictive coding, and mechanistic AI.
This is a living research repository. Code quality, interfaces, and naming conventions reflect an evolving experimental platform rather than a polished software release.
Expect:
- Multiple overlapping implementations
- Partially documented experimental variants
- Research-grade performance rather than production-grade APIs
If you are looking for a clean entry point, start with:
fitVariationalLaplaceThermo.maFitDCM.mdemo_peb_ard.m
If you use this code in academic work, please the github.
Alexander D. Shaw
Senior Lecturer in Neuroscience & Computational Psychiatry
University of Exeter
https://cpnslab.com
This repository is released for academic and research use. Please see the project’s license file or contact the author for commercial usage and collaboration.