---
abstract: 'We focus on automatic feature extraction for raw audio heartbeat sounds, aimed at anomaly detection applications in healthcare. We learn features with the help of an autoencoder composed by a 1D non-causal convolutional encoder and a WaveNet decoder trained with a modified objective based on variational inference, employing the Maximum Mean Discrepancy (MMD). Moreover we model the latent distribution using a Gaussian chain graphical model to capture temporal correlations which characterize the encoded signals. After training the autoencoder on the reconstruction task in a unsupervised manner, we test the significance of the learned latent representations by training an SVM to predict anomalies. We evaluate the methods on a problem proposed by the PASCAL Classifying Heart Sounds Challenge and we compare with results in the literature.'
author:
- Robert George Colt
- Csongor Huba Várady
- |
    \
    Riccardo Volpi
- Luigi Malagò
bibliography:
- 'bibliography.bib'
title: |
    Automatic Feature Extraction\
    for Phonocardiogram Heartbeat Anomaly Detection using WaveNetVAE [^1] 
---

Introduction
============

Anomaly detection is usually characterized by a class imbalance between normal and anomalous data, i.e., outliers differing from the majority of the data. In healthcare this problem is particularly relevant considering the potential for early diagnoses, by triggering expedited emergency responses in time-critical situations, having the potential to improve the quality of life @ukil2016iot [@li2020survey; @vsabichealthcare]. Cardiovascular diseases are the first cause of death worldwide @li2020survey and the problem of anomaly detection in heartbeats has been extensively approached in the literature @vsabichealthcare [@ismail2018localization; @krishnan2020automated; @latif2018phonocardiographic]. Detecting irregularities in ECG signals can be approached efficiently with machine learning methods @vsabichealthcare [@li2020survey] with considerable success, due to the low level of noise in these signals, allowing additionally for a low sampling rate. Classification of heartbeat anomalies from PhonoCardioGram audio signals (PCG) is a considerably more difficult task compared to ECG signals. On the other hand data are easier to obtain and successful anomaly detection algorithms based on PCG are more pervasive in the society due to the wide availability of audio recording devices.

The PASCAL Classifying Heart Sounds Challenge 2011 @pascal-chsc-2011 has introduced the problem of identifying unhealthy heartbeat sounds in PCG signals. Several approaches to this problem take a fully supervised approach, by introducing expert knowledge @gomes2012classifying [@deng2012robust; @oliveira2014heart; @avendano2010feature], with ad-hoc features design, and by using specific wavelet transformations to identify anomalous frequencies @balili2015classification, or through decision trees based on expert knowledge heuristics @chakir2018phonocardiogram. Malik et al. @malik2019localization exploited the periodicity and average heartbeat lengths to highlight anomalous behavior.

In this paper we follow a different perspective in which features are automatically extracted through an autoencoder trained on the reconstruction task. Wang et al. @wang2016research use CNNs and autoencoders to perform anomaly detection on time-series physiological data, Pereira et al. @pereiraIJDMB perform unsupervised LSTM based representation learning and anomaly detection in ECG sequences. Rushe et al. @rushe2019anomaly introduce an anomaly detection algorithm for raw audio data, based on the ability of WaveNet @oord_WaveNet:_2016 to predict the next sample of a normal signal. We aim at combining both approaches, in particular we would like to have a well behaved latent representation and at the same time leverage the expressivity of a WaveNet autoregressive model. Given the importance of interpretable models in medicine @bizopoulos2018deep, we aim at learning a set of expressive and compact features in the latent space by Variational Inference @graves2011practical. We demonstrate that relevant features can be automatically extracted through the reconstruction task, paving the way towards semi-supervised approaches.

Methodology
===========

WaveNetAE @engel_neural_2017 has been proven capable of learning to reconstruct high-fidelity natural sounds like music or human speech. It consists of an encoder employing non-causal convolutional layers with skip connections, and on a conditional WaveNet @oord_WaveNet:_2016 decoder. The training is done with the objective of minimizing the negative log likelihood. Unlike simple Autoencoders, Variational AutoEncoders (VAE) @kingma2013vae [@rezende2014stochastic], based on Variational Inference (VI) @graves2011practical exhibit advantageous properties by regularizing the latent space and being able to learn compact representations, by using a multivariate Gaussian.

Usually the Gaussian distribution is chosen with independent priors, i.e. with a diagonal covariance matrix. In order to model a time correlation between the latent variables, we introduce a Gaussian graphical model @lauritzen1996graphical characterized by a chain structure over the time dimension in the latent space of the encoder, cf. @apeste2017Towards. The overall architecture is shown in Figure \[fig:WaveNetVAE\] and it consists of an encoder-decoder pair. The decoder is a WaveNet model, while the distribution for the approximate posterior in the latent space is either a Gaussian Independent model (GI) or a Gaussian Chain model (GC). A known problem, when using a probabilistic distribution in the latent space of Variational Autoencoder with a powerful autoregressive decoder such as WaveNet, is that the KL term in the Evidence Lower Bound objective (ELBO) $$\label{eq:ELBO}
        \mathcal{L}(x, \theta, \phi) = \mathbb{E}_{q_\theta(z|x)}[\ln p_\phi(x|z)] - D_{KL}(q_\theta(z|x) || p(z))$$ might lead the optimization towards posterior collapse, as also reported in @engel_neural_2017. To solve this problem we propose replacing the KL divergence in the ELBO objective with the Maximum Mean Discrepancy (MMD) @sriperumbudur2010hilbert, a dissimilarity measure between the aggregate posterior and the prior distribution @zhao2017infovae [@tolstikhin2017wasserstein] as $$\label{eq:MMD_formula}
        \begin{gathered}
            D_{MMD}(q||p) = \mathbb{E}_{p(z),p(z')}[k(z, z')] - 2\mathbb{E}_{q(z),p(z')}[k(z, z')] + \mathbb{E}_{q(z),q(z')}[k(z, z)], \\
        k_{gaussian}(z, z') = e^{-\frac{||z-z'||^2}{2\sigma^2}}, \qquad  k_{module}(z, z') = ||z - z'|| - ||z|| - ||z'||\;.
        \end{gathered}$$ In our experiments we used the Gaussian kernel ($k_{gaussian}$) for the GI models and for GC trained only on normal data. For the GC models trained on all both normal and anomalous data, the best results were obtained when using the module kernel ($k_{module}$) to compute the MMD.

<span>.5</span> ![Illustration of a Gaussian chain model with tridiagonal precision matrix.<span data-label="fig:WaveNetVAE"></span>](images/HB_examples.png "fig:"){width=".9\linewidth"}

<span>.5</span> ![Illustration of a Gaussian chain model with tridiagonal precision matrix.<span data-label="fig:WaveNetVAE"></span>](images/WaveNetVAE.png "fig:"){width=".9\linewidth"}

\[fig:fig\]

We train models in two ways: with all the samples (all) or only with normal samples (n). We classify the data using a supervised SVM on the frozen latent space of the pretrained WaveNetAE (abbreviated as AE), GI and GC models which are used as feature extractors.

Experimental Details
====================

We evaluate our methods on the Dataset B of the PASCAL Classifying Heart Sounds Challenge, including 507 records, collected with a 4,000Hz sampling frequency, and divided in three categories: *Normal, Murmur* and *Extrasystole*, see Fig. \[fig:HBs\]. Our preprocessing consists of 3 steps: 1) we clip the signal by the $99.9$ percentile to get rid of odd peaks; 2) we apply a low-pass filter at $195$Hz as recommended by the challenge @pascal-chsc-2011 to smooth out the clipping and to remove high frequency noise; finally 3) we rescale the data between $[-1,1]$. We train on random crops of 6,144 samples. We use WaveNet with 2 stages of 5 layers each in both the 1D non-causal Convolutional encoder and the WaveNet decoder. For the latent space we used 4 latent channels, for each of the different models AE, GI, GC. Downsampling in the temporal dimension for the encoder is performed only in the final average pooling layer with stride 64 (right before the probabilistic layers for GI and GC), leading to a 1:16 compression ratio i.e. an encoding of 96 time steps with 4 channels. We trained all models with a learning rate of $0.0002$ using Adam @kingma2014adam with default learning parameters $\beta_1=0.9$ and $\beta_2=0.999$. We train each of the above mentioned models with a batch size of 10. Our implementation is available at https://github.com/rist-ro/argo.

Results
=======

In order to classify the latent representations we experiment with different crop lengths (6,144, 9,216, 12,288) and number of random crops of the raw signal. We report best results with a crop length of 12,288 and 10 crops per signal. We employ a majority voting policy between the crops of a single signal in order to assign a label. We trained the SVM classifiers both with the raw latent representation as well as with the Fast Fourier Transforms taken on each channel separately. The best results are yielded from the latter method and are reported in Table \[tab:anomaly\_detection\_results\]. We report average on 3 training steps (spaced by 5k steps for VAEs and by 7k steps for AEs) and around the step obtaining the best classification performances on validation. We perform a 3-class classification and compute Total precision (TP) as the sum of all precisions of the 3 classes while the other metrics are computed on a binary classification task, *Murmur* and *Extrasystole* taken together being the positive class with *Normal* as the negative class, as specified by the challenge @pascal-chsc-2011. '**all**' specifies that the model has been trained with both anomalous and normal samples, '**n**' indicates the fact that the model was trained only with normal heartbeats. The models ending in '**bn**' use batch normalization in their encoder. VAE models trained on all samples are more effective than models trained only on normal data, most likely due to the limited data set size. However the AE models seem to perform better when trained only on normal data obtaining good overall performances. GC models trained on all samples exhibits good overall performance as well, similarly to AE. The chain model in the temporal dimension (GC vs GI model) improves the latent space representation, which results more meaningful to the anomaly detection task. Overall, the results obtained with the proposed methods are better than those of other works dealing with this particular challenge, Table \[tab:anomaly\_detection\_results\].

Conclusions
===========

We demonstrate how relevant features for PCG audio signals can automatically be extracted through WaveNet autoencoders. We introduce a WaveNetVAE model, trained using MMD in the latent space and we demonstrate how the introduced regularization produce a benefit in terms of SVM classification in the latent space. Additionally we found that Batch Normalization in the encoder produce benefits in terms of latent representations for the WaveNetVAE models. We obtained better results than other works dealing with the PASCAL Classifying Heart Sounds Challenge 2011, evaluated with several metrics of interest for the challenge. We show how a VAE or AE model can be used to automatically extract relevant features to the anomaly detection task, without the need of expert domain knowledge. We chose a simple method to classify the frozen latent space of the heartbeats (SVM), to probe the latent space representation learned by the autoencoders. The approach presented paves the way towards semi-supervised/self-supervised training for detecting anomalies in audio signals.

Acknowledgements
================

This work was supported by the DeepRiemann project, co-funded by the European Regional Development Fund and the Romanian Government through the Competitiveness Operational Program 2014-2020, Action 1.1.4, project ID P\_37\_714, contract no. 136/27.09.2016.

[^1]: Presented at PharML 2020 Workshop - *European Conference on Machine Learning and Principles and Practice of Knowledge Discovery in Databases* (ECML-PKDD)

{'source': 'arXiv_out/2102'}