Skip to content

Fix EM mixture-frequency optimization#175

Merged
bqminh merged 1 commit into
iqtree:masterfrom
thomaskf:bugfix
Jun 18, 2026
Merged

Fix EM mixture-frequency optimization#175
bqminh merged 1 commit into
iqtree:masterfrom
thomaskf:bugfix

Conversation

@thomaskf

@thomaskf thomaskf commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Two fixes in ModelMixture::optimizeWithEM (used by -mfopt -optalg_qmix EM). The issues were reported by Ryo.

  1. 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.

  2. 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.

@StefanFlaumberg

Copy link
Copy Markdown
Contributor

Hi @thomaskf,

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.

Best regards,
Stefan

@thomaskf

Copy link
Copy Markdown
Collaborator Author

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 thomaskf changed the title Fix EM mixture-frequency optimization: wrong result and -mem crash Fix EM mixture-frequency optimization Jun 18, 2026

@bqminh bqminh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good

@bqminh bqminh merged commit 6c84d82 into iqtree:master Jun 18, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants