Short version: how to estimate the parameters of a mixture of multivariate normal distributions (i.e.: Gaussian mixture model)?
Long version.
I am trying to estimate the parameters of a mixture of multivariate Gaussian distribution.
I know how to do it for a single multivariate normal distribution:
dist = MultinormalDistribution[{0, 0}, {{1, 0}, {0, 1}}];
dataSet = RandomVariate[dist, 300];
estDist = EstimatedDistribution[dataSet, MultinormalDistribution[{m1, m2}, {s11, s12}, {s12, s22]}}]]
Plot[{PDF[dist, {x, 0}], PDF[estDist, {x, 0}]}, {x, -4, 4}, Filling -> Axis]
SmoothDensityHistogram[dataSet]
Plot3D[PDF[estDist, {x, y}], {x, -2, 2}, {y, -2, 2}]
All fine and dandy. However, the same approach does not work for me with mixture distributions. In particular, I am interested in mixtures of Gaussian distribution (Gaussian Mixture Model).
I generate a sample dataset:
targetDist = MixtureDistribution[{1/3, 2/3}, {MultinormalDistribution[{0, 0}, {{1, 0}, {0, 1}}], MultinormalDistribution[{3, 3}, {{1, 0}, {0, 1}}]}];
dataSet = RandomVariate[targetDist, 500];
ListPlot[dataSet]
SmoothHistogram3D[dataSet]
I try to find the estimated distribution with:
estimatedDist = EstimatedDistribution[dataSet,
MixtureDistribution[{w1, w2}, {
MultinormalDistribution[{m11, m12}, {{s111, s112}, {s112, s122}}],
MultinormalDistribution[{m21, m22}, {{s211, s212}, {s212, s222}}]
}]]
But the evaluation always fails with:
NMaximize::cvdiv: Failed to converge to a solution. The function may be unbounded. >>
For some reason, it works if, instead of using MultinormalDistribution
I use BinormalDistribution
with $\rho$=0.
I know how to estimate these parameters using the Expectation Maximization algorithm, but I was wondering if there is a Mathematica-friendly way to do it.
Edit.
Giving initial estimates of the parameters does not really improve much. Even when giving the exact parameters like this:
estimatedDist = EstimatedDistribution[dataSet,
MixtureDistribution[
{w1, w2},
{MultinormalDistribution[{m11, m12}, {{s111, s112}, {s121, s122}}],
MultinormalDistribution[{m21, m22}, {{s211, s212}, {s221, s222}}]}],
{{w1, 1/3}, {w2, 2/3}, {m11, 0}, {m12, 0}, {s111, 1}, {s112, 0}, {s121, 0}, {s122, 1}, {m21, 3}, {m22, 3}, {s211, 1}, {s212, 0}, {s221, 0}, {s222, 1}}]
EstimatedDistribution
seems to take much more time than what it would be reasonable (and, since the estimates are exact, "reasonable" means 0.1 sec).
After about 15 minutes of processing on a 3.3GHz Xeon, I got this error:
FindMaximum::eit: The algorithm does not converge to the tolerance of
4.806217383937354`*^-6 in 500 iterations. The best estimated solution,
with feasibility residual, KKT residual, or complementary residual of
{2.1536*10^-12,0.00200273,5.6281*10^-13}, is returned. >>
Then a popup message:
INTERNAL SELF-TEST ERROR: MLParseStream|c|297
Click here to find out if this problem is known, and to help improve
Mathematica by reporting it to Wolfram Research.
EstimatedDistribution[]
with initial estimates of parameters? $\endgroup$EstimatedDistribution
still fails to return a meaningful result. $\endgroup$