Class MultivariateNormalMixtureExpectationMaximization


  • public class MultivariateNormalMixtureExpectationMaximization
    extends Object
    Expectation-Maximization algorithm for fitting the parameters of multivariate normal mixture model distributions. This implementation is pure original code based on EM Demystified: An Expectation-Maximization Tutorial by Yihua Chen and Maya R. Gupta, Department of Electrical Engineering, University of Washington, Seattle, WA 98195. It was verified using external tools like CRAN Mixtools (see the JUnit test cases) but it is not based on Mixtools code at all. The discussion of the origin of this class can be seen in the comments of the MATH-817 JIRA issue.
    • Method Detail

      • fit

        public void fit​(MixtureMultivariateNormalDistribution initialMixture,
                        int maxIterations,
                        double threshold)
                 throws MathIllegalArgumentException
        Fit a mixture model to the data supplied to the constructor. The quality of the fit depends on the concavity of the data provided to the constructor and the initial mixture provided to this function. If the data has many local optima, multiple runs of the fitting function with different initial mixtures may be required to find the optimal solution. If a MathIllegalArgumentException is encountered, it is possible that another initialization would work.
        Parameters:
        initialMixture - Model containing initial values of weights and multivariate normals
        maxIterations - Maximum iterations allowed for fit
        threshold - Convergence threshold computed as difference in logLikelihoods between successive iterations
        Throws:
        MathIllegalArgumentException - if any component's covariance matrix is singular during fitting
        MathIllegalArgumentException - if numComponents is less than one or threshold is less than Double.MIN_VALUE
        MathIllegalArgumentException - if initialMixture mean vector and data number of columns are not equal
      • fit

        public void fit​(MixtureMultivariateNormalDistribution initialMixture)
                 throws MathIllegalArgumentException
        Fit a mixture model to the data supplied to the constructor. The quality of the fit depends on the concavity of the data provided to the constructor and the initial mixture provided to this function. If the data has many local optima, multiple runs of the fitting function with different initial mixtures may be required to find the optimal solution. If a MathIllegalArgumentException is encountered, it is possible that another initialization would work.
        Parameters:
        initialMixture - Model containing initial values of weights and multivariate normals
        Throws:
        MathIllegalArgumentException - if any component's covariance matrix is singular during fitting
        MathIllegalArgumentException - if numComponents is less than one or threshold is less than Double.MIN_VALUE
      • getLogLikelihood

        public double getLogLikelihood()
        Gets the log likelihood of the data under the fitted model.
        Returns:
        Log likelihood of data or zero of no data has been fit