public int [ ] [ ] getEMClusteringVariances ( double [ ] [ ] pointArray , int k ) { // initialize field and clustering initFields ( pointArray , k ) ; setInitialPartitions ( pointArray , k ) ; // iterate M and E double currentExpectation , newExpectation = 0.0 ; double expectationDeviation ; int count = 0 ; do { currentExpectation = newExpectation ; // reassign objects getNewClusterRepresentation ( ) ; calculateAllProbabilities ( ) ; // calculate new expectation value newExpectation = expectation ( ) ; // stop when the deviation is less than minDeviation expectationDeviation = 1.0 - ( currentExpectation / newExpectation ) ; count ++ ; } while ( expectationDeviation > minDeviation && count < MAXITER ) ; // return the resulting mapping from points to clusters return createProjectedClustering ( ) ; }
Performs an EM clustering on the provided data set !! Only the variances are calculated and used for point assignments ! !!! the number k of returned clusters might be smaller than k !!!