markov-chain-usage-model-0.0.0: Computations for Markov chain usage models

Safe HaskellNone
LanguageHaskell2010

MarkovChain

Synopsis

Documentation

(.*) :: M -> M -> M infixl 7 Source #

(./) :: M -> M -> M infixl 7 Source #

(.-) :: M -> M -> M infixl 6 Source #

(^*) :: Double -> M -> M infixl 7 Source #

fundamental Source #

Arguments

:: M

Reduced matrix (n x n).

-> M

n x n

The fundamental matrix for absorbing chains. Its (i, j)-th entry is the expected number of occurrences of state j prior to absorption at the sink, given that one starts in state i. So the first row indicates the expected occurence of each state starting from the start state.

>>> fundamental (minorMatrix 5 5 p :: M)
┌                                                                                 ┐
│                 1.0  1.2307692307692306  1.2307692307692308  0.9230769230769231 │
│                 0.0  1.2307692307692306  1.2307692307692308  0.9230769230769231 │
│                 0.0 0.15384615384615385  2.1538461538461537  0.6153846153846154 │
│                 0.0  0.3076923076923077  0.3076923076923077  1.2307692307692308 │
└                                                                                 ┘

occVariance Source #

Arguments

:: M

Reduced matrix (n x n).

-> M 

Expected variance of the occurrence for each state. The (i, j)-th entry should be read in the same away as that of the fundamental matrix above.

>>> occVariance (fundamental (minorMatrix 5 5 p :: M))
┌                                                                                 ┐
│                 0.0 0.28402366863905315  2.5562130177514795  0.4970414201183433 │
│                 0.0 0.28402366863905315  2.5562130177514795  0.4970414201183433 │
│                 0.0 0.20118343195266267  2.4852071005917153  0.5207100591715977 │
│                 0.0  0.3550295857988165  0.9230769230769231  0.2840236686390534 │
└                                                                                 ┘

perron Source #

Arguments

:: M

Transition matrix (n x n).

-> V 

The Perron eigenvector (long-run occupancies/probabilities of states).

>>> perron p
[0.1857142857142857,0.22857142857142854,0.22857142857142856,0.17142857142857143,0.1857142857142857]

sigma Source #

Arguments

:: M

Stimulus matrix (n-1 x n).

-> V

Perron eigenvector.

-> V 

Compute the stimulus long-run occupancy.

>>> :{
let s :: M
   s = fromList 4 5
     [ 1,    0,    0,    0,    0
     , 0,    0.5,  0.5,  0,    0
     , 0,    0.5,  0.25, 0.25, 0
     , 0.25, 0,    0,    0.5,  0.25
     ]
in sigma s (perron p)
:}
[0.2807017543859649,0.2807017543859649,0.21052631578947367,0.17543859649122806,5.2631578947368425e-2]

nodeProbabilities Source #

Arguments

:: M

Transition matrix (n x n).

-> M 

Compute the probability of occurrence for each state.

>>> getRow 1 (nodeProbabilities p)
[1.0,1.0,0.5714285714285715,0.75]

expectedLength Source #

Arguments

:: M

Fundamental matrix (n x n).

-> Double 

Expected test case length.

>>> expectedLength (fundamental (minorMatrix 5 5 p :: M))
4.384615384615385

expectedArcReliability Source #

Arguments

:: Maybe (M, M) 
-> (M, M) 
-> (M, M)

(mean, variance)

Success rate matrix.

>>> expectedArcReliability Nothing (fromList 2 2 [10,10,10,10], fromList 2 2 [0,1,2,3])
(┌                                       ┐
│ 0.9166666666666666 0.8461538461538461 │
│ 0.7857142857142857 0.7333333333333333 │
└                                       ┘,┌                                             ┐
│  5.876068376068376e-3  9.298393913778529e-3 │
│ 1.1224489795918367e-2 1.2222222222222223e-2 │
└                                             ┘)
>>> :{
 expectedArcReliability
   (Just (fromList 2 2 [10,10,10,10], fromList 2 2 [1,1,1,1]))
   (fromList 2 2 [10,10,10,10], fromList 2 2 [0,1,2,3])
:}
(┌                                       ┐
│ 0.9130434782608695              0.875 │
│               0.84 0.8076923076923077 │
└                                       ┘,┌                                             ┐
│ 3.3081285444234404e-3              4.375e-3 │
│  5.169230769230769e-3  5.752794214332676e-3 │
└                                             ┘)

transientReliability Source #

Arguments

:: M

Reduced transition matrix (n-1 x n).

-> Maybe (M, M)

Prior successes and failures (n-1 x n).

-> (M, M)

Observed successes and failures (n-1 x n).

-> (M, M)

Reliability vector and reliability variance vector.

singleUseReliability Source #

Arguments

:: M

Reduced transition matrix (n-1 x n).

-> Maybe (M, M)

Prior successes and failures (n-1 x n).

-> (M, M)

Observed successes and failures (n-1 x n).

-> (Double, Double) 

kullbackLeibler Source #

Arguments

:: M

Transitions (n x n).

-> M

Stimulis (m x n).

-> V

State visitations (n).

-> M

Stimulus execution (m x n).

-> Double

Discrimination.

Kullback-Leibler matrix discrimination.

>>> :{
let
 s = fromList 4 5
       [ 1,    0,   0,    0,    0
       , 0,    0.5, 0.5,  0,    0
       , 0,    0.5, 0.25, 0.25, 0
       , 0.25, 0,   0,    0.5,  0.25
       ]
 es = Vector.fromList [4, 5, 7, 3, 4]
 et = fromList 4 5
   [ 4, 0, 0, 0, 0
   , 0, 3, 2, 0, 0
   , 0, 4, 1, 2, 0
   , 1, 0, 0, 1, 1
   ]
in kullbackLeibler p s es et
:}
3.440540391434413e-2