State Space#
State space classes and utilities. The two main state space classes are
LineageCountingStateSpace and BlockCountingStateSpace.
- class StateSpace(lineage_config: LineageConfig, locus_config: LocusConfig = None, model: CoalescentModel = None, epoch: Epoch = None)[source]#
Bases:
ABCState space.
- __init__(lineage_config: LineageConfig, locus_config: LocusConfig = None, model: CoalescentModel = None, epoch: Epoch = None)[source]#
Create a rate matrix.
- Parameters:
lineage_config (
LineageConfig) – Population configuration.locus_config (
LocusConfig) – Locus configuration. One locus is used by default.model (
CoalescentModel) – Coalescent model. By default, the standard coalescent is used.epoch (
Epoch) – The epoch.
-
model:
CoalescentModel# Coalescent model
-
lineage_config:
LineageConfig# Population configuration
-
locus_config:
LocusConfig# Locus configuration
- property lineages: ndarray#
The lineage configurations. Each configuration describes the lineages per block, deme and locus, i.e.,
[[[a_ijk]]]for blocki, demejand locusk.
- property linked: ndarray#
The linked lineages per block, deme and locus. :return:
- property unlinked: ndarray#
Unlinked lineages.
- property e: ndarray#
Vector with ones of size
k.
- property S: ndarray#
Intensity matrix.
- property alpha: ndarray#
Initial state vector.
- property k: int#
Number of states.
- property transition: Transition#
Transition.
- update_epoch(epoch: Epoch)[source]#
Update the epoch.
- Parameters:
epoch (
Epoch) – Epoch.- Returns:
State space.
- get_sparsity()[source]#
Get the sparsity of the rate matrix.
- Return type:
float- Returns:
The sparsity.
- plot_rates(file: str, view: bool = True, cleanup: bool = False, dpi: int = 400, ratio: float = 0.6, background_color: str = 'white', extension: str = 'png', format_state: Callable[[array], str] = None, format_transition: Callable[[Transition], str] = None)[source]#
Plot the rate matrix using graphviz. Note that graphviz must be installed which is an external dependency.
- Parameters:
file (
str) – File to save plot to.view (
bool) – Whether to view the plot.cleanup (
bool) – Whether to remove the source file.dpi (
int) – Dots per inch.ratio (
float) – Aspect ratio.background_color (
str) – Background color.extension (
str) – File format.format_state (
Callable[[array],str]) – Function to format state with state array as argument.format_transition (
Callable[[Transition],str]) – Function to format transition with transition as argument.
- class LineageCountingStateSpace(lineage_config: LineageConfig, locus_config: LocusConfig = None, model: CoalescentModel = None, epoch: Epoch = None)[source]#
Bases:
StateSpaceDefault rate matrix where there is one state per number of lineages for each deme and locus.
- property S: ndarray#
Intensity matrix.
- __init__(lineage_config: LineageConfig, locus_config: LocusConfig = None, model: CoalescentModel = None, epoch: Epoch = None)#
Create a rate matrix.
- Parameters:
lineage_config (
LineageConfig) – Population configuration.locus_config (
LocusConfig) – Locus configuration. One locus is used by default.model (
CoalescentModel) – Coalescent model. By default, the standard coalescent is used.epoch (
Epoch) – The epoch.
- property alpha: ndarray#
Initial state vector.
- drop_S()#
Drop the current rate matrix.
- drop_cache()#
Drop the rate matrix cache and current rate matrix.
- property e: ndarray#
Vector with ones of size
k.
- get_sparsity()#
Get the sparsity of the rate matrix.
- Return type:
float- Returns:
The sparsity.
- get_transitions()#
Get all possible transitions from the given state.
- property k: int#
Number of states.
- property lineages: ndarray#
The lineage configurations. Each configuration describes the lineages per block, deme and locus, i.e.,
[[[a_ijk]]]for blocki, demejand locusk.
- property linked: ndarray#
The linked lineages per block, deme and locus. :return:
- plot_rates(file: str, view: bool = True, cleanup: bool = False, dpi: int = 400, ratio: float = 0.6, background_color: str = 'white', extension: str = 'png', format_state: Callable[[array], str] = None, format_transition: Callable[[Transition], str] = None)#
Plot the rate matrix using graphviz. Note that graphviz must be installed which is an external dependency.
- Parameters:
file (
str) – File to save plot to.view (
bool) – Whether to view the plot.cleanup (
bool) – Whether to remove the source file.dpi (
int) – Dots per inch.ratio (
float) – Aspect ratio.background_color (
str) – Background color.extension (
str) – File format.format_state (
Callable[[array],str]) – Function to format state with state array as argument.format_transition (
Callable[[Transition],str]) – Function to format transition with transition as argument.
- property transition: Transition#
Transition.
- property unlinked: ndarray#
Unlinked lineages.
- update_epoch(epoch: Epoch)#
Update the epoch.
- Parameters:
epoch (
Epoch) – Epoch.- Returns:
State space.
-
model:
CoalescentModel# Coalescent model
-
lineage_config:
LineageConfig# Population configuration
-
locus_config:
LocusConfig# Locus configuration
-
time:
float|None#
- class BlockCountingStateSpace(lineage_config: LineageConfig, locus_config: LocusConfig = None, model: CoalescentModel = None, epoch: Epoch = None)[source]#
Bases:
StateSpaceRate matrix for block-counting state space where there is one state per sample configuration:
A block-counting state is a vector of length
nwhere each element represents the number of lineages subtendingilineages in the coalescent tree.\[(a_1,...,a_n) \in \mathbb{Z}_+^n : \sum_{i=1}^{n} i a_i = n.\]per deme and per locus. This state space can distinguish between different tree topologies and is thus used when computing statistics based on the SFS.
- __init__(lineage_config: LineageConfig, locus_config: LocusConfig = None, model: CoalescentModel = None, epoch: Epoch = None)[source]#
Create a rate matrix.
- Parameters:
lineage_config (
LineageConfig) – Population configuration.locus_config (
LocusConfig) – Locus configuration. One locus is used by default.model (
CoalescentModel) – Coalescent model. By default, the standard coalescent is used.epoch (
Epoch) – The epoch
- property S: ndarray#
Intensity matrix.
- property alpha: ndarray#
Initial state vector.
- drop_S()#
Drop the current rate matrix.
- drop_cache()#
Drop the rate matrix cache and current rate matrix.
- property e: ndarray#
Vector with ones of size
k.
- get_sparsity()#
Get the sparsity of the rate matrix.
- Return type:
float- Returns:
The sparsity.
- get_transitions()#
Get all possible transitions from the given state.
- property k: int#
Number of states.
- property lineages: ndarray#
The lineage configurations. Each configuration describes the lineages per block, deme and locus, i.e.,
[[[a_ijk]]]for blocki, demejand locusk.
- property linked: ndarray#
The linked lineages per block, deme and locus. :return:
- plot_rates(file: str, view: bool = True, cleanup: bool = False, dpi: int = 400, ratio: float = 0.6, background_color: str = 'white', extension: str = 'png', format_state: Callable[[array], str] = None, format_transition: Callable[[Transition], str] = None)#
Plot the rate matrix using graphviz. Note that graphviz must be installed which is an external dependency.
- Parameters:
file (
str) – File to save plot to.view (
bool) – Whether to view the plot.cleanup (
bool) – Whether to remove the source file.dpi (
int) – Dots per inch.ratio (
float) – Aspect ratio.background_color (
str) – Background color.extension (
str) – File format.format_state (
Callable[[array],str]) – Function to format state with state array as argument.format_transition (
Callable[[Transition],str]) – Function to format transition with transition as argument.
- property transition: Transition#
Transition.
- property unlinked: ndarray#
Unlinked lineages.
- update_epoch(epoch: Epoch)#
Update the epoch.
- Parameters:
epoch (
Epoch) – Epoch.- Returns:
State space.
-
model:
CoalescentModel# Coalescent model
-
lineage_config:
LineageConfig# Population configuration
-
locus_config:
LocusConfig# Locus configuration
-
time:
float|None#
- class Transition(state_space: StateSpace)[source]#
Bases:
objectClass representing a transition between two states.
- __init__(state_space: StateSpace)[source]#
Initialize a transition.
- Parameters:
state_space (
StateSpace) – State space.
-
state_space:
StateSpace# State space.
- static add_target(targets: Dict[State, Tuple[float, str]], target: State, rate: float, kind: str)[source]#
Add a target state to the list of targets.
- migrate_unlinked(source: State)[source]#
Get all possible unlinked migration transitions from the given state. Note that we also consider migration to unlinked when there is only one locus.
- class State(data: (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>))[source]#
Bases:
objectState utility class.
- LINKAGE = 0#
Axis for linkage.
- LOCUS = 1#
Axis for loci.
- DEME = 2#
Axis for demes.
- BLOCK = 3#
Axis for lineage blocks.
- __init__(data: (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>))[source]#
Initialize a state.
- Parameters:
data ((
ndarray,ndarray)) – State data.
-
data:
Tuple[ndarray,ndarray]# State data
- is_absorbing()[source]#
Whether a state is absorbing.
- Return type:
bool- Returns:
Whether the state is absorbing.
- property n_demes: int#
Get the number of demes.
- Returns:
The number of demes.
- property n_loci: int#
Get the number of loci.
- Returns:
The number of loci.
- property n_blocks: int#
Get the number of lineage blocks.
- Returns:
The number of lineage blocks.
- property lineages: ndarray#
Get the number of lineages.
- Returns:
The number of lineages.
- property linked: ndarray#
Get the number of linked lineages.
- Returns:
The number of linked lineages.
- property unlinked: ndarray#
Get the number of unlinked lineages.
- Returns:
The number of unlinked lineages.