Graph Neural Networks Recover Interpretable Circuit Models from Neural Activity
Cédric Allier1, Janne K. Lappalainen2, Stephan Saalfeld1
1Janelia Research Campus, Howard Hughes Medical Institute, Ashburn, VA 20147, USA 2Allen Institute, Seattle
Synapse-level connectomes describe the structure of circuits, but not the electrical and chemical dynamics. Conversely, large-scale recordings of neural activity capture these dynamics, but not the circuit structure. We asked whether combining binary connectivity and recorded neural activity can be used to infer mechanistic models of neural circuits. We trained a graph neural network (GNN) [6] (neural-gnn) to forecast the activity of Drosophila visual system simulations. Trained on activity trajectories in response to visual inputs, the model recovered effective connectivity weights, neuron types, and nonlinear activation functions. Moreover, it correctly predicted causal effects of connection removal, demonstrating the ability to infer mechanistic dependencies. Our simple, flexible, and interpretable method recovered both structure and dynamics from neural activity.
Simulation
We simulated neural activity in the Drosophila visual system using flyvis’ pretrained models [1] (Notebook 00). The recurrent neural network contained \(13{,}741\) neurons from \(65\) cell types and \(434{,}122\) synaptic connections, corresponding to real neurons and their synapses. Each neuron was modeled as a non-spiking compartment governed by
\[\tau_i\frac{dv_i(t)}{dt} = -v_i(t) + V_i^{\text{rest}} + \sum_{j\in\mathcal{N}_i} \mathbf{W}_{ij}\,\text{ReLU}\!\big(v_j(t)\big) + I_i(t) + \sigma\,\xi_i(t)\]
where \(\tau_i\) and \(V_i^{\text{rest}}\) are cell-type parameters, \(\mathbf{W}_{ij}\) is the connectome-constrained synaptic weight, \(I_i(t)\) the visual input, and \(\sigma\,\xi_i(t)\) is intrinsic noise (\(\xi_i \sim \mathcal{N}(0,1)\)) modeling e.g. channel noise or synaptic variability. We restricted the original system of \(721\) retinotopic columns to the central subset of \(217\) columns.
Graph neural network model
We approximated the simulated voltage dynamics by a message-passing GNN [2] (Notebook 01)
\[\frac{\widehat{dv}_i(t)}{dt} = f_\theta\!\left(v_i(t),\,\mathbf{a}_i,\,\sum_{j\in\mathcal{N}_i} \widehat{\mathbf{W}}_{ij}\,g_\phi\!\big(v_j(t),\,\mathbf{a}_j\big)^2,\,I_i(t)\right)\]
Nodes of the GNN corresponded to neurons and edges to functional synaptic connections. The GNN learned a latent embedding \(\mathbf{a}_i \in \mathbb{R}^2\) for each neuron \(i\), giving each neuron a compact latent identity to capture cell-type specific properties (like time constants and nonlinearities). Neuron update \(f_\theta = \text{MLP}_0\) and edge message \(g_\phi = \text{MLP}_1\) are three-layer perceptrons (width \(64\), ReLU, linear output). \(g_\phi\) mapped presynaptic inputs \(v_j\) to nonnegative messages (via squaring) depending on neural embedding \(\mathbf{a}_j\), which are weighted by \(\widehat{\mathbf{W}}_{ij}\). \(f_\theta\) processed the postsynaptic voltage \(v_i\), aggregated input, and external input \(I_i(t)\) to predict \(\widehat{dv}_i(t)/dt\), depending on neural embedding \(\mathbf{a}_i\). During training, inputs \(I_i(t)\), adjacency \(\mathcal{N}_i\), and activity \(v_i(t)\) are given. The MLPs, \(\widehat{\mathbf{W}}_{ij}\), and \(\mathbf{a}_i\) are optimized by minimizing \(\mathcal{L}_{\text{pred}} = \sum_{i,t} \| \widehat{y}_i(t) - y_i(t) \|_2\) between simulator \(y_i(t) = dv_i(t)/dt\) and GNN predictions \(\widehat{y}_i(t) = \widehat{dv}_i(t)/dt\). The objective was augmented with sparsity, monotonicity, and normalization regularizers (Notebook 01). By replacing the known stimulus \(I_i(t)\) with a SIREN implicit neural representation that maps coordinates \((t, x, y)\) to the stimulus field, we further learned the visual input itself (Notebook 05).
Experiments
We trained and evaluated across three intrinsic noise regimes: deterministic (\(\sigma=0\)), low (\(\sigma=0.05\)), and high (\(\sigma=0.5\)). Each model was tested on held-out visual stimuli. Models were also evaluated on noise-free test data to verify that they recovered the deterministic dynamics (Notebook 02). We probed causal invariance by pruning 50% of the connections in a new simulation, asking whether a GNN trained on the original network could predict the outcome of such structural perturbation (Notebook 03). Post-training analysis (Notebook 04) showed that the GNN recovered the \(434{,}122\) synaptic weights \(W_{ij}\), the time constants \(\tau_i\) and resting potentials \(V_i^{\text{rest}}\) and the neuron-type identity (the latent embeddings \(\mathbf{a}_i\) cluster by cell type without supervision). Noise proved a stronger lever than any single hyperparameter: at \(\sigma=0.5\) the GNN achieved near-perfect recovery (\(R^2_W=0.99\), \(R^2_\tau=1.00\), \(R^2_{V^{\text{rest}}}=0.98\), clustering accuracy \(=0.91\)). When the SIREN replaced the known stimulus, the joint GNN+SIREN model recovered the visual input sequence (\({\sim}10^8\) values, Notebook 05). To test robustness to false positives in the connectome, we augmented the adjacency matrix with 100%, 200%, and 400% extra random null edges and showed that the GNN still recovers the true synaptic structure (Notebook 06). Conversely, to test robustness to false negatives, we removed 2%, 5%, 10%, and 20% of edges from the connectome and evaluated recovery on the incomplete graph (Notebook 07).
Agentic hyper-parameter optimization
The inverse problem is ill-posed: recovering five coupled components (\(\widehat{W}\), \(\tau\), \(V^{\text{rest}}\), \(f_\theta\), \(g_\phi\)) from voltage traces alone is under-determined, and many parameter combinations produce indistinguishable predictions. The combined space of architecture, regularization, and training hyperparameters (~20 coupled parameters) is too large to explore exhaustively. We optimized these hyperparameters with Claude Code in the loop (Notebook 08). In each iteration, the agent interpreted, compared, and summarized previous experiments into a structured research summary, then created, recorded, and executed a hypothesis for the next experiment. The target was both recovery precision (how accurately the GNN recovers the true circuit parameters) and identifiability (how consistently it does so across different random seeds).
References
[1] J. K. Lappalainen et al., “Connectome-constrained networks predict neural activity across the fly visual system,” Nature, 2024. doi:10.1038/s41586-024-07939-3
[2] J. Gilmer et al., “Neural Message Passing for Quantum Chemistry,” 2017. doi:10.48550/arXiv.1704.01212
[3] L. Mi et al., “Connectome-constrained Latent Variable Model of Whole-Brain Neural Activity,” ICLR, 2021.
[4] D. A. Pospisil et al., “The fly connectome reveals a path to the effectome,” Nature 634, 2024. doi:10.1038/s41586-024-07982-0
[5] E. Y. Wang et al., “Foundation model of neural activity predicts response to new stimulus types,” Nature 640, 2025. doi:10.1038/s41586-025-08829-y
[6] C. Allier, L. Heinrich, M. Schneider, S. Saalfeld, “Graph neural networks uncover structure and functions underlying the activity of simulated neural assemblies,” arXiv:2602.13325, 2026. doi:10.48550/arXiv.2602.13325