Stochastic Sparse Sampling: A Framework for Variable-Length Medical Time Series Classification

## Abstract

Abstract While the majority of time series classification research has focused on modeling fixed-length sequences, variable-length time series classification (VTSC) remains critical in healthcare, where sequence length may vary among patients and events. To address this challenge, we propose S tochastic S parse S ampling (SSS), a novel VTSC framework developed for medical time series. SSS manages variable-length sequences by sparsely sampling fixed windows to compute local predictions, which are then aggregated and calibrated to form a global prediction. We apply SSS to the task of seizure onset zone (SOZ) localization, a critical VTSC problem requiring identification of seizure-inducing brain regions from variable-length electrophysiological time series. We evaluate our method on the Epilepsy iEEG Multicenter Dataset, a heterogeneous collection of intracranial electroencephalography (iEEG) recordings obtained from four independent medical centers. SSS demonstrates superior performance compared to state-of-the-art (SOTA) baselines across most medical centers, and superior performance on all out-of-distribution (OOD) unseen medical centers. Additionally, SSS naturally provides post-hoc insights into local signal characteristics related to the SOZ, by visualizing temporally averaged local predictions throughout the signal.

## 1 Introduction

Artificial intelligence (AI) in medicine has received significant attention in recent years, with various applications to clinical diagnosis and treatment planning (Rajpurkar et al., ). Despite its advancements, the actual integration into everyday clinical practice remains limited, with much of it attributed to the challenges of handling the complexity and variability in medical data. One particularly challenging aspect of this variability lies in the nature of medical time series data. Variable-length time series are prevalent throughout many areas of healthcare, including heart rate monitoring, blood glucose measurements, and electrophysiological recordings where sequence length can vary dependent on the recording or length of an event (Agliari et al., ; Deutsch et al., ; Walther et al., ). Yet, the majority of time series classification (TSC) literature focuses solely on methods that process fixed-length sequences (Ismail Fawaz et al., ; Mohammadi Foumani et al., ).

At the same time, healthcare applications require greater interpretability from modern time series methods to expand their applicability in critical domains and accelerate clinical adoption (Amann et al., ). This interpretability is especially crucial in contexts where the relationship between pathology and signal characteristics is not well understood, as it can provide valuable insights for both clinicians and scientists. Recent studies in time series classification (TSC) have explored the explainability of specific signal segments, as opposed to full-signal analysis, which proves particularly useful for uncovering important characteristics such as motifs, anomalies, or frequency patterns (Early et al., ; Crabbé & Van Der Schaar, ; Huang et al., ). However, there still remains a significant need for models with built-in interpretability in medical applications. Such methods would allevaiate the burden of implementing both a base model and a specialized interpretability method—which may require more domain expertise—and may more effectively facilitate clinical adoption.

The need for variable-length time series classification (VSTC) methods with built-in interpretability is particularly relevant in seizure onset zone (SOZ) localization—the task of identifying brain regions from which seizures originate—as effective treatment requires analysis of variable-length signals (Balaji & Parhi, ). The World Health Organization (WHO) reports epilepsy affects over 50 million people globally, establishing it as one of the most common yet poorly understood neurological disorders (Organization et al., ; Stafstrom & Carmant, ). Additionally, one-third of patients do not respond to antiepileptic drugs, making surgery the last resort and accurate SOZ localization essential for effectively planning the operation. The process of SOZ identification involves a two-step procedure: initial implantation of electrodes in areas suspected to contain the SOZ, followed by recording and visual analysis of intracranial electroencephalography (iEEG) signals by medical experts. The task of SOZ localization reduces to classifying individual electrode recordings, representing different regions within the brain. Effective localization of the SOZ is challenging due to the absence of clinically validated biological markers and the variable-length nature of iEEG signals—consequently, surgical success rates range from 30% to 70% (Löscher et al., ; Li et al., ).

Figure: Figure 1: An overview of Stochastic Sparse Sampling (SSS) training procedure. (A) For a given time series, we sample windows of fixed-length at random throughout the signal. (B) Each window is processed independently by a local model with parameters $\theta$, outputting the local predictions $\hat{y}_{1},\dots,\hat{y}_{k}$. (C) Local predictions are then fed through an aggregation function to form the final prediction $\hat{y}$.
Refer to caption: extracted/5944476/figures/sss/SSSv2.3.png

Contributions. While our work primarily focuses on VTSC, we also evaluate our method’s performance on OOD data and explore its potential for providing local explanations. To this end, we propose Stochastic Sparse Sampling (SSS) a novel framework for VTSC developed for medical time series. The main contributions of our paper are listed as follows:

- •
Robustness to long and variable-length sequences. SSS samples fixed-length windows, and processes them independently through a single model. This prevents context overload in long sequences seen in infinite-context methods, and does not utilize padding, truncation, or interpolation required by finite-context methods. By relying on a single local model, SSS utilizes far fewer parameters compared to finite-context methods that traditionally ingest the entire signal, which significantly reduces computational cost during training and the risk of overfitting over long sequences.
- •
Generalization to unseen patient populations. SSS demonstrates strong performance on out-of-distribution (OOD) data from unseen medical centers. When trained on data from one or more medical centers and evaluated on a completely new center with a different patient population, SSS outperforms all baselines in our comparisons. This result suggests SSS’s potential as a foundation model for TSC, opening new avenues for research and clinical applications.
- •
Explainability through local predictions. Our method enhances model interpretability by directly tying each output—a probability score for each window—to the overall prediction. This capability is crucial in critical clinical settings, such as SOZ localization, which traditionally relies on visual analysis. Given the significant risks associated with brain region removal, any proposal should be designed to integrate within clinical workflows. Moreover, in the absence of universally recognized biological markers for epilepsy, SSS offers the potential to further our understanding the SOZ and to identify novel markers.
- •
Compatibility with modern and classical backbones. SSS integrates with any time series backbone. This ensures that our approach leverages well-established frameworks now and into the future, allowing for adaptability across a diverse array of contexts.

## 2 Related Work

TSC methodologies can be broadly categorized into finite-context methods, which operate on fixed-length input segments, and infinite-context methods, which handle variable-length sequences without being restricted to a predetermined window size. For a formal treatment, please see Appendix A.5.

Finite-context methods. Finite-context methods are among the most commonly used approaches for TSC. Transformer-based models have gained significant attention, with variations such as sparse attention, series decomposition, and patching techniques (Vaswani et al., ; Kitaev et al., ; Zhou et al., ; Wu et al., ; Zhou et al., ; Liu et al., ; Nie et al., ; Liu et al., ). Several temporal convolutional networks (TCNs) have also been proposed, to capture temporal dependencies through dilated convolutions and Inception-like architectures (Lai et al., ; Bai et al., ; Ismail Fawaz et al., ; Wu et al., ; Luo & Wang, ). Recently, multilayer perceptrons (MLPs) and simple linear models have demonstrated competitive performance as well (Chen et al., ; Zeng et al., ). Despite the significant rise of finite-context methods, these methods are inherently limited in their ability to handle variable-length sequences, and will require the use of either padding, truncation, or interpolation for VTSC. Furthermore, as the sequence length increases, so does the number of model parameters, which leads to not only greater computational cost but an increased risk of overfitting.

Infinite-context methods. The recurrent neural network (RNN) family includes several models capable of ingesting variable-length time series (Rumelhart et al., ). Long-short term memory (LSTM) networks introduce memory cells and gating mechanisms to better handle long-term dependencies (Hochreiter & Schmidhuber, ). Gated recurrent units (GRUs) simplify the LSTM architecture while maintaining similar performance (Bahdanau et al., ). State space models (SSMs) have gained recent attention, with approaches such as S4 introducing structured parameterization to enable efficient computation over long sequences, while still attempting to capture long-range dependencies (Gu et al., ). Building on this, Mamba introduces a selective SSM that adapts to input dynamics, further improving processing of long-range dependencies in time series data while while maintaining linear time complexity with respect to sequence length (Gu & Dao, ). Despite these advancements, RNNs and SSMs can still struggle with retaining information in extremely long sequences and may be prone to vanishing or exploding gradients (Salehinejad et al., ). ROCKET offers an alternative, using random convolutional kernels to convert input into a fixed-length representation for VTSC, but at the cost of interpretability and potentially limited model expressivity (Dempster et al., ).

