From 84aff376a7cf44b981e52e58419e8a63a4d8f15f Mon Sep 17 00:00:00 2001 From: Maria Dimashova Date: Fri, 6 Apr 2012 17:06:35 +0000 Subject: [PATCH] fixed em log likelihood --- modules/ml/src/em.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ml/src/em.cpp b/modules/ml/src/em.cpp index 432f7b930b..7b9fc686a7 100644 --- a/modules/ml/src/em.cpp +++ b/modules/ml/src/em.cpp @@ -485,6 +485,7 @@ void EM::computeProbabilities(const Mat& sample, int& label, Mat* probs, float* exp(L, expL); float partExpSum = 0, // sum_j!=q (exp(L_jk) factor; // 1/(1 + sum_j!=q (exp(L_jk)) + float prevL = expL.at(label); for(int clusterIndex = 0; clusterIndex < nclusters; clusterIndex++) { if(clusterIndex != label) @@ -504,7 +505,7 @@ void EM::computeProbabilities(const Mat& sample, int& label, Mat* probs, float* if(likelihood) { // note likelihood = log (sum_j exp(L_ij)) - 0.5 * dims * ln2Pi - *likelihood = std::log(partExpSum + expL.at(label)) - (float)(0.5 * dim * CV_LOG2PI); + *likelihood = std::log(prevL + partExpSum) - (float)(0.5 * dim * CV_LOG2PI); } }