Bayesian inference - iterative updating with Bernoulli distribution Suppose I pull samples from a Bernoulli distribution $\mathcal{B}(\theta)$ 


*

*I don't know the value of $\theta$, but in my case I know that $\theta$ can only have 11 discrete values,  $\theta \in \{0.0, 0.1, 0.2, \ldots, 0.9, 1.0\}$

*I want to figure out the distribution $P[\theta]$ using Bayesian inference. 
Because I know that $\theta$ can only have 11 possible values, $P[\theta]$ will be a discrete distribution over 11 values. 


*

*So, I start with a non informative prior $P_{0}[\theta]=\frac{1}{11}$ for all $\theta$

*I iterate for each new sample, and I set $P_{n+1}[\theta]=\frac{P[\text{data}\mid\theta]\space P_{n}[\theta]}{\sum P[\text{data}\mid\theta]\space P_{n}[\theta]}$
So far so good... but when I use the Bernoulli distribution for $P[\text{data}\mid\theta]$, that is $P[\text{sample}\mid\theta] = \theta^\text{sample} (1-\theta)^{1-\text{sample}}$ the algorithm does not converge! 

Instead, the algorithm converges splendidly when I use the Binomial distribution for $P[\text{data}\mid\theta]$. That is $P[\text{data}\mid\theta] = \theta^\text{successes}(1-\theta)^{n-\text{successes}}$

Why do I need to use the Binomial distribution, to estimate the parameter of a Bernoulli distribution?
 A: The fact that your first graph merely oscillates between two values suggests to me that you are resetting the prior each time you perform an iteration.  So what you are seeing in the graph is a sequence of posteriors, each of which only take one data point into account.  That is not the correct method for iterative Bayesian updating.  Remember that when you do iterative Bayesian updating, the prior for each new iteration is the posterior from the last iteration. So your algorithm should be:

Iterative Bayesian updating: Start with the prior mass function:
$$\pi_0(\theta) = \frac{1}{11} \quad \quad \quad \text{for all } \theta = \tfrac{0}{10},  \tfrac{1}{10}, ..., \tfrac{10}{10}.$$
For $i=1,...,n$ and $x_i \in \{0,1\}$, update your beliefs via the iteration:
$$\pi_i(\theta) = \frac{\theta^{x_i} (1-\theta)^{1-x_i} \pi_{i-1}(\theta)}{\sum_\theta \theta^{x_i} (1-\theta)^{1-x_i} \pi_{i-1} (\theta)}$$ 
Notice that in each iteration the prior $\pi_{i-1}$ is the posterior from the previous iteration.  The mass function $\pi_n$ is the posterior after incorporating all the data.

A: thanks @Ben for insisting that I check my update process. It was broken indeed, I was not updating $P_{posterior}[\theta]$ correctly.
So now I can proclaim that Bayesian inference with Bernoulli works perfectly and I  post here the new chart to show it 

