Edit: This blog post has been developed into a preprint and extended in a number of ways. You can view the preprint on my ResearchGate here.
I was introduced to the concept of aleatoric uncertainty in the context of Bayesian neural networks, but I was recently working on a project for outlier detection and got interested in how reframing approaches from decision theory to a version of aleatoric uncertainty for typical Bayesian models could provide a mechanism for outlier detection. I also want to thank Karl Hallgren for inspiring me to think more about Bayesian outlier dection.
The reason this comes up naturally in the Bayesian context is because the model has some inherent uncertainty. Thinking of a parametric model, acknowledging in the Bayesian paradigm our uncertainty in the parameters we get that a distribution over the parameters maps to a distribution over a finite dimensional subspace of all distributions on the data. Thus the two types of uncertainty: our uncertainty in the model, epistemic, and our uncertainty in the data generating mechanism, aleatoric.
Introduction:
To see why this is useful for large scale outlier detection let us analyze a simple model. Suppose the data are assumed to follow , and we place a Normal-Inverse-Gamma prior,
, on the parameters
. Then we have that, given data
:
These parameters are fairly complicated, so denote the parameters , such that
.
Referring to the point made previously, we have a distribution over and
which is maps to a two-dimensional subset of all distributions over
. This is the epistemic uncertainty. However, if we use the posterior predictive distribution of
we get the aleatoric uncertainty:
which luckily for this simple model has a closed form solution:
Where the distribution is a non-centered student-t distribution, with degrees of freedom, location parameter
, and scale parameter
.
Where Decision Theory Comes In:
Where this idea of uncertainty in the data being inherited from the model uncertainty becomes useful is in outlier detection. Say we observe an observation and we want to know if it’s an outlier or not, we can look at
and select a cutoff to classify the observed value as an outlier if this probability is too large. The problem becomes choosing this cutoff.
Now to incorporate some ideas from decision theory, suppose we observed and want to observe if set of observations
has outliers. If agree with the philosophical leap that we can make decisions based on unobserved predictive values,
, then our goal is to make a decision
; where
means that
was an outlier, and
means it was not. We can construct loss functions similar in spirit to the following:
Where denotes an indicator function, and
is a penalty for total discoveries to control for multiplicity.
This loss function provides an incentive for true positives in the first addendum, , an adjustable penalty for false negatives in the second addendum,
, and a penalty for total discoveries that can be made stronger or weaker,
.
In typical decision theory we use the posterior expected loss and minimize it, but in this context we’re working with aleatoric uncertainty; so we take the posterior predictive expected loss. This gives us:
Denoting by the value
, we readjust the posterior predictive expected loss to the following:
For which the solution, minimizing with respect to , is:
.
This follows along pretty closely with an outline in Section 4 of the article FDR and Bayesian Multiple Comparison Rules by P. Muller, G. Parmigiani, and K. Rice in Bayesian Statistics 8; just using the posterior predictive to calculate probabilities for outliers from the indicator functions, but with the same lower bound on the minimizer of the expected loss.
Alternative Way to Choose Threshold and Data Informed Loss Function:
This means that the optimal decision for this loss function (indicator functions of outliers) is constructed out of some lower bound on . One way to select this lower bound instead of fine tuning the parameters
and
is to optimize the Bayesian FDR outlined here[1]. The posterior predictive CDF values,
, provide evidence in favor of testing the hypothesis
, for unobserved future predictive values
, versus the alternative hypothesis
. Thus the threshold could alternatively be set with multiplicity control by finding, for some fixed
, the threshold would be the largest such
to satisfy the following equation:
This provides a multiplicity control in the correction and offers a less controlled way to manage the false discoveries than tinkering directly with and
.
Let’s now examine, in the context of the previous decision theoretic model, what such a Bayesian FDR dictated threshold means in terms of the values of penalties on multiplicity and false negatives. We set up the following equation and solve for and
:
Rearranging a bit we get:
In other words, the largest such pairing of and
such that the magnitude of the sum of all
is less than the magnitude of the sum of all
(which is going to be less than or equal to 0 because
).
As gets smaller, the number of elements in the first set decreases more rapidly than the number of elements in the second set. This is because the second logical expression makes the first less likely to be true. Inversely, the same is true in the opposite context in the opposite direction, as
gets larger the number of elements increases more rapidly in the first set. An equilibrium needs to be find as the largest such
such that the statement is true.
Note that if for some
, then we have that
and vice versa
. Remembering that
is the penalty for false negatives, this gives us the linear relationship dictated by the BFDR threshold between the penalty for false negatives and the penalty for total discoveries. We have that
is a monotonically (not strictly) decreasing function; for which the rate of increase depends on
Thus, holding the penalty on false negatives, , fixed, we get
is a where the right hand side is a composition of a linear and monotonic function, this monotonicity as a function of
. Note that as
decreases
increases monotonically, and as
increases
increases linearly. This is different from holding
, the penalty for total discoveries fixed, where an increase in
causes a linear decrease in
.
It should be obvious at this point that one can reverse engineer decision criteria to give a loss function for which a particular threshold selection criteria (whatever type, whatever appropriately specified loss function) coincides.
However this is somewhat circular logic, as the Bayesian FDR is necessarily Bayesian, and is taken and evaluated after the expectation is taken. Still I think there’s interesting potential to play around with this generally speaking. Essentially it is saying we have a data dependent loss function. In other words, if you use the the Bayesian FDR a posteriori to select a cutoff, it would have equated to using this decision criteria on that data.
Noting Something Here About Bayesian FDR and the Previous Decision Criteria:
Assume in a typical Bayesian model that we have and
which is a model for
. E.g.
. Then we get a posterior for these two conditional on some data
where
is some observed data. Let
.
Examine the following loss:
Where is just the false discovery rate (which is monotonic in
because it can only be 0 or 1 in this scenario prior to taking the expectation). Note also that
is monotonic in each
. We prove a small theorem here to show that
Theorem 1:
Statement: For , and
, we have the following:
Proof:
Note that [2], and note that
is independently monotonic with respect to all
as well as
. Specifically
is piecewise linear with respect to
, giving us that the monotonicity and piecewise linear combine such that the expectation is just the inverse of the original expectation. Thus
.
This gives us that the posterior expectation of our previous loss function I given by:
Which is a decision criteria with solution:
Additional Note on Bayesian FDR:
We can generalize the Bayesian FDR with the following definition:
Definition:
For we can introduce a modified:
For .
Illustration:
We have that:
Using the sets outlined 2 sections ago we can see that the previous statement is true.
We note that this expression for is piecewise constant and increasing with respect to latex
, and that for a fixed
the BFDR is the minimum such value of
that this expression is true. (This is because the BFDR is satisfied by more than one such
, but the minimum value is the true BFDR). This gives us that
Note that, , giving us that
, giving us that
is going to similarly be in [0,1] for any
. This allows us to modify the previous expression to be:
Note that as the value of q is more emphasized by extreme values, and for values of
going towards
the value is q is more emphasized by moderate values. Note that for
the value for
is just
if
and
otherwise.
It should be obvious that we can reverse engineer this to get an appropriate for
.
Another interesting point to consider is that . Giving us that our solution is the point at which the rate of change of the conditional median is maximized. This is true by induction for all
in the appropriate range. The solution is the minimizer of the change in rate of the conditional absolute
non-central moment of the
. E.g. with respect to the non-centrality parameter:
Theorem 2:
Let and we have the following:
Which is the point which minimizes the change in the non-central absolute moment with respect to the non-centrality parameter.
Proof:
The proof follows from applying the dominated convergence theorem to exchange an expectation and a derivative and using laws from basic calculus. There is a term that has to be considered, but this term can be removed from the expectation and derivative, and the minimum is invariant under scalar multiplication/division for scalars greater than 0, so we can remove this term as well. The same applies to the
normalizing constant in the distribution of
.
This theorem also provides us a way to investigate complexities such as those that arise when is random and correlated. In other words, conditional on
the
are independent, but there are dependencies amongst the
.
Returning to Outlier Detection in the Scenario of Nonparametric Models:
It’s possible to get more abstract with the posterior predictive expection for outlier detection. For example, suppose we don’t want to use a parametric model, but instead some nonparametric approach. Taking species sampling models as an example, and specifically the Dirichlet process:
We get that the posterior predictive is ; where
denotes a point mass measure at
. This can be used to make outlier decisions in a decision theoretic model, and some interesting stuff could fall out.
Another important factor to consider is that we used a pretty simple probability event, , but in general other notions of what an outlier is could be encoded into this expression. For data that is more complex than real numbers, you could look at distance metrics on the space, and come up with a way to detect outliers from a different perspective.
I thought this was an interesting way to look at decision theory, and the loss function can be modified to prioritize different things one might be interested in. Additionally, the flexibility of the approach lends itself to a lot of different applications and generalizations.
Simulations:
I did simulations for both the DP outlier model as well as the NormalInverseGamma outlier model. There are 1000 replicated tests with 750 in the control group and 250 in the “anomalous” group. All data for the control group were simulated according to a distribution, and the previous values for the anomalous group were simulated according to the same distribution. There are 25 experiments, where the
for the outlier group are simulated according to a
distribution with
and
.
is specified to be equal to 10. The
prior has parameters
. For the DP the concentration parameters is specified to be
, and the base measure is a normal estimated from all of the
. Five replications were done of the experiments. The model gives the following results:
For the Area under the curve for the outliers for the NormalInverseGamma model we get the following performance

Where the tick marks from left to right, for each individual plot, indicate .
Using the Bayesian FDR Threshold and estimating accuracy, precision, and recall, we get the following:

Where the tick marks from left to right, for each individual plot, indicate .
Now to examine the DP model, we get the following performance on AUC:

Where the tick marks from left to right, for each individual plot, indicate .
For accuracy, precision, and recall, we get the following:

Where the tick marks from left to right, for each individual plot, indicate .
The previous plots for accuracy, precision, and recall, for both the DP and NIG, are with . Adjusting
we get higher recall but lower accuracy and precision.


Leave a Reply