Copyright | 2021 Dominik Schrempf |
---|---|
License | GPLv3 |
Maintainer | dominik.schrempf@gmail.com |
Stability | unstable |
Portability | non-portable (not tested) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Some helper functions that come handy when working with rate matrices of continuous-time discrete-state Markov processes.
- Changelog
To be imported qualified.
Synopsis
- type RateMatrix = Matrix R
- type ExchangeabilityMatrix = Matrix R
- type StationaryDistribution = Vector R
- isValid :: StationaryDistribution -> Bool
- normalizeSD :: StationaryDistribution -> StationaryDistribution
- totalRate :: RateMatrix -> Double
- totalRateWith :: StationaryDistribution -> RateMatrix -> Double
- normalize :: RateMatrix -> RateMatrix
- normalizeWith :: StationaryDistribution -> RateMatrix -> RateMatrix
- setDiagonal :: RateMatrix -> RateMatrix
- toExchangeabilityMatrix :: RateMatrix -> StationaryDistribution -> ExchangeabilityMatrix
- fromExchangeabilityMatrix :: ExchangeabilityMatrix -> StationaryDistribution -> RateMatrix
- getStationaryDistribution :: RateMatrix -> StationaryDistribution
- exchFromListLower :: (RealFrac a, Container Vector a) => Int -> [a] -> Matrix a
- exchFromListUpper :: (RealFrac a, Container Vector a) => Int -> [a] -> Matrix a
Documentation
type RateMatrix = Matrix R Source #
A rate matrix is just a real matrix.
type ExchangeabilityMatrix = Matrix R Source #
A matrix of exchangeabilities, we have q = e * pi, where q is a rate matrix, e is the exchangeability matrix and pi is the diagonal matrix containing the stationary frequency distribution.
type StationaryDistribution = Vector R Source #
Stationary distribution of a rate matrix.
isValid :: StationaryDistribution -> Bool Source #
True if distribution sums to 1.0.
normalizeSD :: StationaryDistribution -> StationaryDistribution Source #
Normalize a stationary distribution so that the elements sum to 1.0.
totalRate :: RateMatrix -> Double Source #
Get average number of substitutions per unit time.
totalRateWith :: StationaryDistribution -> RateMatrix -> Double Source #
Get average number of substitutions per unit time.
normalize :: RateMatrix -> RateMatrix Source #
Normalizes a Markov process generator such that one event happens per unit time. Calculates stationary distribution from rate matrix.
normalizeWith :: StationaryDistribution -> RateMatrix -> RateMatrix Source #
Normalizes a Markov process generator such that one event happens per unit time. Faster, but stationary distribution has to be given.
setDiagonal :: RateMatrix -> RateMatrix Source #
Set the diagonal entries of a matrix such that the rows sum to 0.
toExchangeabilityMatrix :: RateMatrix -> StationaryDistribution -> ExchangeabilityMatrix Source #
Extract the exchangeability matrix from a rate matrix.
fromExchangeabilityMatrix :: ExchangeabilityMatrix -> StationaryDistribution -> RateMatrix Source #
Convert exchangeability matrix to rate matrix.
getStationaryDistribution :: RateMatrix -> StationaryDistribution Source #
Get stationary distribution from RateMatrix
. Involves eigendecomposition.
If the given matrix does not satisfy the required properties of transition
rate matrices and no eigenvector with an eigenvalue nearly equal to 0 is
found, an error is thrown. Is there an easier way to calculate the stationary
distribution or a better way to handle errors (of course I could use the
Maybe monad, but then the error report is just delayed to the calling
function)?