SOZ localization methods. Several recent proposals have been tailored specifically to SOZ localization. Functional connectivity graphs compute patient-specific channel metrics to capture brain connectivity patterns (Grattarola et al., ; Fang et al., ), offering insights into functional relationships associated with seizures. However, their reliance on intra-patient dynamics makes them unsuitable for a single model that can generalize across multi-patient, heterogeneous datasets. Alternatively, electrical stimulation methods that use intracranial electrodes (Johnson et al., ; Yang et al., ) can enhance localization accuracy through induced responses analyzed by TCNs and logistic regression models. Yet, these approaches require both fixed-length windows and the use of active stimulation. For our purpose of building a general model for SOZ localization, which can be applied to multiple patients (with a potentially varying number of channels) without electrical stimulation, we do not consider such approaches in our study.

## 3 Method

### 3.1 Variable-length time series classification

Consider a collection of time series $X=\big{\{}(\operatorname{\mathbf{x}}_{t}^{(1)})_{t=1}^{T_{1}},\dots,(
\operatorname{\mathbf{x}}_{t}^{(n)})_{t=1}^{T_{n}}\big{\}}$ with labels $Y=\{y^{(1)},\dots,y^{(n)}\}$, where each series $i$ has sequence length $T_{i}\in\operatorname{\mathbb{N}}$, and for each time point $t$, the vector $\operatorname{\mathbf{x}}_{t}^{(i)}\in\operatorname{\mathbb{R}}^{M_{i}}$ has $M_{i}\in\operatorname{\mathbb{N}}$ channels. The goal of VTSC is to learn a classifier $f_{\theta}$ which maps each series $(\operatorname{\mathbf{x}}_{t}^{(i)})_{t=1}^{T_{i}}$ to its corresponding class in $\{1,\dots,K\}$ for $K\in\operatorname{\mathbb{N}}$ classes. We require that $f_{\theta}$ can handle sequences of any length—that is, it has infinite context—since we assume that each $T_{i}$ can be arbitrarily large at inference time. Otherwise, we must adjust a finite-context classifier using padding, truncation, or interpolation.

### 3.2 Stochastic sparse sampling

#### 3.2.1 Sparse Training

Figure 1 provides an overview of SSS at train time. During each training epoch, SSS performs a sampling procedure without replacement to create each batch. Fix $L\in\operatorname{\mathbb{N}}$ as the window size and let $\operatorname{\mathcal{W}}$ be the collection of all windows with size $L$ from all time series in $X$. Within any batch, a window is drawn from $\operatorname{\mathcal{W}}$, where the probability of it originating from series $i$ is set to $p_{i}\approx T_{i}/\big{(}\sum_{j=1}^{n}T_{j}\big{)}$ for every $i$. More formally, for each $i$, let $N_{i}$ be the random variable representing the number of windows from series $i$ in a batch of size $B$. Then $N_{i}\sim\text{Binomial}(B,p_{i})$, and consequently $\mathbb{E}[N_{i}]=Bp_{i}$. This proportional sampling ensures fair representation of each series based on its length, allowing longer sequences—which contain more information—to contribute more samples. By sampling only a subset of windows, SSS introduces sparsity into the training process, reducing computational cost found in finite-context methods, and the likelihood of context overload in infinite-context methods. Also note that by sampling with replacement, the model sees each window exactly once during a single training epoch.

After sampling a batch of windows $\operatorname{\mathcal{W}}_{0}=\{\mathbf{w}_{1},\dots,\mathbf{w}_{B}\}$, each $\mathbf{w}_{b}\in\operatorname{\mathcal{W}}_{0}$ is processed independently by a local model $f_{\theta}$ to obtain a local prediction $\hat{y}_{b}=f_{\theta}(\mathbf{w}_{b})\in[0,1]^{K}$, representing our probability distribution over $K\in\operatorname{\mathbb{N}}$ classes. The choice of $f_{\theta}$ can be any time series backbone, in our experiments we select PatchTST (Nie et al., ). For each time series $1\leq i\leq n$, denote:

$$ $\displaystyle\operatorname{\mathcal{W}}_{i}=\{\operatorname{\mathbf{w}}\in \operatorname{\mathcal{W}}_{0}\ |\ \operatorname{\mathbf{w}}\text{is from series $i$}\},$ (1) $$

as the collection of windows in the batch originating from series $i$, and let:

$$ $\displaystyle\operatorname{\mathcal{Y}}_{i}=\{f_{\theta}(\operatorname{\mathbf {w}})\ |\ \operatorname{\mathbf{w}}\in\operatorname{\mathcal{W}}_{i}\},$ (2) $$

be the set of multiset of window probabilities. To obtain the global prediction for time series $i$, we aggregate window probabilities from all examples originating from it, given by:

$$ $\displaystyle\hat{y}^{(i)}=\text{Aggr}(\mathcal{Y}_{i})=\sum_{\hat{y}\in \mathcal{Y}_{i}}\alpha(\hat{y})\hat{y},$ (3) $$

where each $\alpha(\hat{y})\in[0,1]$ represents the weight of window probability $\hat{y}$ to the final output, satisfying $\sum_{\hat{y}\in\mathcal{Y}_{i}}\alpha(\hat{y})=1$; that is, $\text{Aggr}(\cdot)$ produces a convex combination over $\hat{y}_{1},\dots,\hat{y}_{n}$. In our experiments, we use mean aggregation, i.e., $\alpha(\hat{y})=\frac{1}{|\mathcal{Y}_{i}|}$ for all $\hat{y}\in\mathcal{Y}_{i}$, due to its simplicity and effectiveness for our current objectives. This formulation guarantees that $\hat{y}^{(i)}$ remains a valid probability distribution over $K$ classes (proof in Appendix A.3), and allows for potential of non-uniform aggregation functions, enabling weighting of window predictions based on factors such as prediction uncertainty, or frequency characteristics.

Figure: Algorithm 1 SSS Training Algorithm (Single Epoch)

#### 3.2.2 Inference

To the derive the prediction for a time series $(\operatorname{\mathbf{x}}_{t}^{(i)})_{t=1}^{T_{i}}$ at inference time, we utilize all windows from the selected time series, to form its final prediction $\hat{y}^{(i)}$. Let $\operatorname{\mathcal{W}}_{i}$ be the collection of all windows from series $i$. We pass each window through the local model to obtain the multiset of window probabilities $\operatorname{\mathcal{Y}}_{i}$ as shown in Equation (2). Before the aggregation step, we utilize a calibrator $g_{\phi}:[0,1]^{K}\to[0,1]^{K}$, which adjusts each individual window probability to reduce the presence of noise, and define:

$$ $\displaystyle\tilde{\operatorname{\mathcal{Y}}}_{i}=\{g_{\phi}(\hat{y})\ |\ \hat{y}\in\operatorname{\mathcal{Y}}_{i}\},$ (4) $$

which is then fed into the final prediction during the aggregation step $\hat{y}^{(i)}=\text{Aggr}(\tilde{\operatorname{\mathcal{Y}}}_{i})$. By calibrating the window probabilities before aggregation, we correct for biases or misestimations in the predicted probabilities, which occur when the output probabilities of the local models do not accurately reflect the true likelihood of the event. We consider isotonic regression and Venn-Abers predictors for our calibration method. It is important to note, that these calibration techniques do not alter underlying structure of $f_{\theta}$ and do not utilize input features from the time series; rather, they adjust the output probabilities to mitigate the effect of noise during the aggregation step. For more information regarding calibration methods see Appendix A.4.

## 4 Experiments

### 4.1 Baselines

For our finite-context baselines, we include a variety of modern time series backbones including PatchTST, which uses subwindows as tokens in combination with the traditional Transformer architecture (Nie et al., ; Vaswani et al., ). TimesNet is a TCN architecture that models both interperiod and intraperiod dynamics by leveraging Fast Fourier Transform (FFT) features to slice the signal into multiple views, which are then processed through inception blocks (Wu et al., ; Ismail Fawaz et al., ). ModernTCN, is a recently proposed TCN which decouples temporal and channel information processing by using separate DWConv and ConvFFN modules for more efficient representation learning (Luo & Wang, ). DLinear is linear neural network, which has shown to outperform several modern Transformer-based architecutres, utilizing traditional seasonal-trend decomposition techniques (Zeng et al., ). In our infinite-context baselines, we utilize ROCKET, which applies randomly initialized, fixed convolutional kernels to the input sequence. ROCKET compresses the resulting convolutional outputs to the maximum value and the proportion of positive values (PPV), where these features then fed to a linear classifier (Dempster et al., ). We also consider GRUs and an LSTM network, both of which are popular RNN frameworks designed to capture long-term dependencies in sequential data (Bahdanau et al., ; Hochreiter & Schmidhuber, ). Additionally, we use the recent SSM architecture, Mamba, which applies selective state updates for efficient long-range dependency modeling (Gu & Dao, ). Further details regarding configurations and hyperparameter tuning for each baseline can be found in Appendix C.

