Uncertainty Quantification in Deep Neural Networks through Statistical
  Inference on Latent Space
Uncertainty-quantification methods are applied to estimate the confidence of
deep-neural-networks classifiers over their predictions. However, most widely
used methods are known to be overconfident. We address this problem by
developing an algorithm that exploits the latent-space representation of data
points fed into the network, to assess the accuracy of their prediction. Using
the latent-space representation generated by the fraction of training set that
the network classifies correctly, we build a statistical model that is able to
capture the likelihood of a given prediction. We show on a synthetic dataset
that commonly used methods are mostly overconfident. Overconfidence occurs also
for predictions made on data points that are outside the distribution that
generated the training data. In contrast, our method can detect such
out-of-distribution data points as inaccurately predicted, thus aiding in the
automatic detection of outliers.
Luigi Sbailò, Luca M. Ghiringhelli
# Uncertainty Quantification in Deep Neural Networks through Statistical Inference on Latent Space

###### Abstract

Uncertainty-quantification methods are applied to estimate the confidence of deep-neural-networks classifiers over their predictions. However, most widely used methods are known to be overconfident. We address this problem by developing an algorithm that exploits the latent-space representation of data points fed into the network, to assess the accuracy of their prediction. Using the latent-space representation generated by the fraction of training set that the network classifies correctly, we build a statistical model that is able to capture the likelihood of a given prediction. We show on a synthetic dataset that commonly used methods are mostly overconfident. Overconfidence occurs also for predictions made on data points that are outside the distribution that generated the training data. In contrast, our method can detect such out-of-distribution data points as inaccurately predicted, thus aiding in the automatic detection of outliers.

## 1 Introduction

For the practical, widespread use of artificial-intelligence (AI) predictive models, especially where predictions would impact individuals and societies, the understanding of the limits of applicability of such models is of fundamental importance. An ideal AI model should be able to always provide an accurate prediction in "familiar situations", while, in "less familiar situations", it should be able to at least signal that its prediction might be inaccurate. The challenge is to detect such "(less) familiar situations", by using only the trained model, and therefore the training data, and the (unlabelled) test data points. This challenge is generically referred to as "uncertainty quantification" (UQ)[1].

Uncertainty quantification is important in applications where the consequences of incorrect predictions are severe, such as in medical imaging for diagnosing diseases [2; 3; 4; 5], in autonomous-vehicles driving, where incorrect predictions can lead to accidents [6; 7; 8; 9]. UQ is also important in scientific applications, such as physics data analysis, where neural networks with reliable estimates of prediction uncertainty and robustness are needed [10]. Finally, UQ is of fundamental importance in scientific and technological practice, where experiment design is performed[11]. Therein, active-learning techniques [12] are necessarily based on reliable UQ.

Two types of uncertainties related to the data can be identified [1], one is related to the data that are available, one with the data that are not (yet) available, i.e., it is a knowledge uncertainty. The former is named aleatoric or irreducible uncertainty and is caused by intrinsic noise in the measurements of
the data (both the descriptor and the target quantity) as well as the incompleteness of the descriptor (so that different data points are mapped into the same input description, with different target values). The latter is named epistemic uncertainty and is caused by lack of knowledge on a portion of data. In this context, quantifying the epistemic uncertainty would be related to identifying (test) data points that are different from the training data, i.e., they belong to input domains that are distant or even disjoint from the input domain(s) of the training data.

In this paper, we focus on the estimate of the epistemic uncertainty, in particular for deep-neural-network classifiers model class. Specifically, we address the challenge of identifying data points that are "out of distribution". Out-of-distribution data points could be outliers or novelties/discoveries. Outliers include wrongly collected or labeled data points, typically to be discarded, while novelties/discoveries are data points in which the trained model is still applicable but belong to input domains that are distant/disjoint from the input domain(s) of the training data. In either case, the prediction of the model would require a comparison with the ground truth (assuming it is feasible) in order to decide how to proceed. The actual protocol would be related to the chosen active-learning [13; 14] strategy, but as a first, necessary step, we need to reliably estimate if a test point is out of distribution.

We propose a novel approach based on the analysis of the latent-space representation, which does not require a fine tuning and which we show to be both more reliable and cost-effective than the methods known to us.

