Measuring uncertainty with bayesian neural network One of the ways to measure epistemic uncertainty, is using bayesian inference in neural networks. The idea is to learn the posterior over the weights $P(\phi|X)$ which describe the probability distribution over the weights. And then sample from this distribution, run the NN using this sample and calculate the mean and the variance of these results of the NN for all the samples. The variance should represent the uncertainty. We can assume using variational inference to approximate the posterior.
I have two questions regarding that:

*

*I would expect that uncertainty will be dependent on the specific input i.e. for some parts in the feature space where we lack of data, the network will output high uncertainty and for other parts of the feature space, low uncertainty. If we only learn the posterior over the weights, will the network be able to differentiate between the different inputs? In some cases where the weights are connected directly to the input like categorical feature embedding, i guess it would work fine, but would it work in the general case?

*One way to solve it is learning the posterior over the output of the network layers instead of learning the posterior over the weights. This way it includes also the input.  But in this case my question is: does the mathematical basis of the bayes theorem and variational inference still holds? Should something be changed in the theory\notations if we decide to learn the posterior over the network output layer.

 A: You are confusing posterior with posterior predictive distribution. Posterior distribution is the distribution of the parameter or parameters
$$
\underbrace{p(\theta | X)}_{\text{posterior}} \propto \underbrace{p(X|\theta)}_{\text{likelihood}} \; \underbrace{p(\theta)}_{\text{prior}}
$$
So it's variance tells you about the uncertainty of the parameters, given what you've learned from the data and the prior.
Posterior predictive distribution tells you about the uncertainty of the value predicted by the model $\tilde x$
$$
p(\tilde x | X) = \int_\Theta p(\tilde x | X, \theta) \;\underbrace{p(\theta | X)}_{\text{posterior}} \; d\theta 
$$
We run things as posterior predictive checks to check how well the posterior distribution of the predictions reflects the empirical distribution of the data. You can think of it (loosely) in similar terms as in the case of the difference between confidence intervals and predictive intervals.
So, yes, posterior is only about uncertainty of the weights, and yes, you can use posterior predictive to look at the uncertainty of the predictions.
