Measure protocol#

Protocol defining the interface for diversity measures.

class phypanda.protocol.DiversityMeasure(*args, **kwargs)#

Bases: Protocol

Protocol defining the interface for diversity measures.

Notes

Concrete measures expose two operations:

  • compute_diversity for scoring a fixed taxon set.

  • solve_maximization for selecting taxa under a budget.

compute_diversity(network: DirectedPhyNetwork, taxa: Set[str], **kwargs: Any) float#

Compute diversity for a fixed taxon set.

Parameters:
  • network (DirectedPhyNetwork) – Input phylogenetic network.

  • taxa (Set[str]) – Selected taxa.

  • **kwargs (Any) – Measure-specific keyword arguments.

Returns:

Diversity value.

Return type:

float

Examples

>>> # measure.compute_diversity(network, {"a", "b"})
solve_maximization(network: DirectedPhyNetwork, budget: int, costs: Mapping[str, int] | None = None, **kwargs: Any) tuple[float, Set[str]]#

Solve diversity maximization under budget constraints.

Parameters:
  • network (DirectedPhyNetwork) – Input phylogenetic network.

  • budget (int) – Total integer budget.

  • costs (Mapping[str, int] | None, optional) – Integer costs per taxon. If None, unit costs are assumed.

  • **kwargs (Any) – Measure-specific keyword arguments.

Returns:

Objective value and selected taxa.

Return type:

tuple[float, Set[str]]

Raises:

PhyloZooNotImplementedError – If the concrete measure does not support optimization.

Examples

>>> # measure.solve_maximization(network, budget=5)