### Related work

Two broad classes of (epistemic) UQ strategies have been proposed and developed in the recent years, Bayesian techniques, including Monte Carlo (MC) based approximations (e.g., _MC-dropout_) or _ensemble_ based.

Bayesian techniques and Monte Carlo dropoutIn an ideal Bayesian neural network, distributions of the training weights are learned, rather than specific values [15]. This allows for a direct estimate of the prediction uncertainty. However, in practical application, the Bayesian architecture needs to be approximated, as it is often difficult, if possible at all to compute the exact posterior distribution. A popular approximation is the _MC-dropout_ technique, where in production the network is run several times and a fraction of nodes are randomly switched off. This yields a distribution of prediction from which the average and standard deviation are used as actual prediction and uncertainty estimate, respectively. It is unclear if the output distribution is always a good approximation of the posterior distribution and, in addition, results are sensitive to the dropout ratio.

Ensemble techniques_ensemble_ techniques in general require the training of several instances of a neural network, by varying the network architecture and/or the initial seeds for the training [16; 17]. However, _ensemble_ techniques for UQ do not necessarily yield a Bayesian uncertainty estimate. In fact, _ensemble_ techniques, also beyond the neural-network model class (e.g. random forests), are more robust when the "true model" is not part of the ensemble, which is at odds with a Bayesian estimate [1]. So, in general, it is not evident why and when an ensemble of NNs can generate good uncertainty estimates. _Ensemble_ techniques require training and then running of several models for prediction, which is computationally costly.

## 2 Method

In the context of a data set \(\left\{X_{i}^{(0)},y_{i}\right\}_{i=1}^{N}\), where \(X_{i}^{(0)}\in\mathbb{R}^{D}\) is a \(D\)-dimensional input vector and \(y_{i}\in\{1,\ldots K\}\) is a class label, a deep neural network can be trained to predict the label \(y_{i}\) from the input \(X_{i}^{(0)}\). A feed-forward deep neural network is composed of \(L\) consecutive layers, where each layer takes the output of the previous layer as input. The \(l\)-th layer, where \(l\in 1\ldots L\), takes an input vector \(X_{i}^{(l-1)}\) and returns an output vector \(X_{i}^{(l)}\) defined as:

\[X_{i}^{(l)}=\sigma\left(\sum_{i=1}^{h_{L}}W_{l}X_{i}^{(l-1)}+B_{l}\right), \tag{1}\]
where \(W_{l}\) and \(b_{l}\) are respectively the weights matrix and bias vector learned during training, and \(\sigma(\cdot)\) is a non-linear activation function. The final layer of the network returns a \(K\)-dimensional output vector \(X^{(L)}\), and the predicted category can be inferred using the softmax function, which normalizes the output vector to obtain a probability distribution over the \(K\) classes. The latent representation of an input vector is the set of \(L-1\) vectors \(\left\{X^{(l)}\right\}_{l=1}^{L-1}\) that are generated when the input vector \(X^{(0)}\) is fed into the network. In our method, we use this latent representation to assess the confidence of the network's prediction \(f(X^{(0)})\).

The latent representations for a training set \(\left\{X^{(0)}\right\}\) are obtained by forwarding the entire set through the network, which results in a set of latent representations \(\left\{X^{(l)}_{i}\right\}_{l=1}^{L-1}\) for each input vector \(X^{(0)}_{i}\). These latent representations are then grouped into \(K\) subsets \(\left\{X^{(l,k)}_{i}\right\}\) based on the network's predicted label \(k\). In each subset, we prune all vectors \(X_{j}\) whose predicted label \(f(X^{(0)}_{j})\) does not match the true label \(y_{j}\). This results in the creation of latent confidence sets \(\left\{X^{(l,k)*}\right\}\), which contain the latent representations of only those vectors in the training set that the network classifies accurately. We then use these latent confidence sets to build a statistical model that can be used to estimate the likelihood of a certain prediction. The underlying assumption is that the latent representation of a well-classified input vector will be similar to the latent representations in the corresponding latent confidence set, whereas the latent representation of a misclassified input vector will be dissimilar. In essence, this approach allows us to obtain a measure of confidence for the network's predictions by leveraging the information contained in the latent representations of accurately classified training set vectors.

