Generate random variates that follow a mixture of two bivariate Gaussian distributions by using the mvnrnd
function. Fit a Gaussian mixture model (GMM) to the generated data by using the fitgmdist
function, and then compute the posterior probabilities of the mixture components.
Define the distribution parameters (means and covariances) of two bivariate Gaussian mixture components.
Generate an equal number of random variates from each component, and combine the two sets of random variates.
The combined data set X
contains random variates following a mixture of two bivariate Gaussian distributions.
Fit a two-component GMM to X
.
gm =
Gaussian mixture distribution with 2 components in 2 dimensions
Component 1:
Mixing proportion: 0.500765
Mean: -1.9675 -0.9654
Component 2:
Mixing proportion: 0.499235
Mean: 1.9657 2.0342
Plot X
by using scatter
. Visualize the fitted model gm
by using pdf
and fcontour
.
Compute the posterior probabilities of the components.
P(i,j)
is the posterior probability of the j
th Gaussian mixture component given observation i
.
Plot the posterior probabilities of Component 1
by using the scatter
function. Use the circle colors to visualize the posterior probability values.
Plot the posterior probabilities of Component 2
.