You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two fixes in ModelMixture::optimizeWithEM (used by -mfopt -optalg_qmix EM). The issues were reported by Ryo.
EM made the result worse instead of better (the final log-likelihood was lower than the start). The E-step used old partial-likelihood values that were not updated for the current model, so the per-class weights were wrong. Fix: call clearAllPartialLH() before each computePatternLhCat that builds the weights, so the values are recomputed.
Crash when -mem is used. Fix: copy max_lh_slots to the inner tree.
Tested on LG+C10+G4 (20 taxa, 5000 sites): EM now improves correctly, runs with -mem 4G and -mem 1G without crashing, and the non--mem and BFGS runs are unchanged.
The bug causing the -mem crash has already been fixed by yet not merged #173 in a more safe and general way: the max_lh_slots member, if zero, is always computed by a initializeAllPartialLh() call. In ModelMixture::optimizeWithEM(), this call happens at the end of the across-submodel for-loop.
I think having max_lh_slots always checked and set automatically is a better solution than copying it manually because if a similar problem occurs in some similar place in the code where a temporary copy of the tree is used, it will be already solved.
Thanks @StefanFlaumberg
Since the -mem issue is already addressed in your PR, there is no need to fix it here as well. I have therefore removed that fix, leaving only the fix for the EM optimisation issue.
thomaskf
changed the title
Fix EM mixture-frequency optimization: wrong result and -mem crash
Fix EM mixture-frequency optimization
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two fixes in
ModelMixture::optimizeWithEM(used by-mfopt -optalg_qmix EM). The issues were reported by Ryo.EM made the result worse instead of better (the final log-likelihood was lower than the start). The E-step used old partial-likelihood values that were not updated for the current model, so the per-class weights were wrong. Fix: call
clearAllPartialLH()before eachcomputePatternLhCatthat builds the weights, so the values are recomputed.Crash when
-memis used. Fix: copymax_lh_slotsto the inner tree.-mem 4Gand-mem 1Gwithout crashing, and the non--memand BFGS runs are unchanged.