Every hidden layer \(l\) and each class \(k\) within the latent confidence set \(\left\{X^{(l,k)*}\right\}\) generates an independent statistical model. For our purposes, we opt for a multivariate Gaussian distribution as the prior distribution due to its numerous advantages. Specifically, it is computationally efficient, scalable in high dimensions, and exhibits fast exponential decay. These properties make it an ideal choice for accurately detecting out-of-distribution points. To build the multivariate normal distribution from the latent confidence set \(\left\{X^{(l,k)*}\right\}\), we compute the mean vector \(\mu^{(l,k)*}\) and covariance matrix \(\Sigma^{(l,k)*}\). The distribution is given by:

\begin{table}
\begin{tabular}{l} \hline \hline
**Preparation:** \\ - Collect input data set \(\left\{X^{(0)}_{i},y_{i}\right\}_{i=1}^{N}\); \\ - Train a feed-forward neural network to predict \(f(X^{(0)}_{i})=y_{i}\); \\ - Create training subsets \(\left\{X^{(0,k)}\right\}\) based on network prediction \(k\); \\ - Prune all misclassified data to create confidence sets \(\left\{X^{(0,k)*}\right\}\); \\ - Collect all latent representations in confidence sets \(\left\{X^{(l,k)*}\right\}\); \\ - Compute the mean vector \(\mu^{l,k}\) and covariance matrix \(\Sigma^{l,k}\) \\ - Calculate the log-probability of all confidence sets based on Eq. 2. \\ - Select the \(\alpha\) and \(\beta\) confidence values; \\ - Find the \(q^{(l,k)}_{\alpha}\) and \(q^{(l,k)}_{\beta}\) percentiles; \\ - Select acceptance value \(a\). \\
**Evaluation:** \\ - Given an input point \(X_{i}\) \\ - Predict label \(f(X_{i})=k\) and store latent representation \(\left\{X^{(l,k)}_{i}\right\}\); \\ - For each \(l\) compute likelihood with Eq. 3; \\ - Compute confidence with Eq. 4; \\ - If likelihood \textless{}\(a\) : reject prediction; if likelihood\textgreater{}\(a\) accept prediction. \\ \hline \hline \end{tabular}
\end{table}
Table 1: Algorithm of the _inference_ method.
\[p(X_{i}^{(l,k)})=\frac{1}{\sqrt{(2\pi)^{2}\det\Sigma^{(l,k)*}}}\exp\left(-\frac{1} {2}(X_{i}^{(l,k)}-\mu^{(l,k)*})^{T}\Sigma^{(l,k)*}(X_{i}^{(l,k)}-\mu^{(l,k)*}) \right). \tag{2}\]

To assess the confidence of a prediction using a probabilistic model, we aim for high probabilities for data points where we know the model makes correct predictions and low probabilities for those with lower likelihood. In practice, we normalize the probability distribution in Eq. 2 so that it approaches one for data points with similar likelihoods to those in the latent confidence set, and approaches zero for those with much lower likelihoods. To achieve this, we construct a histogram of the log-probabilities \(\left\{\log p\left(X^{(l,k)*}\right)\right\}\) of the confidence sets and use it to identify the \(\alpha\)-th percentile \(q_{\alpha}^{l,k}\) and the \(\beta\)-th percentile \(q_{\beta}^{l,k}\). Log-probabilities below or equal to \(q_{\alpha}^{l,k}\) are assigned a confidence value of zero, while those above or equal to \(q_{\beta}^{l,k}\) are assigned a confidence value of one. Log-probabilities within the \(q_{\alpha}^{l,k}-q_{\beta}^{l,k}\) interval are assigned a confidence value using the following smoothstep function

\[s(X_{i})=\frac{1}{2}\left(\tanh\left(\frac{X_{i,q}-1}{2\sqrt{X_{i,q}(1-X_{i,q} )}}\right)+1\right), \tag{3}\]

