fixing a bug, improving CvEM::predict and CvEM::calcLikelihood (Patch #1361)


Added by Alexander Alekseychuk over 13 years ago. Updated almost 13 years ago.


Status:Done Start date:
Priority:High Due date:
Assignee:Maria Dimashova % Done:

0%

Category:ml
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

CvEM::predict and CvEM::calcLikelihood have one and the same bug starting at least from release version 2.3.0 and up to the current SVN (rev. 6603). It's merely a typo: somebody tried to account for 2Pi^(dims/2) factor and wrote "cvAndS" instead of "cvAddS" )).

The attached patch corrects this bug and also contains several other improvements of these functions:

1. The log-sum-exp trick can be done in place, without allocation of additional memory and copying of arrays.

2. Correcting for 2Pi^(dims/2) in CvEM::predict is absolutely redundant because of the normalization which comes just several lines afterwards and thus can be avoided for performance reasons. Whereas "-0.5" scaling is still necessary and must be performed only if _probs != NULL (for the same performance reasons).

3. The log-sum-exp trick is surely also useful in CvEM::predict (and even more than in calcLikelihood), thus it is implemented (in the same way as in CvEM::calcLikelihood, with minor changes).

4. If CvEM::run_em runs with "start_step == START_E_STEP" and detects singularity of covariance matrix eigenvalues it just silently exits, leaving "inv_eigen_values" uninitialized and "log_weight_div_det" with wrong values. IMHO it is not a good idea because it is done silently and if one will try to use "predict" after that she/he will wonder about results. It seems to me that a much better solution would be to just let it running, i.e. use pseudoinverce on the first step. After covariances will be recomputed on the m-step they will be almost sure nonsingular so we can proceed as usual and hopefully get meaningful results.

The attached patch has to be applied after my previous patch to rev. 6603 (regarding broken k-means).

With hope that this helps and with best regards,
Alexander Alekseychuk


em.patch - patch to fix problems in CvEM::predict and CvEM::calcLikelihood (7.2 kB) Alexander Alekseychuk, 2011-09-10 02:21 am


Related issues

related to Patch #1351: fixing wrong results, segfaults and out of memory in CvEM Done

Associated revisions

Revision 53818f0f
Added by Roman Donchenko over 11 years ago

Merge pull request #1361 from asmorkalov:winrt_api_container

History

Updated by Nghia Ho over 13 years ago

I hope your patch makes it in as soon as possible! CvEM has been broken for me for a very long time.

Prior to the calcLikelihood() function, there was no way to use CvEM to do something as simple as classifying whether a pixel is foreground/background, because the predict() function returned normalised probability values, instead of absolute. Making comparisons like if(probFG > probBG) invalid. I had to keep modifying the code for every release (I added a ticket about 8 months ago but got no response).

Updated by Alexander Shishkov about 13 years ago

  • Description changed from [[CvEM]]::predict and [[CvEM]]::calcLikelihood have one and the same bug sta... to CvEM::predict and CvEM::calcLikelihood have one and the same bug starting at ... More

Updated by Kirill Kornyakov about 13 years ago

  • Tracker changed from Feature to Patch

Updated by Alexander Shishkov almost 13 years ago

  • Priority changed from High to Normal
  • Target version deleted ()

Updated by Alexander Shishkov almost 13 years ago

  • Priority changed from Normal to High

Updated by Alexander Shishkov almost 13 years ago

  • Assignee deleted (Maria Dimashova)

Updated by Maria Dimashova almost 13 years ago

  • Assignee set to Maria Dimashova

Updated by Alexander Shishkov almost 13 years ago

  • Target version deleted ()

Updated by Maria Dimashova almost 13 years ago

Thanks for this your report too. See my comment to the ticket #1351 about cv::EM. Reported bugs were fixed in cv::EM (in CvEM respectively) and improvements were applied. If you'll find some other problems or ways for improvement, please open an issue.

  • Status changed from Open to Done

Updated by Andrey Kamaev almost 13 years ago

  • Target version set to 2.4.0

Also available in: Atom PDF