Volume 5 | Issue 2
All abstracts in this issue

A Cross-Modal Contrastive Learning and Reinforcement Learning Framework with Safety Constraints for Individualized Transcranial Magnetic Stimulation

Parya Dolatyabi, Mahdi Khodayar

DOI: Pending DOI

Synopsis

Transcranial magnetic stimulation (TMS) outcomes are limited by open-loop protocols that ignore real-time brain states and inter-individual variability. Existing closed-loop systems adapt only stimulation timing, leaving intensity static. We propose a three-component framework combining cross-modal contrastive learning (CL), reinforcement learning (RL), and safety constraints. Cross-modal CL jointly trains functional magnetic resonance imaging (fMRI) and electroencephalography (EEG) encoders into a shared latent space, enabling fMRI-derived therapeutic targets and real-time EEG brain states to be directly compared. An RL controller optimizes intensity and timing, while a safety layer enforces physiological limits. The framework is evaluated on LEMON and HCP datasets.

Background

TMS is a Food and Drug Administration approved therapy for treatment-resistant depression, yet clinical response and remission rates remain highly variable across patients due to differences in individual factors, treatment protocols, and predictors of outcome [1, 2]. Standard clinical protocols are open-loop, meaning stimulation parameters are fixed prior to each session and do not adapt to the patient's ongoing neurophysiological state [3, 4]. Research has progressed through four stages of TMS and EEG integration: EEG-blind, EEG-informed, EEG-triggered, and closed-loop TMS, where real-time EEG feedback dynamically adapts parameters during the session [5]. However, existing closed-loop implementations adapt only stimulation timing, leaving intensity static [6, 7]. The only proof-of-concept integrating RL into closed-loop EEG-TMS addressed timing only in a two-node motor network [8].
A critical barrier is that fMRI-derived therapeutic targets and EEG-measured brain states live in incompatible representation spaces, making it impossible to directly measure progress toward a target during a session. We address this through cross-modal CL, which jointly trains fMRI and EEG encoders so both modalities project into a shared latent space. To our knowledge, no prior framework has unified cross-modal CL, adaptive intensity control, and physiological safety constraints for individualized TMS.

Methods

We propose a three-component framework validated through simulation on publicly available datasets as shown in Figure 1. Coil position is fixed via fMRI-guided neuronavigation targeting the dorsolateral prefrontal cortex (DLPFC) subregion most anti-correlated with the subgenual anterior cingulate cortex (sgACC) [9]. The RL controller adapts only intensity and timing within the session.
Component 1 is Cross-Modal CL. A graph neural network (GNN)-based fMRI encoder and an EEG feature encoder are jointly trained in a self-supervised manner on paired resting-state fMRI and EEG data from the LEMON dataset, where same-subject pairs are positive and different-subject pairs are negative. Contrastive loss trains both encoders into a shared latent space. At inference, the pre-session fMRI connectivity graph yields the therapeutic target vector z*, representing the patient's target brain network organization. Real-time EEG features including theta, alpha, beta band power and TMS-evoked potentials (TEP) amplitude yield the current brain state vector z(t). Because both vectors share a latent space, they are geometrically comparable.
Component 2 is the RL Controller. A Soft Actor-Critic (SAC) agent observes z(t) and adjusts pulse intensity and inter-pulse interval, with reward penalizing the distance between z(t) and z*, incentivizing convergence toward the therapeutic target. The agent is pre-trained on synthetic HCP-derived patient environments. Component 3 is the Safety Layer, enforcing maximum intensity at 120% resting motor threshold, minimum inter-pulse interval per IFCN TMS safety guidelines [10], and real-time TEP amplitude thresholds as dynamic seizure risk markers.

Results

