Substitution Models¶
Rate matrix eigendecomposition and transition probability computation.
EigenDecomp
dataclass
¶
Cached eigendecomposition of a reversible CTMC rate matrix.
Attributes:
| Name | Type | Description |
|---|---|---|
n_states |
int
|
Number of character states (4 for DNA). |
freqs |
ndarray
|
float64, shape (n_states,). Stationary frequencies. |
sqrt_pi |
ndarray
|
float64, shape (n_states,). Element-wise |
inv_sqrt_pi |
ndarray
|
float64, shape (n_states,). Element-wise |
eigvals |
ndarray
|
float64, shape (n_states,). Eigenvalues of the symmetrised matrix S, in ascending order. |
U |
ndarray
|
float64, shape (n_states, n_states). Orthonormal eigenvectors of S (columns); used in the P(t) computation. |
Source code in src/hifuku/substitution.py
|
p_t
¶
Return the transition probability matrix P(t) as float64 (n_states, n_states).
P(t)[i,j] = probability of transitioning from state i to state j in time t. Rows sum to 1. P(0) = identity.
Notes
- Felsenstein (1981) : transition matrix via matrix exponentiation.
- Fourment et al. (2025) : .p_t pattern.
Source code in src/hifuku/substitution.py
|
jc69
¶
JC69 rate matrix eigendecomposition.
Equal stationary frequencies (1/4 each) and equal exchangeabilities. Normalised so that the mean substitution rate equals 1.
Returns:
| Type | Description |
|---|---|
EigenDecomp
|
Ready to pass to |
Notes
- Felsenstein (1981) : JC69 as special case of GTR.
Source code in src/hifuku/substitution.py
|
gtr
¶
GTR rate matrix eigendecomposition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rates
|
float64 (6,) - exchangeability parameters (AC, AG, AT, CG, CT, GT).
|
|
required |
freqs
|
float64 (4,) - stationary base frequencies (A, C, G, T).
|
|
required |
Notes
- Tavaré (1986) : GTR rate matrix parameterization.
- Fourment et al. (2025) : eigendecomposition via symmetrisation.
Source code in src/hifuku/substitution.py
|