where \(X_{i,q}=\frac{X_{i}-q_{\alpha}^{l,k}}{q_{\beta}^{l,k}-q_{\alpha}^{l,k}}\). We notice that the function in Eq. 3 smoothly maps all values in the range \([q_{\alpha}^{l,k},q_{\beta}^{l,k}]\) to the interval \([0,1]\). To sum up, the latent confidence set \(\left\{X^{l,k}\right\}^{*}\) is used to build the probability distribution in Eq. 2, which in turn is used to rank in a histogram the vectors of the latent confidence set according to their probability. The \(\alpha\)-th percentile \(q_{\alpha}^{l,k}\) and the \(\beta\)-th percentile \(q_{\beta}^{l,k}\) of the histogram are used in Eq. 3 to give the confidence of the network prediction.

When training a deep neural network with \(L\) hidden layers on a dataset with \(K\) different class labels, the network generates \(K*L\) probability distributions and smoothstep functions, as in Eq. 2 and Eq. 3. To evaluate the confidence of the network's prediction for a given input vector \(X_{i}\) and predicted class label \(k_{i}\), we calculate the confidence value for each hidden layer, using the activation function corresponding to the predicted class label. Specifically, we compute \(L\) confidence values \(s^{0,l}(X_{i}^{0,k}),\ldots s^{0,l}(X_{i}^{L,k})\), where \(k=y_{i}\). Since each layer in the network has a large number of parameters and involves complex, nonlinear transformations in the latent space, we assume that the probability distribution of the latent representations of the same input vector but in different layers are statistically independent, i.e., \(p(X_{i}^{l,k},X_{i}^{m,k})=p(X_{i}^{l,k})p(X_{i}^{m,k})\). To obtain a final confidence value, we multiply the confidence values of each hidden layer, resulting in the product

\[a(X_{i}^{(0,k)})=s^{1}(X_{i}^{(1,k)})*\ldots*s^{L}(X_{i}^{(L-1,k)}). \tag{4}\]

This final confidence value represents the overall confidence of the network's prediction for the given input vector \(X_{i}^{(0,k)}\). A summary of the algorithm is provided in Table 1.

## 3 Experiments

To demonstrate the validity of our method, we conducted numerical experiments and compared its performance with state-of-the-art methods using the MNIST dataset. Specifically, we trained feedforward neural networks with varying numbers of layers to classify the images. To showcase the ability of our method to detect out-of-distribution samples, we conducted experiments where we removed all samples from the training set associated with a specific label, and then trained the network on the remaining set. This allowed us to evaluate the network's capability to identify instances that it has never encountered during training, and to determine whether it can recognize when it does not know the answer.

