We finally got to the part of Bayesian Updating when both data and prior are continuous. It is, like always, not very different from Bayesian Updating with discrete data and priors except of that we use the PDFs and not the PMFs.

## Continuous Data, Continuous Prior

When we use probability density functions we have to be careful, as the function itself doesn’t give us the probability. It is that gives us the probability. We therefore have to use and . This can be messy sometimes, so we often drop it.

Hypothesis | Prior | Likelihood | unnormalised Posterior | Posterior |

Total | 1 | 1 |

**Example:** Suppose we have a normal distributed hypothesis and normal distributed data. So both data and hypothesis are continuous. Suppose data x is drawn from a normal distribution with unknown mean and .

Suppose further that

What is the posterior PDF?

**Answer: ** Our prior PDF is given by and our likelihood PDF is given by .

We need the product of our prior and likelihood for the unnormalised posterior so we can do these calculations first:

prior x likelihood =

x is a constant because we know the data.

If we now use bayesian updating we get the posterior PDF , what looks like a normal distribution with and . Furthermore we know the normalising constant for normal distributions:

If we use 4.7 as our data, we get the following graphs:

The prior got pulled towards the data.

**NOTE:** I used the following python code for the graphs.

from scipy import stats as s import numpy as np import matplotlib.pyplot as plt import math data = 4.7 def prior(xs): ys = [] for x in xs: y = math.exp((-1*(x-2)**2)/2)/(math.sqrt(2*math.pi)) ys.append(y) return ys def posterior(xs): ys = [] for x in xs: y = math.exp(-(x-(1+data/2))**2)/(math.sqrt(math.pi)) ys.append(y) return ys prior_x = [x for x in np.arange(-6,6,0.1)] prior_y = [y for y in prior(prior_x)] posterior_x = [x for x in np.arange(-6,6,0.1)] posterior_y = [y for y in posterior(posterior_x)] fid = plt.figure() ax1 = plt.subplot2grid((1,1), (0,0)) ax1.plot(prior_x, prior_y, color='blue', label='prior') ax1.plot(posterior_x, posterior_y, color='red', label='posterior, data={}'.format(data)) ax1.set_yticks(np.arange(0, 1.1, 0.1)) plt.legend() plt.show()