Skip to content

CCD2: compute the log probability of a tree with CCD2's own walk (#24) - #25

Open
alexeid wants to merge 1 commit into
masterfrom
fix/24-ccd2-log-probability
Open

alexeid wants to merge 1 commit into
masterfrom
fix/24-ccd2-log-probability

Conversation

@alexeid

@alexeid alexeid commented Nov 26, 2026

Copy link
Copy Markdown
Member

Fixes #24.

The bug

CCD2 overrode getProbabilityOfTree but inherited getLogProbabilityOfTree from AbstractCCD. The inherited method looks up partitions of plain clades, but CCD2's partitions are between ExtendedClades, so the lookup fails and every tree gets -Infinity.

ProbabilityBasedCredibleSetComputer.getCredibleLevel uses the log probability and returns -1 for -Infinity. So TreeCredibleLevel with CCD2 reported -1 for every tree.

The change

CCD2's probability walk (computeProbabilityOfVertices and computeProbabilityOfChildren) now takes a computeLog flag, as AbstractCCD.computeProbabilityOfVertex does. In log space it adds getLogCCP() instead of multiplying CCPs, and gives -Infinity where it gave 0. getProbabilityOfTree and the new getLogProbabilityOfTree both go through computeProbabilityOfTree(tree, computeLog). The non-log result is unchanged.

Testing

  • CCD2LogProbabilityTest (3 tests), on 5 taxa:

    • the log probability equals Math.log of the probability for every base tree and for the MAP tree;
    • an unseen tree gets -Infinity, and so does a tree that CCD1 supports but CCD2 doesn't, because a clade appears next to a sibling it never had in the base trees;
    • the credible level of the MAP tree is in (0, 1].

    On master, the first and third fail (-Infinity, and a credible level of -1).

  • mvn test: 113 tests, 0 failures, 1 skipped, against 110 on master.

  • 270 generated trees with 25 taxa: no tree gets -Infinity, and the largest difference from Math.log(getProbabilityOfTree) is 1.8e-15.

Independent of #23. Both touch CCD2.getProbabilityOfTree, so whichever merges second needs a one-line merge (prepareTree(tree) goes into computeProbabilityOfTree).

CCD2 overrode getProbabilityOfTree but inherited getLogProbabilityOfTree
from AbstractCCD, which looks up partitions of plain clades. CCD2's
partitions are between extended clades, so the lookup failed and every tree
got -Infinity. ProbabilityBasedCredibleSetComputer uses the log probability,
so TreeCredibleLevel with CCD2 reported -1 for every tree.

The probability walk now takes a computeLog flag, and getLogProbabilityOfTree
uses it, adding log CCPs.
@alexeid
alexeid requested a review from yangsoph November 26, 2026 01:39
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.

CCD2.getLogProbabilityOfTree returns -Infinity for trees it gives a positive probability

1 participant