<p>You can use dropout for that. With a dropout layer you can make several different predictions based on different settings of which nodes dropped out. Then you can simply count the outcomes and interpret the result as a measure for uncertainty.</p>

<p>For details, read:</p>

<blockquote>
  <p>Gal, Yarin, and Zoubin Ghahramani. "<a href="https://arxiv.org/pdf/1506.02142.pdf" rel="nofollow noreferrer">Dropout as a bayesian approximation: Representing model uncertainty in deep learning</a>." international conference on machine learning. 2016.</p>
</blockquote>
How can I predict the expected value and the variance simultaneously with a neural network?
<p>I'd like to use a neural network to predict a scalar value which is the sum of a function of the input values and a random value (I'm assuming gaussian distribution) whose variance also depends on the input values. Now I'd like to have a neural network that has two outputs - the first output should approximate the deterministic part - the function, and the second output should approximate the variance of the random part, depending on the input values. What loss function do I need to train such a network?</p>

<p>(It would be nice if there was an example with Python for Tensorflow, but I'm also interested in general answers. I'm also not quite clear how I could write something like in Python code - none of the examples I found so far show how to address individual outputs from the loss function.)</p>