Quickstart#
Import pattern#
import phypanda as pp
All concrete measures are objects implementing DiversityMeasure (compute_diversity for a fixed taxon set, and usually solve_maximization for budgeted selection). They are exposed as module-level singletons on phypanda.
Which PD measures are implemented?#
Measure ( |
Role |
Typical algorithm / backend |
Status |
|---|---|---|---|
|
All-paths diversity (MAPD objective on the network). |
Budgeted MAPPD: node-scanwidth FPT ( |
Implemented (see All-paths (MAPD) measure, All-paths solvers). |
|
Max-tree PD: maximize PD over displayed trees under a budget. |
Node-scanwidth DP on a tree extension (Numba-accelerated merges by default). |
Implemented (Max-tree PD). |
|
Min-tree PD: minimize PD over displayed trees for a fixed taxon set. |
Node-scanwidth DP; optional extension for the full network with automatic adaptation when inducing on a subset (Min-tree PD). |
Implemented (Min-tree PD). |
|
Placeholders for additional measures. |
— |
Stubs (raise |
How a typical solve works#
Input: a
DirectedPhyNetworknetwork, integer budget (B), and a cost per taxon (default: unit costs).Tree extension (unless you supply one): for node-scanwidth solvers,
scanwidthbuilds (or you provide) a tree extension Γ of the network DAG—valid for the DP order.DP: the solver fills tables along Γ (and merges child states at reticulations). For MAPPD, choose
algorithm="nsw_fpt_budget"or"esw_fpt"onAllPathsDiversity.solve_maximization.Output: objective value and a set of selected taxon labels.
Parallel edges: several routines require a network without parallel arcs; phylozoo may merge them in preprocessing.
High-level helpers#
phypanda.base adds generic wrappers that dispatch to any measure:
diversity()— fixed-set score.marginal_diversities()— per-taxon gain/loss vs. a current set.greedy_max_diversity()— greedy budgeted construction.solve_max_diversity()— callsmeasure.solve_maximization(exact when the measure implements it).
See Base helpers for signatures.
Examples#
Fixed taxon set — all-paths diversity
import phypanda as pp
# network: phylozoo DirectedPhyNetwork
value = pp.diversity(network, {"t1", "t2", "t3"}, measure=pp.all_paths)
Budgeted MAPPD (default NSW FPT backend)
import phypanda as pp
costs = {t: 1 for t in network.taxa}
value, taxa = pp.all_paths.solve_maximization(
network,
budget=50,
costs=costs,
algorithm="nsw_fpt_budget",
)
Budgeted max-tree PD
import phypanda as pp
value, taxa = pp.max_tree.solve_maximization(
network,
budget=50,
costs={t: 1 for t in network.taxa},
)
Min-tree PD on a subset of taxa (extension may be computed once on the full network)
import phypanda as pp
from scanwidth import DAG, node_scanwidth
dag = DAG(network._graph._graph)
_, ext = node_scanwidth(dag)
te = ext.to_canonical_tree_extension()
score = pp.min_tree.compute_diversity(
network,
{"t1", "t2"},
tree_extension=te,
)
Next steps#
Full parameter lists, exceptions, and solver kwargs: API reference.
Supplementary scripts and datasets:
experiments/in the GitHub repo.