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[] probabilities=new double[k];
{
      int i=0;
      for (      EMClusterModel<?> m : models) {
        probabilities[i]=m.estimateDensity(vec);
        ++i;
      }
    }
    double priorProbability=0.;
    for (int i=0; i < k; i++) {
      priorProbability+=probabilities[i];
    }
    double logP=Math.max(Math.log(priorProbability),MIN_LOGLIKELIHOOD);
    emSum+=(logP == logP) ? logP : 0.;
    double[] clusterProbabilities=new double[k];
    if (priorProbability > 0.) {
      for (int i=0; i < k; i++) {
        clusterProbabilities[i]=probabilities[i] / priorProbability;
      }
    }
    probClusterIGivenX.put(iditer,clusterProbabilities);
  }
  return emSum / relation.size();
}

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 [ ] probabilities = new double [ k ] ; { int i = 0 ; for ( EMClusterModel < ? > m : models ) { probabilities [ i ] = m . estimateDensity ( vec ) ; ++ i ; } } double priorProbability = 0. ; for ( int i = 0 ; i < k ; i ++ ) { priorProbability += probabilities [ i ] ; } double logP = Math . max ( Math . log ( priorProbability ) , MIN_LOGLIKELIHOOD ) ; emSum += ( logP == logP ) ? logP : 0. ; double [ ] clusterProbabilities = new double [ k ] ; if ( priorProbability > 0. ) { for ( int i = 0 ; i < k ; i ++ ) { clusterProbabilities [ i ] = probabilities [ i ] / priorProbability ; } } probClusterIGivenX . put ( iditer , clusterProbabilities ) ; } 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 . computed as the sum of the logarithms of the prior probability of each instance .
