piEsposito / blitz-bayesian-deep-learning

A simple and extensible library to create Bayesian Neural Network layers on PyTorch.
GNU General Public License v3.0
921 stars 106 forks source link

How to calculate the variance of prediction results when making predictions #42

Closed XingHYu closed 3 years ago

XingHYu commented 4 years ago

Hello, when calculating the variance, should we first denormalize the prediction results and then calculate the variance? In your example, it seems that the variance and mean are calculated first and then denormalized

piEsposito commented 4 years ago

Hello, If we are working with classification, than our output won't be denormalized, as we would use the variance and standard deviation of the probabilities after passing the last layer per a softmax function.

On a regression problem, we could either denormalize it:

image

And then calculate the variance:

image

Or calculate the variance qnd then denormalize it by multiplying for the std:

image

Which would be biased:

image.

So, mathematically, the correct is to denormalize and then calculate the variance.

It occurs that, on practice, on regression problems, we may use the variational inference to either calculate confidence intervals (setting bound as some image or evaluating the uncertainty by comparing the obtained variance with some image. So, if you set your image knowing that, using the biased variance may not harm your predictions.

Hope you find my explanation useful.

piEsposito commented 3 years ago

Closing due to inactivity.