Skip to content

T-200: Decouple R-loop search from MorphyLib; add concavity parameter#216

Closed
ms609 wants to merge 10 commits into
cpp-searchfrom
feature/native-search
Closed

T-200: Decouple R-loop search from MorphyLib; add concavity parameter#216
ms609 wants to merge 10 commits into
cpp-searchfrom
feature/native-search

Conversation

@ms609

@ms609 ms609 commented Mar 24, 2026

Copy link
Copy Markdown
Owner

Agent B

Summary

Replaces MorphyLib scoring in TreeSearch(), Ratchet(), Jackknife() with
native C++ engine (ts_fitch_score()), while retaining backward compatibility
for users passing MorphyLib scorers explicitly.

New exports

  • PrepareNativeData() — replaces PhyDat2Morphy()
  • CleanNativeData() — replaces UnloadMorphy()
  • NativeLength() — replaces MorphyLength()
  • NativeBootstrap() — replaces MorphyBootstrap()

Changed defaults

TreeSearch, Ratchet, Jackknife, and EdgeListSearch now default to
native scorers. New concavity parameter (default Inf = equal weights)
makes implied-weights searches trivial:

TreeSearch(tree, dataset, concavity = 10)

Deprecations

PhyDat2Morphy, UnloadMorphy, MorphyLength, MorphyTreeLength,
MorphyBootstrap emit .Deprecated() warnings.

Vignette

custom.Rmd IW section rewritten from ~150 lines of MorphyLib scaffolding
to ~30 lines.

Tests

7 new tests in test-NativeSearch.R. Existing tests updated to use native
defaults. 50 pass / 0 fail.

Note

Native scorer uses simple IW (fit = e / (e + k)), matching
TreeLength(..., extended_iw = FALSE). XPIWE (Extension 3) remains in the
C++ search path.

ms609 added 2 commits March 26, 2026 11:02
- New R/NativeSearch.R: PrepareNativeData, CleanNativeData,
  NativeLength, NativeBootstrap (4 exported functions)
- TreeSearch(), Ratchet(), Jackknife() now default to native scorer
- New 'concavity' parameter on all three functions
- Jackknife() rewritten to support both native and morphy paths
- EdgeListSearch() default scorer changed to NativeLength
- Deprecated: PhyDat2Morphy, UnloadMorphy, MorphyLength,
  MorphyTreeLength, MorphyBootstrap
- Vignette custom.Rmd IW section rewritten (was ~150 lines of
  MorphyLib scaffolding, now 30 lines using concavity parameter)
- test-NativeSearch.R: 7 tests covering all new functions
- test-CustomSearch.R: updated to use native defaults
Adds NativeSearch.Rd and updates Jackknife.Rd, Ratchet.Rd,
TreeSearch.Rd with new concavity parameter and default changes.
@ms609 ms609 force-pushed the feature/native-search branch from e25cbab to f59a193 Compare March 26, 2026 11:07
ms609 added a commit that referenced this pull request Mar 27, 2026
ms609 added 6 commits March 27, 2026 10:53
- inst/WORDLIST: add 'cleanup' and 'phyDat'
- R/mpl_morphy_objects.R: wrap PhyDat2Morphy/MorphyWeights @examples
  in \donttest{}; use suppressWarnings() for UnloadMorphy in
  GapHandler and SingleCharMorphy examples
- R/Morphy.R: wrap constraint example with suppressWarnings() so
  internal PhyDat2Morphy/UnloadMorphy calls don't emit warnings

Fixes 1 ERROR (spelling) + 1 WARNING (deprecated fns in examples)
Wrap PhyDat2Morphy() and UnloadMorphy() calls in suppressWarnings()
in the \examples{} sections of GapHandler.Rd, MorphyWeights.Rd,
PhyDat2Morphy.Rd, RearrangeEdges.Rd, and SingleCharMorphy.Rd.

Wrap Morphy() in suppressWarnings() in the \donttest{} block of
Morphy.Rd -- Morphy() calls PhyDat2Morphy/UnloadMorphy internally via
lapply/vapply, generating the 'FUN' is deprecated warning stream.

R CMD check --as-cran treats warnings-in-examples as errors.
ms609 added a commit that referenced this pull request Jun 16, 2026
Synthesise the best of PR #251 (this branch) and PR #216 (T-200, Agent B),
which independently decoupled the R-loop search from MorphyLib.

Adopted from #216:
- Efficient native scorer: PrepareData() pre-extracts the scoring matrices
  once and EdgeListScore() calls ts_fitch_score() directly, instead of
  rebuilding a phylo and re-extracting tip data on every score.
- `concavity` parameter on TreeSearch()/Ratchet()/Jackknife(): Inf = equal
  weights (default), finite = implied weights, "profile" = profile parsimony.
  Custom InitializeData hooks still receive the dataset unchanged.
- custom.Rmd implied-weights section rewritten from ~150 lines of hand-rolled
  scaffolding to a few lines using `concavity` directly.

Kept from #251 (and fixing #216's staleness):
- MorphyLib stays fully deleted (#216 retained it as a fallback).
- Score weights use .ScaleWeight() (fractional-weight aware) and Inf for the
  equal-weights concavity, matching current TreeLength(); #216 used
  as.integer(weight) and -1.0, predating those changes.
- Functional resampling + a regression test (doubling weights doubles score).

Naming: the layer is renamed to purpose-based names rather than #216's
`*Native*` prefix, because once MorphyLib is gone "Native" no longer contrasts
with anything.  PhyDat2Morphy->PrepareData, UnloadMorphy->ReleaseData,
is.morphyPtr->is.ParsimonyData, SingleCharMorphy->SingleCharData,
MorphyLength->EdgeListScore, MorphyTreeLength->TreeScore,
MorphyBootstrap->BootstrapTree, RandomMorphyTree->RandomPostorderTree.
The old names remain as .Deprecated() aliases.

TreeScore() == TreeLength() verified across equal weights, implied weights and
profile parsimony; full suite green (only the pre-existing WideSample/MaxMin
API-drift failures remain, unrelated to this change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ms609

ms609 commented Jun 16, 2026

Copy link
Copy Markdown
Owner Author

Superseded in #251

@ms609 ms609 closed this Jun 16, 2026
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.

1 participant