Answers.Body: <p>Your intuition is right. The main reason why a deterministic function can be undesirable (or even dangerous, as I will explain below with an example) is that we may not have enough data to learn the correct function, so we may end up learning the incorrect one. Right now, no other reason, from a theoretical point of view, comes to my mind, but below I will mention a few applications/cases where a deterministic function may not be desirable.</p>
  <p>If we had all data pairs <span class="math-container">$\{(x_i, y_i)\}$</span>, where <span class="math-container">$x_i \in \mathcal{X}$</span> and <span class="math-container">$y_i = \mathcal{Y}$</span> are, respectively, an input and output from the unknown function that you want to learn <span class="math-container">$f: \mathcal{X} \rightarrow \mathcal{Y}$</span>, i.e. <span class="math-container">$f(x_i) = y_i$</span>, then you could reconstruct <span class="math-container">$f$</span>: whenever <span class="math-container">$x_i$</span> is given, you just need to return <span class="math-container">$y_i$</span>.</p>
  <p>Of course, in reality, we almost never have a large enough (training) dataset to approximate out desired (but usually unknown) function. If we learn only one (deterministic) function, then, in principle, you can catastrophically fail, i.e. your approximation of <span class="math-container">$f$</span>, denoted as <span class="math-container">$f_\theta$</span> (where <span class="math-container">$\theta$</span> are the parameters of the neural network or any other model), can produce outputs that are completely wrong.</p>
  <p>Let me try to give you a simple example. Let's say that <span class="math-container">$f$</span> is defined as follows</p>
  <p><span class="math-container">$$f: \mathbb{N} \rightarrow \{0, 1\}$$</span></p>
  <p>You are given a training labelled dataset <span class="math-container">$$D = \{(4, 1), (11, 0), (8, 1), (31, 0), (16, 1), (7, 0) \}.$$</span></p>
  <p><strong>Apparently</strong>, our unknown function is defined as</p>
  <p><span class="math-container">\begin{align}
  h_1(x)=
  \begin{cases}
  1, &amp;x \text{ mod } 2 \equiv 0\\
  0, &amp;\text{otherwise}
  \end{cases}\tag{1}\label{1}
  \end{align}</span>
  Given that <span class="math-container">$D$</span> is small, your neural network, <span class="math-container">$f_\theta$</span>, can easily <strong>overfit</strong> <span class="math-container">$D$</span>, i.e. learn to output <span class="math-container">$1$</span> when <span class="math-container">$x$</span> is even and <span class="math-container">$0$</span> otherwise.</p>
  <p>However, what if <span class="math-container">$f$</span> is not that function in equation \ref{1} and we collected just a dataset that doesn't represent <span class="math-container">$f$</span> well enough? If you look at <span class="math-container">$D$</span> more carefully, you will see that another possible hypothesis for <span class="math-container">$f$</span> is the following</p>
  <p><span class="math-container">\begin{align}
  h_2(x)=
  \begin{cases}
  1, &amp;x \text{ mod } 4 \equiv 0\\
  0, &amp;\text{otherwise}
  \end{cases}\tag{2}\label{2}
  \end{align}</span>
  However, given that your neural network can only compute one of these functions at a time, it could compute the wrong one. Let's say that <span class="math-container">$f_\theta \approx h_1$</span>, then it should produce <span class="math-container">$1$</span> when <span class="math-container">$x = 6$</span> (an even number). If the correct unknown function was <span class="math-container">$h_2$</span>, i.e. <span class="math-container">$f = h_2$</span>, then <span class="math-container">$f_\theta(6) = 1$</span> would be wrong (because <span class="math-container">$6$</span> is not a multiple of <span class="math-container">$4$</span>).</p>
  <p>Of course, this is just a toy example. However, there are many other cases where this can happen, which may not be desirable, such as <strong>healthcare</strong>, <strong>medicine</strong> or <strong>self-driving cars</strong>, where the wrong prediction can lead to catastrophic consequences, such as the death of a person.</p>
  <p>If we maintain a probability distribution over the possible functions that are consistent with the observed data so far, we can (partially) avoid this issue. So, continuing with the example above, this probability distribution over functions should be highly uncertain about <span class="math-container">$x = 6$</span>, whether it produces <span class="math-container">$0$</span> or <span class="math-container">$1$</span>, because it has never seen the label for <span class="math-container">$x=6$</span>, so a medical doctor or the human driver could intervene in the case of (high) uncertainty.</p>
  <p>For this reason, in the last decade, people have started to incorporate uncertainty estimation in neural networks. Neural networks that model uncertainty (to some degree) are often called <strong>Bayesian neural networks</strong> (BNNs), and there are different approaches (such as <a href="http://proceedings.mlr.press/v37/blundell15.html" rel="nofollow noreferrer">variational BNNs</a>, <a href="https://arxiv.org/abs/1506.02142" rel="nofollow noreferrer">MC dropout</a> or <a href="https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.446.9306&amp;rep=rep1&amp;type=pdf" rel="nofollow noreferrer">Monte Carlo-based approaches</a>). If you are interested in this topic, the paper <a href="http://proceedings.mlr.press/v37/blundell15.html" rel="nofollow noreferrer">Weight Uncertainty in Neural Network</a> (2015) is a good start, especially if you are already familiar with VAEs. Given that this is a very new research area, the current solutions are still not very satisfactory. For example, you can find examples in the literature that report that MC dropout can produce very bad estimates of uncertainty (even in my master's thesis I have observed and thus concluded that this is the case), i.e. they can be highly certain when they should be highly uncertain.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-17T01:15:02.113Z
Answers.LastActivityDate: 2021-01-17T11:51:08.703Z
Answers.LastEditDate: 2021-01-17T11:51:08.703Z
Answers.UserDisplayName: nbro
Body: <p>Why is neural networks being a deterministic mapping not always considered a good thing?</p>
  <p>So I'm excluding models like VAEs since those aren't entirely deterministic. I keep thinking about this and my conclusion is that often times neural networks are used to model things in reality, which often time do have some stochasticity and since neural networks are deterministic if they are not trained on enough examples of the possible variance inputs in relation to outputs can have they cannot generalize well. Are there other reasons this is not a good thing?</p>
  
Tags: <neural-networks><bayesian-deep-learning><bayesian-neural-networks>
Title: Why is neural networks being a deterministic mapping not always considered a good thing?
UserDisplayName: user8714896
ThreadText: # Why is neural networks being a deterministic mapping not always considered a good thing?
  
  (Asked by: username_0 on 2021-01-16)
  
  Why is neural networks being a deterministic mapping not always considered a good thing?
  
  So I'm excluding models like VAEs since those aren't entirely deterministic. I keep thinking about this and my conclusion is that often times neural networks are used to model things in reality, which often time do have some stochasticity and since neural networks are deterministic if they are not trained on enough examples of the possible variance inputs in relation to outputs can have they cannot generalize well. Are there other reasons this is not a good thing?
  
  **Tags:** neural-networks, bayesian-deep-learning, bayesian-neural-networks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-01-17. Score: 1 | Accepted answer
  
  Your intuition is right. The main reason why a deterministic function can be undesirable (or even dangerous, as I will explain below with an example) is that we may not have enough data to learn the correct function, so we may end up learning the incorrect one. Right now, no other reason, from a theoretical point of view, comes to my mind, but below I will mention a few applications/cases where a deterministic function may not be desirable.
  
  If we had all data pairs $\{(x\_i, y\_i)\}$, where $x\_i \in \mathcal{X}$ and $y\_i = \mathcal{Y}$ are, respectively, an input and output from the unknown function that you want to learn $f: \mathcal{X} \rightarrow \mathcal{Y}$, i.e. $f(x\_i) = y\_i$, then you could reconstruct $f$: whenever $x\_i$ is given, you just need to return $y\_i$.
  
  Of course, in reality, we almost never have a large enough (training) dataset to approximate out desired (but usually unknown) function. If we learn only one (deterministic) function, then, in principle, you can catastrophically fail, i.e. your approximation of $f$, denoted as $f\_\theta$ (where $\theta$ are the parameters of the neural network or any other model), can produce outputs that are completely wrong.
  
  Let me try to give you a simple example. Let's say that $f$ is defined as follows
  
  $$f: \mathbb{N} \rightarrow \{0, 1\}$$
  
  You are given a training labelled dataset $$D = \{(4, 1), (11, 0), (8, 1), (31, 0), (16, 1), (7, 0) \}.$$
  
  **Apparently**, our unknown function is defined as
  
  \begin{align}
  h\_1(x)=
  \begin{cases}
  1, &x \text{ mod } 2 \equiv 0\\
  0, &\text{otherwise}
  \end{cases}\tag{1}\label{1}
  \end{align}
  Given that $D$ is small, your neural network, $f\_\theta$, can easily **overfit** $D$, i.e. learn to output $1$ when $x$ is even and $0$ otherwise.
  
  However, what if $f$ is not that function in equation \ref{1} and we collected just a dataset that doesn't represent $f$ well enough? If you look at $D$ more carefully, you will see that another possible hypothesis for $f$ is the following
  
  \begin{align}
  h\_2(x)=
  \begin{cases}
  1, &x \text{ mod } 4 \equiv 0\\
  0, &\text{otherwise}
  \end{cases}\tag{2}\label{2}
  \end{align}
  However, given that your neural network can only compute one of these functions at a time, it could compute the wrong one. Let's say that $f\_\theta \approx h\_1$, then it should produce $1$ when $x = 6$ (an even number). If the correct unknown function was $h\_2$, i.e. $f = h\_2$, then $f\_\theta(6) = 1$ would be wrong (because $6$ is not a multiple of $4$).
  
  Of course, this is just a toy example. However, there are many other cases where this can happen, which may not be desirable, such as **healthcare**, **medicine** or **self-driving cars**, where the wrong prediction can lead to catastrophic consequences, such as the death of a person.
  
  If we maintain a probability distribution over the possible functions that are consistent with the observed data so far, we can (partially) avoid this issue. So, continuing with the example above, this probability distribution over functions should be highly uncertain about $x = 6$, whether it produces $0$ or $1$, because it has never seen the label for $x=6$, so a medical doctor or the human driver could intervene in the case of (high) uncertainty.
  
  For this reason, in the last decade, people have started to incorporate uncertainty estimation in neural networks. Neural networks that model uncertainty (to some degree) are often called **Bayesian neural networks** (BNNs), and there are different approaches (such as [variational BNNs](http://proceedings.mlr.press/v37/blundell15.html), [MC dropout](https://arxiv.org/abs/1506.02142) or [Monte Carlo-based approaches](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.446.9306&rep=rep1&type=pdf)). If you are interested in this topic, the paper [Weight Uncertainty in Neural Network](http://proceedings.mlr.press/v37/blundell15.html) (2015) is a good start, especially if you are already familiar with VAEs. Given that this is a very new research area, the current solutions are still not very satisfactory. For example, you can find examples in the literature that report that MC dropout can produce very bad estimates of uncertainty (even in my master's thesis I have observed and thus concluded that this is the case), i.e. they can be highly certain when they should be highly uncertain.
  
  
  ---
  
  