This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: gmdistribution

Posterior probabilities of components


P = posterior(obj,X)
[P,nlogl] = posterior(obj,X)


P = posterior(obj,X) returns the posterior probabilities of each of the k components in the Gaussian mixture distribution defined by obj for each observation in the data matrix X. X is n-by-d, where n is the number of observations and d is the dimension of the data. obj is an object created by gmdistribution or fitgmdist. P is n-by-k, with P(I,J) the probability of component J given observation I.

posterior treats NaN values as missing data. Rows of X with NaN values are excluded from the computation.

[P,nlogl] = posterior(obj,X) also returns nlogl, the negative log-likelihood of the data.


expand all

Generate data from a mixture of two bivariate Gaussian distributions using the mvnrnd function.

MU1 = [2 2];
SIGMA1 = [2 0; 0 1];
MU2 = [-2 -1];
SIGMA2 = [1 0; 0 1];
rng(1); % For reproducibility
X = [mvnrnd(MU1,SIGMA1,1000);mvnrnd(MU2,SIGMA2,1000)];

hold on

Fit a two-component Gaussian mixture model.

obj = fitgmdist(X,2);
h = ezcontour(@(x,y)pdf(obj,[x y]),[-8 6],[-8 6]);

Compute posterior probabilities of the components.

P = posterior(obj,X);

hb = colorbar;
ylabel(hb,'Component 1 Probability')

Was this topic helpful?