public static double assignProbabilitiesToInstances ( Relation < ? extends NumberVector > relation , List < ? extends EMClusterModel < ? > > models , WritableDataStore < double [ ] > probClusterIGivenX ) { final int k = models . size ( ) ; double emSum = 0. ; for ( DBIDIter iditer = relation . iterDBIDs ( ) ; iditer . valid ( ) ; iditer . advance ( ) ) { NumberVector vec = relation . get ( iditer ) ; double [ ] probs = new double [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { double v = models . get ( i ) . estimateLogDensity ( vec ) ; probs [ i ] = v > MIN_LOGLIKELIHOOD ? v : MIN_LOGLIKELIHOOD ; } final double logP = logSumExp ( probs ) ; for ( int i = 0 ; i < k ; i ++ ) { probs [ i ] = FastMath . exp ( probs [ i ] - logP ) ; } probClusterIGivenX . put ( iditer , probs ) ; emSum += logP ; } return emSum / relation . size ( ) ; }
Assigns the current probability values to the instances in the database and compute the expectation value of the current mixture of distributions .