Package elki.clustering.em.models
Class TwoPassMultivariateGaussianModel
- java.lang.Object
-
- elki.clustering.em.models.TwoPassMultivariateGaussianModel
-
- All Implemented Interfaces:
EMClusterModel<NumberVector,EMModel>
public class TwoPassMultivariateGaussianModel extends java.lang.Object implements EMClusterModel<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) CholeskyDecompositioncholDecomposition of covariance matrix.(package private) double[][]covarianceCovariance matrix.(package private) doublelogNormNormalization factor.(package private) doublelogNormDetNormalization factor.(package private) double[]meanMean vector.(package private) double[][]priormatrixMatrix for prior conditioning.(package private) double[]tmpTemporary storage, to avoid reallocations.(package private) doubleweightWeight aggregation sum.(package private) doublewsumWeight aggregation sum.
-
Constructor Summary
Constructors Constructor Description TwoPassMultivariateGaussianModel(double weight, double[] mean)Constructor.TwoPassMultivariateGaussianModel(double weight, double[] mean, double[][] covariance)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginEStep()Begin the E step.doubleestimateLogDensity(NumberVector vec)Estimate the log likelihood of a vector.EMModelfinalizeCluster()Finalize a cluster model.voidfinalizeEStep(double weight, double prior)Finalize the E step.voidfinalizeFirstPassE()Finish computation of the mean.voidfirstPassE(NumberVector vec, double wei)First pass: update the mean only.doublegetWeight()Get the cluster weight.doublemahalanobisDistance(NumberVector vec)Compute the Mahalanobis distance from the centroid for a given vector.booleanneedsTwoPass()True, if the model needs two passes in the E step.voidsetWeight(double weight)Set the cluster weight.voidupdateE(NumberVector vec, double wei)Second pass: compute the covariance matrix.
-
-
-
Field Detail
-
mean
double[] mean
Mean vector.
-
covariance
double[][] covariance
Covariance matrix.
-
chol
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 weightmean- Initial mean
-
TwoPassMultivariateGaussianModel
public TwoPassMultivariateGaussianModel(double weight, double[] mean, double[][] covariance)Constructor.- Parameters:
weight- Cluster weightmean- Initial meancovariance- initial covariance matrix
-
-
Method Detail
-
beginEStep
public void beginEStep()
Description copied from interface:EMClusterModelBegin the E step.- Specified by:
beginEStepin interfaceEMClusterModel<NumberVector,EMModel>
-
needsTwoPass
public boolean needsTwoPass()
Description copied from interface:EMClusterModelTrue, if the model needs two passes in the E step.- Specified by:
needsTwoPassin interfaceEMClusterModel<NumberVector,EMModel>- Returns:
truewhen an initial pass is needed.
-
firstPassE
public void firstPassE(NumberVector vec, double wei)
First pass: update the mean only.- Specified by:
firstPassEin interfaceEMClusterModel<NumberVector,EMModel>- Parameters:
vec- Vector to processwei- Weight of point ("responsibility" of the cluster)
-
finalizeFirstPassE
public void finalizeFirstPassE()
Finish computation of the mean.- Specified by:
finalizeFirstPassEin interfaceEMClusterModel<NumberVector,EMModel>
-
updateE
public void updateE(NumberVector vec, double wei)
Second pass: compute the covariance matrix.- Specified by:
updateEin interfaceEMClusterModel<NumberVector,EMModel>- Parameters:
vec- Vector to processwei- Weight of point ("responsibility" of the cluster)
-
finalizeEStep
public void finalizeEStep(double weight, double prior)Description copied from interface:EMClusterModelFinalize the E step.- Specified by:
finalizeEStepin interfaceEMClusterModel<NumberVector,EMModel>- Parameters:
weight- weight of the clusterprior- MAP prior (0 for MLE)
-
mahalanobisDistance
public double mahalanobisDistance(NumberVector vec)
Compute the Mahalanobis distance from the centroid for a given vector.- Parameters:
vec- Vector- Returns:
- Mahalanobis distance
-
estimateLogDensity
public double estimateLogDensity(NumberVector vec)
Description copied from interface:EMClusterModelEstimate the log likelihood of a vector.- Specified by:
estimateLogDensityin interfaceEMClusterModel<NumberVector,EMModel>- Parameters:
vec- Vector- Returns:
- log likelihood.
-
getWeight
public double getWeight()
Description copied from interface:EMClusterModelGet the cluster weight.- Specified by:
getWeightin interfaceEMClusterModel<NumberVector,EMModel>- Returns:
- Cluster weight
-
setWeight
public void setWeight(double weight)
Description copied from interface:EMClusterModelSet the cluster weight.- Specified by:
setWeightin interfaceEMClusterModel<NumberVector,EMModel>- Parameters:
weight- Cluster weight
-
finalizeCluster
public EMModel finalizeCluster()
Description copied from interface:EMClusterModelFinalize a cluster model.- Specified by:
finalizeClusterin interfaceEMClusterModel<NumberVector,EMModel>- Returns:
- Cluster model
-
-