We utilized two distinct network architectures for our experiments. The first architecture was shallower and comprised of two layers, with each layer having 1024 nodes. The second architecture was deeper, consisting of four layers with 256 nodes each. We employed early stopping during training, which terminated the process once an accuracy threshold of 0.96 was attained. In all training we used dropout
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Method** & **Network** & **Dropout** & **TP** & **TN** & **TN-OOD** \\ \hline \hline Inference - \(q_{1}\) & \(2\cdot[1024]\) & 0.2 & \(0.929\pm 0.002\) & \(0.732\pm 0.05\) & \(0.761\pm 0.158\) \\ \hline Inference - \(q_{1}\) & \(2\cdot[1024]\) & 0.5 & \(0.933\pm 0.003\) & \(0.733\pm 0.046\) & \(0.756\pm 0.161\) \\ \hline Inference - \(q_{4}\) & \(4\cdot[256]\) & 0.1 & \(0.928\pm 0.003\) & \(0.723\pm 0.021\) & \(0.707\pm 0.144\) \\ \hline Inference - \(q_{4}\) & \(4\cdot[256]\) & 0.25 & \(0.928\pm 0.003\) & \(0.745\pm 0.017\) & \(0.732\pm 0.138\) \\ \hline \hline Inference - \(q_{2}\) & \(2\cdot[1024]\) & 0.2 & \(0.873\pm 0.002\) & \(0.855\pm 0.031\) & \(0.877\pm 0.1\) \\ \hline Inference - \(q_{2}\) & \(2\cdot[1024]\) & 0.5 & \(0.877\pm 0.004\) & \(0.866\pm 0.04\) & \(0.879\pm 0.098\) \\ \hline Inference - \(q_{5}\) & \(4\cdot[256]\) & 0.1 & \(0.87\pm 0.006\) & \(0.858\pm 0.021\) & \(0.849\pm 0.113\) \\ \hline Inference - \(q_{5}\) & \(4\cdot[256]\) & 0.25 & \(0.869\pm 0.004\) & \(0.873\pm 0.017\) & \(0.869\pm 0.103\) \\ \hline \hline Inference - \(q_{3}\) & \(2\cdot[1024]\) & 0.2 & \(0.751\pm 0.005\) & \(0.957\pm 0.014\) & \(0.97\pm 0.035\) \\ \hline Inference - \(q_{3}\) & \(2\cdot[1024]\) & 0.5 & \(0.753\pm 0.006\) & \(0.968\pm 0.014\) & \(0.973\pm 0.031\) \\ \hline Inference - \(q_{6}\) & \(4\cdot[256]\) & 0.1 & \(0.748\pm 0.081\) & \(0.957\pm 0.013\) & \(0.951\pm 0.058\) \\ \hline Inference - \(q_{6}\) & \(4\cdot[256]\) & 0.25 & \(0.747\pm 0.007\) & \(0.967\pm 0.012\) & \(0.955\pm 0.052\) \\ \hline \hline MC - dropout & \(2\cdot[1024]\) & 0.2 & \(0.98\pm 0.002\) & \(0.396\pm 0.038\) & \(0.267\pm 0.079\) \\ \hline MC - dropout & \(2\cdot[1024]\) & 0.5 & \(0.902\pm 0.013\) & \(0.819\pm 0.038\) & \(0.674\pm 0.125\) \\ \hline MC - dropout & \(4\cdot[256]\) & 0.1 & \(0.96\pm 0.004\) & \(0.564\pm 0.034\) & \(0.409\pm 0.111\) \\ \hline MC - dropout & \(4\cdot[256]\) & 0.25 & \(0.908\pm 0.006\) & \(0.742\pm 0.024\) & \(0.591\pm 0.141\) \\ \hline \hline Ensemble & \(2\cdot[1024]\) & 0.2 & \(0.952\pm 0.009\) & \(0.684\pm 0.042\) & \(0.517\pm 0.119\) \\ \hline Ensemble & \(2\cdot[1024]\) & 0.5 & \(0.969\pm 0.004\) & \(0.594\pm 0.022\) & \(0.431\pm 0.119\) \\ \hline Ensemble & \(4\cdot[256]\) & 0.1 & \(0.956\pm 0.002\) & \(0.67\pm 0.018\) & \(0.532\pm 0.134\) \\ \hline Ensemble & \(4\cdot[256]\) & 0.25 & \(0.964\pm 0.002\) & \(0.621\pm 0.03\) & \(0.484\pm 0.124\) \\ \hline \hline \end{tabular}
\end{table}
Table 2: Rate of true positives (TP), true negatives (TN) and true negatives on out-of-distribution samples (TN-OOD) detected using our _inference_ method, the _MC-dropout_ method, and the _ensemble_ method. In the _inference_ method the following percentiles \(q=(\alpha,\beta)\) were used: \(q_{1}=(0.01,1),q_{2}=(0.1,50),q_{3}=(3,90)\),\(q_{4}=(2,10),q_{5}=(3,50),q_{6}=(7,90)\) Two different network architectures were employed: one composed of 2 hidden layers with 1024 nodes each - \(2\cdot[1024]\), one composed of 4 hidden layers with 256 nodes each - \(4\cdot[256]\). Dropout was implemented in every layer of all network architectures during training, with a variable dropout rate.
with different values. To evaluate methods performance, we used a hold-out test set that excluded out-of-distribution samples and thus sampled from the same distribution as the training set, as well as a set consisting only of out-of-distribution samples. We conducted the experiment iteratively by removing each label one-by-one and evaluating the confidence of the network's predictions using our inference method, MC dropout, and _ensemble_ methods. The MC dropout method involves obtaining an ensemble of predictions by leaving dropout activated during prediction. In contrast, the _ensemble_ method involves training models with different initial conditions to obtain an ensemble of predictions. Each experiment took approximately 25 minutes for the _inference_ and _MC-dropout_ methods, and approximately 4 hours for the _ensemble_ method. All simulations were performed on a single CPU Intel(R) Core(TM) i7. To make a prediction using an _ensemble_, we take the most frequently predicted value as the network prediction. The uncertainty associated with this prediction is determined by the fraction of predictions that match the most frequently predicted value, relative to the total number of models used in the ensemble. We used 100 passes for the _MC dropout_ (with ratio equal to the one used in training) experiments and 10 models for the _ensemble_ experiments. Uncertainty in our method is calculated using the algorithm described in Table 1.

