Class TwoPassMultivariateGaussianModel

  • All Implemented Interfaces:
    EMClusterModel<elki.data.NumberVector,​EMModel>

    public class TwoPassMultivariateGaussianModel
    extends java.lang.Object
    implements EMClusterModel<elki.data.NumberVector,​EMModel>
    Model for a single Gaussian cluster, using two-passes for slightly better numerics.

    This is the more classic approach, but the savings in numerical precision are usually negligible, since we already use a very stable and fast approach.

    Since:
    0.7.5
    Author:
    Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) elki.math.linearalgebra.CholeskyDecomposition chol
      Decomposition of covariance matrix.
      (package private) double[][] covariance
      Covariance matrix.
      (package private) double logNorm
      Normalization factor.
      (package private) double logNormDet
      Normalization factor.
      (package private) double[] mean
      Mean vector.
      (package private) double[][] priormatrix
      Matrix for prior conditioning.
      (package private) double[] tmp
      Temporary storage, to avoid reallocations.
      (package private) double weight
      Weight aggregation sum.
      (package private) double wsum
      Weight aggregation sum.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void beginEStep()
      Begin the E step.
      double estimateLogDensity​(elki.data.NumberVector vec)
      Estimate the log likelihood of a vector.
      EMModel finalizeCluster()
      Finalize a cluster model.
      void finalizeEStep​(double weight, double prior)
      Finalize the E step.
      void finalizeFirstPassE()
      Finish computation of the mean.
      void firstPassE​(elki.data.NumberVector vec, double wei)
      First pass: update the mean only.
      double getWeight()
      Get the cluster weight.
      double mahalanobisDistance​(elki.data.NumberVector vec)
      Compute the Mahalanobis distance from the centroid for a given vector.
      boolean needsTwoPass()
      True, if the model needs two passes in the E step.
      void setWeight​(double weight)
      Set the cluster weight.
      void updateE​(elki.data.NumberVector vec, double wei)
      Second pass: compute the covariance matrix.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mean

        double[] mean
        Mean vector.
      • covariance

        double[][] covariance
        Covariance matrix.
      • chol

        elki.math.linearalgebra.CholeskyDecomposition chol
        Decomposition of covariance matrix.
      • tmp

        double[] tmp
        Temporary storage, to avoid reallocations.
      • logNorm

        double logNorm
        Normalization factor.
      • logNormDet

        double logNormDet
        Normalization factor.
      • weight

        double weight
        Weight aggregation sum.
      • wsum

        double wsum
        Weight aggregation sum.
      • priormatrix

        double[][] priormatrix
        Matrix for prior conditioning.
    • Constructor Detail

      • TwoPassMultivariateGaussianModel

        public TwoPassMultivariateGaussianModel​(double weight,
                                                double[] mean)
        Constructor.
        Parameters:
        weight - Cluster weight
        mean - Initial mean
      • TwoPassMultivariateGaussianModel

        public TwoPassMultivariateGaussianModel​(double weight,
                                                double[] mean,
                                                double[][] covariance)
        Constructor.
        Parameters:
        weight - Cluster weight
        mean - Initial mean
        covariance - initial covariance matrix
    • Method Detail

      • needsTwoPass

        public boolean needsTwoPass()
        Description copied from interface: EMClusterModel
        True, if the model needs two passes in the E step.
        Specified by:
        needsTwoPass in interface EMClusterModel<elki.data.NumberVector,​EMModel>
        Returns:
        true when an initial pass is needed.
      • firstPassE

        public void firstPassE​(elki.data.NumberVector vec,
                               double wei)
        First pass: update the mean only.
        Specified by:
        firstPassE in interface EMClusterModel<elki.data.NumberVector,​EMModel>
        Parameters:
        vec - Vector to process
        wei - Weight of point ("responsibility" of the cluster)
      • updateE

        public void updateE​(elki.data.NumberVector vec,
                            double wei)
        Second pass: compute the covariance matrix.
        Specified by:
        updateE in interface EMClusterModel<elki.data.NumberVector,​EMModel>
        Parameters:
        vec - Vector to process
        wei - Weight of point ("responsibility" of the cluster)
      • finalizeEStep

        public void finalizeEStep​(double weight,
                                  double prior)
        Description copied from interface: EMClusterModel
        Finalize the E step.
        Specified by:
        finalizeEStep in interface EMClusterModel<elki.data.NumberVector,​EMModel>
        Parameters:
        weight - weight of the cluster
        prior - MAP prior (0 for MLE)
      • mahalanobisDistance

        public double mahalanobisDistance​(elki.data.NumberVector vec)
        Compute the Mahalanobis distance from the centroid for a given vector.
        Parameters:
        vec - Vector
        Returns:
        Mahalanobis distance
      • estimateLogDensity

        public double estimateLogDensity​(elki.data.NumberVector vec)
        Description copied from interface: EMClusterModel
        Estimate the log likelihood of a vector.
        Specified by:
        estimateLogDensity in interface EMClusterModel<elki.data.NumberVector,​EMModel>
        Parameters:
        vec - Vector
        Returns:
        log likelihood.
      • getWeight

        public double getWeight()
        Description copied from interface: EMClusterModel
        Get the cluster weight.
        Specified by:
        getWeight in interface EMClusterModel<elki.data.NumberVector,​EMModel>
        Returns:
        Cluster weight
      • setWeight

        public void setWeight​(double weight)
        Description copied from interface: EMClusterModel
        Set the cluster weight.
        Specified by:
        setWeight in interface EMClusterModel<elki.data.NumberVector,​EMModel>
        Parameters:
        weight - Cluster weight