Last active
September 12, 2016 13:01
-
-
Save DexGroves/39a175b3453887a1ecc05f99f5cfb9c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make a 3D transition matrix T where z-dimension is time | |
T_states <- 3 | |
T_terms <- 4 | |
T <- array(runif(T_states * T_states * Tz)/1.5, dim = c(T_states, T_states, Tz)) | |
# Normalise by rows | |
for (z in seq(Tz)) { | |
T[, , z] <- T[, , z] / apply(T[, , z], 1, sum) | |
} | |
# Starting state | |
start <- matrix(0, nrow = 1, ncol = T_states) | |
start[1] <- 1 | |
# Process across terms | |
end <- start | |
for (term in seq(T_terms)) { | |
end <- end %*% T[, , term] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment