We propose a Continuous Energy Landscape (CEL) model for analyzing brain state transitions, which replaces discrete Ising-style energy landscapes with a continuous quadratic energy over multivariate neural activity. The energy landscape is parameterized by a graph neural network (GNN) that learns a positive-definite precision matrix from functional connectivity, allowing us to capture smooth, high-dimensional state transitions without binarizing the data.
This repository contains Python code for:
- Fitting the continuous energy landscape (CEL) model on neural time series
- Comparing against a discrete maximum-entropy (Ising) energy landscape (DEL) baseline
- Computing evaluation metrics (BR, TMA, SDA) on simulated SLDS and Kuramoto-BOLD data
- Reproducing key behaviors described in the accompanying paper
The full pipeline of the proposed method, including graph construction, GCN-based precision learning, and energy landscape analysis, is illustrated in the following figure from the paper:
If you use this code, please cite the following paper:
Triet M. Tran, Seyed Majid Razavi, Dee H. Wu, and Sina Khanmohammadi. "Continuous Energy Landscape Model for Analyzing Brain State Transitions." arXiv:2601.06991 (2026)
https://doi.org/10.48550/arXiv.2601.06991.
-
Prerequisites
Make sure you have:
-
Python 3.8 or later
-
Recommended libraries:
numpy scipy scikit-learn torch matplotlib tqdm jupyter
-
-
Clone the repository
git clone https://github.com/3sigmalab/ContinuousEnergyLandscape.git cd ContinuousEnergyLandscape -
Install dependencies
Using
pip(optionally inside a virtualenv or conda environment):pip install -r requirements.txt
A minimal
requirements.txtcould contain:numpy scipy scikit-learn torch torch-geometric matplotlib tqdm jupyter
Adjust the dependency list as needed for your environment.
This repository is organized around three main types of experiments:
- A simple Gaussian example to illustrate CEL fitting
- An SLDS (switching VAR) example comparing CEL vs DEL
- A Kuramoto-BOLD example comparing CEL vs DEL
All examples are provided as Jupyter notebooks in the examples/ directory.
Notebook:
examples/example_continuous_energy_landscape.ipynb
This notebook:
- Generates synthetic Gaussian time series data
- Fits the CEL model using
continuous_energy_landscape.py - Computes energies for each time point
- Prints simple covariance fit metrics
Run with:
jupyter notebook examples/example_continuous_energy_landscape.ipynbThen execute all cells.
Notebook:
examples/example_slds_cel_vs_del.ipynb
This notebook:
- Simulates a switching VAR (SLDS-like) process using
simulations/slds_sim.py - Fits a discrete energy landscape (DEL) on binarized data via
discrete_energy.py - Fits the continuous energy landscape (CEL) model via
continuous_energy_landscape.py - Uses k-means clustering on features from each method to recover discrete states
- Computes BR (basin recovery), TMA (transition matrix agreement), and SDA (state distance alignment) via
metrics_energy_landscape.py
Run with:
jupyter notebook examples/example_slds_cel_vs_del.ipynbNotebook:
examples/example_kuramoto_cel_vs_del.ipynb
This notebook:
- Simulates BOLD-like signals from a Kuramoto + hemodynamic model using
simulations/kuramoto_sim.py - Fits DEL on binarized ROIs (with a modest number of ROIs so exact MEM is tractable)
- Fits CEL on the continuous BOLD signals
- Recovers hidden regimes via k-means clustering
- Evaluates BR, TMA, SDA as in the SLDS example
Run with:
jupyter notebook examples/example_kuramoto_cel_vs_del.ipynbTo fit the CEL model on your own data (time series X of shape (T, D)):
import numpy as np
from continuous_energy_landscape import ContinuousEnergyLandscape
# X: numpy array, shape (T, D)
cel = ContinuousEnergyLandscape(
hidden_channels=64,
rank=32,
delta=0.10,
eps=1e-2,
lambda_reg=1e-2,
lr=1e-3,
weight_decay=0.0,
max_epochs=300,
clip_grad=1.0,
verbose=True,
device="cpu", # or "cuda"
seed=0,
)
out = cel.fit(X)
E = cel.predict_energy(X) # shape (T,)
print("Best training loss:", out["best_loss"])
print("Covariance fit metrics:", out["metrics"])We provide a unified interface for computing basin recovery, transition matrix agreement, and state distance alignment in:
metrics_energy_landscape.py
Example usage:
from metrics_energy_landscape import compute_metrics_all
metrics = compute_metrics_all(
g_true, # true discrete states, shape (T,)
g_hat, # inferred states (from CEL or DEL), shape (T,)
K=K, # number of states
P_true=P_true, # true transition matrix, shape (K, K)
X=X, # time series used for inference, shape (T, D)
)
print(metrics) # {'BR_ARI': ..., 'TMA': ..., 'SDA': ...}- BR (Basin Recovery / ARI) – Adjusted Rand Index between true and inferred discrete states
- TMA (Transition Matrix Agreement) – similarity between Markov transition matrices
- SDA (State Distance Alignment) – correlation between pairwise distances of state centroids
These metrics are used in both the SLDS and Kuramoto examples to compare CEL vs DEL.
A typical repository layout is:
ContinuousEnergyLandscape/
README.md
LICENSE
requirements.txt
continuous_energy_landscape.py # continuous energy + GCN model
discrete_energy.py # Ising / MEM baseline
metrics_energy_landscape.py # BR, TMA, SDA
simulations/
slds_sim.py # SLDS-like switching VAR simulator
kuramoto_sim.py # Kuramoto + hemodynamic BOLD simulator
examples/
example_continuous_energy_landscape.ipynb
example_slds_cel_vs_del.ipynb
example_kuramoto_cel_vs_del.ipynb
figs/
pipeline_GCN_energy_updated.pdf # pipeline figure from the paper
-
continuous_energy_landscape.py
Core CEL model:- GNN parameterization of a positive-definite precision matrix
- Gaussian negative log-likelihood training
- Energy computation
E(x) = 0.5 (x - μ)^T S (x - μ)with μ = S⁻¹h - Methods:
fit,predict_energy,evaluate
-
discrete_energy.py
Discrete maximum-entropy (Ising) baseline:- Binarization utilities
- Exact MEM fitting for modest numbers of ROIs
- Discrete energy time series computation
-
metrics_energy_landscape.py
Evaluation metrics:estimate_transition_matrixbasin_recovery_ari(BR)transition_matrix_agreement(TMA)state_distance_alignment(SDA)compute_metrics_all(wrapper)
-
simulations/slds_sim_simple.py
Minimal switching VAR (SLDS-like) simulator:- Multiple scenarios (e.g., different means, different covariance orientations, nonlinear observations)
- Helper
simulate_slds_examplereturning(sim, X, g_true)
-
simulations/kuramoto_sim_simple.py
Kuramoto + hemodynamic simulator:- Graph-coupled phase dynamics
- Hemodynamic smoothing to generate BOLD-like signals
- Helper
simulate_kuramoto_examplereturning(sim, X_bold, g_true)
-
examples/example_continuous_energy_landscape.ipynb– simple CEL fit on synthetic Gaussian dataexample_slds_cel_vs_del.ipynb– SLDS example, CEL vs DEL, with BR/TMA/SDAexample_kuramoto_cel_vs_del.ipynb– Kuramoto-BOLD example, CEL vs DEL, with BR/TMA/SDA
-
Model hyperparameters
Adjust inContinuousEnergyLandscape:hidden_channels,rank– capacity of the latent GNNdelta– threshold for defining the signed graph from correlationseps– diagonal jitter to keepSpositive-definitelambda_reg– Frobenius regularization forSmax_epochs,lr,weight_decay,clip_grad– training settings
-
Simulation settings
Insimulations/slds_sim_simple.pyandsimulations/kuramoto_sim_simple.py, you can change:- Number of ROIs (
d) - Number of states (
K) - Dwell times, noise levels, coupling strengths
- Scenario types (e.g., nonlinear observations, covariance-only differences)
- Number of ROIs (
-
Metrics & clustering
In the example notebooks, you can:- Replace k-means with any clustering method
- Change the feature set for state inference (e.g., add more features from CEL)
-
Masuda, N., Islam, S., Thu Aung, S., & Watanabe, T.
Energy landscape analysis based on the Ising model: Tutorial review.
PLOS Complex Systems, 2025, 2.5: e0000039. -
Ezaki, T., Watanabe, T., Ohzeki, M., & Masuda, N. Energy landscape analysis of neuroimaging data.
Philosophical Transactions of the Royal Society A: Mathematical, Physical and Engineering Sciences, 375(2096), 20160287.