The objective of our experiments is to compare the aforementioned uncertainty quantification methods and assess the algorithms' ability to differentiate between well-classified and misclassified predictions. To achieve this, we calculate uncertainties on separate holdout test sets and reject predictions whose uncertainty falls below a certain threshold, denoted as \(a\). We then assess the method's performance by counting the number of well-classified vectors that are assigned a value above the threshold, which represents true positives (TP). Additionally, we count the number of misclassified vectors below the threshold (TN) and the number of vectors from the out-of-distribution test set below the threshold (TN-OOD). These three values serve as indicators to evaluate the quality of the method, with higher values indicating better performance. Of particular importance in our analysis is the TN-OOD value, as it helps us understand the algorithm's ability to identify samples that lie outside the distribution of the training set. For the _MC-dropout_ and _ensemble_ methods, we employ a high threshold of \(a=0.99\) due to the tendency of both these methods to exhibit overconfidence[1]. Conversely, our inference method employs the conceptually intuitive threshold of \(a=0.5\). Our method utilizes two parameters: the percentiles \(\alpha\) and \(\beta\). These parameters determine the distribution of confidence values within

Figure 1: Histograms of the confidence rate assessed on a hold out test set with the _inference_, the ’MC-dropout’ and ’ensemble’ methods. The histogram is relative to the experiment conducted with a network composed of 2 hidden layers with 1024 nodes each and dropout rate fixed to 0.5. The _inference_ method employs percentile values \(q_{2}=(0.1,50)\). We can see in the histograms that most _misclassified_ and _out-of-distribution_ samples are assigned a confidence close to zero with the _inference_ method, while the _MC-dropout_ and the _ensemble_ methods assign much higher values to the same samples. Note that, in this figure, we show the histograms relative to the experiment where the _MC-dropout_ method features the best values in detecting true negatives.
the sets of vectors. Specifically, the percentage of vectors assigned a confidence value of 1 is equal to \(100-\beta\), while the percentage of vectors assigned a value of 0 is equal to \(\alpha\). The parameters \(q=(\alpha,\beta)\) used in our experiments are: \(q_{1}=(0.01,1),\ q_{2}=(0.1,50),\ q_{3}=(3,90)\) in the network composed of 2 hidden layers with 1024 nodes each, \(q_{4}=(2,10),\ q_{5}=(3,50),\ q_{6}=(7,90)\) in the network composed of 4 hidden layers with 256 nodes each.

## 4 Discussion

The results of our experiments are summarized in Table 2. The table demonstrates that our _inference_ method successfully detects both high true positives and true negatives. By tuning the percentiles \(q=(\alpha,\beta)\), we can determine the balance between true positive and true negative detection. At the top of the table, using values \(q_{1}\) and \(q_{2}\) yields high true positives. Using values \(q_{2}\) and \(q_{5}\) provides a balance between true positives and true negatives, while values \(q_{3}\) and \(q_{6}\) below allow for high true negatives. Our method consistently produces reliable results, regardless of the dropout rate and number of hidden layers. This is achieved by tuning the percentiles while utilizing different network architectures. As previously discussed, both the _MC-dropout_ and _ensemble_ methods demonstrate overconfidence in their predictions. They exhibit high true positive detection and low true negative detection. As expected, _MC-dropout_ shows higher true negatives and lower true positives with increased dropout rates. Conversely, the _ensemble_ method seems to follow the opposite trend.

