After we understand the concept of Bernoulli, Binomial and Beta distribution we discuss here, we are ready to understand online learning used in Bayesian inference now. In Bayesian theorem we discuss here, we have equation below.

And for multi classes with multi attributes , we can write as follow.

Using rule of sum with is the number of classes, we can change the denominator becomes:

, for discrete system

, for continuous system

Here, we can say is posterior probability, is likelihood, is posterior probability, and is evidence or marginal probability.

In online learning, we will update our prior probability when we do some new trials. For example, in the first stage, we do some tossing coin, and we model the prior probability with . And at this point, we will use prior probability to estimate our posterior probability. Let it (posterior probability) be . In the next stage trials, we will use as our prior probability to estimate our next posterior probability. And we will continue to do this when we do some trials again. That’s why we call this online learning. Some references also call it sequential learning.

To do scenario above, we have to choose “suitable” probability model for our prior probability. Why? Because if we choose “wrong” probability model, we will find difficulty to calculate . Otherwise, we cannot get analytic function *a.k.a *closed-form expression to solve that equation, and we might solve it using numerical method. **This “suitable” prior probability model is then called conjugate prior.**

In Bayesian inference, if the posterior distributions are in the same family as the prior probability distribution , the prior and posterior are called **conjugate distributions**. Binomial and Beta distribution that we already discuss here are conjugate distributions, which Beta distribution is the conjugate prior. Furthermore, conjugate prior of Gaussian distribution is Gaussian itself, thus we call Gaussian distribution *self-conjugate. *Now, let’s try to proof that conjugate prior of Binomial distribution is Beta distribution. And we will still use our tossing coin case resulting H (head) and T (tail) as our example to make it easier to understand.

We have Binomial distribution written below.

,

with number resulting H in trials, where .

and Beta distribution is written below.

, which describes the distribution of probability

Next, we will try to solve equation , where our prior probability is and our likelihood is . Let’s say we do some new trials resulting number of heads and number of tails. Then, our likelihood and prior probability become:

Likelihood

Prior

By plugging those two equations into Bayesian formula, we can proof that Beta distribution is conjugate prior of Binomial distribution. Here we go.

which is another form of Beta distribution with parameters . This posterior distribution could then be used as the prior for more samples, which is only simply adding how many numbers resulting and . And if we do this again and again, we will get our prediction more accurate. Awesome, right? 😀 And since we can solve our Bayesian formula using our Binomial likelihood and Beta prior distribution resulting analytic function, we can say that Binomial and Beta distributions are conjugate distributions.

## (#) Multinomial distribution

We already know how online learning works in binomial distribution. Let’s expand to multinomial distribution. Multinomial distribution describe the probability distribution of a trail having more than two outcomes, such as rolling a dice which gives us six outcomes results . Mutltinomial distribution is defines as follows.

,

where .

The conjugate prior of multinomial distribution is Dirichlet distribution, which is defined as follows.

We can calculate the posterior probability with the similar procedure we already did before in beta posterior calculation. Thus, we will skip the detail, and let’s just put the result.

We get the posterior probability which is another Dirichlet distribution. We can iterate to update the parameter once we have new experiment result to do online learning.