Created
September 2, 2015 11:24
-
-
Save jdevoo/c3372666b4c65f1e6bd7 to your computer and use it in GitHub Desktop.
This file contains 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
# FCM iteration function | |
# returns a table of (iterations x state vectors) | |
fcm.iterate = function(mat, init, peg, iter, trans, fn, ...) { | |
acc = matrix(0, iter, ncol(mat)) | |
acc[1,] = init | |
if(!missing(peg)) { | |
acc[1,which(!is.na(peg))] = peg[!is.na(peg)] | |
} | |
for(i in 2:iter) { | |
if(trans) { | |
acc[i,] = sapply(t(acc[i-1,]) %*% mat, fn, ...) | |
} else { | |
acc[i,] = sapply(mat %*% acc[i-1,], fn, ...) | |
} | |
if(!missing(peg)) { | |
acc[i,which(!is.na(peg))] = peg[!is.na(peg)] | |
} | |
} | |
return(acc) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment