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 implement the operations that the public helpers in phypanda.base call on their behalf.

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

>>> # value = pp.compute_diversity(network, {"a", "b"}, measure=pp.all_paths)
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

>>> # value, taxa = pp.solve_max_diversity(network, budget=5, measure=pp.all_paths)