11  Stochastic Processes

TOC

Misc

Terms

matrixpower(printers, 100)
    [,0]      [,1]      [,2]
[0,] 0.5882353 0.2941176 0.1176471
[1,] 0.5882353 0.2941176 0.1176471
[2,] 0.5882353 0.2941176 0.1176471

Transitions

# this is just matrix exponentiation and multiplying the square (based on row dim) identity matrix at the end for some reason (probably makes a diff for non-square matrices)
matrixpower <- function(mat,k) {
  if (k == 0) return (diag(dim(mat)[1]))  # 3x3 identity matrix
  if (k == 1) return(mat)
  if (k > 1) return( mat %*% matrixpower(mat, k-1))
} # matrix power function from Introduction to Stochastic Processes with R by Robert Dobrow

printers <- matrix(c(.7, .2, 1, .3, .4, 0, 0, .4, 0), nrow = 3, ncol = 3) # make the matrix
printers
    [,0] [,1] [,2]
[0,]  0.7  0.3  0.0
[1,]  0.2  0.4  0.4
[2,]  1.0  0.0  0.0

# 2-step
matrixpower(printers, 2)
    [,0] [,1] [,2]
[0,] 0.55 0.33 0.12
[1,] 0.62 0.22 0.16
[2,] 0.70 0.30 0.00

# also 3-step
matrixpower(printers, 3) 
      [,0]  [,1]  [,2] 
[0,] 0.571 0.297 0.132 
[1,] 0.638 0.274 0.088 
[2,] 0.550 0.330 0.120

Communication

reducible <-  matrix(c(0, 0, 0, 0, 0, .4, .9, .7, 0, 0, 0, .1, .3, 0, 0, .6, 0, 0, .5, .5, 0, 0, 0, .5, .5), nrow = 5, ncol = 5)
reducible
  [,0] [,1] [,2] [,3] [,4]
[0,]    0  0.4  0.0  0.6  0.0
[1,]    0  0.9  0.1  0.0  0.0
[2,]    0  0.7  0.3  0.0  0.0
[3,]    0  0.0  0.0  0.5  0.5
[4,]    0  0.0  0.0  0.5  0.5

matrixpower(reducible, 100)
  [,0]  [,1]  [,2] [,3] [,4]
[0,]    0 0.350 0.050  0.3  0.3
[1,]    0 0.875 0.125  0.0  0.0
[2,]    0 0.875 0.125  0.0  0.0
[3,]    0 0.000 0.000  0.5  0.5
[4,]    0 0.000 0.000  0.5  0.5

Random Walk

random_walk <- matrix(c(1, .5, 0, 0, 0, 0, 0, .5, 0, 0, 0, .5, 0, .5, 0, 0, 0, .5, 0, 0, 0, 0, 0, .5, 1),
                      nrow = 5,
                      ncol = 5)
    [,0] [,1] [,2] [,3] [,4]
[0,]  1.0  0.0  0.0  0.0  0.0
[1,]  0.5  0.0  0.5  0.0  0.0
[2,]  0.0  0.5  0.0  0.5  0.0
[3,]  0.0  0.0  0.5  0.0  0.5
[4,]  0.0  0.0  0.0  0.0  1.0
matrixpower(random_walk, 100)
    [,0]        [,1]        [,2]        [,3] [,4]
[0,] 1.00 0.000000e+00 0.000000e+00 0.000000e+00 0.00
[1,] 0.75 4.440892e-16 0.000000e+00 4.440892e-16 0.25
[2,] 0.50 0.000000e+00 8.881784e-16 0.000000e+00 0.50
[3,] 0.25 4.440892e-16 0.000000e+00 4.440892e-16 0.75
[4,] 0.00 0.000000e+00 0.000000e+00 0.000000e+00 1.00

Hidden Markov Models (HMM)