Manuscript Offprint

arXiv:2609.04804

MedFlow: Class-Aware Multi-Scale Generation for Medical Time-Series Synthesis

Yanhao Huang, Shibo Feng, Wanjin Feng, Peilin Zhao, Chunyan Miao

Abstract

Synthetic medical time-series generation can alleviate data scarcity and support the development of reliable clinical prediction models. However, existing methods mainly focus on matching the overall distribution and temporal dynamics of real data, which does not necessarily ensure strong downstream utility on imbalanced medical datasets. Clinically informative patterns often occur at heterogeneous temporal scales, while rare minority-class characteristics can be obscured by dominant population patterns. To address these challenges, we propose MedFlow, a class-aware multi-scale flow matching framework for medical time-series synthesis. MedFlow employs a vector-quantized multi-scale tokenizer to represent medical sequences at complementary temporal resolutions, capturing both coarse clinical trends and fine-grained dynamics. We further introduce Token Marginal Guidance, which incorporates class-conditional token statistics directly into the flow matching process to steer generation toward class-specific regions of the learned tokens. This mechanism strengthens minority-class patterns, while preserving the global and tail distributions of real data. Experiments on four public datasets covering electronic health records, EEG, and ECG signals demonstrate that MedFlow consistently outperforms recent state-of-the-art diffusion-based baselines across downstream prediction tasks. On average, it improves AUPRC by 5.8%, reduces Context-FID by 88.6%, and achieves 3.8×3.8\times higher sampling throughput.

Code —

https://github.com/YanhaoHuang23/medflow-release

Introduction

Medical time series, including electronic health record (EHR) trajectories, electroencephalography (EEG), and electrocardiography (ECG), capture the temporal evolution of patient states and provide essential evidence for clinical prediction and diagnosis (Shickel et al. 2018; Wang et al. 2024). However, their collection and reuse are often constrained by high acquisition costs, limited institutional access, and the sensitivity of patient records. Medical time-series synthesis therefore offers a practical way to expand data availability and support model development when real cohorts are scarce or inaccessible (Goncalves et al. 2020;

Tucker et al. 2020). Its success, however, requires more than matching aggregate statistics. Synthetic sequences must preserve both temporal dependencies and class-specific predictive patterns so that models trained on them can generalize to held-out real cohorts. Thus, distributional fidelity and downstream utility constitute two distinct yet jointly essential objectives for medical time-series synthesis.

Medical time-series synthesis faces two key challenges. First, clinically relevant patterns span multiple temporal scales, from slow trends to transient events and fine-grained waveform dynamics. Single-scale representations may therefore miss structures at other resolutions (Wang et al. 2024; Zhang et al. 2023). Second, medical datasets are often highly imbalanced across outcomes (Rahman and Davis 2013; Huynh, Nibali, and He 2022), causing conditional generators to favor dominant patterns and underrepresent minority-class characteristics. Such discrepancies may also be obscured by global fidelity metrics, particularly in distribution tails. Effective class-conditional medical time-series synthesis must jointly preserve cross-scale temporal dynamics and the class-specific distributional support of both majority and minority populations.

Existing generators address parts of this problem through adversarial temporal modeling (Yoon, Jarrett, and van der Schaar 2019), iterative denoising (Yuan and Qiao 2024; Li et al. 2024), or task-oriented guidance (Deng et al. 2025). Vector-quantized models (van den Oord, Vinyals, and Kavukcuoglu 2017) have recently shown competitive performance in time-series modeling by representing temporal patterns as compact discrete tokens (Lee, Malacarne, and Aune 2023; Feng et al. 2025). However, the severe class imbalance and long-tail distributions common in medical data make class-conditioned synthesis difficult, as minority-class patterns can remain underrepresented during generation. Flow matching (Lipman et al. 2023) provides an efficient framework for generative transport. Building on it, MedFlow introduces class-aware guidance into the transport process to preserve class-specific token distributions and improve the synthesis of imbalanced medical time series.

We propose MedFlow, a class-aware multi-scale flow matching framework for medical time-series synthesis. MedFlow first employs a multi-scale tokenizer to decompose each sequence into complementary coarse-to-fine token representations. At each temporal scale, a class-

Copyright © 2026, Association for the Advancement of Artificial Intelligence (www.aaai.org). All rights reserved.

conditioned flow transports structured source representations in normalized codebook-embedding space and predicts categorical endpoint tokens. The resulting multi-scale token endpoints are decoded and combined to reconstruct the final medical sequence. To preserve class-specific patterns under outcome imbalance, we further introduce Token Marginal Guidance (TMG), a training-statistics-based calibration mechanism that adds a fixed class-specific bias to the endpoint logits using smoothed class-conditional token-frequency statistics estimated from the real training data. During sampling, this correction encourages token usage consistent with the requested class without requiring an auxiliary classifier or an additional learned guidance network.

Experiments on four public EHR, EEG, and ECG datasets (Johnson et al. 2016; Pollard et al. 2018) show that MedFlow achieves strong synthesis performance across utility, fidelity, and efficiency. On EHR benchmarks, it improves AUPRC by 5.8% on average and reduces Context-FID by 88.6% relative to strong diffusion baselines, while also achieving substantially faster sampling. It further maintains strong downstream utility and smaller tail-distribution gaps on physiological-signal benchmarks.

