scieee AI-readable full text Open interactive document viewer

Towards Domain Generalization for ECG and EEG Classification: Algorithms and Benchmarks

Ballas, Aristotelis; Diou, Christos

Abstract

Abstract - Despite their immense success in numerous fields, machine and deep learning systems have not yet been able to firmly establish themselves in mission-critical applications in healthcare. One of the main reasons lies in the fact that when models are presented with previously unseen, Out-of-Distribution samples, their performance deteriorates significantly. This is known as the Domain Generalization (DG) problem. Our objective in this work is to propose a benchmark for evaluating DG algorithms, in addition to introducing a novel architecture for tackling DG in biosignal classification. In this article, we describe the Domain Generalization problem for biosignals, focusing on electrocardiograms (ECG) and electroencephalograms (EEG) and propose and implement an open-source biosignal DG evaluation benchmark. Furthermore, we adapt state-of-the-art DG algorithms from computer vision to the problem of 1D biosignal classification and evaluate their effectiveness. Finally, we also introduce a novel neural network architecture that leverages multi-layer representations for improved model generalizability. By implementing the above DG setup we are able to experimentally demonstrate the presence of the DG problem in ECG and EEG datasets. In addition, our proposed model demonstrates improved effectiveness compared to the baseline algorithms, exceeding the state-of-the-art in both datasets. Recognizing the significance of the distribution shift present in biosignal datasets, the presented benchmark aims at urging further research into the field of biomedical DG by simplifying the evaluation process of proposed algorithms. To our knowledge, this is the first attempt at developing an open-source framework for evaluating ECG and EEG DG algorithms.

Full text

PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 1 Towards Domain Generalization for ECG and EEG Classification: Algorithms and Benchmarks Aristotelis Ballas and Christos Diou, Member, IEEE Abstract—Despite their immense success in numerous fields, machine and deep learning systems have not yet been able to firmly establish themselves in mission-critical applications in healthcare. One of the main reasons lies in the fact that when models are presented with previously unseen, Out-ofDistribution samples, their performance deteriorates significantly. This is known as the Domain Generalization (DG) problem. Our objective in this work is to propose a benchmark for evaluating DG algorithms, in addition to introducing a novel architecture for tackling DG in biosignal classification. In this paper, we describe the Domain Generalization problem for biosignals, focusing on electrocardiograms (ECG) and electroencephalograms (EEG) and propose and implement an open-source biosignal DG evaluation benchmark. Furthermore, we adapt state-of-the-art DG algorithms from computer vision to the problem of 1D biosignal classification and evaluate their effectiveness. Finally, we also introduce a novel neural network architecture that leverages multi-layer representations for improved model generalizability. By implementing the above DG setup we are able to experimentally demonstrate the presence of the DG problem in ECG and EEG datasets. In addition, our proposed model demonstrates improved effectiveness compared to the baseline algorithms, exceeding the state-of-the-art in both datasets. Recognizing the significance of the distribution shift present in biosignal datasets, the presented benchmark aims at urging further research into the field of biomedical DG by simplifying the evaluation process of proposed algorithms. To our knowledge, this is the first attempt at developing an open-source framework for evaluating ECG and EEG DG algorithms. Index Terms—Biosignal classification, deep learning, domain generalization, 1D signal classification, electrocardiogram (ECG) classification, electroencephalogram (EEG) classification I. INTRODUCTION DOMAIN generalization is a fundamental problem in machine learning (ML) today [1]. Despite the fact that deep learning (DL) [2] models have seen immense success in the past few years [3], [4], [5], even surpassing experts in some cases [6], [7], [8], they often fail to mimic the adaptability prowess of humans. The development of highly generalizable and robust ML models proves to be exceptionally difficult in numerous cases, as the distribution shifts present across separate datasets or databases cause a model’s performance to deteriorate [9], or even completely break down [10], when evaluated on previously unseen data. Most ML models depend on the assumption that the test samples are independent from and identically distributed Manuscript received 18 November 2022; revised 2 May 2023; accepted 22 June 2023. The work leading to these results has received funding from the European Union’s Horizon 2020 research and innovation programme under Grant Agreement No. 965231, project REBECCA (REsearch on BrEast Cancer induced chronic conditions supported by Causal Analysis of multisource data). Fig. 1. Visualization of the alternative architectures for the ECG and EEG classification experiments. The backbone of both models is a small ResNet or S-ResNet (Fig. 2) with 13 convolutional layers (including the conv layers in the residual connections) in total. In the ECG model, we extract features from a total of 8 intermediate layers and concatenate them to the backbone network’s output, as shown in the above figure. In the EEG model, we connect concentration pipelines to 3 intermediate layers and concatenate the processed features to the backbone network output. The solid lines represent normal residual connections between CNN layers where the passed features retain their dimension, while the features passed through the dashed lined connections are downsampled to match the dimension of the previous layer output. (i.i.d.) with the training data. In practice, the independence assumption commonly holds, however the test data often follows a different data generating distribution than the training data. These differences are often the result of contextual changes e.g., in the background of images (for natural images) or the use of different medical imaging equipment (for medical images). ML models tend to incorporate statistical correlations present in their training data, even if these are spurious, in the sense that they do not convey useful information about the problem at hand. The fact that these correlations may not be arXiv:2303.11338v3 [eess.SP] 3 Jul 2023 PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 2 present (or may manifest differently) in the test data, leads to significant degradation in performance when DL models are applied in practice. This is one of the main reasons why DL models have not been able to establish themselves in production and several mission-critical applications, including healthcare settings. This problem was firstly introduced in the ML literature as domain generalization (DG) [11]. DG emphasizes on developing algorithms which are not affected by the distributional shift present in distinct data domains of the same problem, by not incorporating spurious correlations in their representations. DG models should ideally maintain their performance among different training or source and test or target data domains of the same problem. Lately, an abundance of works have been proposed towards tackling the DG problem. Nonetheless, although noteworthy progress has been made mostly in computer vision, the field currently lacks in researching methods for DG in onedimensional (1D) signals. To this end, in this work we turn our attention to biosignals and specifically to 1D signals originating from electrodes: electrocardiograms (ECG) and electroencephalograms (EEG). Due to their medical nature, biosignal classification renders the need for highly robust and generalizable algorithms of the utmost importance. In a field of constantly evolving equipment and screening methods, AI-enhanced clinical support systems must gain the trust of medical practitioners by maintaining their performance against diverse data distributions. Additionally, most biosignal datasets suffer from class imbalance, creating a need for models with the ability to identify rarely represented categories (i.e., diseases). Our aim in this work is to encourage future research in biosignal domain generalization, by describing and experimentally demonstrating the DG problem in biosignals and by developing an open-source evaluation benchmark based on publicly available biosignal datasets. Specifically, we look into the classification of 12-lead ECGs and 62-channel EEGs. The main contributions of this paper are the following: •We introduce a DG evaluation benchmark, namely BioDG1, for 12-lead ECG and 62-channel EEG biosignals. For our experiments we use the 6 datasets from PhysioNet’s [12] public database, for the ECG signals, and the SEED [13], [14], SEED-FRA [15], [16] and SEED-GER [15], [16] for the EEGs. To our knowledge, this is the first attempt at developing an open-source and reproducible evaluation framework, combining both ECG and EEG signals. Moreover, in this setup we follow the classic leave-one-domain-out DG protocol [17] and move past the leave-one or leave-multiple subjects-out protocols described in previous works. •We experimentally exhibit the distributional shift present in the above datasets, thus validating our claim that additional DG research should be poured into the medical AI field. •We adapt and implement state-of-the-art DG computer vision algorithms for 1D data and experiment on our proposed DG evaluation setting. 1Code is available at https://github.com/aristotelisballas/biodg. •We build on our previous work [18], [19] and propose a DG neural network architecture which takes advantage of representations from multiple layers of a Convolutional Neural Network and exhibit its capabilities against stateof-the-art DG methods, in both ECG and EEG classification. II. BACKGROUND AND TERMINOLOGY Let Xand Ybe a nonempty input and output space respectively. A domain Dis a composition of sample and label pairs (x, y)in (X,Y), drawn from the (unknown) data distribution PXY . In contrast to fully supervised learning, in which the common assumption is that both training and evaluation data are identically distributed, Domain Generalization algorithms aim to learn a parametric model f(·;θ)trained on samples (x(s), y(s))drawn from Nsource (N > 1) domains, which is able to generalize to K(K > 1) unseen target domains. In the context of DG, classification problems can be grouped into two main categories [10], namely multi-source and singlesource. Multi-source DG aims at training models which are aware of the distinction between multiple but related source domains (N > 1). As a result, the goal is to learn representations which remain unaffected by the distribution shift between the marginal distributions of each source domain. On the other hand, the presence of several underlying data domains is irrelevant to single-source DG algorithms, as they are trained under the assumption that all training data is sampled from a single distribution (N= 1). Single-source DG algorithms can therefore be labeled as domain-agnostic. In the current work, we attempt to improve the generalization ability of a model Mθ:X → Y to detect domain-invariant attributes of 1D ECG and EEG signals and minimize the affect of the distributional shift present in distinct biosignal datasets. Since our method is not aware of the presence of separate data domain distributions, it falls under the category of singlesource DG algorithms. III. RELATED WORK A. Methods for Improving Generalizability in Biosignal Classification Although only a limited number of works have dealt directly with the problem of domain generalization for biosignal classification, there have been several attempts to implicitly address the problem. In this section, we discuss the state-ofthe-art and most noteworthy non-DG methods proposed for the improvement of the generalization ability of ML algorithms and mitigation of domain-shift. Domain Adaptation (DA) [20] methods are the most common approach for enabling a model to generalize to new domains and are perhaps the closest to DG. DA algorithms leverage pre-trained models and use their feature extraction capabilities, by fine-turning them on unseen data distributions or target domains in order to improve model generalizability. Although similar, the difference between DA and DG is apparent as DA models update their parameters based on data drawn from target domains and are evaluated on the same target distributions, whereas DG algorithms hold no prior PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 3 information regarding the target domains. In [21] the authors propose using a cluster-aligning loss, coupled with a clustermaintaining loss, in order to respectively align the training and test data distributions and reinforce the discriminative ability of their model, for the classification of arrhythmia heartbeats. The authors of [22] demonstrate the effectiveness of pretraining vanilla convolutional neural networks (CNN) on large public raw ECG datasets, which are then fine-tuned for the classification of heart arrhythmias as well, finding a significant improvement in the downstream classification task. A plethora of DA methods have also been proposed in EEG processing. In an attempt to produce a model which generalizes across two different emotion recognition datasets, [23] investigates the implementation of several DA algorithms, such as MIDA [24], TCA [25], SA [26] and others. The authors report an overall improvement over the baseline model. In turn, the authors of [27] employ an end-to-end deep DA method which leverages a domain adversarial discriminator to match the distribution shift between source and target data, in a motor imagery classification problem. Self-Supervised Learning (SSL) [28] methods have also proven effective in boosting a model’s generalizability, as the main goal is for the model to learn domain-invariant representations by discriminating transformed or augmented input data from the initial signal. A first example in ECG classification is [29], in which the use of contrastive predictive coding produces a model with increased accuracy against its fully supervised counterpart, along with some level of robustness against physiological noise. Moreover, in [30] the authors investigate the effectiveness of SSL for heart murmur detection, while also explore the most effective input data augmentations. SSL has also been implemented for emotion recognition from ECGs in [31], where the authors report stateof-the-art results for the respective dataset. As far as EEG is concerned, several works tackling sleep stage classification and pathology detection [32], [33], [34], attempt to extract representations and the underlying structure of the physiological signals signals via contrastive learning. Attention-based architectures [5] seem to be effective and successful in improving the generalization ability of biosignal classification models as well. The use of handcrafted ECG features paired with a transformer network is explored in [35], for the classification of cardiac abnormalities, yielding promising results. Furthermore, in [36] the authors apply several attention-based models and report improved results on a public motor movement/imagery dataset, while [37] uses a similar model to hierarchically learn the discriminative spatial information from electrode level to brain-region level. B. Domain Generalization Methods in Biosignal Classification Even though the prior work in biosignal DG is limited, researchers have shown some interest in the past. For example, the authors of [38] propose a DG setup for normal vs abnormal phonocardiogram classification and claim their ensemble classifier fusion method yields significant accuracy improvement across domains. In [39] multi-source domain-adversarial training [40] is implemented to overcome the heterogeneity present Fig. 2. Visualization of the backbone networks used in our experiments. The top network is a standard ResNet-18. The bottom network is a smaller ResNet or S-ResNet, consisting of 4 residual blocks, with 2 convolutional layers each. Therefore, the S-ResNet consists of a total of 9 convolutional layers. The lines above the network blocks and conv layers represent ResNet skip connections. The solid lines indicate that the passed feature maps retain their dimension, while the feature maps passed through the dashed connection lines are downsampled to match the dimension of the previous layer output. Both networks are adapted for 1D signal classification. in ECG signals, but no results are presented between source and target domains. The same follows in [41], where the authors propose an adversarial domain generalization framework to reduce variability between signals originating from distinct subjects but not from different datasets (domains). With the exception of [38], all previously proposed DG biosignal papers formulate each patient as a separate domain and aim to improve cross-subject generalization in their models. However, in each respective dataset the data distribution remains similar (e.g. population groups with matching characteristics, same hospital with specific equipment) and the produced models are evaluated on comparable data originating from similar data generating processes. DG algorithms take into consideration the above and focus on producing robust models which are able to extract domain-invariant representations from input signals and generalize to completely unseen data distributions [1]. In the sections to come, after describing methods similar to our own, we discuss DG algorithms which derive from computer vision, adapt them accordingly and explore their effectiveness on 1D biosignal data. C. Multi-Layer Representation Learning Several aspects of multi-layer representation learning have been researched in the machine learning literature, from which we drew inspiration for our proposed method. In their paper [42], Hariharan et al. propose to utilize features throughout multiple layers in a CNN, to build Hypercolumns for image segmentation. However, to build Hypercolumns an initial set of bounding boxes indicating the point of interest on the image is required. Hypercolumns have been also adopted in the medical image domain, where the authors of [43] use them to detect stages of Alzheimer’s disease. In addition, Feature Pyramid Networks (FPNs) stack representations from several layers of the network in a pyramid-like manner and were proposed for object detection in images. The pyramids are constructed by pooling 7×7 features from provided regions of interest and are passed through two hidden fully connected layers PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 4 Fig. 3. Illustration of the proposed BioDG benchmark, for ECG and EEG classification. Each dataset is split into Source and Target domains. The models are trained only on source domain data and are then evaluated on both held-out intra-distribution (drawn from Source domains) and OOD (drawn from Target domains) data. before the final classification. Another approach in multilayer representation learning is feature reuse. For example, the authors of [44] propose connecting all layers with matching feature-map sizes via dense connections to tackle the vanishing gradient problem and report improved performance in several image object recognition benchmarks. Recently, [45] proposed employing self-attention mechanisms to image feature maps from multiple layers of a CNN, to push the model to attend to class-relevant cross-channel attributes. Finally, U-Nets [46] were proposed for improved medical image segmentation, in which extracted feature maps from early layers of a CNN are upsampled and concatenated to deeper layers of the network. In contrast to previous methods designed for image processing, our multi-layer representation algorithm is proposed for 1D biosignal classification. The novelty of our method lies in the fact that each level of information extracted is processed independently, without getting inserted back into the network and potentially polluted with representations corresponding to spurious correlations. As a result, we hypothesize that a classifier will be able to base its predictions on the representations which remain invariant between different domains. IV. ADAPTING COMPUTER VISION DOMAIN GENERALIZATION METHODS TO BIOSIGNAL CLASSIFICATION Domain Generalization methods focus on maintaining high accuracy across both known and unknown data distributions. The core difference between DG and other paradigms is the fact that during training, the model has no access to the test distributions whatsoever, which makes it a significantly more difficult problem than DA. In the ML literature, most DG methods have been proposed for computer vision tasks. Therefore, for our evaluation we select to use as baselines the most widely accepted algorithms, after adapting them for 1D biosignal classification. To push a model to learn invariances related to causal structures of a class and therefore enable out-of-distribution generalization, [47] introduces invariant risk minimization or IRM. IRM is used in order to estimate invariant correlations across numerous training distributions and to learn a data representation for which an optimal classifier matches throughout all training distributions. In the context of 1D biosignal classification, IRM could push a model to learn the parts or attributes of the signal, which remain invariant between different datasets. The authors of [48] use Random Fourier Features and sample weighting to compensate for the complex, non-linear correlations amongst non-iid data distributions, while JiGen [49] proposes solving jigsaw puzzles via a self-supervision task, in an attempt to restrict semantic feature learning. Specifically, JiGen’s objective is split into two parts. First, the model attempts to minimize the error between predicted and true label and secondly, tries to reconstruct the permuted, decomposed and split-into-patches source images. Additionally, SagNets [50] aim to reduce domain gap in images by disentangling their style encodings. Meta-learning approaches have also been proposed [51], [52]. In a recent work, [53] leverages the variational bounds of mutual information in the meta-learning setting and uses episodic training to extract invariant representations. In [54], the authors introduce a self-challenging training heuristic (RSC) that discards representations associated with the higher gradients of a neural network. They hypothesize that the dominant features present in the dataset are associated with their model’s activations with higher gradients. Under this scope, they demonstrate that by discarding the higher activations, and therefore by iteratively challenging the model, the network is forced to activate the remaining features which should correlate with the data labels. A similar trend should hold in signal classification, as the network should be able to disregard features attributing to noise or distributional shift. The authors of [55] combine batch and instance normalization to extract domain-agnostic feature representations, in contrast to [56], which explores the use of data augmentation techniques in the DG setting. Furthermore, [57] extends adversarial autoencoders with a maximum mean discrepancy (MMD) measure for the alignment of different domain distributions and also uses adversarial feature learning to match the PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 5 aligned distributions to an arbitrary prior distribution. Finally, correlation alignment or CORAL [58] was extended in [59] for aligning correlations of DNN layer activations and addressing performance degradation due to domain shift. TABLE I TRAINING PARAMETERS FOR THE BASELINE METHODS EVALUATION. ON THE LEFT COLUMN,WE SUMMARIZE THE PARAMETERS FOR EACH OF THE BACKBONE NETWORKS IMPLEMENTED FOR THE ECG DATASET AND ON THE RIGHT FOR THE EEG DATASET. Dataset Intra-Distribution OOD Backbone ResNet-18 S-ResNet S-ResNet Optimizer Adam Adam Adam Learning Rate 0.001 0.001 0.00009 Weight Decay 0.0005 0.0005 0.00005 Batch Size 128 128 64 LR Decay Epoch 24 24 14 Epochs 30 30 20 Unfortunately, not all of the above methods can be adapted to 1D biosignal classification. The abundance of the algorithms either need to have knowledge about the number of separate domains (multi-source DG) in the training data or are based on image style transfer. Therefore, we elect to adapt a subset of the top performing single-source DG algorithms for our experiments. As they were initially proposed for CV, their backbone networks consisted of vanilla ResNet-18 or ResNet50 residual networks [3]. As a first step, we converted all 2D layers to 1D layers in order to be able to train them on the available ECG and EEG signals and experimented with a ResNet-18 backbone network. For the ECG classification task we found that the ResNet-18 was able to achieve good convergence. However, due to the limited number of signals, and therefore a small overall dataset size (more in Sections V-A and V-B), it was not able to succeed in converging on the EEG data and thus experimented with a smaller network with fewer parameters. We therefore propose to use a smaller custom ResNet, or S-ResNet consisting of 4 residual blocks, with 2 convolutional layers each. Both backbone networks are depicted in Figure 2. To summarize, for our implementation we adopt the baseline single-source DG methods of CORAL, IRM, MMD and RSC, along with a classic fully supervised model based solely on Empirical Risk Minimization (ERM) [60], [61]. In addition, the “S-ResNet” and “ResNet-18” notations, reflect the backbone architecture implemented in each experiment. For the ECG dataset we use a 1D ResNet18 and a 1D S-ResNet with randomized weights for backbone networks. We train all models for 30 epochs and use a batch size of 128 signals. We also adopt the Adam optimizer, with a weight decay of 0.0005 and set the initial learning rate to 0.001. After 24 epochs, the learning rate decays by 0.1 for each remaining epoch. For the EEG classification task, we implement a S-ResNet with randomly initialized weights and adapt all available algorithms to use it as a backbone. For the above setting we train all models for 20 epochs, again using the Adam optimizer, with an initial learning rate of 9e−05, decaying at epoch 14 with a 0.1 rate and a batch size of 64. All the above training parameters are summarized in Table Fig. 4. Visualization of the proposed concentration pipeline. To transform the extracted feature maps into compressed representations of the initial signal, each concentration pipeline consists of 3 sequentially connected layers: A 1x1 Conv layer, a Spatial Dropout layer and an Average Pooling layer. We hypothesize that these representations could contain disentangled attributes of the input data, invariant to the distributional shift present between domains. I and all additional hyperparameters for each DG algorithm were set as described in their respective papers. All methods were implemented using PyTorch [62] and all models were trained using an NVIDIA RTX A5000 GPU. A. A Concentration Pipeline for DG in Biosignal Classification In addition to the models adapted from the computer vision DG literature, we also propose an alternative approach towards tackling DG in biosignals. To be more concise, after producing promising results in computer vision [18], we adapt our method for biosignals by building upon our preliminary work in [19]. In this section, we present our proposed method. Our approach lies somewhat between the aforementioned DG methods. In most cases, the above algorithms are implemented with networks which contain convolutional layers. We hypothesize that a model is unable to infer based on entangled representations, i.e representations containing both class-invariant information and domain-specific features, when relying only on the final layers of a deep CNN. Consequentially, the model is prone to base its predictions on spurious correlations present in its training data. We argue that the distribution shift problem between data drawn from unknown domains can be mitigated by leveraging information passed throughout the network. Hence, we propose building representations from features extracted from several layers of a CNN. The extraction of these features is accomplished by attaching a custom sequential concentration pipeline (Figure 4) of layers to multiple levels of the corresponding backbone model. To demonstrate the proposed architecture, we use the same backbones as the above DG methods and choose to extract features from a total of 15, 9 and 5 layers across the ECG ResNet-18, ECG S-ResNet and EEG S-ResNet respectively, as depicted in Figures 1 and 5. After experimenting with the position and number of connected concentration pipelines we found that for the ECG task, the performance of our model improved when features where extracted from across the network and the majority of the intermediate layers. In contrast, for the EEG experiments we found that less extracted features were needed to boost the model’s generalization abil- PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 6 Fig. 5. Visualization of our proposed DG neural network architecture. Our method utilizes a standard ResNet-18 as the backbone model. We hypothesize that the extraction and combination of feature maps from multiple layers of a CNN, enables the model to disentangle the input data and infer based on the invariant attributes of the signal. In this implementation we select to connect extraction blocks to 14 different location throughout the backbone network, as shown in the figure. In addition to extracting features from convolutional layers, we also choose to process features extracted from skip connections. As in Figure 2, the solid lines represent normal connections between network layers where the passed features retain their dimension, while the features passed through the dashed lined connections are downsampled to match the dimension of the previous layer output. ity. Furthermore, we implement the same training parameters as in Table I, for the respective backbone and dataset. The proposed pipeline contains a 1x1 Convolutional layer, a Spatial Dropout layer and an Average Pooling layer. Each component of the pipeline is implemented for reducing the dimensionality of the extracted feature maps and hopefully yielding invariant attributes of the unstructured input data. Initially, the extracted features are projected into a lower dimensionality by the 1x1 conv layer, leading to a compressed representation of the signal. The spatial dropout layer promotes the independence of the compressed feature maps and acts as a regularizer, while the average pooling layer extracts the average level of information present in the compressed features. Finally, the output vectors of each pipeline are concatenated and passed through the network’s classification head, which consists of a fully connected linear layer and the appropriate activation layer. Moreover, as our method has no knowledge of any domain labels whatsoever, it can be categorized as a single-source DG algorithm. For simplicity, the above implementations will hereafter be referred to as “BioDG baseline”. V. EVALUATION BENCHMARK Our primary contribution in this work, is an open-source evaluation benchmark for DG algorithms in ECG and EEG classification. We argue that a generalizable model should be able to maintain its performance across data originating from several experimental settings, equipment and populations with different characteristics. For our experiments we select 6 ECG datasets from PhysioNet’s public database [12] and 3 of the SEED [13], [14], [15], [16] EEG datasets. In the following subsections we will describe the experimental setup for each biosignal dataset, from data preprocessing, to data separation, model training and ultimately model evaluation. A. Datasets The PhysioNet ECG database contains 6 12-lead ECG datasets. However, the data derive from 4 separate sources. In total, the ECG data sources are: •CPSC, CPSC Extra. Since both datasets were published during the China Physiological Signal Challenge 2018 (CPSC2018) [63] and originate from the same source, we handle them as a single domain. •G12EC. The second source is the Georgia 12-lead ECG Challenge (G12EC) Database, Emory University, Atlanta, Georgia, USA [12]. •INCART. The third source is the public dataset from the St. Petersburg Institute of Cardiological Technics (INCART) 12-lead Arrhythmia Database, St. Petersburg, Russia [64]. •PTB, PTB-XL. Finally, the PTB datasets were published by Physikalisch-Technische Bundesanstalt (PTB) Database, Brunswick, Germany [65]. As the signals were taken from separate sources, they differ significantly. As a first step, we had to convert them into a common form. Since most of the signals were sampled at 500 Hz and were about 10 seconds long, we resample each signal to 500 Hz and either zero-pad, truncate or split each one into 10-second non-overlapping windows accordingly, to homogenize the input data. Moreover, each ECG recording PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 7 can be labeled with more than one class. Therefore, this problem falls into the category of multi-label classification. Nonetheless, as the number of present ECG diagnoses is over 100 across all datasets, we followed PhysioNet’s guidelines and decided to only classify 24 classes. If none of the signal’s labels are present in the 24 classes, we exclude it from the dataset. After this process, 37,749 signal recordings remain in total and each of them is normalized in the [−1,1] range. For the EEG setup we adopt 3 SEED datasets, namely SEED, SEED-FRA and SEED-GER. The above datasets are used for EEG-based emotion recognition research and contain data from 3 different populations from China, France and Germany. In all 3 experiments, while presenting the subjects with a series of film clips chosen to elicit emotions between “Negative”, “Neutral” and “Positive”, a 62-channel EEG signal, sampled at 1 kHz was captured. After preprocessing the raw EEG signals, the authors provide the EEG differential entropy (DE) features which have proven to be more discriminative than the raw signals [66]. The DE features have a dimension of [N, 5], where Nis the length of the EEG signal and each of the 5 channels corresponds to a different brain wave frequency, between Alpha, Beta, Gamma, Delta and Theta waves. Hence, we select to use the DE features as input to our models. As the length of each EEG signal varies depending on the length of the provided clip, we once again split the corresponding DE features into 10-second non-overlapping windows. Each window inherits the label from the original signal and is then fed into the model. After splitting the features, we get a total of 852 windows with a dimension of 170 ×5. B. Experimental Setup For the DG problem in 1D biosignal data, we move past the leave-one or leave-multiple-subjects-out protocol and implement the widely accepted in DG, leave-one or leave-multiple domains-out protocol, as described in [17]. Specifically, in this setting we think of each distinct dataset, or different data source, as a domain and split all available domains into Source and Target domains. We train each model on the source domain data only. Since a DG model should be able to generalize on data from both source and target domains, we split the model evaluation in Intra-Distribution and OOD evaluation. To that end, for both biosignal datasets, we split the source data into a standard train-val-test split with a 70 −10 −20% ratio respectively and use the test split for the Intra-Distribution evaluation. For the OOD evaluation, we use all of the target domain data. For the ECGs, we split the available databases as follows. The CPSC, CPSC Extra, PTB and PTB-XL are considered as source domains and the INCART and G12EC as target domains, following [19]. As the number of represented classes differ between datasets, we choose the above target domains to balance the classes in both splits2. Since the ECG labels are highly unbalanced, we omit reporting results in terms of accuracy (which can be misleading) and instead compare 2The total number of classes in each data source can be found here: https://github.com/physionetchallenges/evaluation-2020/blob/master/dx mapping scored.csv. Fig. 6. Plots of the training and validation losses of all methods for the BioDG experimental setup. Both training and validation data originate from the Source Domains. On the top plots, we illustrate the convergence analysis for the ECG datasets for all models utilizing both the ResNet-18 and S-ResNet backbone networks. The bottom plots depict the training and validation loss progression for the EEG classification task. As in Table IV, the labels on the right side of the EEG analysis indicate the (source) domains on which each model was trained on. the per-class F1-scores of each method. Note that in some cases, models do not predict any true positive for some classes (leading to a zero F1 score). For this reason, we also report the number of classes with at least one true positive example, as an additional indicator of model effectiveness (denoted as “# of Predicted Classes” in the results tables). Using this number, we report the Macro-F1 scores of these predicted classes in addition to the Macro-F1 score for all the classes present in the datasets. For the EEGs, we design three iterations of the experiment based on the leave-one-domain-out protocol. In each iteration, we select one of the three datasets as the target domain and use the remaining two as source data domains. For example, in the first iteration we select the data from the SEED dataset as the target domain, originating from China - CHI. Therefore the intra-distribution evaluation will consist of data from the remaining two datasets, SEED-FRA and SEED-GER and the OOD evaluation split will contain data only from CHI. Since this is a multiclass classification problem, we select to report and evaluate all methods in terms of their total accuracy. In our experiments, we repeat each iteration 10 times and present the average accuracies, along with the respective standard PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 8 TABLE II PER-CLASS RESULTS FOR INTRA-DISTRIBUTION AND OUT-OF-DISTRIBUTION ECG CLASSIFICATION,WITH A RESNET-18 AS THE BACKBONE NETWORK. WE COMPARE WIDELY ACCEPTED DG ALGORITHMS WITH THE BASELINE (I.E., NO DG) MODEL AND EVALUATE EACH MODEL’S PERFORMANCE ON INTRA AND OOD DATA. THE TOP RESULTS FOR EACH SETTING ARE HIGHLIGHTED IN BOLD AND ARE UNDERLINED,RESPECTIVELY. THE TOTAL EVALUATION IS BASED ONLY THE PER CLASS F1-SCORES. ADDITIONALLY,WE ALSO REPORT THE MACRO-F1 SCORES OF EACH MODEL,WHEN AVERAGED OVER THE CLASSES WITH AT LEAST ONE TRUE POSITIVE EXAMPLE AND OVER THE TOTAL NUMBER OF CLASSES IN THE DATASET. Backbone: ResNet-18 Intra-Distribution OOD Diagnosis ERM IRM MMD RSC CORAL BioDG ERM IRM MMD RSC CORAL BioDG 1st degree AV block 67.05 0 60.87 32.33 58.35 67.81 75.26 0 71.78 44.76 70.17 70.64 Atrial fibrillation 86.14 18.18 74.21 58.89 78.76 88.38 63.94 12.16 44.97 35.29 46.92 64.40 Atrial flutter 0 0 0 0 0 30.00 0 0 0 0 0 4.35 Bradycardia 0 0 0 0 0 19.05 0 0 0 0 0 0 Complete right bundle branch block 77.69 16.16 68.90 72.92 66.32 82.41 62.35 11.50 46.92 65.42 42.83 63.97 Incomplete right bundle branch block 0 0 31.97 0 32.86 47.98 0.48 0 32.74 0 29.08 28.22 Left anterior fascicular block 41.59 0 57.78 0 54.55 70.44 22.22 0 22.52 0 19.79 39.77 Left axis deviation 54.11 31.15 59.34 31.15 55.50 72.88 26.51 17.79 38.38 17.79 35.11 40.87 Left bundle branch block 81.82 0 58.63 0 63.71 88.54 67.50 0 58.22 0 64.23 75.29 Low QRS voltages 0 0 0 0 0 0 0 0 0 0 0 0 Non-specific intraventricular conduction disorder 0 0 0 0 0 0 0 0 0 0 0 5.33 Pacing rhythm 87.94 0 69.90 0 72.73 91.78 0 0 0 0 0 0 Premature ventricular contractions 0 0 0 0 0 0 0 0 0 0 0 0 Prolonged PR interval 0 0 0 0 0 15.38 0 0 0 0 0 0 Prolonged QT interval 0 0 0 0 0 0 0 0 0 0 0 0 Q wave abnormal 0 0 0 0 0 1.71 0 0 0 0 0 0 Right axis deviation 0 0 0 0 0 30.95 0 0 0 0 0 2.11 Sinus arrhythmia 0 0 0 0 0 0 0 0 0 0 0 0 Sinus bradycardia 52.24 0 0 0 0 53.01 13.76 0 0 0 0 18.34 Sinus rhythm 93.04 80.94 80.94 82.56 80.94 93.59 52.29 31.56 31.56 31.56 31.56 50.97 Sinus tachycardia 81.31 0 80.15 0 76.68 78.22 81.49 0 89.40 0 89.29 79.39 Supraventricular premature beats 0 0 10.02 0 6.26 5.84 0 0 11.46 0 9.79 1.43 T wave abnormal 23.36 15.68 31.27 30.28 34.14 32.49 1.39 38.40 38.43 29.04 36.66 1.46 T wave inversion 0 0 0 0 0 0 0 0 0 0 0 0 #of Predicted Classes 11 5 12 6 12 18 11 5 11 6 11 15 Macro-F1 (Predicted) 30.4 8.53 21.34 27.87 25.69 48.63 23.40 7.43 17.25 11.88 20.09 35.88 Macro-F1 (All) 24.16 6.75 16.89 22.07 20.34 38.50 14.63 4.64 10.78 7.43 12.56 22.42 Fig. 7. Visualizing the final layer feature vectors of each model in the EEG classification setting using t-Distributed Stochastic Neighbor Embedding (tSNE). The blue, green and red circles indicate the features which correspond to the Positive, Neutral and Negative emotion classes using EEG signals from the unseen test CHI target Domain. deviations. The experimental setup for both biosignals is illustrated in Figure 3. VI. RESULTS For both datasets we implement the baseline models in addition to the BioDG baseline method, described in Section IV-A. The results for the ResNet-18 and S-ResNet backbones in the ECG experiments are shown in Tables II and III respectively, as the results of the EEG experiments are presented in Table IV. For our experiments, we also provide convergence analysis plots (Fig. 6) of the training and validation losses for all models in both settings, along with t-SNE feature vector visualizations for the EEG biosignal classification task3. The experimental results are discussed in the following section. A. Discussion To ensure the validity of our framework we choose to plot the training and validation loss progression for all methods in each experiment. As illustrated in Figure 6, all algorithms seem to successfully converge on the training and validation data drawn from the source domains. With the exception of RSC in the ECG setting, all algorithms appear to reach about the same validation loss at the end of their training. However, when we dive deeper into the experimental results the distribution shift between the source and target domains clearly affects the performance of each model. In the case of the ECG dataset, the overall drop in the Macro F1-score for both evaluation settings is quite obvious. When comparing each model between their intra-distribution and OOD results, 3We provide t-SNE visualizations only for the the EEG data as the ECG signals are multi-labeled and only a very small subset of them hold a single label and can therefore be attributed to a single feature cluster. PREPRINT. ACCEPTED IN: IEEE TRANSACTIONS ON EMERGING TOPICS IN COMPUTATIONAL INTELLIGENCE, JUNE 2023 9 TABLE III PER-CLASS RESULTS FOR INTRA-DISTRIBUTION AND OUT-OF-DISTRIBUTION ECG CLASSIFICATION,WITH A S-RESNET AS THE BACKBONE NETWORK. WE COMPARE WIDELY ACCEPTED DG ALGORITHMS WITH THE BASELINE (I.E., NO DG) MODEL AND EVALUATE EACH MODEL’S PERFORMANCE ON INTRA AND OOD DATA. THE TOP RESULTS FOR EACH SETTING ARE HIGHLIGHTED IN BOLD AND ARE UNDERLINED,RESPECTIVELY. THE TOTAL EVALUATION IS BASED ONLY THE PER CLASS F1-SCORES. ADDITIONALLY,WE ALSO REPORT THE MACRO-F1 SCORES OF EACH MODEL,WHEN AVERAGED OVER THE CLASSES WITH AT LEAST ONE TRUE POSITIVE EXAMPLE AND OVER THE TOTAL NUMBER OF CLASSES IN THE DATASET. Backbone: S-ResNet Intra-Distribution OOD Diagnosis ERM IRM MMD RSC CORAL BioDG ERM IRM MMD RSC CORAL BioDG 1st degree AV block 16.14 0 7.69 15.00 10.67 61.88 7.30 0 5.84 0.51 7.38 62.24 Atrial fibrillation 55.84 18.18 23.98 36.99 24.81 87.05 32.58 12.16 13.28 12.16 13.22 62.51 Atrial flutter 19.05 0 0 13.33 0 50.00 0 0 0 0 0 10.70 Bradycardia 0 0 0 5.26 7.69 0 0 0 0 0 0 0 Complete right bundle branch block 73.38 16.16 60.41 72.58 64.19 82.46 60.15 11.50 50.90 47.75 52.64 64.55 Incomplete right bundle branch block 11.01 0 13.05 4.86 22.19 43.03 14.56 0 20.09 10.85 25.65 30.27 Left anterior fascicular block 54.67 0 50.83 52.8 53.37 70.29 31.03 0 21.01 17.16 20.84 33.29 Left axis deviation 58.10 31.15 58.34 56.26 60.56 66.87 44.98 17.79 37.75 36.09 39.16 50.42 Left bundle branch block 80.49 0 0 78.33 45.49 85.48 62.44 0 0 0 40 74.04 Low QRS voltages 0 0 0 0 0 0 0 0 0 0 0 0 Non-specific intraventricular conduction disorder 0 0 0 4.55 0 2.34 0 0 0 0 0 0 Pacing rhythm 58.62 0 37.84 43.90 48.15 78.46 0 0 0 0 0 0 Premature ventricular contractions 0 0 0 0 0 0 0 0 0 0 0 0 Prolonged PR interval 0 0 0 0 0 15.00 0 0 0 0 0 0 Prolonged QT interval 0 0 0 0 0 0 0 0 0 0 0 0 Q wave abnormal 0 0 0 0 0 11.11 0 0 0 0 0 0 Right axis deviation 5.48 0 23.27 9.52 27.92 24.53 0 0 18.58 21.54 17.35 2.84 Sinus arrhythmia 2.17 0 0 0 0 0 1.94 0 0 0 0 10.85 Sinus bradycardia 4.49 0 0 9.03 0 36.70 31.56 31.56 31.56 31.56 31.56 47.33 Sinus rhythm 84.60 80.94 80.94 82.56 80.94 91.44 38.89 0 12.54 0.62 15.17 82.68 Sinus tachycardia 27.86 0 10.37 20 15.54 79.82 1.35 0 9.98 0 8.07 1.92 Supraventricular premature beats 9.27 0 10.07 11.28 8.17 3.68 0 0 10.02 0 6.26 5.84 T wave abnormal 18.57 15.68 28.62 13.31 26.14 33.89 8.11 38.40 37.22 0 30.35 4.53 T wave inversion 0 0 0 0 0 0 0 0 0 0 0 0 #of Predicted Classes 16 5 12 17 15 18 12 5 12 9 13 15 Macro-F1 (Predicted) 41.46 9.01 38.00 17.03 37.82 53.91 31.15 7.43 32.43 14.92 31.70 36.44 Macro-F1 (All) 31.10 6.75 28.50 12.77 28.37 40.44 19.47 4.64 20.27 9.33 19.81 22.77 TABLE IV INTRA-DISTRIBUTION AND OUT-OF-DISTRIBUTION RESULTS FOR THE EEG EXPERIMENTS,WITH AN S-RESNET AS THE BACKBONE NETWORK. WE COMPARE WIDELY ACCEPTED DG ALGORITHMS WITH THE BASELINE (I.E., NO DG) MODEL AND EVALUATE EACH MODEL’S PERFORMANCE ON INTRA AND OOD DATA. THE TOP RESULTS FOR EACH SETTING ARE HIGHLIGHTED IN BOLD WHILE THE SECOND BEST ARE UNDERLINED. CHI, FRA AND GER CORRESPOND TO DATA FROM SEED, SEED-FRA AND SEED-GER RESPECTIVELY. Intra Method FRA-GER CHI-GER CHI-FRA ERM 70.94 ±2.51 73.63 ±2.08 76.10 ±2.27 IRM 70.75 ±2.81 71.42 ±2.98 73.90 ±3.15 CORAL 71.42 ±1.67 73.72 ±1.91 74.96 ±2.59 MMD 71.23 ±2.23 74.34 ±1.87 76.26 ±1.95 RSC 70.15 ±2.43 72.01 ±2.37 76.15 ±2.08 BioDG 77.59 ±2.23 76.11 ±1.25 75.61 ±1.15 OOD Method CHI FRA GER ERM 54.60 ±3.44 45.83 ±3.53 63.75 ±4.01 IRM 53.70 ±1.42 43.82 ±0.75 66.87 ±3.49 CORAL 53.18 ±3.29 45.00 ±2.51 67.04 ±3.27 MMD 54.17 ±2.68 45.80 ±3.46 66.04 ±3.39 RSC 53.86 ±2.55 44.37 ±2.99 58.79 ±3.93 BioDG 57.09 ±0.44 51.74 ±0.35 68.04 ±0.24 it is evident that they are not able to sufficiently generalize to unseen data. However, there is a difference in the performance of each method. In both cases of backbone models the BioDG baseline is consistently one step ahead, as it is able to achieve top performances in both evaluation setups. Furthermore, our method is also able to successfully recognize an additional number of diagnoses in both cases. Another interesting result, is the fact that despite the difference in model parameters (details in Table VI-B) the performance of the S-ResNet BioDG model is comparable to that of its ResNet-18 counterpart. What’s more, in both cases of backbone models the rest of DG algorithms seem to overfit on the sinus rhythm class (normal heartbeat) in contrast to the BioDG baseline. The DG problem can also be observed in datasets containing data from different populations, as in the case of the EEG experiments. Even though the performance of all models clearly drops when evaluated on unseen data, the proposed BioDG algorithm continues to outperform the rest of the baseline methods. With the exception of the intra-distribution evaluation of CHI-FRA, our network consistently surpasses all other models, in all settings. To provide further evidence of the feature extraction capabilities of our proposed method we visualize the feature vectors of each model’s final layer in the EEG setting using t-Distributed Stochastic Neighbor Embedding or t-SNE [67]. Admittedly, the visualized feature maps are quite erratic and a somewhat clear separation of clusters is not present for any method besides perhaps our own. Even though not all vectors of the same label are grouped together, our algorithm seems to make a more explicit distinction than the baseline models where three clusters appear for the Positive, Neutral and Negative classes.