This is a proposed computational framework currently under development, validated through simulation on the LEMON dataset with paired resting-state fMRI and EEG from N=50 subjects and HCP resting-state fMRI profiles from N=100 unrelated subjects. Specific quantitative results will be reported upon completion of simulations. The following describes anticipated outcomes and evaluation metrics.
Cross-Modal Contrastive Learning: The jointly trained GNN fMRI encoder and EEG encoder will be evaluated on same-subject versus cross-subject cross-modal cosine similarity in the shared latent space, to confirm that fMRI and EEG representations of the same individual are more similar than those of different individuals. Target identification quality will be assessed by comparing inter-individual variance of GNN-derived DLPFC-sgACC targets against those from standard manual connectivity analysis pipelines.
RL Controller: The soft actor critic (SAC) agent will be evaluated on time-to-therapeutic-target convergence, reward area under the curve (AUC) over simulated sessions, and inter-individual variance in stimulation parameter trajectories, compared across three conditions including fixed-parameter baseline, RL without cross-modal domain adaptation (DA), and the full framework. We anticipate that cross-modal DA will reduce inter-individual variance in learned policies and improve convergence speed relative to both baselines, by providing the RL agent with a geometrically consistent state-goal representation across patients.
Safety Layer: The veto module will be characterized by its trigger rate across RL training epochs and its effect on convergence, confirming that safety constraints intercept out-of-bounds parameter proposals without disrupting learning. Pipeline inference latency will be benchmarked to verify real-time compatibility.

Discussion

This framework resolves a fundamental incompatibility in fMRI and EEG integration for closed-loop TMS by projecting both modalities into a shared latent space via cross-modal CL, analogous to how joint training on paired data in multimodal artificial intelligence systems enables direct comparison of representations from different modalities. For a new patient, only a standard pre-session fMRI scan and real-time EEG are needed, as the cross-modal alignment is already encoded in the trained encoders.
This advances closed-loop TMS from timing-only control to adaptive intensity control with cross-patient generalization. Three design choices ensure clinical realism: coil position is fixed via fMRI neuronavigation; RL adapts only intensity and timing on existing hardware; and the safety layer uses dynamic EEG excitability markers. A key hypothesis, whether convergence of the brain state vector toward the therapeutic target vector predicts clinical outcome, is the central aim of planned future clinical validation. Future work will explore session-level target updating, richer EEG representations from raw time series using self-supervised encoders, and extension to transcranial electrical stimulation (tES) and transcranial focused ultrasound stimulation (tFUS).

Disclosures

Nothing to disclose by any authors.

References

[1] Trapp et al. Predictive modeling of response to repetitive TMS in treatment-resistant depression. Transl Psychiatry. 2025;15:160.
[2] Kar. Predictors of response to repetitive TMS in depression: a review of recent updates. Clin Psychopharmacol Neurosci. 2019;17(1):25-33.
[3] Lefaucheur et al. Evidence-based guidelines on the therapeutic use of repetitive TMS. Clin Neurophysiol. 2020;131(2):474-528.
[4] Gogulski et al. Personalized repetitive transcranial magnetic stimulation for depression. Biol Psychiatry Cogn Neurosci Neuroimaging. 2023;8(4):351-360.
[5] Varone et al. The golden age of online readout: EEG-informed TMS from manual probing to closed-loop neuromodulation. NeuroImage. 2025. doi:10.1016/j.neuroimage.2025.005464.
[6] Wischnewski et al. Real-time TMS-EEG for brain state-controlled research and precision treatment. J Neural Eng. 2024;21(6):061001.
[7] Faller et al. Daily prefrontal closed-loop rTMS produces progressive EEG quasi-alpha phase entrainment in depressed adults. Brain Stimul. 2022;15(2):458-471.
[8] Humaidan et al. Towards real-time EEG-TMS modulation of brain state in a closed-loop approach. Clin Neurophysiol. 2024;158:212-217.
[9] Fox et al. Efficacy of TMS targets for depression is related to intrinsic functional connectivity with the subgenual cingulate. Biol Psychiatry. 2012;72(7):595-603.
[10] Rossi et al. Safety and recommendations for TMS use in healthy subjects and patient populations: expert guidelines. Clin Neurophysiol. 2021;132(1):269-306.