IntelLabs / bayesian-torch

A library for Bayesian neural network layers and uncertainty estimation in Deep Learning extending the core of PyTorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variance/standard deviation

jeiglsperger opened this issue · comments

Is it possible to let the net give back a variance or standard deviation with the prediction (when using the bayesian network for regression) to calculate a confidence interval?
Or in other words, is it possible to calculate a let's say 95% confidence interval with the entropy?

@Zepp3 you can calculate the variance or standard deviation with multiple Monte Carlo samples (forward-passes) from the Bayesian neural network model for regression (example snipped below):

predictions_mc = []
for _ in range(args.num_monte_carlo):
    output = model.forward(data)
    predictions_mc.append(output)
predictions_ = torch.stack(predictions_mc)
predictive_mean = torch.mean(predictions_, dim=0)
predictive_variance = torch.var(predictions_, dim=0)