elynx-markov-0.5.0.2: Simulate molecular sequences along trees
Copyright(c) Dominik Schrempf 2017
LicenseGPLv3
Maintainerdominik.schrempf@gmail.com
Stabilityunstable
Portabilitynon-portable (not tested)
Safe HaskellNone
LanguageHaskell2010

ELynx.Data.MarkovProcess.RateMatrix

Description

Some helper functions that come handy when working with rate matrices of continuous-time discrete-state Markov processes.

  • Changelog

To be imported qualified.

Synopsis

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)?

exchFromListLower :: (RealFrac a, Container Vector a) => Int -> [a] -> Matrix a Source #

Build exchangeability matrix from list denoting lower triangular matrix, and excluding diagonal. This is how the exchangeabilities are specified in PAML.

exchFromListUpper :: (RealFrac a, Container Vector a) => Int -> [a] -> Matrix a Source #

Build exchangeability matrix from list denoting upper triangular matrix, and excluding diagonal.