This repository contains standalone code and analyses for examining the effects of Transcranial Magnetic Stimulation (TMS) on brain connectivity using resting-state fMRI and Variational Autoencoders (VAEs).
It is part of a larger cognitive neuroscience project; other components of the analysis can be found in the companion repository: project-nodeap-core.
The resting-state fMRI data have been publicly deposited on OpenNeuro (ds006693).
Transcranial Magnetic Stimulation (TMS) is a widely used non-invasive technique in cognitive neuroscience for probing the causal role of brain regions in cognition. Here, we investigate whether deep learning approaches can detect subtle TMS-induced changes in brain connectivity.
Although non-invasive stimulation often produces modest and difficult-to-detect neural changes, TMS in our study did alter behavioral task performance. This motivates the search for converging neural evidence to better understand the origins of the observed behavioral effects.
The central question is straightforward:
Can resting-state FC reveal neural evidence of TMS effects?
We focus on functional connectivity (FC) derived from resting-state fMRI, collected after participants received either sham stimulation or continuous theta burst stimulation (cTBS).
I proposed using unsupervised deep learning methods—specifically a Variational Autoencoder (VAE) and its conditional variant (CVAE)—because of their ability to extract latent embedding dimensions. My working hypothesis was that cTBS would produce a greater shift in the embedded vectors than sham stimulation, relative to the null (baseline) session collected on the initial experiment day.
I tested several VAE-based models with different input features and training schemes:
-
VAE on AAL-based FC
- Sanity check for subject identification using VAEs.
-
VAE on AAL-sphere FC
- Restricts analysis to seed and target ROIs.
- Involves 4 ROIs:
0: aOFC seed1: aOFC target2: pOFC seed3: pOFC target
- See fc_AAL_spheres scripts for implementation details.
-
Conditional VAE (cVAE) on AAL-sphere FC
- Adds subject ID as a condition to both encoder and decoder.
- Raw (
raw): Unmodified data. - Weighted (
wtd): Resampled to address class imbalance.
cTBS over the anterior OFC (aOFC) produced greater deviations in functional connectivity from baseline compared to sham stimulation, with no effects for other ROIs. Moreover, in the aOFC group, connectivity changes predicted individual differences in subsequent behavior, linking anterior (but not posterior) OFC stimulation to learning of specific stimulus–outcome associations.
For more details on the analyses, equations, behavioral links, and plots, see our manuscript:
Liu et al., Distinct contributions of anterior and posterior orbitofrontal cortex to outcome-guided behavior,
Current Biology (in press).
The results reported in the manuscript are based on the cVAE raw version, while the weighted version serves as an important robustness check for potential class imbalance.
You can find the exact notebook here:
project-nodeap-fmri-cvae/scripts/cvae/cvae_fc_aal_spheres_raw.ipynb
project-nodeap-fmri-cvae/
├── data/
│ ├── data_FC/ # Functional connectivity (FC) matrices organized by subject/session
│ │ └── NODEAP_06/ # Example subject
│ │ └── D0/ # Example session (Day 0 / baseline)
│ │ ├── conn_matrix.mat # AAL-based FC matrix
│ │ └── conn_matrix_w_sphere.mat # FC matrix between AAL ROIs and spherical ROIs
│ └── SubConds.xlsx # Subject metadata (stimulation site, order, demographics, etc.)
│
├── outputs/ # Model outputs for downstream analyses and plotting
│
├── scripts/ # Main analysis scripts
│ ├── vae/ # Variational Autoencoder (VAE) notebooks
│ │ ├── vae_fc_aal_raw.ipynb
│ │ ├── vae_fc_aal_wtd.ipynb
│ │ ├── vae_fc_aal_spheres_raw.ipynb
│ │ └── vae_fc_aal_spheres_wtd.ipynb
│ │
│ ├── cvae/ # Conditional VAE (cVAE) notebooks
│ │ ├── cvae_fc_aal_spheres_raw.ipynb # Main notebook (results reported in the manuscript)
│ │ └── cvae_fc_aal_spheres_wtd.ipynb # Weighted variant (robustness check for class imbalance)
│ │
│ └── utils/ # Shared helper modules
│ ├── bootstrap.py # Package imports and setup
│ ├── data_utils.py # Data loading and preprocessing functions
│ ├── models.py # Model architectures (VAE / cVAE)
│ ├── train_utils.py # Training loops and evaluation utilities
│ └── utils_plotting.py # Plotting and visualization utilities
│
└── README.md # Main project description
-
Functional Connectivity (FC) Matrices
Stored indata/data_FC/, organized by subject and session. Each session folder contains:conn_matrix.mat: AAL-based FC matrixconn_matrix_w_sphere.mat: FC matrix between AAL ROIs and spherical ROIs (seed/target focused)
-
Subject Metadata
data/SubConds.xlsxcontains subject-level information used for model conditioning and analysis (copied from the core repo):- SubID: Subject identifier (e.g.,
NODEAP_*) - StimLoc: Stimulation site (Anterior vs. Posterior OFC)
- StimOrder: Numeric session order code
- tms_order_letters: Human-readable session sequence (C = cTBS, S = sham)
- Age, Sex: Demographic information
- SubID: Subject identifier (e.g.,
Qingfang Liu
Research Fellow, National Institute on Drug Abuse (NIDA)
Email: psychliuqf@gmail.com