This extension is required for this article. Load it here if you haven't yet.
In this article, we'll explore how to find the parameters of a probability distribution that best fit observed data using maximum likelihood estimation (MLE). We'll work with both normal distribution.
Let's start with a normal distribution. We have some observed data points and want to find the mean () and standard deviation () that maximize the likelihood of observing this data.
The MLE parameters for a Gaussian distribution have a nice closed form formula - the estimated mean and std are the same as the mean and std of the observed data. This will be our reference.
The true parameters of our data are and . These represent the actual distribution that generated our data points.
The gray curve shows the true probability density function (PDF) of our data.
Now let's start with arbitrary initial guesses for our parameters and see if we can recover the true values through optimization.
The blue curve shows our initial guess - a standard normal distribution centered at 0 with σ = 1. This is quite different from the true distribution!
We'll use gradient descent to minimize the negative log-likelihood, which is equivalent to maximizing the likelihood.
Now let's minimize the negative loss likelihood:
The optimization adjusts and to maximize the probability of observing our data. After 100 iterations, the parameters should converge close to the true values.
We can and the . If trained well, these plots will almost coincide.
(This strategy won't work for uniform distribution since the gradients will be all zero)