### 4.2 Dataset

The Epilepsy iEEG Multicenter Dataset(^1^11https://openneuro.org/datasets/ds003029/versions/1.0.7) consists of iEEG signals with SOZ clinical annotations from four medical centers including the Johns Hopkins Hospital (JHH), the National Institute of Health (NIH), University of Maryland Medical Center (UMMC), and University of Miami Jackson Memorial Hospital (UMH). Since UMH contained only a single patient with clinical SOZ annotations, we did not consider it in our main evaluations; however, we did use UMH within the multicenter evaluation in 1 and the training set for OOD experiments for SOZ localization on unseen medical centers in Table 2. We select the F1 score, Area Under the Receiver Operator Curve (AUC), and accuracy for our evaluation metrics. For summary statistics and information on the dataset see Appendix B.1.

### 4.3 Univariate VTSC

The objective of SOZ localization for each patient-specific iEEG recording is to precisely identify the channels or electrodes that belong to the seizure onset zone. This effectively reduces the task to univariate TSC. While several channel-dependent methods have been proposed for SOZ localization (see section 2), we focus primarily on channel-independent solutions for two key reasons: (1) they are more resilient to interpatient variability and are unaffected by factors like channel count and therefore can be applied in multiple hospital settings, and (2) they generalize better to domains beyond electrophysiological data, as they learn local signal characteristics rather than explicitly modeling functional connectivity between electrode sites, which may not be present in other medical time series.

**Table 1: SOZ localization. F1 score, AUC, and Accuracy are reported for each medical center, averaged over $5$ seeds. For each center, we train and evaluate a separate model; the first column represents training and evaluation on all centers. Bolded values with ^∗ and ^† denote the best and second-best results, respectively.**
|  | All | JHH | NIH | UMMC |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Model | F1 | AUC | Acc. | F1 | AUC | Acc. | F1 | AUC | Acc. | F1 | AUC | Acc. |
| SSS (Ours) | $\textbf{0.7629}^{*}$ | $\textbf{0.7999}^{*}$ | $\textbf{72.35}^{*}$ | $\textbf{0.8187}^{*}$ | $\textbf{0.8851}^{*}$ | $\textbf{81.37}^{*}$ | $\textbf{0.6716}^{*}$ | 0.6853 | $\textbf{64.22}^{\dagger}$ | $\textbf{0.7978}^{\dagger}$ | $\textbf{0.8279}^{\dagger}$ | $\text{76.06}^{\ \ }$ |
| PatchTST (Nie et al., ) | $\textbf{0.7097}^{\dagger}$ | $\textbf{0.7852}^{\dagger}$ | $\text{66.83}^{\ \ }$ | $\textbf{0.7419}^{\dagger}$ | $\textbf{0.8045}^{\dagger}$ | $\text{71.82}^{\ \ }$ | $\text{0.6402}^{\ \ }$ | $\textbf{0.7036}^{\dagger}$ | $\text{62.11}^{\ \ }$ | $\textbf{0.8015}^{*}$ | $\text{0.8121}^{\ \ }$ | $\text{77.58}^{\ \ }$ |
| TimesNet (Wu et al., ) | $\text{0.6897}^{\ \ }$ | $\text{0.7174}^{\ \ }$ | $\text{65.98}^{\ \ }$ | $\text{0.6891}^{\ \ }$ | $\text{0.8029}^{\ \ }$ | $\textbf{73.64}^{\dagger}$ | $\text{0.5950}^{\ \ }$ | $\text{0.6806}^{\ \ }$ | $\textbf{66.00}^{*}$ | $\text{0.7821}^{\ \ }$ | $\text{0.8099}^{\ \ }$ | $\textbf{77.06}^{\dagger}$ |
| ModernTCN (Luo & Wang, ) | $\text{0.6938}^{\ \ }$ | $\text{0.7305}^{\ \ }$ | $\text{68.42}^{\ \ }$ | $\text{0.6710}^{\ \ }$ | $\text{0.7508}^{\ \ }$ | $\text{67.73}^{\ \ }$ | $\text{0.5055}^{\ \ }$ | $\textbf{0.7220}^{*}$ | $\text{64.00}^{\ \ }$ | $\text{0.6371}^{\ \ }$ | $\text{0.8203}^{\ \ }$ | $\text{71.76}^{\ \ }$ |
| DLinear (Zeng et al., ) | $\text{0.6916}^{\ \ }$ | $\text{0.7044}^{\ \ }$ | $\text{68.41}^{\ \ }$ | $\text{0.6873}^{\ \ }$ | $\text{0.7395}^{\ \ }$ | $\text{66.36}^{\ \ }$ | $\text{0.6055}^{\ \ }$ | $\text{0.6405}^{\ \ }$ | $\text{59.50}^{\ \ }$ | $\text{0.7658}^{\ \ }$ | $\text{0.7729}^{\ \ }$ | $\text{77.05}^{\ \ }$ |
| ROCKET (Dempster et al., ) | $\text{0.6847}^{\ \ }$ | $\text{0.7481}^{\ \ }$ | $\text{69.27}^{\ \ }$ | $\text{0.6753}^{\ \ }$ | $\text{0.7752}^{\ \ }$ | $\text{69.09}^{\ \ }$ | $\textbf{0.6520}^{\dagger}$ | $\text{0.6546}^{\ \ }$ | $\text{62.63}^{\ \ }$ | $\text{0.7686}^{\ \ }$ | $\text{0.7900}^{\ \ }$ | $\text{74.55}^{\ \ }$ |
| Mamba (Gu & Dao, ) | $\text{0.6452}^{\ \ }$ | $\text{0.7134}^{\ \ }$ | $\text{64.39}^{\ \ }$ | $\text{0.6456}^{\ \ }$ | $\text{0.6764}^{\ \ }$ | $\text{62.27}^{\ \ }$ | $\text{0.5974}^{\ \ }$ | $\text{0.6050}^{\ \ }$ | $\text{58.95}^{\ \ }$ | $\text{0.7900}^{\ \ }$ | $\textbf{0.8424}^{*}$ | $\text{76.36}^{\ \ }$ |
| GRUs (Bahdanau et al., ) | $\text{0.6948}^{\ \ }$ | $\text{0.7340}^{\ \ }$ | $\text{65.85}^{\ \ }$ | $\text{0.6140}^{\ \ }$ | $\text{0.6959}^{\ \ }$ | $\text{63.18}^{\ \ }$ | $\text{0.6171}^{\ \ }$ | $\text{0.6283}^{\ \ }$ | $\text{62.63}^{\ \ }$ | $\text{0.7920}^{\ \ }$ | $\text{0.8211}^{\ \ }$ | $\textbf{77.27}^{*}$ |
| LSTM (Hochreiter & Schmidhuber, ) | $\text{0.6709}^{\ \ }$ | $\text{0.7144}^{\ \ }$ | $\text{65.43}^{\ \ }$ | $\text{0.6571}^{\ \ }$ | $\text{0.6190}^{\ \ }$ | $\text{59.09}^{\ \ }$ | $\text{0.5657}^{\ \ }$ | $\text{0.5909}^{\ \ }$ | $\text{54.74}^{\ \ }$ | $\text{0.7604}^{\ \ }$ | $\text{0.8060}^{\ \ }$ | $\text{73.64}^{\ \ }$ |

Table  1 summarizes our experimental results for SOZ localization on each individual medical center, along with training and evaluation on all medical centers. Within the multicenter evaluation, SSS outperforms all baselines for each evaluation metric. SSS also shows strong performance for the JHH and NIH centers, with comparable results in the UMMC center. We attribute this difference in performance for UMMC due to the fact that it is the only center where the sampling frequency of patient recordings can differ between patients (250-1000 Hz), whereas JHH and NIH both have sampling frequencies of 1000 Hz. We also observe that in general, finite-context perform better on the chosen evaluation metrics in comparison to infinite-context methods, for in-distribution univariate VTSC.

### 4.4 Out-of-Distribution VTSC

Table 2 reports our results for SOZ localization in the OOD setting. At train time, from the collection of four medical center datasets, we omit one and train on the remaining three. At inference time, we test solely on the omitted medical center to gauge how well each method performs OOD. For iEEG signals from epilepsy patients, inter-patient variability can be significant due to differences in placement of electrodes in the brain, and the inherent heterogeneity of epileptogenic networks across individuals. Thus, even among medical time series, this can be one of the most challenging tasks to perform OOD. SSS outperforms each baseline on each unseen medical center, often by a considerable margin when compared to finite-context methods.

**Table 2: Out-of-Distribution SOZ localization. F1 score, AUC, and Accuracy are reported for unseen medical centers, averaged over $5$ seeds. For each center, we train on all other centers and evaluate on the selected center. Bolded values with ^∗ and ^† denote the best and second-best results, respectively.**
|  | JHH | NIH | UMMC |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Model | F1 | AUC | Acc. | F1 | AUC | Acc. | F1 | AUC | Acc. |
| SSS (Ours) | $\textbf{0.6981}^{*}$ | $\textbf{0.6590}^{*}$ | $\textbf{57.80}^{*}$ | $\textbf{0.6492}^{*}$ | $\textbf{0.6092}^{*}$ | $\textbf{54.73}^{\dagger}$ | $\textbf{0.7243}^{*}$ | $\textbf{0.8048}^{*}$ | $\textbf{72.42}^{*}$ |
| PatchTST (Nie et al., ) | $\text{0.6175}^{\ \ }$ | $\text{0.5267}^{\ \ }$ | $\text{50.46}^{\ \ }$ | $\text{0.5986}^{\ \ }$ | $\text{0.4829}^{\ \ }$ | $\text{48.17}^{\ \ }$ | $\text{0.5067}^{\ \ }$ | $\text{0.5274}^{\ \ }$ | $\text{57.63}^{\ \ }$ |
| TimesNet (Wu et al., ) | $\text{0.5261}^{\ \ }$ | $\text{0.4501}^{\ \ }$ | $\text{47.00}^{\ \ }$ | $\text{0.4461}^{\ \ }$ | $\text{0.4407}^{\ \ }$ | $\text{45.85}^{\ \ }$ | $\text{0.3177}^{\ \ }$ | $\text{0.3108}^{\ \ }$ | $\text{46.14}^{\ \ }$ |
| ModernTCN (Luo & Wang, ) | $\text{0.4934}^{\ \ }$ | $\text{0.4970}^{\ \ }$ | $\text{49.54}^{\ \ }$ | $\text{0.4019}^{\ \ }$ | $\text{0.4651}^{\ \ }$ | $\text{48.71}^{\ \ }$ | $\text{0.3804}^{\ \ }$ | $\text{0.4474}^{\ \ }$ | $\text{50.55}^{\ \ }$ |
| DLinear (Zeng et al., ) | $\text{0.4205}^{\ \ }$ | $\text{0.4775}^{\ \ }$ | $\text{47.25}^{\ \ }$ | $\text{0.5090}^{\ \ }$ | $\text{0.4945}^{\ \ }$ | $\text{50.54}^{\ \ }$ | $\text{0.5602}^{\ \ }$ | $\text{0.5236}^{\ \ }$ | $\text{56.00}^{\ \ }$ |
| ROCKET (Dempster et al., ) | $\text{0.5784}^{\ \ }$ | $\text{0.5777}^{\ \ }$ | $\textbf{56.71}^{\dagger}$ | $\text{0.5051}^{\ \ }$ | $\text{0.5522}^{\ \ }$ | $\text{52.91}^{\ \ }$ | $\text{0.5608}^{\ \ }$ | $\text{0.5941}^{\ \ }$ | $\text{58.36}^{\ \ }$ |
| Mamba (Gu & Dao, ) | $\text{0.5790}^{\ \ }$ | $\textbf{0.5835}^{\dagger}$ | $\text{55.68}^{\ \ }$ | $\textbf{0.6183}^{\dagger}$ | $\textbf{0.5767}^{\dagger}$ | $\textbf{55.69}^{*}$ | $\text{0.5715}^{\ \ }$ | $\text{0.5953}^{\ \ }$ | $\text{55.76}^{\ \ }$ |
| GRUs (Bahdanau et al., ) | $\text{0.5779}^{\ \ }$ | $\text{0.4868}^{\ \ }$ | $\text{48.80}^{\ \ }$ | $\text{0.5824}^{\ \ }$ | $\text{0.5588}^{\ \ }$ | $\text{53.66}^{\ \ }$ | $\textbf{0.6689}^{\dagger}$ | $\textbf{0.7645}^{\dagger}$ | $\textbf{69.30}^{\dagger}$ |
| LSTM (Hochreiter & Schmidhuber, ) | $\textbf{0.6362}^{\dagger}$ | $\text{0.5165}^{\ \ }$ | $\text{50.92}^{\ \ }$ | $\text{0.5774}^{\ \ }$ | $\text{0.5678}^{\ \ }$ | $\text{53.87}^{\ \ }$ | $\text{0.6581}^{\ \ }$ | $\text{0.6616}^{\ \ }$ | $\text{62.36}^{\ \ }$ |

In comparison to Table 1, we observe the opposite trend between finite- and infinite-context methods, whereas infinite-context methods seem to perform better OOD. In contrast, SSS demonstrates robust performance both in distribution (where finite-context methods excel) and OOD (where infinite-context methods excel).

Figure: Figure 2: Visualization of SSS window probabilities throughout iEEG channels at inference time, using the PatchTST backbone with window size $1024$. The heatmap represents locally averaged window probabilities over time, with color intensity being proportional to the likelihood of the channel belonging to the SOZ.
Refer to caption: extracted/5944476/figures/heatmaps/probs/regular/SOZ-8472_channel_1552_SOZ_ummc.png

Figure: Figure 3: Visualization of SSS window probabilities for OOD iEEG channels at inference time, using the PatchTST backbone with window size $1024$. The heatmap represents locally averaged window probabilities over time, with color intensity being proportional to the likelihood of the channel belonging to the SOZ.
Refer to caption: extracted/5944476/figures/heatmaps/probs/ood/SOZ-9777_channel_542_SOZ_jh.png

## 5 Discussion

### 5.1 Review of Results

In general, we observe that SSS outperforms modern finite-context and infinite-context methods both in-distribution and OOD for univariate VTSC. SOZ localization presents a significant challenge due to intra-patient and inter-patient variability, and with our evaluation the collection of 3 heterogeneous datasets, serving rigorous testbed for assessing the generalizability of SSS’s capabilities for learning local signal characteristics in medical time series. While our experiments focus on univariate VTSC, as outlined in section 3.2.1 and 3.2.2, SSS can be easily applied to the multivariate setting.

Our results from the multicenter evaluation Table 1 indicate that SSS benefits from a diversity of data distributions and volume of training examples, given by the magnitude in performance differences, when compared to single cluster results. Furthermore, our OOD experiments from Table 2 suggest that SSS may be learning local signal characteristics present in different patient populations, leading to a advantage over finite-context and infinite-context methods. Our visualizations of SSS’s predictions OOD in Figure 3 supports this notion, as there exist clear qualitative differences in locally averaged window probabilities with respect to anomalous signal characteristics, such as spikes or increases in amplitude or frequency. Figure 2 shows SSS’s predictions in-distribution which also suggest a form of implicit semantic segmentation for anomalous local regions of the signal with respect to the SOZ probability. More analysis is needed to further solidify our understanding, which would benefit from a rigorous explainability study in future works.

### 5.2 Conclusion

To conclude, this work introduces novel VTSC framework, Stochastic Sparse Sampling (SSS), specifically tailored for medical time series applications. SSS blends the best of both worlds between finite-context methods (enabling usage of finite-context backbones) while allowing sampling of the entire signal in a computationally efficient manner that is less prone to context overload from infinite-context methods. SSS learns local signal characteristics, which provides the added benefit of inherent interpretability, and provides superior performance to the SOTA in-distritbuion and OOD for unseen medical centers. For future work, it would be valuable to: (1) benchmark SSS across a wider variety of variable-length medical time series, (2) provide further rigorous post-hoc insights into the window probability distribution given by SSS, and (3) potentially include uncertainty estimates within the aggregation function to highlight anomalous regions of the signal.

## Appendix A Stochastic Sparse Sampling

### A.1 Sampling Implementation

Let $X=\big{\{}(\operatorname{\mathbf{x}}_{t}^{(1)})_{t=1}^{T_{1}},\dots,(
\operatorname{\mathbf{x}}_{t}^{(n)})_{t=1}^{T_{n}}\big{\}}$ be the collection of variable-length time series. To achieve the sampling procedure outlined in section 3.2, we first construct the set all windows $\operatorname{\mathcal{W}}$ by performing the slicing window method over each individual time series in $X$. For a window size $L$, with window stride $S$, and a time series $i$ with sequence length $T_{i}$, we obtain $A_{i}=\lfloor\frac{T_{i}-L}{S}\rfloor+1$ windows. Note that $A_{i}\propto T_{i}$ for each $i$. During training, we convert $\operatorname{\mathcal{W}}$ to a PyTorch dataset and use the native PyTorch dataloader with batch size $B$. When a batch is sampled, windows are drawn uniformly from $\operatorname{\mathcal{W}}$, and thus for each $i$, the probability of observing a window from series $i$ is $p_{i}=A_{i}/(\sum_{j=1}^{n}A_{j})\approx T_{i}/(\sum_{j=1}^{n}T_{j})$. If $N_{i}$ represents the number of windows in the batch from series $i$, then we achieve the desired sampling property of $N_{i}\sim\text{Binomial}(B,p_{i})$ where $p_{i}\approx T_{i}/(\sum_{j=1}^{n}T_{j})$. Note that this procedure uses sampling without replacement; one may consider replacement, however, we did not experiment with this and leave modifications with more complex sampling procedures as a future direction.

### A.2 Ablations

#### A.2.1 Batch Size

**Table 3: Performance of SSS over various batch sizes.**
| Batch Size | F1 Score | AUC | Acc. (%) |
| --- | --- | --- | --- |
| 128 | 0.7563 $\pm$ 0.02717 | 0.8139 $\pm$ 0.04302 | 70.79 $\pm$ 2.323 |
| 512 | 0.7498 $\pm$ 0.02354 | 0.7965 $\pm$ 0.03526 | 69.46 $\pm$ 3.109 |
| 2048 | 0.7651 $\pm$ 0.03568 | 0.8194 $\pm$ 0.05166 | 71.40 $\pm$ 6.078 |
| 4096 | 0.7441 $\pm$ 0.02987 | 0.7979 $\pm$ 0.06818 | 68.09 $\pm$ 4.848 |
| 8192 | 0.7629 $\pm$ 0.02829 | 0.7999 $\pm$ 0.05331 | 72.35 $\pm$ 4.965 |

Table 3 reports mean F1 score, AUC, and accuracy (%) with standard deviations, are reported over 5 seeds, for the evaluation on all medical centers. Each experiment uses the best configuration described in Table 6. While the aggregation function in Equation (3) may benefit from a higher number of samples within the batch (due to mean approximation), we observe that the performance of SSS remains relatively constant across various batch sizes, and thus does not require large batch sizes to achieve adequate performance.

#### A.2.2 Window Size

**Table 4: Performance of SSS over various window sizes $L$.**
| $L$ | F1 Score | AUC | Acc. (%) |
| --- | --- | --- | --- |
| 512 | 0.7567 $\pm$ 0.01075 | 0.8141 $\pm$ 0.03054 | 70.62 $\pm$ 2.165 |
| 1024 | 0.7629 $\pm$ 0.02829 | 0.7999 $\pm$ 0.05331 | 72.35 $\pm$ 4.965 |
| 2048 | 0.7334 $\pm$ 0.03003 | 0.7719 $\pm$ 0.04762 | 68.52 $\pm$ 3.353 |

Table 4 follows the same experimental setup as Table 3, but varies over the window size $L$ instead of batch size. While the performance of $L=512$ and $L=1024$ remain relatively on par, we notice that the F1 score drops significantly for $L=2048$ along with all other metrics. This suggests that a large receptive field may not be advantageous, and that SSS benefits from processing localized areas of the signal. Indeed, as $L$ increases we expect to reach a similar performance to the finite-context PatchTST baseline, with a decrease in performance as a result.

#### A.2.3 Calibration

Table 5 follows the same experimental setup as Table 3, where we explore different calibration methods. We observe that while the performance of Venn-Abers Predictors and isotonic regression remain relatively close among all evaluation metrics, removing calibration makes a significant impact on model performance, suggesting that our calibration likely reduces noise among window predictions, and as a result, enhances the aggregation step.

**Table 5: Performance of SSS with different calibration methods.**
| Calibration Method | F1 Score | AUC | Acc. (%) |
| --- | --- | --- | --- |
| Isotonic Regression | 0.7629 $\pm$ 0.02829 | 0.7999 $\pm$ 0.05331 | 72.35 $\pm$ 4.965 |
| Venn-ABERS | 0.7637 $\pm$ 0.02704 | 0.8003 $\pm$ 0.05308 | 72.47 $\pm$ 4.773 |
| No Calibration | 0.7291 $\pm$ 0.06909 | 0.7830 $\pm$ 0.03844 | 69.93 $\pm$ 4.635 |

### A.3 Convex Aggregation

###### Theorem 1 (Probability Distribution Guarantee) .

Fix $K,n\in\operatorname{\mathbb{N}}$. Suppose $\alpha_{1},\dots,\alpha_{n}\geq 0$ satisfies $\sum_{i=1}^{n}\alpha_{i}=1$, and $\operatorname{\mathbf{v}}_{1},\dots,\operatorname{\mathbf{v}}_{n}\in[0,1]^{K}$ each satisfy $\sum_{j=1}^{K}v_{ik}=1$ for $1\leq i\leq n$. That is, each $\operatorname{\mathbf{v}}_{i}=(v_{i1},v_{i2},\dots,v_{iK})^{T}$ represents a valid discrete probability distribution over $K$ classes. Then the convex combination:

$$ $\displaystyle\operatorname{\mathbf{y}}=\sum_{i=1}^{n}\alpha_{i}\operatorname{ \mathbf{v}}_{i},$ (5) $$

also represents a valid discrete probability distribution, satisfying $\sum_{j=1}^{K}y_{j}=1$.

###### Proof.

By construction, $y_{j}=\sum_{i=1}^{n}\alpha_{i}v_{ij}$ for each entry $1\leq j\leq K$. Then $y_{j}\geq 0$, since for each $1\leq i\leq n$ and $1\leq j\leq K$ we are given that $\alpha_{i}\geq 0$ and $v_{ij}\geq 0$. Furthermore, we can write:

$$ $\displaystyle\sum_{j=1}^{n}y_{j}$ $\displaystyle=\sum_{j=1}^{K}\sum_{i=1}^{n}\alpha_{i}v_{ij}$ $\displaystyle=\sum_{i=1}^{n}\sum_{j=1}^{K}\alpha_{i}v_{ij}$ (Swap summation order) $\displaystyle=\sum_{i=1}^{n}\alpha_{i}\sum_{j=1}^{K}v_{ij}$ $\displaystyle=\sum_{i=1}^{n}\alpha_{i}$ ( $\sum_{j=1}^{K}v_{ij}=1$ for all $i$ ) $\displaystyle=1$ ( $\sum_{i=1}^{n}\alpha_{i}=1$ ) $$

It follows that since each $y_{j}\geq 0$ and $\sum_{j=1}^{K}y_{j}=1$, then $\operatorname{\mathbf{y}}$ represents a valid discrete probability distribution over $K$ classes.
∎

###### Theorem 1 (Probability Distribution Guarantee) .

###### Proof.

### A.4 Calibration

Let $\hat{y}_{1},\dots,\hat{y}_{n}\in[0,1]$ be the uncalibrated window probabilities, each with a corresponding binary label $y_{1},\dots,y_{n}\in\{0,1\}$ derived from the label of the time series; that is, if $\hat{y}_{i}=f_{\theta}(\operatorname{\mathbf{w}}_{i})$ for a window $\operatorname{\mathbf{w}}_{i}$, then the window label $y_{i}$ is inherited from the global time series it was sampled from. The goal of probability calibration is to transform each $\hat{y}_{i}$ into $\tilde{y}_{i}=g_{\phi}(\hat{y}_{i})$, such that $\tilde{y}_{i}$ represents true likelihood of a class. Within this context, probability calibration can help mitigate the impact of temporal fluctuations and local anomalies by adjusting probabilities for each individual windows. Note that while calibration may yield more refined probability estimates with reduced noise, it is an integral intermediate step rather than a global optimization procedure on the final probabilities. For each calibration we considered, we provide a short description below.

Isotonic regression is a nonparametric method that fits a weighted least-squares model subject to motonicity constraints (Silvapulle & Sen, ). Formally, this can be stated as a quadratic program (QP) given by:

$$ $\min_{g}\sum_{i=1}^{n}w_{i}(\tilde{y}_{i}-y_{i})^{2}\text{ subject to }\tilde{ y}_{i}\leq\tilde{y}_{j}\text{ for all }i,j\text{ where }\hat{y}_{i}\leq\hat{y} _{j}.$ (6) $$

where $\tilde{y}_{i}=g(\hat{y}_{i})$ and $w_{i}\geq 0$ are weights assigned to each datapoint, which are often each set to $w_{i}=1$ to provide equal importance over all inputs. The monotonicity constraint ensures that uncalibrated probabilities will always map to equal or higher calibrated probabilities. Due its nonparametric nature, isotonic regression can adapt to various probability distributions across diverse datasets. However, this flexibility comes at a cost as it is also prone to overfitting on smaller datasets, potentially adjusting to noise rather than properly calibrating its inputs.

Venn-Abers predictors is based on the concept of isotonic regression but extends it to ensure validity within the framework of conformal prediction, which provides uncertainty estimates with distribution-free theoretical guarantees (Vovk & Petej, ; Angelopoulos & Bates, ). For an uncalibrated probability $\hat{y}$, two isotonic calibrators are trained:

$$ $p_{0}=g_{0}(\hat{y})\text{ and }p_{1}=g_{1}(\hat{y})$ (7) $$

where $g_{0}$ and $g_{1}$ are isotonic functions derived from augmented sets. These sets include $(\hat{y},0)$ and $(\hat{y},1)$ respectively, alongside all other uncalibrated probabilities and their respective labels. The values $p_{0}$ and $p_{1}$ represent likelihoods for class 0 0 and class $1$, while the interval $[p_{0},p_{1}]$ provides an uncertainty estimate of where the true probability resides. The final calibrated probability is then given by:

$$ $\tilde{y}=\frac{p_{1}}{1-p_{0}+p_{1}}.$ (8) $$

Venn-Abers predictors provide guaranteed validity in terms of calibration, meaning the predicted probabilities closely match empirical frequencies. While we do not explicitly utilize the uncertainty interval $[p_{0},p_{1}]$ (only the calibrated score $\tilde{y}$), this method can be effective in scenarios requiring risk assessment or critical tasks where rigorous uncertainty estimates are crucial. We leave this as a future direction to implement conformal prediction within the context of SSS, to provide uncertainty guarantees based off of window predictions, which may be useful for post-hoc interpretability. In comparsion to isotonic regression, Venn-Abers can be more computationally intensive, as it requires fitting two isotonic functions simultaneously.

### A.5 Finite-context & infinite-context methods

###### Definition 2 .

Let $\operatorname{\mathcal{X}}$ be a vector space over $\operatorname{\mathbb{R}}$ and $f_{\theta}:\operatorname{\mathcal{X}}\to\operatorname{\mathcal{Y}}$ be a model with parameters $\theta$ and output space $\operatorname{\mathcal{Y}}$. We say that $f_{\theta}$ has finite-context if $\operatorname{\mathcal{X}}$ is finite-dimensional, that is, there exists some $n\in\operatorname{\mathbb{N}}$ such that $\operatorname{\mathcal{X}}\cong\operatorname{\mathbb{R}}^{n}$ as vector spaces. Whereas $f_{\theta}$ is said to have infinite-context if $\operatorname{\mathcal{X}}=\operatorname{\mathbb{R}}^{(\infty)}$ is the space of real number sequences with finite support(^2^22Every sequence in $\operatorname{\mathbb{R}}^{(\infty)}$ must have finitely many non-zero terms.).

Note that this definition refers to the native capabilities of $f_{\theta}$, without the usage of data manipulation techniques such as padding, truncation, and interpolation. We utilize this formalization to separate our baselines, so that we may better understand the advantages and limitations of both.

###### Definition 2 .

### A.6 SSS implementation and configurations

**Table 6: Hyperparameter search space for SSS (with PatchTST backbone). Best configuration is highlighted in red.**
| Parameter | Search Values |
| --- | --- |
| $d_{\text{model}}$ | $\{16,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}32},64\}$ |
| $d_{\text{ff}}$ | $\{32,64,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}128}\}$ |
| num_heads | $\{2,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}4},8\}$ |
| num_enc_layers | $\{1,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}2},3\}$ |
| lr | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}10^{-4}},1<br>0^{-5}\}$ |
| $L$ | $\{512,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}1024},<br>2048\}$ |
| batch_size | $\{2048,4096,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}<br>8192}\}$ |
| $g_{\phi}$ | {isotonic regression,Venn-Abers predictors} |

