Adams: O(kn log n) centroid-path consensus (Jansson, Li & Sung 2017)#7
Open
ms609 wants to merge 2 commits into
Open
Adams: O(kn log n) centroid-path consensus (Jansson, Li & Sung 2017)#7ms609 wants to merge 2 commits into
ms609 wants to merge 2 commits into
Conversation
Replace the pure-R Adams recursion (plus per-level Newick round-trip) with a C++ implementation of the O(kn log n) centroid-path algorithm of Jansson, Li & Sung (2017), filling the pre-registered adamsConsensusCpp stub. - src/cons_adams.cpp: per-input-tree Euler tour + sparse-table O(1) LCA; per recursion level the restricted subtree (nub) is rebuilt via the consecutive- LCA auxiliary-tree construction; the consensus "spine" (leaves under the heavy child of every input tree's root) is expanded iteratively down the centroid paths in unison -- the remaining block's per-tree position is its LCA depth, so path compression is handled -- recursing only on the <= |L'|/2 off-spine blocks. Reentrant, VLA-free, RAII. - R/adams.R: call the C++ path on each tree's OWN root (Adams is rooted; no re-rooting); drop the .AdamsNewick/.AdamsPartition helpers; @details updated. - Validated clade-for-clade against the slow FACT Adams (rule 512, rooted=1) across small, n=50/137, caterpillar and incongruent datasets (extended dev/oracle/check-oracle.R), plus an in-suite R reference fuzz and degree-1- suppression / n=3 traps (tests/testthat/test-adams.R). Full suite green; ~45x faster at n=200/k=50, scaling far better. - Housekeeping: DESCRIPTION 0.0.0.9008; NEWS bullet; AGENTS.md FACT_RULE fix (adams=512 slow, not 1024 buggy-fast); inst/WORDLIST. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Integrate the MajorityPlus, Frequency and tooling commits from main. Conflicts resolved: - NEWS.md: keep the 0.0.0.9007 dev heading (no separate bump) and both the Adams and MajorityPlus bullets. - inst/WORDLIST: keep both `radix` (main) and `reentrant` (here). - DESCRIPTION: keep Version 0.0.0.9007. Also extend the oracle self-guard to verify Adams (not only MajorityPlus) is on the C++ path. Full test suite (454) green; dev/oracle/check-oracle.R exits 0 (self-guard OK, Adams clade-exact vs slow FACT at scale, all methods MATCH). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7 +/- ##
==========================================
- Coverage 99.06% 98.98% -0.08%
==========================================
Files 18 18
Lines 2879 3154 +275
==========================================
+ Hits 2852 3122 +270
- Misses 27 32 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Reimplements
Adams()with the O(kn log n) centroid-path algorithm of Jansson, Li & Sung (2017) ("On finding the Adams consensus tree", Inf. Comput. 256:334–347;New_Adams_consensus_k, §3), replacing the pure-R recursion + per-level Newick round-trip and filling the pre-registeredadamsConsensusCppstub. The Adams consensus tree is unique, so the output is identical to the classical definition — only the running time changes.Algorithm (
src/cons_adams.cpp)lca_{T_j}(L')).R/adams.Rcalls the C++ path on each tree's own root (Adams is rooted — no re-rooting), keeps the trivial guards + integer round-trip, and drops the.AdamsNewick/.AdamsPartitionhelpers.Validation
fact.exerule 512, rooted = 1): clade-exact MATCH on every dataset, including the added larger-n / caterpillar / incongruent ones (n = 50/k20, n = 137/k10, n = 40 caterpillars).dev/oracle/check-oracle.Rexits 0; its self-guard now also verifies Adams is on the C++ path.tests/testthat/test-adams.R: 15 → 60 assertions — an independent in-suite R reference (the classical recursion) fuzzed over ~40 random / caterpillar / perturbed profiles, plus degree-1-suppression traps (star, identical caterpillar) and n = 3.dev/profiling/compare.R Adams): large win (e.g. n = 200 / k = 50: 0.905 s → 0.02 s, ~45×), scaling far better; no flagged regressions.Housekeeping
NEWS bullet (kept under the shared
0.0.0.9007dev heading);AGENTS.mdFACT_RULE fix (adams=512slow, not the stale1024buggy-fast) + method-roster line;inst/WORDLIST.roxygenise()only —RcppExports.*content untouched.🤖 Generated with Claude Code