Our method demonstrates robust performance in detecting true negatives, even in the presence of out-of-distribution samples, unlike the _MC-dropout_ and _ensemble_ methods, as we can see in Fig. 1. In our experiments, the _MC-dropout_ method achieves a maximum out-of-distribution sample detection rate of only 68%. Similarly, the _ensemble_ method reaches a maximum of 53% true negative detection for out-of-distribution samples. In contrast, our _inference_ method consistently maintains a true negative out-of-distribution sample detection rate above 70%, even when percentile values are adjusted to prioritize true positive detection over true negatives. Notably, our _inference_ method achieves a true negative detection rate of over 95% while still maintaining a reasonable level of approximately 75% true positive detection. However, our _inference_ method seems to be slightly less reliable when it comes to true positive detection compared to the other methods, although the difference is minimal. Our method can still achieve over 92% true positive detection. Increasing the true positive detection rate can be achieved by tuning the percentile values, but this would come at the cost of decreasing the true negative detection rate. Since our focus is on the capability of the method to detect true negatives, we don't show higher values of true positives that would compromise this capability. Additionally, it is possible to adjust the acceptance rate threshold, currently fixed at \(a=0.5\), to further balance the detection towards true negatives or true positives. However, in these experiments, tuning the percentile values proves to be sufficient to obtain satisfactory results.

We would like to emphasize that our _inference_ method not only yields superior overall results but also offers greater ease of application compared to other methods. For instance, the _MC-dropout_ method requires the network to utilize dropout, which may adversely affect network performance in many applications. Moreover, when dropout can be employed, finding the optimal dropout rate necessitates training multiple models until a suitable rate is discovered. The ensemble method instead, while conceptually simpler to apply, demands training multiple models to assess uncertainty. This computational expense renders it unfeasible for many applications. In contrast, our _inference_ method only requires tuning the percentile values, a task that can be performed after training. This means that only one model needs to be trained, simplifying the process. Furthermore, the computational cost remains low as it scales quadratically with the number of nodes in the layers, which typically do not exceed thousands of units. In practice, the time required to construct the statistical model employed in our method is negligible compared to the time needed to train the neural network. Tuning the percentile parameters can be done after training on a test set. Since our _inference_ method demonstrates consistent results on misclassified test vectors sampled from the same distribution as the training set, as well as on out-of-distribution samples (see Table 2), parameter tuning on a test sample can effectively generalize to out-of-distribution scenarios.

## 5 Limitations and outlook

Although the _inference_ method demonstrates promising results, it is important to acknowledge its limitations. Firstly, the method assumes that the data are well approximated by a normal distribution
in the latent space. Although this assumption holds true in our experiments, it is possible that in more complex scenarios, a different prior or inference method might be more appropriate. Additionally, the assumption of statistical independence among the probability distributions across different layers in the latent space, as shown in Eq. (4), is quite strong. When dealing with numerous hidden layers, this assumption can potentially impact the quality of the results. Nevertheless, it is worth mentioning that this method can still be utilized selectively on certain layers, where the assumption of independence among probabilities holds true.

We employed a technique to measure uncertainty in classification, which involved creating a distinct statistical model for each potential label. This approach played a significant role in our analysis. It would be advantageous to extend this method to inference problems that involve predicting continuous values. In such scenarios, we cannot rely on the differentiation of data based on their labels, so an alternative strategy must be employed. One potential strategy is to utilize a statistical model based on the training set vectors, where the model's prediction is similar to the prediction we wish to assess the uncertainty for. However, the specific measure of similarity needs to be defined carefully to ensure accurate results.

## 6 Conclusions

This paper presents a novel approach for quantifying uncertainty in classification tasks using feed-forward neural networks. We conducted a comparative analysis of our method against state-of-the-art techniques on a benchmarking synthetic dataset. The results demonstrate that our method outperforms the examined state-of-the-art approaches, particularly excelling in the detection of true negatives. This advantage extends to out-of-distribution samples as well, where other methods fall short.

Although it is difficult to assess the impact of a work in a rapidly evolving field like machine learning, we believe that this work can have a positive impact in the field. Especially in contexts where the identification of out-of-distribution samples is crucial, such as autonomous driving and active learning.

## Acknowledgements

LS acknowledges for funding the Leibniz Association, project "Memristors Materials by Design, MeMabyDe". LMG acknowledges for funding the NFDI project "FAIRmat" (FAIR Data Infrastructure for Condensed-Matter Physics and the Chemical Physics of Solids, German Research Foundation, project N\({}^{\text{o}}\) 460197019).
