---
author:
- |
    Jörg Martin, Clemens Elster\
    Physikalisch-Technische Bundesanstalt (PTB)
title: Detecting unusual input to neural networks
---

Introduction {#sec:introduction}
============

[0.32]{} ![image](street.pdf){width="\textwidth"}

 

[0.32]{} ![image](red_street.pdf){width="\textwidth"}

 

[0.32]{} ![image](noisy_street.pdf){width="\textwidth"}

The reliability and performance of a machine learning algorithm depends crucially on the data that were used for training it [@Cortes1995]. Having an incomplete training set or encountering input data that have unprecedented deviations might lead to unexpected, erroneous behavior [@Amodei2016; @GooglePhotos; @Marcus2018]. In this work we consider the task of judging whether an input to a neural network, trained for classification, is *unusual* in the sense that it is different from the training data. For this purpose we consider a quantity based on the Fisher information matrix [@Cover2012]. A similar quantity was shown by the authors to be useful for the related task of detecting adversarial examples [@Martin2020]. Two kinds of scenarios are studied:

-   The input data were *modified*, e.g. by being noisy or contorted.

-   The training set is *incomplete*, by missing some structural component that will emerge in practice.

Our considerations are carried out along various datasets and in comparison with related methods from the literature. In particular, we present an easy and efficient method to directly compare different metrics that judge the uncertainty behind a prediction.

We consider neural networks that are trained for classifying inputs into $C$ classes $1,\ldots,C$. After application of a softmax activation the output of a neural network for an input $x$ can be read as a vector of probabilities $(p_\theta(y|x))_{y=1,\ldots,C}$, where we wrote $\theta$ for the parameters of the neural network (usually weights and biases) [@Bishop2006]. The class $\hat{y}$ where this vector is maximal is then the prediction of the network. It is quite tempting to consider $p_\theta(\hat{y}|x)$ as a measure for the confidence behind this prediction. The leftmost column of Figure \[fig:intro\_monochrome\] shows an image from the Intel Image Classification dataset [@IntelImageClassification] and the output of a neural network that was trained on it, details will follow in Section \[sec:experiments\] below. The image is classified correctly as “sea” with $p(\hat{y}|x)=98.8\%$. In this article we are more interested in the probability of *misclassification* $$\begin{aligned}
\label{eq:intro_error_prob}
 1- p(\hat{y} | x) = 1.2 \% \,.\end{aligned}$$ One might expect that the higher this probability, the more unreliable is the prediction of the network. The second column of Figure \[fig:intro\_monochrome\] shows the same image but with with an inverted green color channel. While the classification remains“sea”, the probability of error rises to $14.1\%$ which appears to be a sensible behavior. Unfortunately, the behavior of the output probability is not always meaningful. The rightmost column of Figure \[fig:intro\_monochrome\] shows the same picture with Gaussian noise added. The image is misclassified as showing a “forest” but with a quite small error probability $1-p(\hat{y} | x )$ of around $2.1\%$. The fact that the softmax probability is not fully exhaustive or even misleading in judging the reliability of the prediction of the network led to various developments in the literature like a Bayesian judgement of uncertainty [@Gal2016; @Kingma2015; @Kingma2013; @Gal2016Thesis; @Gal2017; @Blundell2015; @Filos2019] and deep ensembles [@Lakshminarayanan2017]. We here study the behavior of a quantity, called the *Fisher form* and denoted by $\mathcal{F}_\theta$, that evaluates if the input $x$ differs from what the network “has learned”. $\mathcal{F}_\theta(x)$ was introduced by the authors, with slight modifications, for the purpose of adversarial detection [@Szegedy2013; @Goodfellow2014] for the first time in [@Martin2020]. Below Figure \[fig:intro\_monochrome\] we listed the values of $\langle\mathcal{F}_\theta(x) \rangle$, where $\langle\ldots\rangle$ denotes some normalization we introduce below. As we see in Figure \[fig:intro\_monochrome\] $\langle\mathcal{F}_\theta(x)\rangle$ shows a quite natural behavior on the depicted images, where values close to 100% indicate an unusual input.

This article is structured as follows: In Section \[sec:method\] we introduce, and motivate, the method used in this article and introduce the normalization that allows us to compare different metrics. Section \[sec:experiments\] presents the results for various datsets and splits in two halfs: in Subsection \[subsec:modified\_data\] we study the effect of modifying the input, while Subsection \[subsec:incomplete\_training\_data\] considers the case where the training data lack some structural aspects. Finally we provide some conclusions and an outlook for future research.

Method {#sec:method}
======

[0.32]{} ![image](Intel_Probability_Hist.pdf){width="\textwidth"}

 

[0.32]{} ![image](Intel_Entropy_Hist.pdf){width="\textwidth"}

 

[0.32]{} ![image](Intel_Fisher_Hist.pdf){width="\textwidth"}

A slightly more complete summary of the output probabilities than can be gained by considering the *entropy* instead [@Cover2012; @Gal2016Thesis]: $$\begin{aligned}
    \label{eq:entropy}
    \mathcal{H}_\theta(x) {=} {-}\!\sum_{y=1}^C p_\theta(y|x) \log p_\theta(y|x).\end{aligned}$$ If the entropy is high the output probabilities $(p(y|x))_{y=1,\ldots, C}$ are roughly equal in magnitude and the prediction is uncertain. $\mathcal{H}_\theta(x)$ suffers still from the same drawback than $p_\theta(\hat{y} | x)$: Specifically, it completely ignores the uncertainties of $\theta$ and uses their point estimates only. One way around this problem is to use another, more elaborate distribution such as an approximate to the posterior predictive or a mixed distribution from a deep ensemble.

In [@Martin2020] the authors introduced a quantity that gives a deeper insight than and is based on the Fisher information. The Fisher information matrix for a neural network with output $p_\theta(y|x)$ for an input $x$ and a $p$-dimensional parameter $\theta$ equals ${\mathbb{F}}_\theta(x) = \sum_{y=1}^C \nabla_\theta p_\theta(y|x) \cdot \nabla_\theta \log p_\theta(y|x)^T\,. $ Even a smaller network has around $p=10^6$ parameters, which makes ${\mathbb{F}}_\theta$ a matrix with $10^{12}$ entries and is thus, in practice, infeasible. A way out, proposed in [@Martin2020], is to consider the effect of this matrix in a specific direction $v$, i.e. to consider the quadratic form $$\begin{aligned}
    \label{eq:FisherForm}
    \mathcal{F}_\theta(x) = v^T {\mathbb{F}}_\theta(x) v  \,,\end{aligned}$$ where $v$ has the same dimensionality as $\theta$. We will refer to as the *Fisher form*. The quantity measures *how much information is gained/lost* in a (small) step in the direction $v$. More precisely, the Kullback-Leibler divergence between $p_{\theta}(y|x)$ and $p_{\theta +{\varepsilon}v}(y|x)$ can be written as $\frac{{\varepsilon}^2}{2}\, \mathcal{F}_\theta(x)$$+$$\mathcal{O}({\varepsilon}^3)$ [@Kullback1997]. After the parameter $\theta$ is learned, this divergence will be large for $x$ that are informative, that is *different from those used to infer the learned value of $\theta$*. To use we have to fix a suitable direction $v$. A natural choice, which we will use throughout this article, is the negative gradient of the entropy $$\begin{aligned}
\label{eq:v}
v = -  \partial_\theta {\mathcal{H}}_\theta(x) \,,\end{aligned}$$ where ${\mathcal{H}}_\theta(x)$ is as in . The motivation behind a choice like is as follows: Once trained the network will produce for an input the highest probability for one class $\hat{y}$, its “prediction”, and lower probabilities for all other classes $y \neq \hat{y}$. The vector $v$ then denotes the direction in parameter space that decreases the entropy, in other words that tends to increase the probability for $\hat{y}$ further and to decrease all other probabilities.

If the input is unusual and leads to a wrong classification $\hat{y}$, then a step in the direction of $v$ will increase the information substantially, as the used $x$ will usually be completely different from the training data that were used for inferring $\theta$. For another choice of $v$ compare [@Martin2020].

Taking the expression $\mathcal{F}_\theta(x)$ has the useful consequence that we can rewrite the quadratic form in as $
    \mathcal{F}_\theta(x) {=} \sum_{y=1}^C \! D_v p_\theta(y|x)\, D_v\! \log p_\theta(y|x)
$, where $D_v f(\theta)=v^T \nabla_\theta f(\theta)$ denotes the directional derivative w.r.t $\theta$ in direction of $v$, which can be computed either directly or using a finite difference approximation that avoids the need for backpropagation [@Martin2020].

Before analyzing how the quantity performs in practice, there is one final point that needs some consideration. While quantities such as the Fisher form or the entropy can each be compared for two different datapoints there is no direct possibility for a comparison between the value of the entropy and the Fisher information for the same datapoint. Moreover, requiring someone applying these quantities to get an intuition first before they can judge whether a quantity is “high enough” to rise suspicion is rather unsatisfactory.

When faced with a binary decision problem, such as “will produce unexpected behavior or not”, we can use the *receiver operator characteristic* (ROC) and the associated *area under the ROC curve* (AUC) to compare different metrics, cf., for example [@Martin2020]. However, a comparison based on the ROC/AUC still has the drawback that it is not applicable for *single datapoints* and, moreover, that not all problems can be seen as a binary decision. We here describe a rather easy, yet efficient approach that solves these issues. Let us introduce the following *normalization* for a quantity $q(x)$ and a test set $T$ $$\begin{aligned}
    \label{eq:normalization}
    \langle q(x) \rangle = \frac{\#\{x'\mbox{ in $T$ s.t. } q(x') < q(x)\}}{\#\{x'\mbox{ in $T$}\}},\end{aligned}$$ where $\#$ counts the number of elements. In other words $\langle q(x) \rangle$ denotes fraction of test samples $x'$ in $T$ for which $q(x') < q(x)$. By construction, $\langle q(x) \rangle$ depends on the input $x$ and on the test set $T$ that is used. This normalization has a few nice properties: It is

-   *bounded*, as it lies always between 0 and 1,

-   *monotone*: from $q(x_1) < q(x_2)$ it follows $\langle q(x_1) \rangle < \langle q(x_2) \rangle$,

-   *invariant* under strictly monotone transformations such as taking a logarithm or scaling.

[0.49]{}

![image](mnist_interpolation.pdf){width="\textwidth"}

\

![image](mnist_x0){width="\textwidth"}

 

![image](mnist_xh1){width="\textwidth"}

 

![image](mnist_xh){width="\textwidth"}

![image](mnist_xh2){width="\textwidth"}

![image](mnist_x1){width="\textwidth"}

\[fig:mnist\_interpolation\]

[0.49]{}

![image](symmetric_noise){width="\textwidth"}

\

![image]({intel_noise_scale_0.00}.pdf){width="\textwidth"}

 

![image]({intel_noise_scale_0.10}.pdf){width="\textwidth"}

 

![image]({intel_noise_scale_0.20}.pdf){width="\textwidth"}

![image]({intel_noise_scale_0.30}.pdf){width="\textwidth"}

![image]({intel_noise_scale_0.40}.pdf){width="\textwidth"}

\[fig:intel\_noise\]

This normalization allows us to compare different measures of reliability/ uncertainty, since relations such as $ \langle \mathcal{F}_\theta(x) \rangle =75\% \mbox{ and } \langle {\mathcal{H}}_\theta(x)\rangle=75\% $ have a similar meaning: $75\%$ of the test samples have a smaller value than the one for $x$. If we see the magnitude of a quantity such as $\mathcal{F}_\theta(x)$ as an indicator for the “unusualness” of a datapoint $x$, then a value of $\langle \mathcal{F}_\theta(x)\rangle$ close to 100% can be seen as a strong indication that the reliability for a prediction based on $x$ will be quite questionable. In particular a relation such as $ \langle \mathcal{F}_\theta(x) \rangle > \langle \mathcal{H}_\theta(x) \rangle $ for an $x$ that causes a wrong prediction will indicate that $\mathcal{F}_\theta(x)$ detected the underlying uncertainty more clearly than $\mathcal{H}_\theta(x)$ (based on the test set), so that a normalization via $\langle\ldots \rangle$ make measures of reliability directly comparable.

Figure \[fig:intel\_monochrome\_hist\] shows the distribution of $\langle 1-p_\theta(\hat{y}|x) \rangle$ (left), the normalized version of , the normalized entropy $\langle \mathcal{H}_\theta(x) \rangle$ (middle) and Fisher form $\langle\mathcal{F}_\theta(x) \rangle$ (right) for the same neural network as in Figure \[fig:intro\_monochrome\] for the original images (in green) and those with inverted green color channel (in magenta). The test set for the normalization was chosen equal to the test set from [@IntelImageClassification]. Note that only the Fisher information has a distinct peak at high values for the modified images.

Experiments {#sec:experiments}
===========

In this section we discuss the behavior of the Fisher form $\mathcal{F}_\theta$, the entropy $\mathcal{H}_\theta$, the entropy $\mathcal{H}_\theta^{\mathrm{DE}}$ for the mixture distribution predicted by a deep ensemble [@Lakshminarayanan2017] and the entropy $\mathcal{H}_\theta^{\mathrm{GD}/\mathrm{BD}}$ of an approximate to the posterior predictive. More precisely, $\mathcal{H}_\theta^{\mathrm{DE}}$ refers to the average of entropies produced by each member of the ensemble, and $\mathcal{H}_\theta^{\mathrm{GD}/\mathrm{BD}}$ to the mean of entropies obtained by repeated predictions of the trained net using dropout. All deep ensembles were constructed using 5 networks, trained independently of each other. To approximate the posterior predictive we used Gaussian dropout [@Kingma2015] for MNIST and Bernoulli dropout [@Gal2016] (with rate 0.5) for all other examples, as the latter seemed to converge substantially faster. The entropy for the distribution produced by the Gaussian dropout will be denoted by $\mathcal{H}_\theta^{\mathrm{GD}}$ and we will write $\mathcal{H}_\theta^{\mathrm{BD}}$ for Bernoulli dropout. The architecture of all used networks is sketched in the Appendix of this article.

In Section \[subsec:modified\_data\] we will analyze the behavior of $\mathcal{F}_\theta, \mathcal{H}_\theta, \mathcal{H}_\theta^{\mathrm{DE}}$ and $\mathcal{H}_\theta^{\mathrm{GD}/\mathrm{BD}}$ on datapoints that are modified, either by adding noise or by a transformation based on a variational autoencoder. Section \[subsec:incomplete\_training\_data\] studies the effect of missing certain features while training.

Modified data {#subsec:modified_data}
-------------

As a first example we will consider the MNIST dataset [@LeCun2010] for digit recognition. We trained a convolutional neural network (Fig. \[fig:mnist\_net\]) for 25 epochs until it reached an accuracy of around $99\%$ on both, the test and training set. Finally we trained a *variational autoencoder* (VAE) [@Kingma2013], sketched in Figure \[fig:mnist\_vae\], for 100 epochs until it reached a mean squared error accuracy of around 1% of the pixel range. Using a VAE is a popular form for interpolating between datapoints [@Berthelot2018; @Smith2018]. To this end, we split the VAE into an encoder $E$ and a decoder $D$. For single input images $\tilde{x}_0$ and $\tilde{x}_1$ we then take $ z_0 = E(\tilde{x}_0)$, $z_1 = E(\tilde{x}_1 ) $ and set for $\lambda$ between 0 and 1: $$\begin{aligned}
    \label{eq:x_lambda_mnist}
    x_\lambda = D(z_0 + \lambda (z_1 - z_0))\,.\end{aligned}$$ Figure \[fig:mnist\_interpolation\] shows the interpolation between an image showing a 4 and an image showing a 9 for different values of $\lambda$. The curves above the reconstructed images show the dependency of $\langle \mathcal{H}_\theta(x_\lambda) \rangle$ (in black), $\langle \mathcal{F}_\theta(x_\lambda) \rangle$ (in magenta), the Gaussian dropout entropy $\langle \mathcal{H}_\theta^{\mathrm{GD}}(x_\lambda) \rangle$ (in blue) and the deep ensemble entropy $\langle \mathcal{H}_\theta^{\mathrm{DE}}(x_\lambda) \rangle$ (in cyan) on $\lambda$. We used the MNIST test set as the set $T$ for normalization. All methods show a similar behavior with a distinct peak in the transition phase.

![The ROC for detecting whether an image from the Intel Image Classification dataset was modified by inverting its green color channel (as in the middle of Figure \[fig:intro\_monochrome\]) via the entropies $\mathcal{H}_\theta(x)$, $\mathcal{H}_\theta^{\mathrm{BD}}(x)$, $\mathcal{H}_\theta^{\mathrm{DE}}(x)$ (in black, blue and cyan) and the Fisher form $\mathcal{F}_\theta(x)$ (in purple)[]{data-label="fig:intel_roc"}](intel_roc){width="48.00000%"}

As a next dataset we will consider the *Intel Image Classification* dataset [@IntelImageClassification] that contains images of 6 different classes (street, building, forest, mountain, glacier, sea). We touched this example already in the introduction of this article. We trained a convolutional neural network (Fig. \[fig:credit\_net\]) on this dataset for 15 epochs until it reached an accuracy of around $80\%$ on the test set of [@IntelImageClassification], which we also used for normalization. We here want to consider the effect of two modifications on the datapoints. The effect of inverting the green color channel was already shown in Figure \[fig:intro\_monochrome\] and Figure \[fig:intel\_monochrome\_hist\]. This modification lets the accuracy of the network drop from around 80% to 30%. Figure \[fig:intel\_roc\] shows the ROC for $ \mathcal{H}_\theta $ $\mathcal{F}_\theta$, $\mathcal{H}_\theta^{\mathrm{DE}}$ and $\mathcal{H}_\theta^{\mathrm{BD}}$ (now with Bernoulli dropout) for detecting such modified images, where we used once more the test set as reference. Note that a normalization as in is not needed as the ROC is invariant under monotone transformations. The AUC for $\mathcal{H}_\theta$ and $\mathcal{H}_\theta^{\mathrm{BD}}$ are 0.63 and 0.72, while $\mathcal{H}_\theta^{\mathrm{DE}}$ and $\mathcal{F}_\theta$ both share an AUC of $0.76$.

Next, we consider the effect of noise. The upper plot in Figure \[fig:intel\_noise\] shows the evolution of $\langle \mathcal{H}_\theta(x_\lambda) \rangle $, $\langle \mathcal{H}_\theta^{\mathrm{BD}}(x_\lambda) \rangle $, $\langle \mathcal{H}_\theta^{\mathrm{DE}}(x_\lambda) \rangle $ and $\langle \mathcal{F}_\theta (x_\lambda) \rangle$ where $x_\lambda$ is now given as $$\begin{aligned}
    \label{eq:x_lambda_intel}
    x_\lambda = x + \lambda \cdot {\varepsilon}\,,\end{aligned}$$ with $x$ being a single image from the Intel Image Classification dataset that shows a street and with ${\varepsilon}$ being an array of standard normal noise of the same shape as $x$. The lower row of Figure \[fig:intel\_noise\] displays $x_\lambda$ for various $\lambda$.

The crosses in the upper plot in Figure \[fig:intel\_noise\] depict if the network classifies the image correctly as a street (in green) or whether it chooses the wrong class (in red). We observe that while all quantities $\langle \mathcal{H}_\theta(x_\lambda)\rangle$, $\langle \mathcal{F}_\theta (x_\lambda) \rangle$, $\langle\mathcal{H}_\theta^{\mathrm{DE}}(x_\lambda)\rangle$ and $\langle\mathcal{H}_\theta^{\mathrm{BD}}(x_\lambda)\rangle$ share a similar trend, the Fisher form, is well above all other quantities in the transition phase where the noise starts flipping the classification. Inspecting the maximal Softmax output $p(\hat{y}|x_\lambda)$ shows that beyond $\lambda =0.3$ this probability is almost identical to 1, which finally pushes all quantities down towards 0.

Incomplete training data {#subsec:incomplete_training_data}
------------------------

[0.45]{} ![image](creditcard_data){width="\textwidth"}

\[fig:creditcard\_data\]

 

[0.45]{} ![image](creditcard_roc_compare_border_True.pdf){width="\textwidth"}

\[fig:creditcard\_roc\_1\]

While in Section \[subsec:modified\_data\] we looked at the behavior of $\mathcal{F}_\theta$, $\mathcal{H}_\theta$, $\mathcal{H}_\theta^{\mathrm{DE}}$ and $\mathcal{H}_\theta^{\mathrm{GD/DE}}$ for modified data, we will now analyze another scenario. What happens if the data we used in training was *incomplete*, in the sense that it lacked one or several important features that will occur in its application after training [@Amodei2016; @Doshi2017; @Snoek2019]?

As a first example we use the *Credit Card Fraud Detection* dataset [@CreditCardFraudDetection; @Dal2014]. This, extremely unbalanced, dataset contains 284,807 transactions with 492 frauds which are indicated by a binary label. The data were anonymized using a principal component analysis. The distribution of the main component, dubbed ‘V1‘, is shown in Figure \[fig:creditcard\_data\]. We split the data in two halfs. A training set, where V1 is below a threshold of -3.0 (in green), and a test set where V1 is bigger than the threshold (in red). On the green part we trained, balancing the classes, a small fully connected neural network (Fig. \[fig:credit\_net\]) for 20 epochs until it reached an accuracy of $95\%$ on a smaller subset of the “train” set that was excluded from the training process. On the “test” set from Figure \[fig:creditcard\_data\] the accuracy is with $79\%$ markedly lower.

[0.32]{} ![image](dog.pdf){width="\textwidth"}

\[fig:dog\]

 

[0.32]{} ![image](dogcats_enc){width="\textwidth"}

\[fig:En\]

 

[0.32]{} ![image](changed_dog.pdf){width="\textwidth"}

\[fig:changed\_dog\]

Figure \[fig:creditcard\_roc\_1\] shows the ROC for the detection whether a datapoint $x$ is from the red part of Figure \[fig:creditcard\_data\] based on $\mathcal{H}_\theta(x)$, $\mathcal{F}_\theta(x)$, $\mathcal{H}_\theta^{\mathrm{DE}}(x)$ and $\mathcal{H}_\theta^{\mathrm{BD}}(x)$. The AUC for $\mathcal{F}_\theta$ and $\mathcal{H}_\theta^{\mathrm{DE}}$ is around 0.70, while $\mathcal{H}_\theta$ and $\mathcal{H}_\theta^{\mathrm{BD}}$ arrive both at $0.63$.

We will now consider a problem where the splitting is more subtle and, maybe, more realistic. For this purpose we will use the *DogsVsCats* dataset from [@DogsVsCats]. We trained a variational autoencoder (Fig. \[fig:dog\_vae\]) [@Kingma2013] on the combined collection of dog images from [@DogsVsCats; @CatandDog] for 30 epochs until it reached a mean squared error accuracy of around 2% of the pixel range. A reconstructed image can be seen in Figure \[fig:dog\]. We then selected the bottleneck node, called $\mathrm{En}$ from now on, that exhibits the largest variance when evaluated on these dog images. Figure \[fig:En\] shows the distribution of $\mathrm{En}$ for dog images from [@DogsVsCats] together with $\mathrm{median}(\mathrm{En}) = 0.3$. What is the meaning of $\mathrm{En}$? Figure \[fig:changed\_dog\] shows the same reconstructed image as in \[fig:dog\] but with flipped sign of $\mathrm{En}$.

We can see that the background of the depicted image becomes darker. Looking at various datapoints from the dataset hardens this impression so that we will see this as the “meaning” of $\mathrm{En}$, although there is, probably, no one-to-one correspondence with a human interpretation. We trained a convolutional neural network (Fig. \[fig:dog\_net\]) on the data from [@DogsVsCats], but by omitting those dog images with $$\begin{aligned}
    \label{eq:dog_unusual}
\mathrm{En} < \mathrm{median}(\mathrm{En}) = 0.3 \,,\end{aligned}$$ i.e. those on the left side of the median in Figure \[fig:En\] or, with the interpretation above, those images with dark background. We trained this network for 20 epochs until it reached an accuracy of around $80\%$ on a subset of the images with $\mathrm{En} \geq \mathrm{median}(\mathrm{En})$ that we ignored while training. Evaluating now the network on dog images from [@DogsVsCats; @CatandDog] with $\mathrm{En} < \mathrm{median}(\mathrm{En})$ lets the accuracy drop to 1%! In other words almost all dogs images with $\mathrm{En}<0.3$ are classified as cats.

![** :** Evolution the AUC for detecting whether a dog image from the DogsVsCats datset [@DogsVsCats] is “unusual” in the sense of while training on datapoints where is wrong. As metrics for detecting we use the entropies $\mathcal{H}_\theta(x)$, $\mathcal{H}_\theta^{\mathrm{BD}}(x)$, $\mathcal{H}_\theta^{\mathrm{DE}}(x)$ (in black, blue and cyan) and the Fisher form $\mathcal{F}_\theta(x)$ (in purple). The dashed gray line shows the accuracy of the trained network.](dogs_auc_evolution){width="48.00000%"}

\[fig:auc\_evolution\]

Our task is now to detect whether an input is *unusual* in the sense that holds. Figure \[fig:auc\_evolution\] depicts the evolution of the AUC for the quantities $\mathcal{F}_\theta$, $\mathcal{H}_\theta$, $\mathcal{H}_\theta^{\mathrm{DE}}$ and $\mathcal{H}_\theta^{\mathrm{BD}}$ for each epoch and the accuracy of the trained network (in dashed gray). The difference between the Fisher form $\mathcal{F}_\theta$ and all other forms is striking. The quantities based on entropy seem to completely fail in detecting the “unusualness” of images with $\mathrm{En}<0.3$. In fact they yield AUCs below 0.5, thereby marking the actual training images as more suspicious than the modified images on which the classification actually fails. The Fisher form $\mathcal{F}_\theta$ however is yielding a value well above 0.5 for a wide range of the training. After around 15 epochs the AUC for the Fisher form starts to drop down as well.

[0.45]{} ![image](DeepEnsemble_VAE_coloracc.pdf){width="\textwidth"}

[0.45]{} ![image](Fisher_VAE_coloracc){width="\textwidth"}

\[fig:dogs\_cacc\]

As this coincides roughly with the point where the accuracy starts stabilizing we suspect that this is a similar effect as we observed in Figure \[fig:intel\_noise\]: Once the maximal probability of the softmax output becomes almost identical to one, this forces the Fisher information to decrease. In fact it turns out that after 20 epochs the maximal probabilities on the unusual data are in average around $99\%$. Compare this to the tiny accuracy of $1\%$! We will focus now on a point before this, apparently unreasonable, saturation happened, namely on the trained state after 8 epochs, marked by a gray cross.

The normalization from , for which we here used the training data, allows us to compare the behavior of $\mathcal{H}_\theta(x)$, $\mathcal{H}^{\mathrm{DE}}_\theta(x)$, $\mathcal{H}_\theta^{\mathrm{BD}}(x)$ and $\mathcal{F}_\theta(x)$ for single datapoints $x$. As all entropies show a quite a similar behavior for this example, we will only compare $\mathcal{H}_\theta^{\mathrm{DE}}$ and $\mathcal{F}_\theta$. We drew 1200 images all showing dogs and depicted the value of $\mathrm{En}$ versus $\langle\mathcal{H}_\theta^{\mathrm{DE}}(x)\rangle$ and $\langle\mathcal{F}_\theta(x)\rangle$ in Figure \[fig:dogs\_cacc\]. Wrong classifications as cats are marked in red. The median $0.3$ of $\mathrm{En}$ is drawn as a blue dashed line, so that the “unusual datapoints” are below this line. The marginal distributions of the detection quantities and of $\mathrm{En}$ are shown, split according to classified correctly (in black) and wrongly (in red).

Note first, that indeed most of the images satisfying are classified wrong, so that the network is in fact not suitable for classifying these datapoints. Moreover, the deep ensemble entropy is not able to capture that there is something off with these data. Even worse, the corresponding points are cumulated in the lower left corner which should actually indicate a high confidence in the prediction for these points. The Fisher information on the other hand leads to a cumulation in the lower right corner and thus correctly detects many of the “unusual” datapoints. In fact, even for “normal” datapoints we observe that most of those that were classified wrong have an encoder value $\mathrm{En}$ close to $0.3$ and possess again a high $\mathcal{F}_\theta$.

Conclusion and outlook
======================

We studied the *Fisher form* to detect whether an input is unusual, in the sense that it differs from the data that were used to infer the learned parameters. Spotting such a disparity is important, as it can substantially decrease the reliability. Several examples for this have been presented in Section \[sec:experiments\]. We observed that the Fisher form performs equally or even better than competing methods in detecting unusual inputs. In particular, we introduced a normalization that allows to directly compare these metrics for single datapoints.

The last example treated in this article showed an effect, which could be a starting point for future research. As we observed in Figure \[fig:auc\_evolution\] the ability to detect unusual data might erode for a too long training. When only looking at the accuracy for an incomplete test set, as we did in Figure \[fig:auc\_evolution\], such a process might happen unnoticed. This somehow different flavor of overfitting could be worth studying.

Another point that would deserve a more detailed investigation is of a more conceptual nature. For each of the examples treated in this work we used a single network to evaluate its Fisher form. One might wonder whether the effect we observed when considering unusual data will differ for another network whose training was carried out with, say, different initial conditions. As neural networks are bound to end up in local minima it is not obvious whether a datapoint will be unusual for two of these networks, even if they are trained on the same training set. However, this is not what we observed. In fact, the behavior of the Fisher form seems rather robust in this regard. It is hard to say, whether this indicates that neural networks tend to learn similar patterns when presented with the same data. Looking at the quadratic form for more than only one direction $v$ could help to shed a bit of light on this question.

Appendix {#appendix .unnumbered}
========

[0.38]{} ![** :** Architecture for the variational autoencoder we train on the MNIST dataset and use in Section \[subsec:modified\_data\]. Note that the bottleneck is random: From the 10“means” and 10 “variances” in the bottleneck we construct 10 Gaussian distributions from which we draw 10 random numbers that are than feeded through the decoder.](mnist_net "fig:"){width="\textwidth"}

\[fig:mnist\_net\]

 

[0.38]{} ![** :** Architecture for the variational autoencoder we train on the MNIST dataset and use in Section \[subsec:modified\_data\]. Note that the bottleneck is random: From the 10“means” and 10 “variances” in the bottleneck we construct 10 Gaussian distributions from which we draw 10 random numbers that are than feeded through the decoder.](mnist_vae "fig:"){width="\textwidth"}

\[fig:mnist\_vae\]

[0.38]{} ![** :** Architecture for the fully connected neural network trained on the Credit Card Fraud Detection dataset that we use in Section \[subsec:incomplete\_training\_data\].](intel_net "fig:"){width="\textwidth"}

\[fig:intel\_net\]

 

[0.38]{} ![** :** Architecture for the fully connected neural network trained on the Credit Card Fraud Detection dataset that we use in Section \[subsec:incomplete\_training\_data\].](credit_net "fig:"){width="\textwidth"}

\[fig:credit\_net\]

[0.38]{} ![** :** Architecture for the variational autoencoder we train on the dog images from [@DogsVsCats; @CatandDog] and use in Section \[subsec:incomplete\_training\_data\]. Note that the bottleneck is random: From the 500“means” and 500 “variances” in the bottleneck we construct 500 Gaussian distributions from which we draw 500 random numbers that are than feeded through the decoder.](dog_net "fig:"){width="\textwidth"}

\[fig:dog\_net\]

 

[0.38]{} ![** :** Architecture for the variational autoencoder we train on the dog images from [@DogsVsCats; @CatandDog] and use in Section \[subsec:incomplete\_training\_data\]. Note that the bottleneck is random: From the 500“means” and 500 “variances” in the bottleneck we construct 500 Gaussian distributions from which we draw 500 random numbers that are than feeded through the decoder.](dog_vae "fig:"){width="\textwidth"}

\[fig:dog\_vae\]