## Appendix B Dataset and preprocessing

### B.1 Dataset

**Table 7: iEEG Multicenter Dataset Summary: For each medical center, we report the total number of patients recorded ($n$), the number of patients with seizure onset zone (SOZ) annotations ($n_{\text{SOZ}}$), the number of time series recordings ($n_{\text{ts}}$), the percentage of time series labeled as SOZ ($p_{\text{SOZ}}$), the type of iEEG method used (e.g., electrocorticography, ECoG), the sampling frequency (Hz) (noting that some recordings may vary), and post-operative patient outcomes following SOZ surgical resection.**
| Medical Center | $n$ | $n_{\text{SOZ}}$ | $n_{\text{ts}}$ | $p_{\text{SOZ}}$ | iEEG Type | Frequency (Hz) | Patient Outcomes |
| --- | --- | --- | --- | --- | --- | --- | --- |
| JHH | 7 | 3 | 1458 | 7.48% | ECoG | 1000 | No |
| NIH | 14 | 11 | 3057 | 12.23% | ECoG | 1000 | Yes |
| UMMC | 9 | 9 | 2967 | 5.56% | ECoG | 250-1000 | Yes |
| UMF | 5 | 1 | 129 | 25.58% | ECoG | 1000 | No |

Table 7 provides an overview of the iEEG Multicenter Dataset. For each cluster, we filter out patients $(n)$ who have SOZ annotations $(n_{\text{SOZ}})$. All channels for all patients are group together into one dataset per medical center, where $n_{\text{ts}}$ indicates the number of examples. However, due to the heavy imbalance between SOZ-labeled time series and non-SOZ labeled time series, the number of examples used for training and validation decreases significantly once we employ class balancing, resulting in $\lfloor 2\cdot p_{\text{SOZ}}\cdot n_{\text{ts}}\rfloor$ examples for each medical center, which is then split into training, validation, and testing.

### B.2 Data preprocessing

Each patient recording contains multiple channels corresponding to individual electrodes from the iEEG device. During preprocessing, for all patients, we extract all channels and balance the dataset to have an equal number of SOZ and non-SOZ channels. After, we partition this dataset into train, validation, and test channels with a $70\%/10\%/20\%$ split respectively, and ensure that during the window sampling phase of SSS there is no temporal leakage from the test set. Each channel, or univariate time series, is $z-$score normalized to have zero mean and unit standard deviation.

Due to the extremely long sequence length of several channels, we required downsampling to fit the dataset into memory (250GB RAM). To achieve this, for each channel we applied a 1D average pooling layer with kernel_size=24 and kernel_stride=12 before feeding it to the baseline model or before performing the window sampling procedure for SSS at train-time.

Finite-context methods required either padding, truncation, or interpolation due to fit each sequence into its limited context window. For each finite-context method we perform a combination of padding and truncation according to the chosen window size $L$: if the sequence length of the original time series exceeded $L$, it was truncated to obtain the first $L$ time points, otherwise if it was less than $L$, it was padded with zeros at the end of the sequence to ensure a sequence length of $L$.

### B.3 Evaluation metrics

#### B.3.1 F1

The F1 score is defined as the harmonic mean of precision and recall, given by:

$$ $\displaystyle F_{1}=2\cdot\frac{\text{Precision}\cdot\text{Recall}}{\text{ Precision}+\text{Recall}},$ (9) $$

where,

$$ $\displaystyle\text{Precision}=\frac{\text{True Positives (TP)}}{\text{True Positives (TP)}+\text{False Positives (FP)}},$ (10) $$

and,

$$ $\displaystyle\text{Recall}=\frac{\text{True Positives (TP)}}{\text{True Positives (TP)}+\text{False Negatives (FN)}}.$ (11) $$

We select the F1 score as our primary evaluation metric for SOZ localization for the following reasons. The F1 score balances the need to correctly identify all regions of the SOZ (recall) with the need to avoid misclassifying healthy regions as SOZ (precision). This balance is crucial in surgical planning, where both missing SOZs and unnecessarily removing healthy tissue can have severe consequences. Unlike accuracy, which overlooks the difference between false positives and false negatives, the F1 score provides a more nuanced evaluation by considering both, making it well-suited in clinical contexts such as SOZ localization.

#### B.3.2 AUC

We complement the F1 score with the Area Under the Receiver Operating Characteristic curve (AUC), defined by:

$$ $\displaystyle\text{AUC}=\int_{0}^{1}\text{TPR}(t)\cdot\frac{d\text{FPR}(t)}{dt }dt$ (12) $$

While the F1 score provides insight into the balance between precision and recall at a specific threshold, AUC assesses the model’s overall discriminative ability across all thresholds. This threshold-independent evaluation is relevant for critical scenarios where the threshold maybe be adjusted from $0.5$, which is not common in clinical settings.

## Appendix C Implementation and experimental configurations

For each baseline, we perform grid search and optimize with respect to best accuracy score on the evaluation for all medical centers. $L$ refers to the window size parameter, $d_{\text{model}}$ is the model dimension, and $d_{\text{ff}}$ is the dimension of the feed-forward network. The grid search parameters for each baseline are shown below; for information on the implementation of SSS, see Appendix A.6. In all experiments, we train using the Adam optimizer (Kingma & Ba, ), for $50$ epochs, with cosine learning rate annealing (one cycle with $50$ epochs in length) which adjusts the learning rate down by two orders of magnitude (e.g., $10^{-4}$ to $10^{-6}$) by the last epoch. We also implement early stopping with a patience of $15$, and apply learnable instance normalization (Kim et al., ) for each input. For most of the baselines we use a dropout rate of $0.2-0.3$, and weight decay to $10^{-4}-10^{-5}$, but do not explicitly tune these parameters in our grid search. For finite-context methods we set the batch size to the entire dataset ($596$ individual univariate time series for all clusters), whereas infinite-context methods required batch size of $1$ due to their variable-length. The code for SSS and baseline implementations is available at the following anonymous link: [https://anonymous.4open.science/r/sss-0D75/](https://anonymous.4open.science/r/sss-0D75/README.md).

PatchTST: We adapt the official implementation [github.com/yuqinie98/PatchTST](https://github.com/yuqinie98/PatchTST), but swap out the attention module with the native PyTorch $\href https://pytorch.org/docs/stable/generated/torch.nn.MultiheadAttention.html$ module.

**Table 8: Hyperparameter search space for PatchTST. Best configuration is highlighted in red.**
| Parameter | Search Values |
| --- | --- |
| $d_{\text{model}}$ | $\{16,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}32},64\}$ |
| $d_{\text{ff}}$ | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}32},64,128\}$ |
| num_heads | $\{2,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}4},8\}$ |
| num_enc_layers | $\{1,2,3\}$ |
| lr | $\{10^{-4},{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}10<br>^{-5}}\}$ |
| $L$ | $\{1000,3000,5000,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{<br>1,0,0}10000}\}$ |

TimesNet: We use the official implementation [github.com/thuml/Time-Series-Library](https://github.com/thuml/Time-Series-Library).

**Table 9: Hyperparameter search space for TimesNet. Best configuration is highlighted in red.**
| Parameter | Search Values |
| --- | --- |
| $d_{\text{model}}$ | $\{16,32,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}64}\}$ |
| $d_{\text{ff}}$ | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}32},64,128\}$ |
| num_kernels | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}4},6\}$ |
| top_k | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}3},5\}$ |
| num_enc_layers | $\{1,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}2}\}$ |
| lr | $\{10^{-4},{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}10<br>^{-5}}\}$ |
| $L$ | $\{1000,3000,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}<br>5000},10000\}$ |

ModernTCN: We use the official implementation [github.com/luodhhh/ModernTCN](https://github.com/luodhhh/ModernTCN).

**Table 10: Hyperparameter search space for ModernTCN. Best configuration is highlighted in red.**
| Parameter | Search Values |
| --- | --- |
| lr | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}10^{-4}},1<br>0^{-5}\}$ |
| $d_{\text{model}}$ | $\{16,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}32},64\}$ |
| num_enc_layers | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}1},2\}$ |
| large_size_kernel | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}9},13,21,51\}$ |
| small_size_kernel | ${\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}5}$ |
| dw_dims | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}128},256\}$ |
| ffn_ratio | $\{1,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}4}\}$ |
| $L$ | $\{1000,3000,5000,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{<br>1,0,0}10000}\}$ |

DLinear: We use the implementation from [github.com/thuml/Time-Series-Library](https://github.com/thuml/Time-Series-Library).

**Table 11: Hyperparameter search space for DLinear. Best configuration is highlighted in red.**
| Parameter | Search Values |
| --- | --- |
| moving_avg | $\{10,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}25}\}$ |
| lr | $\{10^{-4},10^{-5},{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{<br>1,0,0}10^{-6}}\}$ |
| $L$ | $\{1000,3000,5000,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{<br>1,0,0}10000}\}$ |

ROCKET: We use the official implementation [github.com/angus924/rocket](https://github.com/angus924/rocket/blob/master/code/rocket_functions.py) and follow the standard implementation of $10,000$ kernels.

**Table 12: Hyperparameter search space for ROCKET. Best configuration is highlighted in red.**
| Parameter | Search Values |
| --- | --- |
| num_kernels | {${\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}10000}$} |
| lr | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}10^{-4}},1<br>0^{-5},10^{-6}\}$ |

Mamba: We use the package [mambapy](https://github.com/alxndrTL/mamba.py) which builds upon the official Mamba implementation.

**Table 13: Hyperparameter search space for Mamba. Best configuration is highlighted in red.**
| Parameter | Search Values |
| --- | --- |
| lr | $\{10^{-4},10^{-5},{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{<br>1,0,0}10^{-6}}\}$ |
| $d_{\text{model}}$ | $\{16,32,64\}$ |
| num_enc_layers | $\{1,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}2},3\}$ |

We also employ patching from (Nie et al., ), which we observed led to greater to performance, with $\texttt{patch_size}=64$ and $\texttt{patch_stride}=16$.

GRUs: We utilized the native PyTorch module [torch.nn.GRU](https://pytorch.org/docs/stable/generated/torch.nn.GRU.html).

**Table 14: Hyperparameter search space for GRUs. Best configuration is highlighted in red.**
| Parameter | Search Values |
| --- | --- |
| lr | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}10^{-4}},1<br>0^{-5},10^{-6}\}$ |
| $d_{\text{model}}$ | $\{16,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}32},64\}$ |
| num_enc_layers | $\{1,2,{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}3}\}$ |
| bidirectional | $\{{\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}\text{True<br>}},\text{False}\}$ |

### C.1 Computational Resources

Our experiments were conducted on $4\text{x}$ NVIDIA RTX 6000 Ada Generation GPUs using the PyTorch framework with CUDA (Paszke et al., ). Although we have not tracked explicitly the amount of consumed GPU hours, all experiments can be conducted for $5$ seeds no more than $2-3$ hours with a similar setup.

## Peer Reviews

confidence: 3
contribution: 3
initial_rating: 5
presentation: 3
questions: - Approaches based on convolutions can handle variable lengths, and the number of parameters does not increase with the signal length, contrary to what is stated in the section on related work. Can the authors clarify or revise their statement about convolutional approaches in the related work section?
- The sampling is said to be sparse. How does the performance vary with the number of drawn windows? Consider doing an ablation study or experiment showing performance as a function of the number of sampled windows.
- To improve the statistical rigor of the results, can the authors report standard deviations or confidence intervals for all reported performance metrics?
- Certain notations can be misleading : $y^{(i)}$ is an integer while $\hat{y}^{(i)}$ is vector. Consider changing them to more consistent notations.
- Current baselines are mostly deep-learning-based, but many other classification algorithms exist [1]. Can the authors include a few other baselines that they think are relevant?
- In Section 4.5, what are the labels of the displayed signals? Do they belong to the same individual? Are the highlighted areas related to a known physiological phenomenon?
- How important is the smoothing step presented in Section 3.2.2? Its influence could be for instance illustrated with an ablatio study.

[1] Ruiz, A. P., Flynn, M., Large, J., Middlehurst, M., & Bagnall, A. (2021). The great multivariate time series classification bake off: a review and experimental evaluation of recent algorithmic advances. Data Mining and Knowledge Discovery, 35(2).
soundness: 2
strengths: - The article is well-written and easy to follow.
- The methodology is sound and has the potential to provide an interpretable time series classification strategy that can be combined with virtually any time series classification algorithm.
summary: This article proposes a meta-heuristic to improve time series classification algorithms by classifying random windows and aggregating scores. The algorithm is tested on a real-world task where it achieves promising performance.
weaknesses: - The proposed approach is simple, which is perfectly fine, but lacks a more thorough analysis, at least empirical. For a reader with a use case in mind, it is difficult to assess if this method is appropriate.
- Another drawback is that this approach has only been tested on one data set. To assess its generalization capability, the authors could test their method on additional publicly available time series datasets.
- Section 4.5 on qualitative interpretation needs to (re)written to be more convincing as it lacks much information or comments. Interpretability is one of the contributions listed in the introduction.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 3
questions: In the main body, the discussion of what portion of the training or validation set is used for the calibration is missing.  
 
Line 797 "with respect to best accuracy score on the evaluation" . This doesn't seem like a valid hyper-parameter selection if this is done on test instead of validation. Also it should be noted that hyper-parameter is selected in terms of accuracy, even if F1 and AUC are reported. 

In Algorithm 1, the windows from the time series are sampled proportional to their length. It would seem that stratified sampling by label or group may be motivated in cases of imbalanced training data.  This could be mentioned.

Typos:
180 "by sampling with replacement," -> "by sampling without replacement,"

268 "the the correct "

388 "a advantage"
soundness: 3
strengths: Very clear presentation and well-fit for this type of time series classification problem. The calibration step after pooling during training is a thoughtful addition.
summary: The paper describes using aggregation of time-series classification model predictions across windows during training and inference a way to go beyond fixed-context length window processing and infinite context models recurrent neural networks.  The aggregation method explored here is simple averaging. An additional calibration step is used after the model is trained. 

The method is applied to different EEG channels in order to learn to classify a channel as being in the seizure originating zone or not. Cross-subject and cross institution results show very promising performance compared to fixed-context length approach and infinite context models.
weaknesses: Main concern is the single domain/task used to test the method. While the single domain is very interesting, there is something different in the fact that the seizure periods are themselves randomly occurring throughout the time series. In other tasks, long-term dynamics of the time series may require extracting patterns through time rather than this which is more akin to multiple instance learning where the search is for any evidence of positive class. 

The lack of other tasks weakens the generality of the method, but I don't have the perfect case of variable length it is hard to say where there would

---

confidence: 4
contribution: 1
initial_rating: 3
presentation: 2
questions: My main concern is the motivation. Clinically, the brain regions requiring surgical removal include the SOZ and early propagation zones. These areas contain numerous neurons that exhibit abnormal discharges and are typically distributed across multiple iEEG channels. These regions show the earliest electrophysiological changes in a seizure, often before clinical symptoms appear. 
Suppose the model can only consider a single iEEG data channel. In that case, it may miss the timing differences of abnormal discharges across channels, making it difficult to determine which neurons initiated the seizure. 
Experts have developed many graph topology-based methods and biomarkers to capture these distinctions. 
In this paper, the authors justify their choice of a single-channel approach by explaining that varying numbers of iEEG channels across recordings create challenges for developing multi-channel analysis methods. 
However, this limitation alone does not prove that single-channel analysis is more effective. Could the authors offer more theoretical or experimental support to justify the potential effectiveness of a single-channel method?
soundness: 2
strengths: 1) Seizure onset zone (SOZ) detection is a novel direction that may be important for clinical intracranial EEG (iEEG) research.
2) The method is described in detail, ensuring clarity and reproducibility. 
3) The experiments use a large-scale public iEEG dataset for evaluation, showing the robustness and effectiveness across diverse and heterogeneous data sources.
summary: This paper introduces Stochastic Sparse Sampling (SSS), a new framework for classifying variable-length medical time series. SSS employs fixed windows sparsely to make local predictions, which are then combined to form a global prediction.
weaknesses: 1) This paper uses a single-channel approach for SOZ detection, justifying it by citing the challenges posed by varying numbers of iEEG channels across iEEG recordings. However, this reason does not demonstrate that single-channel analysis is more effective. In clinical practice, SOZ and early propagation zones involve multiple channels with timing differences in abnormal discharges [1]. The authors do not provide sufficient theoretical or experimental support to explain why a single-channel approach would effectively capture these critical distinctions.
2) This paper defines SOZ detection as a variable-length time series classification (VTSC) task. Still, the authors do not clarify the specific benefits of VTSC over general anomaly detection for this application. Their justification, that “effective treatment requires analysis of variable-length signals,” lacks concrete references or explanations relevant to variable-length signals, weakening the rationale for using VTSC in this context.
3) The proposed method is quite simple. How does it differ from other downsampling or sparse sampling approaches?  Model output still provides a global classification result, which seems no different from a standard classification model. The paper should compare its approach with more methods that share a similar motivation and more details of related works to clarify its position within the research field. 
4) The authors state in the abstract that their method outperforms "state-of-the-art (SOTA) baselines across most medical centers." However, none of these baselines were designed for the SOZ detection task or medical time series data.Instead, all baseline models were built for general time series or other sequential data forecasting tasks, not even for time series classification. The authors should have used baselines developed for iEEG or EEG signal analysis, such as methods in references [2-4], or, at the very least, models designed for time series classification or anomaly detection [4,5]. 


[1] Li et al., Neural fragility as an EEG marker of the seizure onset zone, Nature Neuroscience, 2021.

[2] Tang et al., Self-Supervised Graph Neural Networks for Improved Electroencephalographic Seizure Analysis, ICLR, 2022.

[3] Luo et al., Exploring Adaptive Graph Topologies and Temporal Graph Networks for EEG-Based Depression Detection, IEEE Transactions on Neural System and Rehabilitation Engineering, 2023.

[4] Rikuto et al., SplitSEE: A Splittable Self-supervised Framework for Single-Channel EEG Representation Learning, ICDM, 2024.

[5] tang et al., Omni-Scale CNNs: a simple and effective kernel size configuration for time series classification, ICLR, 2022.

[6] Lu et al., Out-of-Distribution Representation Learning for Time Series Classification, ICLR, 2023.

---

confidence: 5
contribution: 2
initial_rating: 5
presentation: 2
questions: See Weaknesses
soundness: 2
strengths: The use of sparse sampling for computational savings in multi-scale learning is an interesting idea. Additionally, the out-of-distribution classification on unseen subjects from different medical centers demonstrates strong potential for generalizability in real-world applications.
summary: This paper introduces a multi-scale learning approach for medical time series classification. The proposed method comprises multiple independent models, each with a distinct patch length, allowing it to capture information across various temporal scales. The patching method follows the PatchTST framework, which employs single-channel patching. To reduce computational costs, the authors implement stochastic sparse sampling, randomly selecting models during training. The final representation is an aggregation of outputs from all models, combining multi-scale information. The model is evaluated on intracranial EEG (iEEG) data for seizure onset zone classification, using a dataset collected from four independent medical centers.
weaknesses: The motivation to save computational resources is well-intentioned, though I am concerned about its practicality in actual training. For a given set of window sizes with corresponding independent models, even if only subsets of window sizes are selected during training, the space complexity of the models remains unchanged. This approach primarily improves training speed without reducing memory requirements. Additionally, using an independent model for each patch length may not be optimal for memory efficiency. A shared backbone across different patch lengths could be a more effective choice for memory savings. Overall, the method resembles an enhanced version of MTST [1], employing a random subset of models with varying patch lengths during training.

Moreover, while the paper’s title refers to medical time series, only a single seizure dataset is used for evaluation. Expanding the evaluation to include additional datasets would strengthen the claim of generalizability. The ablation study could also benefit from a deeper investigation into multi-scale learning with various patch lengths. For instance, exploring which combinations of patch lengths yield the best performance would be informative. Additionally, the impact of stochastic sparse sampling should be assessed in detail. For a given list of patch lengths, how do memory usage and running time between training with and without stochastic sparse sampling? Lastly, a recent work, Medformer[2], should be compared in baseline methods, as it is also designed for medical time series classification using multi-scale patching. A discussion on the differences between this method and Medformer would also be valuable for highlighting the unique aspects of the proposed approach.


[1] Multi-resolution Time-Series Transformer for Long-term Forecasting
[2] Medformer: A Multi-Granularity Patching Transformer for Medical Time-Series Classification