Base helpers#
Base functions for diversity calculations.
- phypanda.base.diversity(network: DirectedPhyNetwork, taxa: set[str], measure: DiversityMeasure, **kwargs: Any) float#
Compute diversity for a fixed taxon set.
- Parameters:
network (DirectedPhyNetwork) – Input phylogenetic network.
measure (DiversityMeasure) – Diversity measure implementation.
**kwargs (Any) – Measure-specific keyword arguments.
- Returns:
Diversity value for
taxa.- Return type:
- Raises:
PhyloZooValueError – If one or more taxa are not present in the network.
Examples
>>> import phypanda as pp >>> # value = pp.diversity(network, {"a", "b"}, measure=pp.all_paths)
- phypanda.base.greedy_max_diversity(network: DirectedPhyNetwork, budget: int, measure: DiversityMeasure, costs: Mapping[str, int] | None = None, **kwargs: Any) tuple[float, Set[str]]#
Greedily maximize diversity under an integer budget.
The selected taxon at each step is the affordable taxon with highest normalized gain
marginal_diversity / cost.- Parameters:
network (DirectedPhyNetwork) – Input phylogenetic network.
budget (int) – Total integer budget.
measure (DiversityMeasure) – Diversity measure implementation.
costs (Mapping[str, int] | None, optional) – Integer cost per taxon. If
None, unit costs are used.**kwargs (Any) – Measure-specific keyword arguments.
- Returns:
Greedy objective value and selected taxa.
- Return type:
Examples
>>> import phypanda as pp >>> # value, taxa = pp.greedy_max_diversity(network, 5, measure=pp.all_paths) >>> # sorted(taxa)
- phypanda.base.marginal_diversities(network: DirectedPhyNetwork, saved_taxa: set[str], measure: DiversityMeasure, **kwargs: Any) Dict[str, float]#
Compute marginal diversity contributions for all taxa.
- Parameters:
network (DirectedPhyNetwork) – Input phylogenetic network.
measure (DiversityMeasure) – Diversity measure implementation.
**kwargs (Any) – Measure-specific keyword arguments.
- Returns:
Mapping from taxon to marginal gain/loss relative to
saved_taxa.- Return type:
Examples
>>> import phypanda as pp >>> # marg = pp.marginal_diversities(network, {"a"}, measure=pp.all_paths)
- phypanda.base.solve_max_diversity(network: DirectedPhyNetwork, budget: int, measure: DiversityMeasure, costs: Mapping[str, int] | None = None, **kwargs: Any) tuple[float, Set[str]]#
Solve maximum diversity under an integer budget.
- Parameters:
network (DirectedPhyNetwork) – Input phylogenetic network.
budget (int) – Total integer budget.
measure (DiversityMeasure) – Diversity measure implementation.
costs (Mapping[str, int] | None, optional) – Integer cost per taxon. If
None, unit costs are used.**kwargs (Any) – Measure-specific keyword arguments.
- Returns:
Optimal objective value and selected taxa.
- Return type:
Examples
>>> import phypanda as pp >>> # value, taxa = pp.solve_max_diversity(network, 5, measure=pp.all_paths) >>> # len(taxa) <= 5