Rewards#
Rewards assign weights to states in the state space. They are used behind the scenes
to calculate different coalescent tree statistics but can also be passed directly to
moment() to calculate more complex statistics.
- class Reward[source]#
Bases:
ABCBase class for reward generation.
- prod(*rewards: Reward)[source]#
Product of this reward with other rewards.
- Parameters:
rewards (
Reward) – Rewards to take the product with.- Return type:
- Returns:
Product of the rewards.
- supports(state_space: Type[StateSpace])[source]#
Check if the reward supports the given state space.
- Parameters:
state_space (
Type[StateSpace]) – state space- Return type:
bool- Returns:
True if the reward supports the state space, False otherwise
- static support(state_space: Type[StateSpace], rewards: Iterable[Reward])[source]#
Check if the rewards support the given state space.
- Parameters:
state_space (
Type[StateSpace]) – state spacerewards (
Iterable[Reward]) – rewards
- Return type:
bool- Returns:
True if the rewards support the state space, False otherwise
- class LineageCountingReward[source]#
Bases:
Reward,ABCBase class for rewards that count lineages. Such rewards are compatible with
LineageCountingStateSpace.
- class BlockCountingReward[source]#
Bases:
Reward,ABCBase class for rewards that count blocks. Such rewards are compatible with
BlockCountingStateSpace.
- class TreeHeightReward[source]#
Bases:
LineageCountingReward,BlockCountingRewardReward for tree height. Note that when using multiple loci, this will provide the height of the locus with the highest tree.
- class TotalTreeHeightReward[source]#
Bases:
LineageCountingReward,BlockCountingRewardReward based on tree height. When using multiple loci, this will provide the sum of the tree heights over all loci, regardless of whether they are linked or not.
- class TotalBranchLengthReward[source]#
Bases:
LineageCountingReward,BlockCountingRewardReward for total branch length. When using multiple loci, this will provide the sum of the total branch lengths over all loci, regardless of whether they are linked or not. Note that due to inherent limitation to rewards, we cannot determine the total branch length of the tree with the largest total branch length as done in
TreeHeightReward.
- class UnfoldedSFSReward(index: int)[source]#
Bases:
SFSReward,BlockCountingRewardReward for unfolded site frequency spectrum (SFS).
- class FoldedSFSReward(index: int)[source]#
Bases:
SFSReward,BlockCountingRewardReward for folded site frequency spectrum (SFS).
- class StateReward(state: int)[source]#
Bases:
RewardReward for a specific state in the state space. This is useful for debugging or testing purposes.
- class LineageReward(n: int)[source]#
Bases:
LineageCountingRewardReward for a specific number of lineages present in across all demes and loci. This reward can be used to, for example, track the individual coalescent times.
- class DemeReward(pop: str)[source]#
Bases:
LineageCountingReward,BlockCountingRewardReward fraction of lineages in a specific deme. Taking the product of this reward with another reward will result in a reward that only considers the specified deme. Use
SumRewardto marginalize over several demes.
- class LocusReward(locus: int)[source]#
Bases:
LineageCountingRewardReward fraction of lineages in a specific locus. Taking the product of this reward with another reward will result in a reward that only considers the specified locus.
- class UnitReward[source]#
Bases:
LineageCountingReward,BlockCountingRewardReward all states with 1 (including absorbing states).
- class BlockCountingUnitReward[source]#
Bases:
BlockCountingRewardReward all states with 1 (including absorbing states), and only support block-counting state spaces. This reward can be used to force usage of the block-counting state space.
- class TotalBranchLengthLocusReward(locus: int)[source]#
Bases:
LocusReward,LineageCountingRewardReward for total branch length per locus. This is needed as the taking the product of
TotalBranchLengthRewardandLocusRewardwill not work as expected (seeCombinedReward).
- class ProductReward(rewards: List[Reward])[source]#
Bases:
CompositeRewardThe product of multiple rewards.
- class CombinedReward(rewards: List[Reward])[source]#
Bases:
ProductRewardClass extending ProductReward to allow for more intuitive combination of rewards.
- class CustomReward(func: ~typing.Callable[[~phasegen.state_space.StateSpace], ~numpy.ndarray], supports: ~typing.Callable[[~typing.Type[~phasegen.state_space.StateSpace]], bool] = <function CustomReward.<lambda>>)[source]#
Bases:
RewardCustom reward based on a user-defined function.
- __init__(func: ~typing.Callable[[~phasegen.state_space.StateSpace], ~numpy.ndarray], supports: ~typing.Callable[[~typing.Type[~phasegen.state_space.StateSpace]], bool] = <function CustomReward.<lambda>>)[source]#
Initialize the custom reward.
- Parameters:
func (
Callable[[StateSpace],ndarray]) – The function to use to calculate the reward vector.supports (
Callable[[Type[StateSpace]],bool]) – The function to use to check if the reward supports the state space.
-
func:
Callable[[StateSpace],ndarray]# The function to calculate the reward vector
- supports(state_space: Type[StateSpace])[source]#
Check if the reward supports the given state space.
- Parameters:
state_space (
Type[StateSpace]) – state space- Return type:
bool- Returns:
True if the reward supports the state space, False otherwise