Éval de perf, TD4: Analyse du comportement d’un cache à l'aide de chaînes de Markov

Illustration de l'utilisation du package markovchain

library(markovchain)
weatherStates <- c("sunny", "cloudy", "rain")
byRow <- TRUE
weatherMatrix <- matrix(data = c(0.7, 0.2, 0.1, 0.3, 0.4, 0.3, 0.2, 0.45, 0.35), 
    byrow = byRow, nrow = 3, dimnames = list(weatherStates, weatherStates))
mcWeather <- new("markovchain", states = weatherStates, byrow = byRow, transitionMatrix = weatherMatrix, 
    name = "Weather")
show(mcWeather)
## Weather 
##  A  3 - dimensional discrete Markov Chain with following states 
##  sunny cloudy rain 
##  The transition matrix   (by rows)  is defined as follows 
##        sunny cloudy rain
## sunny    0.7   0.20 0.10
## cloudy   0.3   0.40 0.30
## rain     0.2   0.45 0.35
initialState <- c(0, 1, 0)
after2Days <- initialState * (mcWeather * mcWeather)
after7Days <- initialState * (mcWeather^7)
after2Days
##      sunny cloudy  rain
## [1,]  0.39  0.355 0.255
library(igraph)
mcIgraph <- as(mcWeather, "igraph")
plot(mcIgraph)

plot of chunk unnamed-chunk-3

steadyStates(mcWeather)
##       sunny cloudy   rain
## [1,] 0.4636 0.3182 0.2182