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 (pp.…)

Role

Typical algorithm / backend

Status

all_paths

All-paths diversity (MAPD objective on the network).

Budgeted MAPPD: node-scanwidth FPT (algorithm="nsw_fpt_budget"); optional edge-scanwidth FPT (algorithm="esw_fpt"). Uses scanwidth for extensions unless you pass a TreeExtension.

Implemented (see All-paths (MAPD) measure, All-paths solvers).

max_tree

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

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).

tree, network, average_tree

Placeholders for additional measures.

Stubs (raise NotImplementedError; see Tree diversity (stub), Network diversity (stub), Average-tree diversity (stub)).

How a typical solve works#

  1. Input: a DirectedPhyNetwork network, integer budget (B), and a cost per taxon (default: unit costs).

  2. Tree extension (unless you supply one): for node-scanwidth solvers, scanwidth builds (or you provide) a tree extension Γ of the network DAG—valid for the DP order.

  3. DP: the solver fills tables along Γ (and merges child states at reticulations). For MAPPD, choose algorithm="nsw_fpt_budget" or "esw_fpt" on AllPathsDiversity.solve_maximization.

  4. 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:

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.