Pre-training Epidemic Time Series Forecasters with Compartmental Prototypes Zewen Liu, Juntong Ni, Bohan Wang, Max S. Y. Lau, Wei Jin Abstract . Accurate epidemic forecasting is crucial for outbreak preparedness, but existing data-driven models are often brittle. Typically trained on a single pathogen, they struggle with data scarcity during new outbreaks and fail under distribution shifts caused by viral evolution or interventions. However, decades of surveillance data and the design of various compartmental models from diverse diseases offer an untapped source of transferable knowledge. To leverage the collective lessons from history, we propose CAPE, the first open-source pre-trained model for epidemic forecasting. Unlike existing time series foundation models that overlook epidemiological challenges, CAPE models epidemic dynamics as mixtures of latent compartmental population states, termed compartmental prototypes . It models a flexible dictionary of compartment prototypes directly from a large collection of simulation data, enabling each outbreak to be expressed as a time-varying mixture that links observed infections to latent population states. To promote robust generalization, CAPE adopts the next-token-prediction paradigm during pre-training with lightweight epidemic-aware regularization that aligns the learned prototypes with epidemiological semantics. On a comprehensive benchmark spanning 17 diseases, CAPE significantly outperforms strong baselines with zero-shot forecasting. This work represents a principled step toward pre-trained epidemic models that are both transferable and epidemiologically grounded. We provide our code in: https://github.com/nuuuh/CAPE . DOI: XXXXXXX.XXXXXXX Conference: Conference Title; June 2025; Woodstock, NY ISBN: 978-1-4503-XXXX-X/2018/06 1. Introduction Infectious disease outbreaks pose a persistent threat to global public health and economic stability ( Nicola et al., 2020 ) . Effective outbreak management relies on accurate epidemic forecasting—the prediction of future cases, hospitalizations, and other critical metrics ( Liu et al., 2024b ; Wan et al., 2024 ; Adhikari et al., 2019 ) . A wide range of models have been developed to provide these crucial forecasts, which generally fall into two categories. Knowledge-driven mechanistic models, such as the classic Susceptible-Infected-Recovered (SIR) ( Cooper et al., 2020 ) approach, are grounded in epidemiological principles; they divide the population into compartments that represent distinct population states (e.g., susceptible, infectious, recovered) and use differential equations to explicitly model flows among these states. In contrast, modern data-driven methods like LSTMs ( Shahid et al., 2020 ) learn complex patterns directly from historical data, offering greater flexibility without imposing a predefined structure of dynamics. However, these data-driven forecasters are often trained for a single pathogen. This narrow scope makes them brittle: they face acute data scarcity during the critical early stages of a novel outbreak, and they fail under distribution shifts induced by viral evolution. While training across diverse pathogens and geographies proves to enhance downstream forecasting tasks ( Kamarthi and Prakash, 2023 ) , real-world data often lacks of observation of hidden population groups (e.g., susceptible, exposed, vaccinated), which are essential for disclosing the underlying disease dynamics. Nevertheless, with decades of studies across various diseases, epidemiologists have uncovered diverse disease dynamics through mathematical modeling with extensive prior knowledge, which are often formulated as coupled ordinary differential equations, capable of simulating disease outbreaks. Motivated by the success of physics-informed neural networks in epidemic forecasting ( Wan et al., 2024 ; Rodríguez et al., 2023 ) , which make use of such prior knowledge, and large pre-trained models in language, vision, and time-series domains ( Zhao et al., 2023 ) , we ask: Can we build a pre-trained epidemic forecaster that learns from the collective dynamics of infectious diseases to generalize effectively across real-world outbreaks? Simply applying a general time series foundation model ( Liang et al., 2024 ) or training an epidemic-informed neural network is insufficient, as it overlooks core epidemiological challenges for generalization: (1) Structural heterogeneity : Pathogens follow different effective compartmental progressions (e.g., SIR vs. SEIR ( He et al., 2020 ) ), so a single fixed mechanism cannot transfer broadly across diseases and regions. (2) Hidden population states : Surveillance data records only reported infections, while important states such as exposure, susceptibility, and immunity are not directly observed. These properties demand both large-scale and diverse simulations of diseases to capture various dynamics and a powerful epidemic pre-trained model structure that can adapt to different pathogens and provide forecasts under different hidden population groups. Our Solution. First , we introduce EpiRecipe , a pipeline for building compartmental models and conducting large-scale simulations of diverse disease dynamics. Second , with the produced supervision data from EpiRecipe and real-world historical disease data, we introduce a novel pre-training-based epidemic model: CAPE ( C omp A rtment P re-training for E pidemics), which learns epidemic dynamics as a mixture of latent population groups, termed compartmental prototypes . To address structural heterogeneity and hidden states, rather than relying on a rigid, pre-defined structure, CAPE learns a flexible dictionary of prototypes directly from data via next-token prediction. This allows the model to transfer to downstream forecasting tasks by dynamically composing these prototypes via compartmental masking. Our contributions include: (1) Large Scale Simulation Pipeline: To enlarge the pre-training corpus, we propose EpiRecipe , a comprehensive simulation pipeline that maintains a catalog of 12 epidemiological compartments and over 20 transition dynamics to generate millions of structurally valid, diverse disease simulations (2) Pre-training framework for epidemic time series forecasting: We introduce the first open-source pre-training framework 1 1 1 https://github.com/nuuuh/CAPE for epidemic forecasting. It learns latent compartmental prototypes directly from disease dynamics and provides uncertainty quantification by conducting stochastic structural inference via compartmental masking. (3) Comprehensive evaluation benchmark and state-of-the-art performance: We assemble a comprehensive evaluation pipeline spanning 17 diverse diseases in the US under an online forecasting setting. Even in a zero-shot setting, CAPE exhibits the best MSE and MAE against baselines and achieves a stronger performance compared to time series foundation models. (4) In-depth analysis: We conduct extensive analyses to uncover how pre-training improves representation learning. We provide the first evidence of epidemic scaling laws on simulation data and visualize how the model captures important epidemic properties like peak timing without explicit supervision. 2. Related Work and Problem Definition Epidemic Forecasting Models. Traditionally, epidemic forecasting employs models like ARIMA ( Sahai et al., 2020 ) , SEIR ( He et al., 2020 ) , and VAR ( Shang et al., 2021 ) . ARIMA predicts infections by analyzing past data and errors, SEIR models population transitions using differential equations, and VAR captures linear inter-dependencies by modeling each variable based on past values. Recently, deep learning models, categorized into RNN-based, MLP-based, and transformer-based, have surpassed these methods. RNN-based models like LSTM ( Wang et al., 2020 ) , GRU ( Natarajan et al., 2023 ) , and more epidemic-specific models like EpiDeep ( Adhikari et al., 2019 ) and EINNs ( Rodríguez et al., 2023 ) use gating mechanisms to manage information flow. MLP-based models use linear layers ( Zeng et al., 2023 ) or multi-layer perceptrons ( Borghi et al., 2021 ; Madden et al., 2024 ) for efficient data-to-prediction mapping and physics-informed distillation ( Wang et al., 2021 ) . Transformer-based models ( Wu et al., 2021 ; Zhou et al., 2021 ; Zhou et al., 2022b ) apply self-attention to encode time series and generate predictions via a decoder. However, these models are limited as they typically utilize data from only one type of disease without considering valuable insights from diverse disease datasets. Pre-trained Time Series Models. To enable few-shot or zero-shot capabilities, transformer-based models often employ pre-training on large datasets, which typically use masked data reconstruction ( Zerveas et al., 2021 ; Rasul et al., 2023 ) or promote alignment across different contexts ( Fraikin et al., 2023 ; Zhang et al., 2022 ; Yue et al., 2022 ) . For example, PatchTST ( Nie et al., 2022 ) segments time series into patches, masks some, and reconstructs the masked segments. Larger foundational models like MOMENT ( Goswami et al., 2024 ) and Chronos ( Ansari et al., 2024 ) aim to excel in multiple tasks (e.g., forecasting, imputation, classification) and prove useful in epidemic forecasting ( Panja et al., 2025 ; Kalahasti et al., 2025 ; Dey et al., 2024 ) , but training them requires substantial data and computational resources. In epidemic contexts, Kamarthi et al. ( Kamarthi and Prakash, 2023 ) pre-train a model on various diseases, improving downstream performance and highlighting pre-training’s potential in epidemic forecasting. However, the complete implementation is not publicly available. Moreover, existing approaches overlook hidden compartmental influence and zero-shot ability in epidemic forecasting and lack a deep analysis of how pre-training materials impact downstream performance. In this study, we introduce latent compartment modeling and conduct a thorough analysis of these questions. Problem Definition. Given historical observations \mathbf{x}\in\mathbb{R}^{T} , the goal is to forecast future infections \mathbf{y}\in\mathbb{R}^{H} , where T and H denote the lookback window and forecast horizon, respectively. We employ a pre-training framework on a hybrid corpus \mathcal{D}_{\text{pre}}=\mathcal{D}_{\text{syn}}\cup\mathcal{D}_{\text{real}} , comprising synthetic samples from EpiRecipe and historical real-world data. Adopting a next-token-prediction paradigm, we define a patching operator \mathcal{P}:\mathbb{R}^{T}\to\mathbb{R}^{N\times P} that segments \mathbf{x} into a sequence of N tokens \mathbf{X^{\prime}}=(\mathbf{x^{\prime}}_{1},\dots,\mathbf{x^{\prime}}_{N}) , where each \mathbf{x^{\prime}}_{i}\in\mathbb{R}^{P} is a patch of length P . The model f_{\theta} is trained to autoregressively predict the next token \mathbf{x^{\prime}}_{t+1} and latent epidemic states \mathbf{z}_{t+1} (e.g., compartmental dynamics, R_{t} ) conditioned on the context \mathbf{X^{\prime}}_{1:t} . The optimization objective is: (1) \min_{\theta}\mathbb{E}_{\mathbf{x}\sim\mathcal{D}_{\text{pre}}}\left[\sum\nolimits_{t=1}^{N-1}\left(\mathcal{L}_{\text{rec}}(\hat{\mathbf{x^{\prime}}}_{t+1},\mathbf{x^{\prime}}_{t+1})+\lambda\mathcal{L}_{\text{epi}}(\hat{\mathbf{z}}_{t+1},\mathbf{z}_{t+1})\right)\right] where \hat{\mathbf{x^{\prime}}}_{t+1},\hat{\mathbf{z}}_{t+1}=f_{\theta}(\mathbf{X^{\prime}}_{1:t}) are the predicted token and latent states, and \lambda balances the reconstruction loss \mathcal{L}_{\text{rec}} with the epidemic consistency loss \mathcal{L}_{\text{epi}} . 3. Proposed Method Our pre-training framework aims to overcome the core challenges of structural heterogeneity and hidden population states inherent in epidemic forecasting. We address these issues through two main contributions: (1) a comprehensive pipeline for producing random systems of disease dynamics (section 3.1 ), and (2) a flexible model architecture that learns latent compartmental prototypes directly from simulation data, with epidemic-aware pre-training objectives that guide the model to learn robust, generalizable representations (section 3.2 ). In addition, derived naturally from the model structure, we also introduce a stochastic structural inference for both effective adaptation to downstream tasks and uncertainty estimation (section 3.3 ). Figure 1 . Pipeline of EpiRecipe. 3.1. EpiRecipe A fundamental challenge in pre-training epidemic forecasting models is the scarcity and heterogeneity of real-world outbreak data. To address this, we develop EpiRecipe , a constraint-based simulation pipeline for generating diverse, epidemiologically valid compartmental models and their corresponding synthetic time series. This augments our pre-training corpus by exposing the model to a wide range of disease dynamics. The overall pipeline is shown in Figure 1 and more details are provided in Appendix B . Constraint-Based Model Generation. To ensure coverage of diverse compartment states and resolve the challenge of structural heterogeneity behind disease outbreaks, EpiRecipe maintains a catalog of 12 epidemiological compartments ( Brauer, 2008 ) , representing diverse population groups (e.g., infectious individuals ( I )): (2) \mathcal{C}=\{\textbf{S},\textbf{E},\textbf{I},\textbf{R},\textbf{H},\textbf{V},\textbf{Q},\textbf{D},\textbf{P},\textbf{W},\textbf{A},\textbf{C}\}, along with their dependency constraints encoded as requirements, defined as a mapping f_{\text{req}}:\mathcal{C}\to\mathcal{P}(\mathcal{C}) , where each compartment maps to a subset of required prerequisite compartments \mathcal{P}(\mathcal{C}) . For instance, the Infectious ( I ) compartment requires the Susceptible ( S ) compartment to exist, i.e., \textbf{E}\in f_{\text{req}}(\textbf{A}) ( Anggriani et al., 2022 ) . Automatic Transition Construction. Even with the same set of compartments, different diseases can have diverse transition dynamics. Therefore, once compartments are selected, EpiRecipe automatically constructs a transition network \mathcal{T} by randomly selecting from predefined mechanistic variants, where each transition from compartment i to j is governed by a flow function f_{ij} . For example, infection dynamics can follow standard mass-action f_{\textbf{S}\to\textbf{E}}=\beta SI/N ( Kolokolnikov and Iron, 2021 ) . The pipeline selects appropriate variants of flow functions based on the available compartments, and the complete system evolves according to: (3) \frac{dx_{c}}{dt}=\underbrace{\sum_{i\to c}f_{ic}(\mathbf{x};\theta)}_{\text{inflow}}-\underbrace{\sum_{c\to j}f_{cj}(\mathbf{x};\theta)}_{\text{outflow}}, where \mathbf{x} is the state vector representing the population in each compartment, and the sums represent all incoming and outgoing transitions for compartment c . Population Stratification. Real epidemics exhibit heterogeneous dynamics across demographic groups. To capture this, EpiRecipe partitions the population into G groups (e.g., children, adults, elderly), following the implementation in CovidSim ( Wilson et al., 2020 ) . Each group g is a population fraction and has its own group-specific properties like transmission rate \beta_{g}(t) . Inter-group transmission is governed by a mixing matrix \mathbf{M}\in\mathbb{R}^{G\times G} with predefined patterns (e.g., homogeneous or assortative). The stratified infection dynamics become: f^{(g)}_{\textbf{S}\to\textbf{I}}=\beta_{g}\frac{S_{g}}{N_{g}}\sum_{h=1}^{G}M_{gh}\iota_{h}I_{h} , where S_{g} , I_{g} , and N_{g} denote the susceptible, infectious, and total population in group g , respectively. This produces epidemic curves with realistic subpopulation dynamics and complex aggregate patterns. Specific sampling distributions for all multipliers are provided in Appendix B . Hierarchical Parameter Sampling. To ensure epidemiological realism, parameters are sampled hierarchically in three stages. First , primary epidemiological quantities, e.g., the basic reproduction number R_{0} , are sampled from informed prior distributions. Second , derived parameters are computed deterministically to maintain consistency, e.g., the baseline transmission rate \beta_{0}=R_{0}\cdot\gamma . Seasonal forcing is optionally applied via: (4) \beta(t)=\beta_{0}\left[1+\varepsilon\cos\left(\frac{2\pi t}{T_{\text{period}}}+\phi\right)\right], where \varepsilon , T_{\text{period}} , and \phi control the amplitude, period, and phase of seasonal variation, respectively. Lastly , secondary parameters required by the selected transitions (e.g., hospitalization and vaccination rates) are sampled from predefined ranges. All sampling distributions and ranges are provided in Appendix B . Validation and Simulation. Each generated model undergoes validation to ensure: (1) population conservation across living compartments, (2) no dead-end states, i.e., every non-terminal compartment has at least one outflow transition, and (3) existence of a valid infectious pathway from S to I in the transition graph. Valid models are then integrated using a fourth-order Runge-Kutta (RK4) solver, and Gaussian observation noise is injected to mimic real-world reporting imperfections: (5) \{\mathbf{x}(t)\}_{t=0}^{T}=\textsc{RK4}\left(\frac{d\mathbf{x}}{dt},\mathbf{x}_{0},T\right),\quad\tilde{\mathbf{x}}(t)=\max\left(\mathbf{x}(t)+\boldsymbol{\eta}(t),\mathbf{0}\right), where \boldsymbol{\eta}(t)\sim\mathcal{N}(\mathbf{0},\lambda^{2}\cdot\text{diag}(\text{Var}(\mathbf{x}))) and \lambda controls the noise level. Through this process, EpiRecipe generates millions of samples with varied compartmental structures, transition mechanisms, and parameter regimes, providing the diverse pre-training corpus essential for learning generalizable patterns. Figure 2 . CAPE model structure and pre-training pipeline with EpiRecipe. 3.2. Model Structure for Epidemic Pre-training Similar to the current large language models and foundation models in time series ( Ansari et al., 2024 ) , CAPE conducts next-token-prediction in an autoregressive way. CAPE is composed of three major components: (1) Autoregressive temporal encoder f_{enc} , (2) Compartmental decoding f_{comp} , and (3) Masked multi-groups attention f_{dec} . Autoregressive Temporal Encoder ( f_{enc} ). To effectively capture the evolving momentum and latent inertia of an outbreak, it is important to distill raw, often non-stationary infection trends into a high-dimensional temporal context that preserves both local fluctuations and global epidemiological trajectories. Given an observed infection trajectory \mathbf{x}\in\mathbb{R}^{T\times 1} , smoothing ( Chung, 2020 ) and patching ( Nie et al., 2022 ) is performed to formulate the denoised token sequence \mathbf{x^{\prime}}\in\mathbb{R}^{N\times t} , where N is the number of tokens and t=T/N is the token size. Then, an autoregressive model (e.g., LSTM, TCN, or Transformer) is applied to encode temporal information, producing embeddings for each patch \mathbf{h_{i+1}}=f_{enc}(\mathbf{x^{\prime}_{0}},...,\mathbf{x^{\prime}_{i}})\in\mathbb{R}^{D} , where i denotes the token index and D is the embedding size. This encoding formulates the temporal context of past infections \mathbf{H}\in\mathbb{R}^{N\times D} . Compartmental Decoding ( f_{comp} ). Decoding directly from the univariate context is insufficient, as it not only ignores the provided supervision signals from different compartments but also the influence of hidden compartments on the forecast of future infections. Therefore, we propose to decode compartmental context in the latent space with both temporal context \mathbf{H} and a codebook ( Zhou et al., 2022a ) of learnable compartmental prototypes, denoted as \mathbf{Z}\in\mathbb{R}^{|C|\times D} , where C is a set of compartments that match with the ones in EpiRecipe. Finally, we use cross-attention to produce the contextualized compartment embeddings as: (6) \mathbf{H}^{\prime}=f_{comp}(\mathbf{H},\mathbf{Z})=\text{softmax}\left({\mathbf{Z}\mathbf{H}^{\top}}/{\sqrt{D}}\right)\quad\mathbf{H}\in\mathbb{R}^{|C|\times N\times D}. Eventually, the prediction of the next token is decoded from the corresponding compartment embedding. Masked Multi-groups Attention ( f_{dec} ). The observed dynamics of a compartment are often the result of complex, unobserved interactions among multiple latent population groups (e.g., age, occupation, or mobility-based strata) with differing contact rates and vulnerabilities. To bridge the gap between these hidden population states and visible compartmental outcomes, we propose Masked Multi-groups Attention . By implicitly modeling these heterogeneous group dynamics through the regularization of the effective reproduction number R_{t} ( Lim et al., 2020 ) , where R_{t}>1 signals expansion and R_{t}<1 signals decline of infections, we enforce an epidemiologically coherent latent space that ensures the model’s predictions align with the physical laws of disease transmission. Overall, this process produces predictions \mathbf{Y}=f_{dec}(\mathbf{H}^{\prime},\mathbf{M}) with a compartment mask \mathbf{M} , as detailed below. First , each compartment \mathbf{H}_{C_{i}}^{\prime} is projected to P multiple groups via linear projections \mathbf{\hat{H}}_{C_{i},j}=\mathbf{W}_{j}\mathbf{H}_{C_{i}}^{\prime} , each corresponding to a population group. Such an idea is similar to the linear projections in computing query, key, and value in self-attention and the mappings in multi-head attention ( Vaswani et al., 2017 ) , which enhances the expressiveness of the model. Second , giving the mask \mathbf{M} , the masked self-attention is applied to model the interactions among compartments of interest in the latent space, producing \mathbf{\bar{H}}=\text{MaskedAttention}(\mathbf{\hat{H}},\mathbf{M}) . Third , with the attention scores indicating the strength of contributions/interactions, we regularize the attention scores within the infectious group to match the actual dynamics. To bridge the gap between these latent attention patterns and R_{t} , we map the learned attention matrix to the components of the Next-Generation Matrix ( Diekmann et al., 2010 ) , where off-diagonal entries correspond to cross-group transmission rates (matrix \mathbf{F} ) and diagonal entries reflect within-group stability (matrix \mathbf{V} ). Consequently, Theorem 3.1 provides the spectral bound for estimating R_{t} (Proof in Appendix C ). Theorem 3.1 (Bounds for R_{t} ) . Let \mathbf{F},\mathbf{V}\in\mathbb{R}^{n\times n} with \mathbf{V} invertible, and define R_{t}\equiv\rho(\mathbf{F}\mathbf{V}^{-1}) , where \rho(\cdot) is the spectral radius. Then: (7) \frac{\sigma_{\min}(\mathbf{F})}{\sigma_{\max}(\mathbf{V})}\;\leq\;R_{t}\;\leq\;\frac{\sigma_{\max}(\mathbf{F})}{\sigma_{\min}(\mathbf{V})}, where \sigma_{\max}(\cdot) and \sigma_{\min}(\cdot) denote the maximal and minimal singular values, respectively. Based on Theorem 3.1 , we derive a differentiable estimation of \hat{R}_{t} from the attention scores via Algorithm 1 , and match the estimation with ground truth using \mathcal{L}_{R_{t}}=\text{MSE}(\hat{R}_{t},R_{t}) . Lastly, for each compartment C_{i} , the latent groups are aggregated and projected to the next token via \mathbf{Y}_{i}=\text{MLP}(\sum_{j=1}^{P}\bar{H}_{C_{i},j}) , where \mathbf{Y}_{i} is the future trajectory of compartment C_{i} . Algorithm 1 R(t) Estimation from Attention Patterns 1: Attention scores \mathbf{A} , number of views P 2: R(t) time series \{\hat{R}_{1},\hat{R}_{2},\ldots,\hat{R}_{T}\} 3: for t=1 to T do 4: Extract I-to-I attention submatrix: \mathbf{A}_{t}^{(I)}\in\mathbb{R}^{P\times P} 5: Construct F matrix: 6: \mathbf{F}\leftarrow\mathbf{A}_{t}^{(I)} , F_{ii}\leftarrow 0 \triangleright cross-group infections 7: Construct V matrix: 8: \gamma_{i}\leftarrow 1/(A^{(I)}_{t,ii}+\epsilon) \triangleright within-group transitions 9: \mathbf{V}\leftarrow\text{diag}(\gamma_{1},\ldots,\gamma_{P}) 10: Compute spectral bounds (Theorem 3.1 ): 11: R_{t}^{\text{lower}}\leftarrow\sigma_{\min}(\mathbf{F})\,/\,(\sigma_{\max}(\mathbf{V})+\epsilon) 12: R_{t}^{\text{upper}}\leftarrow\sigma_{\max}(\mathbf{F})\,/\,(\sigma_{\min}(\mathbf{V})+\epsilon) 13: \tilde{R}_{t}\leftarrow(R_{t}^{\text{lower}}+R_{t}^{\text{upper}})/2 14: end for 15: \hat{R}_{t}\leftarrow\text{Softplus}(\mathbf{W}_{R}\tilde{R}_{t}+b_{R}) for all t 16: return \{\hat{R}_{1},\hat{R}_{2},\ldots,\hat{R}_{T}\} 3.3. Epidemic Pre-training and Inference Pre-training. We proposed a dual stage pre-training strategy, where the first stage is to inject epidemic inductive bias into the model via large scale simulation data and the second stage is to adapt to real-world data. During first stage of pre-training, for each sample, EpiRecipe provides ground truth for (1) the next token of all compartments and the R_{t} , and (2) a binary compartment mask \mathbf{M} to block the irrelevant compartments. Therefore, the loss function is formulated as: (8) \mathcal{L}=\sum_{i}^{|C|}\alpha_{i}M_{i}\cdot\text{MSE}(\mathbf{Y}_{i},\mathbf{\hat{Y}}_{i})+\beta\mathcal{L}_{R_{t}}, where \mathbf{\alpha} and \beta are weights to control the alignment with the ground truth compartments and the underlying effective reproduction number. In the second stage, we collect historical infections from different diseases and conduct the same pretraining strategy while only activating S and I compartments and without applying \mathcal{L}_{R_{t}} . Stochastic Structural Inference. While pre-training provides labels for each compartment and the compartment mask, structural heterogeneity and hidden population states remain challenges for downstream real-world samples. Therefore, during inference on downstream datasets, CAPE provides predictions with uncertainty by predicting K times while randomly masking each compartment with a probability of 50% (Basic compartments like S and I will never be masked). This process implicitly samples K distinct epidemic model structures, producing a distribution of plausible forecasts. The final forecast is derived by aggregating these realizations (e.g., pooling for point prediction and quantiles for uncertainty quantification), which effectively mimics an ensemble of diverse compartmental models ( Reich et al., 2019 ) . Table 1 . Zero-shot forecasting performance (MSE / MAE) across 17 diseases. Bold : best, underline : second best. First Count: number of diseases where CAPE beats the best baseline (for CAPE) or ranks #1 among all models (for baselines). CAPE (Ours) Baselines Disease CAPE CAPE {}_{\text{2nd}} ARIMA SIR GRU EINN EpiDeep DLinear PatchTST N-BEATS PEM MSE MAE MSE MAE MSE MAE MSE MAE MSE MAE MSE MAE MSE MAE MSE MAE MSE MAE MSE MAE MSE MAE Poliomyelitis 0.235 \pm 0.002 0.226 \pm 0.001 0.244 \pm 0.000 0.231 \pm 0.001 0.326 0.261 0.833 0.535 0.435 0.251 0.672 0.315 0.860 0.417 0.365 0.291 0.910 0.380 0.417 0.302 0.820 0.365 Diphtheria 0.168 \pm 0.000 0.196 \pm 0.000 0.163 \pm 0.000 0.192 \pm 0.000 0.157 0.211 0.437 0.478 1.008 0.551 1.859 0.735 1.322 0.636 1.200 0.546 2.591 0.790 2.720 0.874 1.115 0.549 Gonorrhea 0.060 \pm 0.001 0.138 \pm 0.001 0.059 \pm 0.002 0.139 \pm 0.004 0.052 0.128 0.652 0.758 0.116 0.241 1.760 0.788 0.877 0.784 0.157 0.304 1.333 0.752 1.077 0.659 0.333 0.390 Hepatitis A 0.207 \pm 0.006 0.318 \pm 0.005 0.190 \pm 0.008 0.294 \pm 0.002 0.228 0.324 0.740 0.702 0.253 0.350 0.489 0.535 0.679 0.693 0.267 0.382 0.683 0.667 0.514 0.560 0.863 0.741 Hepatitis B 0.058 \pm 0.001 0.146 \pm 0.002 0.058 \pm 0.004 0.145 \pm 0.004 0.061 0.143 0.254 0.409 0.083 0.208 0.087 0.213 0.269 0.442 0.094 0.238 0.156 0.286 0.238 0.303 0.211 0.359 Influenza 0.450 \pm 0.008 0.283 \pm 0.018 0.435 \pm 0.001 0.191 \pm 0.001 1.725 0.307 0.399 0.313 0.368 0.197 0.401 0.230 0.261 0.239 0.465 0.252 0.666 0.405 0.446 0.191 0.526 0.261 Meningitis 0.183 \pm 0.024 0.237 \pm 0.009 0.129 \pm 0.000 0.204 \pm 0.001 0.150 0.233 0.487 0.549 0.129 0.218 0.153 0.234 0.239 0.363 0.211 0.275 0.309 0.394 0.103 0.203 0.167 0.252 Mumps 0.019 \pm 0.000 0.062 \pm 0.001 0.019 \pm 0.001 0.060 \pm 0.002 0.025 0.068 0.249 0.475 0.046 0.154 0.024 0.102 0.156 0.373 0.058 0.208 0.054 0.181 0.046 0.160 0.075 0.217 Pertussis 0.080 \pm 0.000 0.120 \pm 0.000 0.085 \pm 0.000 0.123 \pm 0.001 0.109 0.142 0.226 0.376 1.258 0.590 2.030 0.760 1.514 0.681 0.756 0.434 1.775 0.708 2.149 0.753 1.716 0.701 Pneumonia 0.043 \pm 0.000 0.118 \pm 0.000 0.043 \pm 0.000 0.120 \pm 0.000 0.057 0.141 0.201 0.392 0.097 0.210 0.081 0.167 0.128 0.282 0.130 0.294 0.130 0.230 0.091 0.226 0.115 0.202 Rubella 0.025 \pm 0.001 0.080 \pm 0.001 0.023 \pm 0.000 0.074 \pm 0.001 0.029 0.083 0.239 0.469 0.278 0.331 0.090 0.240 0.600 0.713 0.131 0.320 2.224 1.161 1.679 0.776 1.325 0.875 Scarlet Fever 0.092 \pm 0.000 0.188 \pm 0.000 0.088 \pm 0.000 0.184 \pm 0.000 0.092 0.178 0.273 0.425 0.263 0.330 1.154 0.659 1.707 0.836 0.339 0.378 0.750 0.530 2.159 0.948 1.325 0.735 Smallpox 0.146 \pm 0.000 0.194 \pm 0.000 0.142 \pm 0.001 0.192 \pm 0.000 0.170 0.213 0.382 0.424 0.605 0.396 1.451 0.613 0.915 0.488 0.694 0.405 0.976 0.522 0.733 0.418 0.780 0.439 Tuberculosis 0.207 \pm 0.003 0.294 \pm 0.002 0.192 \pm 0.002 0.307 \pm 0.003 0.173 0.268 0.328 0.420 0.858 0.622 1.816 0.876 1.264 0.753 0.329 0.395 1.328 0.735 1.855 0.865 1.549 0.830 Typhoid Fever 0.485 \pm 0.000 0.320 \pm 0.000 0.473 \pm 0.001 0.318 \pm 0.001 0.330 0.308 0.705 0.575 0.635 0.411 1.491 0.622 1.268 0.578 0.896 0.475 0.810 0.479 10.26 1.299 1.716 0.709 Varicella 0.076 \pm 0.000 0.144 \pm 0.000 0.076 \pm 0.000 0.145 \pm 0.001 0.086 0.154 0.206 0.403 0.322 0.386 0.476 0.423 0.567 0.571 0.491 0.512 0.591 0.535 0.642 0.582 0.611 0.603 Measles 0.207 \pm 0.001 0.206 \pm 0.000 0.206 \pm 0.001 0.209 \pm 0.001 0.230 0.208 0.652 0.515 1.127 0.470 1.530 0.581 1.358 0.547 1.072 0.548 1.277 0.524 1.635 0.612 1.224 0.487 Average 0.161 0.192 0.154 0.184 0.235 0.198 0.427 0.483 0.464 0.348 0.915 0.476 0.823 0.553 0.450 0.368 0.974 0.546 1.575 0.572 0.851 0.513 1st Count 11 10 11 10 4 5 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 Table 2 . Ablation Study Results (MSE \pm Std). We conduct evaluations on the full data without train/val/test splits. Subscripts show relative improvement. Note that both pre-training methods are compared against the w/o pre-training baseline. Method Influenza Diphtheria Gonorrhea Poliomyelitis Tuberculosis Rubella Avg w/o Pre-training 0.805 \pm 0.004 2.048 \pm 0.003 4.018 \pm 0.002 1.747 \pm 0.003 2.171 \pm 0.003 1.135 \pm 0.006 1.987 + Pre-training (Real-world) 0.835 \pm 0.032 ↑3.8% 1.674 \pm 0.032 ↓18.3% 0.491 \pm 0.032 ↓87.8% 1.685 \pm 0.032 ↓3.6% 1.619 \pm 0.032 ↓25.4% 0.116 \pm 0.032 ↓89.8% 1.070 ↓46.2% + Pre-training (Naive Synth) 0.803 \pm 0.039 ↓0.3% 1.481 \pm 0.043 ↓27.7% 0.768 \pm 0.039 ↓80.9% 1.572 \pm 0.042 ↓10.0% 1.379 \pm 0.040 ↓36.5% 0.277 \pm 0.041 ↓75.6% 1.047 ↓47.3% + Comp. Decoding 0.678 \pm 0.100 ↓15.6% 0.549 \pm 0.066 ↓62.9% 0.059 \pm 0.020 ↓92.3% 0.448 \pm 0.097 ↓71.5% 0.603 \pm 0.086 ↓56.3% 0.064 \pm 0.048 ↓76.8% 0.400 ↓61.8% + Multi-groups Attn. 0.652 \pm 0.112 ↓3.7% 0.547 \pm 0.093 ↓0.5% 0.046 \pm 0.025 ↓22.4% 0.463 \pm 0.090 ↑3.2% 0.450 \pm 0.092 ↓25.3% 0.068 \pm 0.040 ↑5.9% 0.371 ↓7.3% Figure 3 . Comparison with foundation models across all datasets. Per-disease comparison is shown in Appendix G . 4. Experiment 4.1. Setup Datasets. Pre-train Corpus: To support pre-training without loading the large-scale pre-compiled datasets. Our pipeline applies a streaming data style by simulating a batch of samples on-the-fly, with padding to match the varying length of time series. We formulate 4 time steps as a token (one month) and pre-train the model with approximately 240M tokens. Then, the second stage pre-training is conducted on 7 distinct real-world diseases with the same token size. Downstream Evaluation Datasets: We collect 17 diverse diseases from Project Tycho ( van Panhuis et al., 2018 ) with outbreaks across the US states. We adopt an online setting ( Rodríguez et al., 2023 ) by using the first 30% for the base training, and the remaining data for evaluation. More details of the datasets can be found in Appendix D . Baselines. We adopt baseline models from the comprehensive EpiLearn toolkit ( Liu et al., 2024a ) , comparing our model against two categories: non-pretrained and pre-trained models. Non-pretrained baselines including RNN-based epidemic forecasters like EpiDeep and EINNs ( Adhikari et al., 2019 ; Rodríguez et al., 2023 ) , the MLP-based model DLinear ( Zeng et al., 2023 ) , and transformer-based architectures like PatchTST ( Nie et al., 2022 ; Kamarthi and Prakash, 2023 ) . Pre-trained baselines include state-of-the-art models such as PEM ( Kamarthi and Prakash, 2023 ) and the time series foundation model MOMENT ( Goswami et al., 2024 ) , CHRONOS ( Ansari et al., 2024 ) and Moirai ( Woo et al., 2024 ) . We provide further comparisons with statistical models that are fitted per sample, including ARIMA ( Panagopoulos et al., 2021 ) and SIR ( Cooper et al., 2020 ) . We perform hyperparameter tuning on the hidden sizes, layers, learning rate, weight decay etc, for all baseline models. (See Appendix E for more details) Research Questions. In the following experiments, we propose and answer the following questions: Q1: How does CAPE compare against state-of-the-art non-pretrained and pretrained baselines? Q2: What is the contribution of each component in CAPE’s architecture? Q3: What is CAPE learning from the vast pre-training corpus? Q4: Do epidemic forecasting models exhibit scaling laws similar to those observed in language models? Q5: What’s the impact of pre-training on forecasting downstream real-world diseases? Specifically: (1) How does the diversity of pre-training data affect downstream performance? (2) What is the relationship between pre-train compute and downstream improvement? (3) Can CAPE learn meaningful disease representations? (4) Can CAPE produce uncertainty quantification? 4.2. Comparison with Baselines To answer Q1 , we benchmark CAPE against both full-shot and zero-shot baselines across 17 diseases, demonstrating state-of-the-art performance in both settings. Comparison with Full-shot Models. As shown in Table 1 , both CAPE variants, pre-trained solely on synthetic data (CAPE {}_{\text{ZERO}} ) and with additional second-stage pre-training on real-world surveillance data (CAPE), outperform the best baseline on 11/17 diseases in MSE and 10/17 in MAE, without finetuning on the training set. CAPE achieves the best overall performance (MSE: 0.154, MAE: 0.184), substantially outperforming the strongest baseline ARIMA (MSE: 0.235, MAE: 0.198). All deep learning baselines struggle in this data-scarce regime, with several exhibiting catastrophic failures. CAPE’s advantages are most pronounced on vaccine-preventable diseases (e.g., Measles, Mumps, Pertussis, Poliomyelitis), reducing MSE by 20–30% over the best baseline, suggesting that compartmental pre-training effectively captures nonlinear transmission dynamics. ARIMA retains an edge on trend-dominated diseases (e.g., Typhoid Fever), while Influenza remains challenging due to sharp seasonal spikes. Comparison with Zero-shot Foundation Models. We further compare CAPE against state-of-the-art time series foundation models, e.g., Chronos2 ( Ansari et al., 2024 ) , Moirai ( Woo et al., 2024 ) , and Moment ( Goswami et al., 2024 ) , in the zero-shot setting. As shown in Figure 3 , CAPE achieves the lowest MSE and Rising Phase MAE, demonstrating superior point forecast accuracy. More importantly, CAPE excels on epidemiologically critical metrics with the highest Alert Sensitivity (78.35% vs. 64.21% for Moirai), Outbreak Recall (86.65% vs. 74.04% for Moirai), and the lowest Peak Underestimate Rate (55.29% vs. 66.99% for Moirai), indicating better detection of emerging outbreaks and the power of pre-training with domain-specific synthetic data. 4.3. Ablation Study To answer Q2 , we evaluate the contribution of each proposed component through an ablation study over 6 diseases, using the entire time series as the test set. As shown in Table 2 , pre-training with naive synthetic data (only the infectious compartment) achieves comparable performance to pre-training with real-world epidemic data (47.3% vs. 46.2% average improvement), demonstrating that synthetic pre-training can effectively substitute for scarce real-world outbreak data. Adding compartmental decoding provides the most substantial marginal improvement (61.8%), validating our hypothesis that explicitly modeling latent compartmental states helps capture hidden transmission dynamics across diverse pathogens. The improvement is particularly pronounced for diseases with complex dynamics such as Gonorrhea (92.3%) and Rubella (76.8%). The masked multi-groups attention contributes a further 7.3% average improvement, with notable gains on Tuberculosis (25.3%) and Gonorrhea (22.4%), diseases known to exhibit heterogeneous transmission across demographic groups ( Trauer et al., 2019 ; Kirkcaldy et al., 2019 ) . Together, these components reduce the average MSE from 1.987 to 0.371, representing an overall improvement of 81.3%. (a) Peak Timing (b) R_{t} Volatility (c) R_{t} Dominant Period (d) Epidemic Intensity Figure 4 . t-SNE visualization of CAPE encodings colored by four key epidemiological properties. The visualization reveals that CAPE learns to organize epidemic trajectories into coherent local clusters that correlate strongly with properties such as peak timing, volatility, periodicity, and intensity, capturing both fine-grained temporal dynamics and higher-level structural patterns. More properties are shown in Appendix F . 4.4. Learning from Simulation Data To answer Q3 , we investigate the representations learned by CAPE and find that not only EpiRecipe is able to produce infection trajectories with diverse epidemic properties but also CAPE is learn good representation of these properties from the synthetic data. Specifically, we extract patch embeddings from 10,000 synthetic epidemic trajectories generated by EpiRecipe and visualize them using t-SNE, colored by various eight epidemiological properties (See details in Appendix F ), as shown in Figure 4 . The visualization reveals that CAPE learns to organize epidemic trajectories into coherent local clusters that correlate strongly with meaningful epidemiological properties. Notably, the embeddings exhibit smooth gradients for continuous properties (e.g., peak timing, R_{t} dominant period, etc) and distinct groupings for discrete properties (e.g., wave patterns), suggesting that CAPE captures both fine-grained temporal dynamics and higher-level structural patterns. This organization emerges purely from next-token prediction on diverse compartmental simulations, without explicit supervision on these properties, demonstrating that the pre-training objective naturally induces meaningful epidemic representations. 4.5. Epidemic Scaling Law To answer Q4 , we investigate whether neural scaling laws ( Kaplan et al., 2020 ) , well-established in language and vision domains, also hold for epidemic forecasting. Interestingly, we find that the CAPE models pretrained on EpiRecipe-generated simulations exhibit a certain degree of scaling behavior on both model sizes and the amount of training samples. (a) Scaling with Model Size. As shown in Figure 5 , test error decreases following a power law L=24.80\times N^{-0.085} as the number of parameters N increases. The exponent -0.085 indicates relatively slow but consistent improvement. This modest scaling exponent suggests that epidemic dynamics, while complex, may have lower intrinsic dimensionality compared to natural language, where exponents typically range from -0.05 to -0.10 ( Kaplan et al., 2020 ) . (b) Scaling with Pre-training Compute. Figure 5 reveals that all model sizes exhibit consistent error reduction as training samples increase, with larger models achieving lower asymptotic error. Interestingly, smaller models (617K–1.3M) show faster initial convergence but plateau earlier, while larger models (7.0M–7.4M) continue improving with more data. This indicates that model capacity and data scale must be balanced: over-parameterized models require sufficient training samples to realize their potential. (e) MSE vs model size (f) MSE vs pre-train compute Figure 5 . Scaling under model size and pre-train compute. (a) Vendi-Scores of each disease group and the synthetic data. (b) Target group MSE with different pre-training corpora. Figure 6 . Diversity scores and transferability experiment. 4.6. From Simulation to Reality: Impact of Pre-training on Downstream Forecasts To answer Q5 , we explore the effect of epidemic pretraining from both diversity and compute perspectives, and quantified the impact of pre-training over downstream performance, representation quality, and enabling uncertainty estimation. (a) Impact of Data Diversity on Cross-diseases Transferability. We hypothesize that pre-training data diversity, rather than similarity to the target domain, is the key driver of downstream performance. To test this, we cluster 17 diseases from the Tycho dataset into 4 groups based on trajectory features (peak timing, asymmetry, autocorrelation, etc.) using hierarchical clustering, and measure diversity using the Vendi Score ( Friedman and Dieng, 2022 ) , which computes the diversity of elements in a dataset based on eigenvalue entropy of the similarity matrix. To isolate the effect of diversity from data quantity, we conduct a controlled experiment: for each target group, we pre-train on (1) the same group (similar), (2) other groups excluding the target (dissimilar) group, or (3) all groups (most diverse), with the sample count held constant across conditions. As shown in Figure 6 , pre-training on diverse data (All Groups: 0.309 MSE) consistently outperforms pre-training on similar data (Same Group: 0.338 MSE), with an 8.6% relative improvement. Even pre-training on dissimilar data (Other Groups: 0.324 MSE) outperforms the similar condition, suggesting that exposure to varied dynamics is more valuable than data from the same dynamics. These findings support our design choice of using EpiRecipe’s diverse synthetic corpus for pre-training CAPE, which achieves higher diversity as shown in Figure 6 . (b) Pre-training Compute vs Downstream Performance. We investigate how pre-training computation affects downstream zero-shot performance by evaluating CAPE checkpoints saved at different epochs on 8 diseases from the Tycho dataset. Figure 7 (left) shows that MSE decreases monotonically with additional pre-training epochs across all model sizes on the Influenza data. Notably, most improvement occurs in the first 5 epochs, after which gains diminish, consistent with the scaling law findings. Figure 7 (right) quantifies the average relative improvement over epoch 1 across all diseases. The BASE model achieves consistent improvements of 15–28% throughout training, while smaller models like TYNY and SMALL do not show consistent gains or decrease after two epochs, indicating larger models may benefit more from additional compute without overfitting. Figure 7 . Pre-training compute vs downstream performance. Left: Zero-shot MSE on the Influenza data. Right: Relative improvement over epoch 1 across all diseases. Table 3 . Disease Classification (17 disease labels) with linear and non-linear classifiers. (Acc. / F1) Model Random Logistic Reg. Ridge KNN Random Forest CAPE 5.9 / 6 22.1 / 9.8 23.3 / 11.8 55.6 / 50.8 62.7 / 57.3 PEM 5.9 / 6 56.6 / 51.8 48.6 / 39.1 64.8 / 61.3 72.9 / 68.6 (c) Learning of Disease Representations. Visual analysis via t-SNE (Figure 8 a) reveals overlapping clusters, suggesting CAPE captures shared epidemic dynamics alongside disease-specific features. This balance is supported by pairwise Davies-Bouldin Index (DBI) analysis (Figures 8 b-c), confirming CAPE learns both discriminative and shared patterns. Furthermore, disease classification results (Table 3 ) show that CAPE representations, unlike PEM, significantly improve non-linear classifier performance, demonstrating the model’s ability to encode complex non-linear correlations among diseases. Figure 8 . CAPE encodings of downstream diseases and pairwise DBI scores from CAPE and PEM (higher the darker). (d) Uncertainty Modeling via Pre-training. CAPE’s compartmental masking during pre-training enables uncertainty quantification via stochastic structural inference. By running K=50 forward passes with randomly masked compartments, each pass samples a different epidemic model structure. Pooling methods like mean serve as the point forecast, while standard deviation quantifies uncertainty. Figure 9 validates calibration quality, as the strong correlations (Pearson r=0.68 , Spearman \rho=0.81 ) between predicted uncertainty and actual error confirm that the model reliably knows when its predictions are less certain. Figure 9 . The strong positive correlations (Pearson r , Spearman \rho ) indicate that higher predicted uncertainty corresponds to larger actual errors. 5. Conclusion We present CAPE, the first open-source pre-training framework for epidemic forecasting that learns flexible latent population states, termed compartmental prototypes, to address structural heterogeneity and hidden population states in epidemic pre-training. By designing a large-scale pre-training corpus with the proposed EpiRecipe simulation pipeline, CAPE captures generalizable dynamics across diseases. Extensive experiments demonstrate state-of-the-art generalization. In the future, we plan to extend CAPE to incorporate spatial dynamics and textual reasoning abilities for richer generalization, ultimately advancing toward trustworthy and actionable epidemic forecasting. 6. GenAI Disclosure Generative AI tools were employed in this work solely for the purpose of refining the language, correcting grammatical and coding errors. Appendix A Appendix A.1. Potential Impact This paper advances the interdisciplinary fields of machine learning and epidemiology by enhancing the accuracy of epidemic forecasting in data-limited settings. We outline the potential impacts as follows: Early Insights. We provide novel insights into how pre-training and compartment modeling improve epidemic forecasting. Our results demonstrate that pre-training significantly enhances model accuracy, with gains increasing as more pre-training data is incorporated. This finding paves the way for future research to develop foundational models in epidemic analysis using larger datasets. Additionally, we confirm the importance of accounting for both inherent disease dynamics and compartmental factors to achieve robust forecasting performance. Social Impact. Epidemic time series data are often sparse due to limited sampling rates, hindering public health organizations’ ability to accurately predict infections during novel disease outbreaks. This paper addresses this challenge by showcasing the few-shot and zero-shot forecasting capabilities of pre-trained models. These capabilities can provide powerful tools for early warning and timely intervention, ultimately supporting more effective public health responses and safeguarding communities against emerging infectious diseases. A.2. Limitations and Ethical Considerations We use publicly available data without ethical concerns. While CAPE shows strong performance, it has several limitations. First, the compartment model combinations defined in EpiRecipe can be further expanded. Second, its effectiveness may be constrained by the scale and diversity of available data. Appendix B EpiRecipe EpiRecipe is a constraint-based pipeline for generating diverse, epidemiologically valid compartmental models. The system features automatic compartment dependency resolution, rule-driven transition construction, hierarchical parameter sampling, and comprehensive model validation. It supports 12 compartment types, 28 transition rules across 14 dynamics categories, and population stratification with configurable mixing patterns. The EpiRecipe pipeline consists of six sequential stages as shown in Figure 10 . 1. Compartment Selection 2. Transition Construction 3. Parameter Sampling 4. Model Validation 5. Noise Injection 6. Simulation Figure 10 . The EpiRecipe pipeline generates valid compartmental models through constraint satisfaction, hierarchical parameter sampling, and ODEs simulation. B.1. Compartment Library Let N denote the total population size. EpiRecipe supports 12 compartment types, where each compartment X(t) represents the number of individuals in state X at time t . Details are provided in Table 4 . constraint-based selection: Our pipeline performs constraint-based selection. It first includes the mandatory compartments \{\textbf{S},\textbf{I}\}\subseteq\mathcal{C}^{*} , then iteratively adds optional compartments while automatically resolving their dependencies, ensuring a valid structure as \forall c\in\mathcal{C}^{*}:f_{\text{req}}(c)\subseteq\mathcal{C}^{*} . Table 4 . Compartment types and structural constraints. Required compartments (S, I) are always included; optional compartments are sampled with automatic dependency resolution. “Cons.” indicates population-conserved compartments. Symbol Type Description Req. Cons. S Susceptible Individuals who can contract the disease \checkmark \checkmark I Infectious Symptomatic individuals who transmit disease \checkmark \checkmark E Exposed Infected but not yet infectious (latent period) – \checkmark R Recovered Individuals with immunity after infection – \checkmark A Asymptomatic Infectious individuals without symptoms – \checkmark H Hospitalized Severe cases requiring medical care – \checkmark D Deceased Cumulative disease-induced deaths – – V Vaccinated Individuals protected by vaccination – \checkmark Q Quarantined Isolated individuals (from I or E ) – \checkmark W Reservoir Environmental pathogen concentration – – C Chronic Long-term carriers with prolonged infectivity – \checkmark P Prophylaxis Temporarily protected individuals – \checkmark Population Conservation: Let \mathcal{L}=\{S,E,I,A,R,H,V,Q,C,P\} denote the set of “living” compartments. The total living population satisfies \sum_{X\in\mathcal{L}}X(t)=N-D(t) , where D(t) is cumulative deaths. The reservoir W represents environmental pathogen load and is excluded from conservation. B.2. Transition Rules EpiRecipe implements 28 transition rules organized into 14 dynamics categories. Each rule specifies a flow rate between compartments, as shown in Table 4 . Table 5 . Complete transition dynamics catalog (28 rules). “Req.” indicates compartments that must be present for the rule to apply. All rate parameters are defined in Table 8 . Category Rule Name Flow Rate Equation Req. Infection (7) mass_action \beta\cdot S\cdot I/N – with_asymptomatic \beta\cdot S\cdot(I+\epsilon A)/N A with_chronic \beta\cdot S\cdot(I+\delta_{C}C)/N C environmental \beta_{W}\cdot S\cdot W/(K+W) W combined_env \beta\cdot S\cdot(I+\rho W)/N W hospital_nosocomial \beta\cdot S\cdot(I+\theta H)/N H saturating \beta\cdot S\cdot I/(N(1+\alpha I)) – Latent prog. (2) simple \sigma\cdot E\to I E branching \sigma E\to p_{\text{sym}}I+(1{-}p_{\text{sym}})A E,A Recovery (2) constant_rate \gamma\cdot X (where X\in\{I,A,H\} ) – resource_limited \gamma\cdot X/(1+\omega X) – Hospitalization (2) constant_rate \eta\cdot I\to H H severity_dependent \eta\cdot I\cdot(1+\kappa I/N)\to H H Death (2) from_infectious \mu\cdot I\to D – from_hospital \mu_{H}\cdot H\to D H Vaccination (2) constant_campaign \nu (fixed rate) \to V V proportional p_{\text{vax}}\cdot S\to V V Quarantine (2) from_infectious \tau_{Q}\cdot I\to Q Q from_exposed \tau_{Q}\cdot E\to Q Q,E Q release (2) to_recovered \rho_{Q}\cdot Q\to R Q,R to_susceptible \rho_{Q}\cdot Q\to S Q Shedding (2) from_infectious \xi\cdot I\to W W with_asymptomatic \xi\cdot(I+\delta_{A}A)\to W W,A Env. decay (1) decay -\zeta\cdot W W Chronic prog. (1) constant \chi\cdot I\to C C Chronic clear. (1) constant \gamma_{C}\cdot C\to R C Waning imm. (1) constant \omega\cdot R\to S R Vaccine wane (1) constant \omega_{V}\cdot V\to S V B.3. Hierarchical Parameter Sampling Parameters are sampled in three hierarchical tiers to ensure epidemiological consistency: (1) Tier 1 – Primary Parameters (Table 6 ): Core epidemiological quantities sampled from informed prior distributions. (2) Tier 2 – Derived Parameters (Table 7 ): Computed deterministically from Tier 1 to maintain mathematical consistency. (3) Tier 3 – Secondary Parameters (Table 8 ): Transition-specific rates sampled uniformly within plausible ranges. Table 6 . Tier 1: Primary parameters sampled from epidemiologically-motivated distributions. Values are clipped to the specified range after sampling. Parameter Description Distribution Range R_{0} Basic reproduction number LogNormal (\mu{=}2.5,\sigma{=}0.8) [1.1,18.0] T_{\text{inf}} Infectious period (days) Gamma (k{=}3.0,\theta{=}3.0) [3,21] T_{\text{lat}} Latent period (days, if E present) Gamma (k{=}2.0,\theta{=}2.5) [1,14] Table 7 . Tier 2: Derived parameters computed deterministically from Tier 1 to ensure epidemiological consistency (e.g., \beta=R_{0}\cdot\gamma ). Parameter Formula Description \gamma 1/T_{\text{inf}} Recovery rate (inverse of infectious period) \sigma 1/T_{\text{lat}} Latent progression rate (inverse of latent period) \beta R_{0}\cdot\gamma Transmission rate (ensures correct R_{0} ) Table 8 . Tier 3: Secondary parameters (24 total) sampled uniformly within biologically plausible ranges. These govern transition-specific dynamics. Param. Range Description \epsilon [0.3,0.9] Relative infectiousness of asymptomatic vs symptomatic \delta_{C} [0.1,0.5] Relative infectiousness of chronic carriers p_{\text{sym}} [0.3,0.8] Fraction of exposed becoming symptomatic \eta [0.01,0.15] Rate of hospitalization from I \mu [0.001,0.03] Disease-induced mortality rate from I \mu_{H} [0.02,0.15] Mortality rate from hospital H \gamma_{H} [0.05,0.2] Hospital discharge rate \gamma_{A} [0.1,0.3] Recovery rate for asymptomatic \gamma_{C} [0.005,0.05] Clearance rate for chronic carriers \chi [0.01,0.1] Rate of developing chronic carriage \omega [0.001,0.02] Immunity waning rate ( R\to S ) \omega_{V} [0.002,0.01] Vaccine waning rate ( V\to S ) p_{\text{vax}} [0.001,0.02] Proportional vaccination rate \nu [10,500] Constant vaccination rate (individuals/time) \tau_{Q} [0.01,0.1] Quarantine rate \rho_{Q} [0.05,0.15] Quarantine release rate \xi [0.001,0.1] Environmental shedding rate \delta_{A} [0.3,1.0] Relative shedding from asymptomatic \zeta [0.05,0.5] Environmental decay rate \beta_{W} [0.001,0.1] Environmental transmission rate K [100,10000] Half-saturation constant for environmental transmission \rho [0.1,1.0] Environmental contribution weight \theta [0.1,0.5] Nosocomial transmission factor \alpha [0.0001,0.01] Behavioral saturation parameter Seasonal Forcing (applied to 50% of models): The transmission rate varies periodically as \beta(t)=\beta_{0}(1+\varepsilon\cos(2\pi t/T+\phi)) , where \varepsilon\in[0.1,0.5] is the amplitude, T\in\{26,52,104,156\} weeks is the period, and \phi\sim\text{Uniform}(0,2\pi) is the phase offset. B.4. Model Validation Every generated model is validated against five invariants: (1) population conservation, (2) no dead-ends (every non-terminal compartment has outflow), (3) infectious pathway exists from S to \{I,A,C\} , (4) R_{0}>0 , and (5) numerical stability (all rates \leq 10.0 ). Models failing any check are rejected and regenerated. B.5. Population Stratification EpiRecipe supports stratification by age, risk, spatial, or custom groupings. Each group g has: population fraction f_{g} ( \sum_{g}f_{g}=1 ), contact multiplier c_{g} , and susceptibility multiplier s_{g} .. Table 9 . Preset population stratifications with group-specific multipliers and default mixing patterns. Preset Group f_{g} c_{g} s_{g} Default Mixing Age (3 groups) Children 0.20 1.5 0.8 Assortative ( a{=}0.7 ) Adults 0.60 1.0 1.0 Elderly 0.20 0.6 1.5 Risk (2 groups) Low-risk 0.85 1.0 1.0 Homogeneous High-risk 0.15 1.0 1.2 Mixing Matrices: The matrix \mathbf{M}\in\mathbb{R}^{n\times n} specifies contact patterns, where M_{ij} is the relative contact rate from group i to j (rows sum to 1): • Homogeneous : M_{ij}=1/n (equal contact probability) • Assortative : M_{ii}=a , M_{ij}=(1{-}a)/(n{-}1) for i\neq j (default a{=}0.7 ) • Hierarchical : M_{ij}\propto e^{-|i-j|/\sigma} (age-like decay with distance) B.6. Simulation Models are integrated using RK4 with time step \Delta t=1.0 , duration 250 steps, and population N\in[1000,100000] . Post-step rescaling enforces population conservation. Gaussian observation noise with \sigma_{\text{noise}}\sim\text{Uniform}(0,0.05) is injected. Computed observables include incidence, prevalence ( I+A+C ), R_{t}=R_{0}\cdot S(t)/N , hospitalizations, and cumulative deaths. Appendix C Theoretical Analysis C.1. Estimation of R_{t} Epidemiological Interpretation of Attention Patterns. The construction of \mathbf{F} and \mathbf{V} matrices from attention scores follows the next-generation matrix framework for computing R_{t} ( Diekmann et al., 2010 ) . In this framework, \mathbf{F} represents new infection rates (transmission) and \mathbf{V} represents transition rates out of infectious states (removal), with R_{t}=\rho(\mathbf{FV}^{-1}) where \rho(\cdot) denotes the spectral radius. F Matrix (Transmission): The off-diagonal elements of the I-to-I attention submatrix A^{(I)}_{ij} ( i\neq j ) capture how strongly infectious group j influences group i . This directly parallels transmission rates \beta_{ij} in heterogeneous compartmental models, where infections spread between different population groups. We zero the diagonal since self-infection is not meaningful in this context. V Matrix (Removal): The diagonal elements A^{(I)}_{ii} represent self-attention—how much each infectious group attends to itself. In attention mechanisms, higher self-attention indicates that the token’s representation is more self-contained and persistent across layers. This is analogous to the mean infectious period 1/\gamma in epidemiology: a longer infectious period means individuals remain in the infectious state longer before transitioning out (via recovery, hospitalization, or death). The inverse relationship \gamma_{i}=1/(A^{(I)}_{ii}+\epsilon) arises because: • High self-attention A_{ii} \rightarrow state persists longer \rightarrow low removal rate \gamma_{i} • Low self-attention A_{ii} \rightarrow rapid state transition \rightarrow high removal rate \gamma_{i} This mirrors the classical SIR relationship where R=\beta/\gamma : the reproduction number increases with transmission rate \beta (off-diagonal attention) and decreases with removal rate \gamma (inverse of diagonal attention). By computing spectral bounds on \mathbf{FV}^{-1} , we obtain time-varying R(t) estimates that reflect learned epidemic dynamics without requiring explicit compartmental supervision. C.2. Proof of spectral bounds in Algo. 1 Setup and Preliminaries. Let V\in\mathbb{C}^{m\times n} . The (operator) 2 -norm of a matrix M is \left\lVert M\right\rVert_{2}\;=\;\sup_{x\neq 0}\frac{\left\lVert Mx\right\rVert_{2}}{\left\lVert x\right\rVert_{2}}\;=\;\max_{\left\lVert x\right\rVert_{2}=1}\left\lVert Mx\right\rVert_{2}. The singular values \sigma_{1}(V)\geq\cdots\geq\sigma_{r}(V)\geq 0 (with r=\operatorname{rank}(V) ) are, by definition, the nonnegative square roots of the eigenvalues of V^{\ast}V (where ∗ denotes conjugate transpose), counted with multiplicity and ordered nonincreasingly. For any matrix M and any vector x , \sigma_{\min}(M)\,\|x\|_{2}\;\leq\;\|Mx\|_{2}\;\leq\;\sigma_{\max}(M)\,\|x\|_{2},\quad\|M\|_{2}=\sigma_{\max}(M). For square M , the singular values \{\sigma_{i}(M)\}_{i=1}^{n} and eigenvalues \{\lambda_{i}(M)\}_{i=1}^{n} satisfy \prod_{i=1}^{n}\sigma_{i}(M)=\sqrt{\det(M^{*}M)}=|\det M|=\prod_{i=1}^{n}|\lambda_{i}(M)|. In particular, by comparing geometric means to extrema, \displaystyle\sigma_{\min}(M)\;\leq\;\Big(\prod_{i=1}^{n}\sigma_{i}(M)\Big)^{1/n}=\Big(\prod_{i=1}^{n}|\lambda_{i}(M)|\Big)^{1/n}\;\leq\;\max_{i}|\lambda_{i}(M)|=\rho(M). Thus, for any square M , \sigma_{\min}(M)\;\leq\;\rho(M)\;\leq\;\sigma_{\max}(M)=\|M\|_{2}. Theorem C.1 (Bounds for R_{t} ) . Let F,V\in\mathbb{C}^{n\times n} with V invertible, and define R_{t}\;\equiv\;\rho(FV^{-1}), where \rho(\cdot) denotes the spectral radius, \|\cdot\|_{2} the operator 2 -norm, and \sigma_{\max}(\cdot),\sigma_{\min}(\cdot) the maximal and minimal singular values, respectively. Then R_{t} satisfies the bounds \boxed{\;\frac{\sigma_{\min}(F)}{\sigma_{\max}(V)}\;\leq\;\rho(FV^{-1})\;\leq\;\frac{\sigma_{\max}(F)}{\sigma_{\min}(V)}.\;} Derivation for Lower bound. Proof. For any compatible A,B and any unit vector x , \|ABx\|_{2}\;\geq\;\sigma_{\min}(A)\,\|Bx\|_{2}\;\geq\;\sigma_{\min}(A)\,\sigma_{\min}(B)\,\|x\|_{2}, hence \sigma_{\min}(AB)\;\geq\;\sigma_{\min}(A)\,\sigma_{\min}(B). Apply (S1) with A=F and B=V^{-1} (with V invertible): \sigma_{\min}(FV^{-1})\;\geq\;\sigma_{\min}(F)\,\sigma_{\min}(V^{-1}). Using the inversion identity for singular values, \sigma_{\min}(V^{-1})=\frac{1}{\sigma_{\max}(V)}, we obtain \boxed{\;\sigma_{\min}(FV^{-1})\;\geq\;\dfrac{\sigma_{\min}(F)}{\sigma_{\max}(V)}.\;} By (P1) applied to M=FV^{-1} , we get: \sigma_{\min}(FV^{-1})\;\leq\;\rho(FV^{-1}). Combining (L1) and (L2) yields the rigorous lower bound \boxed{\;\dfrac{\sigma_{\min}(F)}{\sigma_{\max}(V)}\;\leq\;\rho(FV^{-1}).\;} ∎ Derivation for Upper bound. Proof. For any square M , \rho(M)\leq\|M\|_{2} by (P2). Thus \rho(FV^{-1})\;\leq\;\|FV^{-1}\|_{2}\;\leq\;\|F\|_{2}\,\|V^{-1}\|_{2}=\sigma_{\max}(F)\,\frac{1}{\sigma_{\min}(V)}. Hence the rigorous upper bound is \boxed{\;\rho(FV^{-1})\;\leq\;\dfrac{\sigma_{\max}(F)}{\sigma_{\min}(V)}.\;} Final result. Putting (LB) and (UB) together, we obtain \boxed{\;\frac{\sigma_{\min}(F)}{\sigma_{\max}(V)}\;\leq\;\rho(FV^{-1})\;\leq\;\frac{\sigma_{\max}(F)}{\sigma_{\min}(V)}.\;} ∎ Appendix D Pre-train and Evaluation Datasets D.1. Pre-training In the first stage, CAPE is pretrained on synthetically generated epidemic time series produced by the EpiRecipe pipeline, which programmatically generates diverse compartmental models with realistic dynamics. This approach enables unlimited pretraining data with known ground truth compartmental structures. In the second stage, we use the following 8 diseases for the same style pre-training: Pertussis, Varicella, Tuberculosis, Measles, TyphoidFever, Mumps, Diphtheria, and ScarletFever. Here, we discuss the details of the first stage pret-train setting as following. Compartmental Model Generation. The EpiRecipe pipeline implements constraint-based model generation with 12 possible compartments: Susceptible (S), Infected (I), Exposed (E), Recovered (R), Hospitalized (H), Vaccinated (V), Quarantined (Q), Deceased (D), Protected (P), Environmental Reservoir (W), Asymptomatic (A), and Chronic carriers (C). We randomly select 3–7 compartments, with S and I as mandatory compartments. Simulation Parameters. Each synthetic epidemic is simulated with: • Basic reproduction number : R_{0}\sim\text{LogNormal}(\mu=2.5,\sigma=0.8) , clipped to [1.1,18.0] • Infectious period : \gamma^{-1}\sim\text{Gamma}(k=3,\theta=3) , ranging 3–21 days • Latent period (if E exists): \sigma^{-1}\sim\text{Gamma}(k=2,\theta=2.5) , ranging 1–14 days • Population size : Uniformly sampled from [10^{4},10^{6}] • Simulation length : 52–260 weeks (1–5 years) • Time resolution : Weekly aggregation (default), with optional daily resolution Seasonal Forcing. 50% of generated models include seasonal transmission modulation: (9) \beta(t)=\beta_{0}\times\left(1+\epsilon\cos\left(\frac{2\pi t}{T}+\phi\right)\right) where \epsilon\in[0.1,0.5] is the forcing amplitude, T\in\{26,52,104,156\} weeks represents the period (biannual, annual, 2-year, or 3-year cycles), and \phi\in[0,2\pi] is a random phase offset. This captures the seasonal patterns observed in respiratory diseases like influenza and measles. Group-Stratified Models. To capture heterogeneous contact patterns, 50% of training samples use group-stratified models with 2–5 population groups. Each group has distinct: • Population fraction (sampled from Dirichlet distribution) • Contact rate multiplier \in[0.5,1.5] • Susceptibility multiplier \in[0.8,1.2] • Infectivity multiplier \in[0.8,1.2] Mixing patterns include homogeneous, assortative (with assortativity \in[0.5,0.9] ), hierarchical, and spatial structures. Gaussian Process Augmentation. Following the KernelSynth approach ( Ansari et al., 2024 ) , 20% of pretraining samples are generated using Gaussian Process (GP) priors with epidemic-relevant kernels: • Periodic kernels : Capturing weekly (7 days), annual (52 weeks), biannual (26 weeks), and multi-year cycles (104–208 weeks) • RBF kernels : Modeling outbreak shapes at various scales (length scales 0.02–0.5) • Linear kernels : Capturing endemic trends • Composite kernels : Random combinations of 1–4 base kernels using + or \times operators This augmentation improves the model’s ability to learn diverse periodic patterns commonly observed in epidemic data. Pretraining Data Volume. The streaming data generation produces samples on-the-fly during training, providing effectively unlimited data diversity. Each batch generates 64 synthetic epidemics (configurable), and the pre-training generally takes over 80,000 batches. D.2. Downstream Evaluation Datasets We evaluate CAPE on 17 real-world disease datasets from Project Tycho ( van Panhuis et al., 2018 ) , a database of historical disease incidence in the United States. These datasets span diverse disease types with varying epidemiological characteristics. Data Processing. Each disease dataset is processed as follows: (1) Aggregation : Weekly case counts are aggregated across all reporting states to create a single national-level time series, avoiding the complexity of spatial modeling. (2) Normalization : Time series are standardized using z-score normalization applied on the time series prior to tokenization. Online Evaluation Protocol. We adopt an online (rolling) evaluation setting ( Rodríguez et al., 2023 ) that simulates real-world deployment scenarios where models must forecast future outbreaks using only historically available data. The evaluation proceeds as follows: (1) Initial Training Window : The first 30% of the tokenized time series is used as the initial training set (base training rate = 0.3). (2) Rolling Folds : The remaining 70% of data is divided into K=2 non-overlapping evaluation folds. Each fold uses an expanding training window that includes all data up to the fold boundary. (3) Fold Structure : For fold k ( k=0,1 ): • Training set: tokens [0,\text{train\_end}_{k}] where \text{train\_end}_{k}=\lfloor 0.3\times T\rfloor+k\times\text{fold\_size} • Validation set: Last 20% of training tokens (used for hyperparameter tuning) • Test set: tokens [\text{train\_end}_{k},\text{train\_end}_{k}+\text{fold\_size}] (4) Forecasting Task : Given 8 input tokens (32 weeks of history), predict 1 output token (4 weeks ahead). This online setting differs from standard train/test splits by: (1) Respecting temporal order (no future data leakage); (2) Using expanding training windows that simulate incremental model updates; (3) Evaluating on multiple time periods to assess robustness across different epidemic phases. Dataset Characteristics. Table 10 provides comprehensive statistics for each downstream dataset. The diseases exhibit substantial heterogeneity in: • Temporal coverage : 21–122 years of observations (1888–2017) • Aggregated series length : 1,096–6,373 weeks after aggregation • Transmission modes : Including respiratory (12 diseases), sexually transmitted (1), fecal-oral (3), and bloodborne (1) • Basic reproduction number : Ranging from R_{0}\approx 1 (gonorrhea) to R_{0}\approx 12 –18 (measles, pertussis) Table 10 . Detailed statistics of downstream datasets from Project Tycho. “Agg. Len.” refers to the number of weeks after aggregating across states. Disease States Agg. Len. Years Total Cases Trans. R_{0} Measles 50 6,373 1888–2001 23,559,000 Resp. 12–18 Diphtheria 46 6,191 1888–1981 1,980,152 Resp. 1.7–4.3 Typhoid Fever 44 5,816 1888–1983 579,833 Fecal 2.8–7.0 Pertussis 46 5,719 1888–2017 3,325,547 Resp. 12–17 Scarlet Fever 48 4,957 1888–1969 9,171,413 Resp. 0.6–2.0 Tuberculosis 39 4,881 1890–2014 1,916,967 Resp. 0.24–4.3 Smallpox 44 3,122 1888–1952 458,485 Resp. 3.5–6.0 Acute Poliomyelitis 47 2,534 1912–1971 573,743 Fecal 5–7 Mumps 41 2,419 1924–2017 1,073,690 Resp. 4–7 Pneumonia 41 2,060 1912–1951 1,347,512 Resp. 1.4 Influenza 42 1,673 1919–1951 7,215,995 Resp. 1.2–1.6 Varicella 30 1,571 1889–2017 1,973,108 Resp. 10–12 Hepatitis B 31 1,449 1952–2007 422,522 Blood 1.0–3.3 Rubella 7 1,427 1966–2017 191,091 Resp. 3.4–7.0 Meningococcal Meningitis 37 1,330 1926–1964 166,509 Resp. 0.6–1.6 Gonorrhea 39 1,126 1972–2017 9,455,568 Sexual 1.0 Hepatitis A 38 1,096 1966–2007 651,553 Fecal 1.1–3.5 Appendix E Implementation Details Motivation for Our Settings. Our primary focus is on pre-training epidemic forecasting models using temporal (time series) data rather than spatiotemporal data. This design choice is motivated by the following considerations: • We aim to establish the foundation for epidemic pre-training in the temporal setting, which remains unexplored — only one prior work ( Kamarthi and Prakash, 2023 ) addresses this area, and it also focuses on the temporal setting. As shown in Sections 4.2-4.5, we address critical questions around generalization and pre-training influence in the epidemic domain, which remain open even without spatial context. • Temporal models are broadly applicable and more data-efficient, especially when spatial data is unavailable or unreliable. Many real-world epidemic datasets lack well-defined spatial graphs, and building them (e.g., from mobility or administrative data) is costly and complex, particularly at scale. These inconsistencies also hinder fair comparisons between temporal and spatiotemporal models. • Our framework is extensible to spatiotemporal modeling. Specifically, the temporal input can be replaced with graph-structured data, and the predictor can incorporate graph-based encoders. Exploring this direction is exciting future work, but we believe temporal pre-training is a crucial first step toward that goal. Model Details. We design our model by stacking 4 layers of the CAPE encoder, each with a hidden size of 512 and 4 attention heads. For compartment representations, each is encoded with a learnable embedding of size 512 and is mapped to 6 distinct groups. The patch encoder uses a decoder-only transformer with causal masking and GELU activations. Positional encoding is applied via sinusoidal embeddings. Pre-training. We pre-train CAPE on synthetic epidemic data generated using the EpiRecipe simulation framework. The synthetic dataset consists of 5,000 validation samples and 5,000 test samples, covering diverse epidemic dynamics including SIR, SEIR, and SEIR-V models. We use a token size of 4 time steps per patch. Training uses the AdamW optimizer with learning rate 1\times 10^{-4} , weight decay 1\times 10^{-3} , batch size 64, and CosineAnnealingWarmRestarts scheduler ( T_{0}=10 , T_{\text{mult}}=2 ). For the loss function, we set the \alpha of the I compartment to be 1 and 0.5 for the rest of the compartments, and set the \beta to be 0.5. First-stage pre-training runs for 150 epochs. The second stage uses the first 20% of each disease’s time series in chronological order (with 10% of this portion held for validation), ensuring strict temporal separation from downstream evaluation data. Training continues from the first-stage checkpoint using the same architecture, with AdamW optimizer (learning rate 1\times 10^{-4} , weight decay 1\times 10^{-4} ), batch size 32, Huber loss ( \delta=1.0 ), and 15 epochs. Only the I (Infectious) compartment receives supervision during this stage. The best checkpoint is selected based on validation loss. Both stages utilize 8 NVIDIA A100-SXM4-80GB. PEM Pre-training. For the PEM baseline ( Kamarthi and Prakash, 2023 ) , we pre-train a PatchTST-based architecture ( d_{\text{model}}=256 , 6 layers, 8 attention heads, patch length 4, dropout 0.1) using self-supervised masked prediction. We use all 17 diseases with the first 30% of each time series for pre-training. Three complementary masking strategies are employed: RANDMASK (random segment masking, 40% probability), LASTMASK (masking final segments for forecasting, 30% probability), and PEAKMASK (masking around epidemic peaks, 30% probability). The masking ratio \gamma is set to 0.3. Training uses AdamW with learning rate 1\times 10^{-4} , weight decay 1\times 10^{-3} , batch size 64, for 25 epochs. Downstream Evaluation. All models use 8 input tokens (32 weeks) to predict 1 output token (4 weeks ahead). Ensemble Aggregation Strategies. In epidemic forecasting, underestimation poses greater risks than overestimation: underestimating an outbreak can lead to inadequate resource allocation, delayed interventions, and preventable morbidity, whereas moderate overestimation simply results in conservative preparedness. Consequently, our ensemble aggregation strategies are deliberately designed with an upward bias , favoring predictions from more pessimistic (higher-predicting) ensemble members. Given M ensemble members with predictions \{\hat{y}^{(m)}\}_{m=1}^{M} , we employ 14 pooling strategies spanning conservative to aggressive estimation: (1) percentile_75 : 75th percentile of ensemble predictions. \hat{y}=\hat{y}^{(\lceil 0.75M\rceil)}_{\text{sorted}} (2) median_max_blend : Equal blend of median and maximum. \hat{y}=0.5\cdot\text{median}(\{\hat{y}^{(m)}\})+0.5\cdot\max_{m}\hat{y}^{(m)} (3) upper_half_mean : Mean of predictions above the median. \hat{y}=\frac{2}{M}\sum_{m:\hat{y}^{(m)}\geq\text{median}}\hat{y}^{(m)} (4) biased_mean_50 : Mean with 50% bias toward maximum. \hat{y}=0.5\cdot\bar{y}+0.5\cdot\max_{m}\hat{y}^{(m)} (5) optimistic_weighted : Weights proportional to prediction magnitude. \hat{y}=\sum_{m}w_{m}\hat{y}^{(m)} , where w_{m}=\hat{y}^{(m)}/\sum_{j}\hat{y}^{(j)} (6) robust_optimal : Maximum of (75th percentile, upper-half mean, optimistic weighted). \hat{y}=\max\left(P_{75},\bar{y}_{\text{upper}},\hat{y}_{\text{optim}}\right) (7) adaptive_percentile : Variance-adaptive percentile (70th–90th). \hat{y}=P_{q} where q=0.7+0.2\cdot\min(1,\sigma/\bar{y}) (8) trimmed_upper : Mean of top 70% of predictions. (9) quantile_blend_60_80 : Average of 60th and 80th percentiles. \hat{y}=0.5\cdot P_{60}+0.5\cdot P_{80} (10) shrinkage_upper_50 : Upper-half mean shrunk 50% toward median. \hat{y}=0.5\cdot\bar{y}_{\text{upper}}+0.5\cdot\text{median} (11) variance_adaptive_blend : Blend median/max based on coefficient of variation. \hat{y}=\alpha\cdot\text{median}+(1-\alpha)\cdot\max , where \alpha=\max(0.3,1-\sigma/\bar{y}) (12) max_plus_std : Maximum plus one standard deviation. \hat{y}=\max_{m}\hat{y}^{(m)}+\sigma (13) max_plus_std_100 : Maximum plus standard deviation, scaled by 100. \hat{y}=\max_{m}\hat{y}^{(m)}+100\cdot\sigma (14) beyond_max_20 : Maximum extended by 20% of ensemble range. \hat{y}=\max_{m}\hat{y}^{(m)}+0.2\cdot(\max-\min) (15) residual_correction : Observation-anchored correction: \hat{y}=y_{\text{last\_obs}}+\alpha\cdot e^{-\text{CV}(\mathbf{r})}\cdot\text{median}(\{r^{(m)}\}) , where r^{(m)}=\hat{y}^{(m)}-y_{\text{last\_obs}} and \alpha\in\{0.2,0.3,0.4\} . Corrections shrink toward the last observation when masks disagree (high CV). This collection spans a spectrum from moderately conservative (percentile-based) to aggressively cautious (beyond-maximum) strategies, allowing validation-based selection to identify the appropriate risk-sensitivity for each disease. During evaluation, strategy selection is performed on a held-out validation set based on MSE, and test metrics are reported for the validation-selected strategy. Baseline Comparison. We compare against 12 baseline methods spanning statistical models (ARIMA, SIR), deep learning architectures (GRU, LSTM, CNN), specialized epidemic models (EINN, EpiDeep, PEM), and modern time series transformers (DLinear, PatchTST, NBeats, XGBoost). All baselines undergo hyperparameter tuning on the validation set within each fold, with grid search over hidden sizes \{128,512\} , number of layers \{2,3\} , and learning rates \{0.001,0.005\} . CAPE operates in zero-shot mode with only the smoothing window size and ensemble strategy tuned on validation data. Evaluation Metrics. Results are aggregated across all folds using mean and standard deviation. Primary metrics are Mean Squared Error (MSE) and Mean Absolute Error (MAE), computed on the final token of each prediction (4 weeks ahead). For CAPE, we additionally report uncertainty quantification via ensemble predictions using multiple random compartment masks. Appendix F Representation Properties We extract the following properties from each trajectory to analyze what representations CAPE learns. Let I(t) denote the infection time series of length T , with peak at time t^{*}=\arg\max_{t}I(t) and peak value I^{*}=\max_{t}I(t) . The full visualization is shown in Figure 11 . • Peak Timing : Normalized position of the infection peak. \tau_{\text{peak}}=t^{*}/T • Trajectory Variability : Variance of the infection time series. \sigma^{2}_{I}=\frac{1}{T}\sum_{t=1}^{T}(I(t)-\bar{I})^{2} • Epidemic Intensity : Log-scaled peak height. \mathcal{I}=\log_{10}(I^{*}+1) • Epidemic Duration : Fraction of time above 10% of peak. \mathcal{D}=\frac{1}{T}\sum_{t=1}^{T}\mathbf{1}[I(t)>0.1\cdot I^{*}] • R_{t} Dominant Period : Dominant periodicity from FFT of R_{t} (log-scaled). \mathcal{P}=\log_{10}(1/f^{*}+1) where f^{*}=\arg\max_{f>0}|\mathcal{F}\{R_{t}-\bar{R}_{t}\}(f)| • R_{t} Volatility : Coefficient of variation of R_{t} . \text{CV}_{R_{t}}=\sigma_{R_{t}}/\bar{R}_{t} • Wave Pattern : Number of local maxima exceeding 30% of peak height. N_{\text{waves}}=|\{t:I(t)>I(t\pm 1),\,I(t)/I^{*}>0.3\}| • Post-Peak Burden : Ratio of cumulative infections after vs. before peak. \mathcal{B}=\sum_{t>t^{*}}I(t)\,/\,\sum_{t\leq t^{*}}I(t) Figure 11 . t-SNE visualization of CAPE encodings of synthetic samples from EpiRecipe. Figure 12 . Comparison with zero-shot foundation models across all datasets. Appendix G Comparison with General Time Series Foundation Models We compare CAPE against three state-of-the-art time series foundation models: Chronos2, Moirai, and Moment. The radar plots below visualize the performance across five key epidemic forecasting metrics for each disease: • MSE (Mean Squared Error, lower is better): \text{MSE}=\frac{1}{N}\sum_{i=1}^{N}(\hat{y}_{i}-y_{i})^{2} where \hat{y}_{i} is the prediction and y_{i} is the ground truth. • Outbreak Sensitivity (higher is better): Measures the recall of high-value detection—when actual values exceed a threshold, how often does the model also predict above that threshold? \text{Outbreak Sens.}=\frac{|\{i:\hat{y}_{i}>\tau\land y_{i}>\tau\}|}{|\{i:y_{i}>\tau\}|}\times 100\% We evaluate at two threshold levels: a moderate threshold \tau_{1}=\text{median}(y)+0.5\sigma_{y} for general outbreak detection, and a strict threshold \tau_{2}=\mu_{y}+\sigma_{y} for severe alert detection. • Rising Phase MAE (lower is better): Mean Absolute Error during epidemic growth phases when values are increasing. \text{Rising MAE}=\frac{1}{|R|}\sum_{i\in R}|\hat{y}_{i}-y_{i}|,\quad R=\{i:y_{i}-x_{i}^{\text{last}}>0.1\} where x_{i}^{\text{last}} is the last observed value before prediction and R is the set of rising-phase samples. • Peak Underestimate Rate (lower is better): Among peak values (top 10%), how often does the model underestimate? \text{Peak Underest.}=\frac{|\{i:\hat{y}_{i}