Repository navigation
feat: add BME objective and branch lengths - #232
Merged
Merged
Conversation
Add vector/objectives.rs with: - bme_objective: Pauplin's balanced minimum evolution (BME) length of the unrooted tree encoded by a vector, for a distance matrix D. - bme_branch_lengths: FastME/Desper & Gascuel BME branch lengths, in the branch-length layout of a Phylo2Vec matrix. They sum to the BME length, are returned unclamped, and the edge through the root is split equally between the root's two child edges. Both come from one pass that visits each leaf pair once, at its lowest common ancestor, and spreads its weight over the edges of its path with a difference array: O(n^2) time and O(n) extra memory. Also ignore the local notes/ folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Expose bme_objective and bme_branch_lengths in phylo2vec.opt. Both take a Phylo2Vec vector or matrix (only the topology is used) and a distance matrix, which must be n x n: otherwise they raise a ValueError instead of a Rust panic. Branch lengths are returned unclamped, in the layout of the branch lengths of a Phylo2Vec matrix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Export bme_objective and bme_branch_lengths from a new R/opt.R, mirroring phylo2vec.opt in Python. Both take a phylo2vec vector or matrix (only the topology is used) and a distance matrix, whose shape is checked in R so that a wrong one raises a readable error. Branch lengths are returned unclamped, in the layout of the branch lengths of a phylo2vec matrix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Adds the balanced minimum evolution (BME) criterion, as a first step towards BME tree search in
phylo2vec.opt.bme_objective(tree, dm): Pauplin's BME length of the unrooted tree,L = sum_{i<j} 2^(1 - tau_ij) * dm[i, j], wheretau_ijis the number of edges between leavesiandj.bme_branch_lengths(tree, dm): FastME/Desper & Gascuel BME branch lengths, in the branch-length layout of a Phylo2Vec matrix. They sum toLand are returned unclamped: negative lengths signal a topology that fitsdmpoorly.Both take a vector or a matrix (only the topology is used) and visit each leaf pair once, at its lowest common ancestor: O(n²) time, O(n) extra memory. Rust core in
vector/objectives.rs, Python inphylo2vec.opt, R inR/opt.R.