Our contributions are threefold:

  • We propose MedFlow, a class-aware multi-scale generative framework for medical time-series synthesis. By combining residual vector-quantized representations with scale-specific conditional transport, MedFlow captures temporal patterns ranging from coarse clinical trends to fine-grained local dynamics.

  • We introduce Token Marginal Guidance (TMG), which calibrates endpoint predictions using class-conditional token statistics derived from the training data. TMG steers generation toward class-relevant token regions, improving minority-class preservation and class-conditional fidelity under data imbalance.

  • We evaluate MedFlow on four public EHR, EEG, and ECG datasets. The results demonstrate consistent gains in synthetic-data utility, distributional fidelity, and sampling efficiency over strong generative baselines.

References (54)

  • TarDiff: Target-Oriented Diffusion Guidance for Synthetic Electronic Health Record Time Series Generation (opens arXiv in a new tab)
  • TimeVAE: A Variational Auto-Encoder for Multivariate Time Series Generation (opens arXiv in a new tab)
  • Diffusion Models Beat GANs on Image Synthesis
  • Analysis of Electroencephalograms in Alzheimer's Disease Patients with Multiscale Entropy
  • Real-Valued (Medical) Time Series Generation with Recurrent Conditional GANs
  • Hdt: Hierarchical discrete transformer for multivariate time series forecasting (opens arXiv in a new tab)
  • L.; Amaral, L. A. N.; Glass, L.; Hausdorff, J. M.; Ivanov, P. C.; Mark, R. G.; Mietus, J. E.; Moody, G. B.; Peng, C.-K.; and Stanley, H. E. 2000
  • Generation and Evaluation of Synthetic Patient Data
  • Denoising Diffusion Probabilistic Models
  • Classifier-Free Diffusion Guidance
  • Semi-supervised learning for medical image classification using imbalanced training data
  • W.; Pollard, T. J.; Shen, L.; Lehman, L.-w
  • Vector Quantized Time Series Generation with a Bidirectional Prior Model
  • BioDiffusion: A Versatile Diffusion Model for Biomedical Signal Synthesis (opens arXiv in a new tab)
  • Flow Matching for Generative Modeling
  • J.; Johnson, A. E. W.; Raffa, J. D.; Celi, L. A.; Mark, R. G.; and Badawi, O. 2018
  • M.; and Davis, D. N. 2013
  • Deep EHR: A Survey of Recent Advances in Deep Learning Techniques for Electronic Health Record Analysis
  • Generating High-Fidelity Synthetic Patient Data for Assessing Machine Learning Healthcare Software
  • Membership Inference Attacks against Synthetic Data through Overfitting Detection
  • Neural Discrete Representation Learning
  • Medformer: A Multi-Granularity Patching Transformer for Medical Time-Series Classification
  • Time-Series Generative Adversarial Networks
  • Diffusion-TS: Interpretable Diffusion for General Time Series Generation
  • Warpformer: A multi-scale modeling approach for irregular clinical time series
  • TimeGAN (Yoon, Jarrett, and van der Schaar 2019), TimeVAE (Desai et al. 2021), and TimeVQ-VAE (Lee, Malacarne, and Aune 2023) subsequently modeled temporal dynamics in learned continuous or discrete representation spaces
  • VQ-VAE (van den Oord, Vinyals, and Kavukcuoglu 2017) learns compact categorical latent representations, while RQ-VAE (Lee et al. 2022) progressively quantizes residual information across multiple stages
  • These strategies do not directly calibrate the empirical class-wise frequencies of learned tokens and may therefore underrepresent minority patterns in imbalanced datasets
  • The commitment term keeps encoder outputs close in cosine similarity to their selected frozen-gradient codes
  • The bank is encouraged to remain centered and non-degenerate while preserving the relative geometry of the token endpoints
  • For a mini-batch $\mathcal{B}$, we use
  • We draw $q \sim \text{Beta}(\alpha, \alpha)$ and set $\lambda = \max(q, 1 - q)$
  • Flow time is sampled as $t \sim \mathcal{U}(0,1)$ and transformed with
  • For the MIMIC-III mortality and APAVA core experiments, TMG uses additive smoothing $\eta = 1$, clipping threshold $\kappa = 3$, and guidance strength $\gamma = 0.2$
  • All values are computed from the original training splits
  • The sample shape is reported as channels × time steps
  • Panel (a) reports the class proportions, and panel (b) reports $\max(n_0, n_1)/\min(n_0, n_1)$, where $n_c$ is the number of training samples in class $c$
  • APAVA contains 16-channel EEG segments of length 256 and uses the fixed Medformer subject split: 15 subjects for training, four for validation, and four for testing
  • Area Under the Precision–Recall Curve (AUPRC)
  • Higher AUPRC indicates stronger recovery of the positive class and is particularly informative under class imbalance
  • The discriminator uses 2,000 optimization iterations and batch size 128
  • The Real Data reference uses the same evaluator trained on the real training split
  • 0.01</td></tr></table>
  • It is optimized with AdamW using learning rate $10^{-3}$, weight decay $10^{-4}$, and batch size 256
  • Table 8 gives the dataset-specific sequence shapes and token lengths
  • CFG uses $s_{CFG} = 2.0$ and replaces TMG during sampling
  • The CFG-ready variant is trained with label dropout probability 0.1
  • The tokenizer, structured source, flow architecture, solver, synthetic-cohort size, and downstream evaluator are otherwise unchanged
  • CFG learns its unconditional branch through label dropout within a single model evaluation, whereas TMG estimates class-conditional token marginals once from the frozen training tokens
  • The best and second-best results on each dataset are bolded and underlined, respectively
  • MIMIC-III mortality is strongly imbalanced, with a positive-class rate of approximately 11.2%
  • This result suggests that CFG concentrates generation around globally representative class patterns
  • ><tr><td colspan=
  • We report membership-inference risk as the excess