Displaying 1 result from an estimated 1 matches for "findstatedim".
2009 May 07
2
for loop vectorization
...pecific conditions.
thanks
Mira
tmp = 0:(maxvals[1])
for(i in 2:nchars) {
tmp <- outer(tmp, 0:(maxvals[i]), FUN="paste", sep=".")
}
states = tmp
stateidx = array(1:length(states), dim=dim(states))
transition <- matrix(data=0, nrow=length(states), ncol=length(states))
findstatedim <- function(x) which(stateidx==x, arr.ind = TRUE)
manhattandistance <- function(x,y) sum(abs(findstatedim(x)-findstatedim(y)))
for(i in 1:length(states)) {
for (j in 1:length(states)) {
if (manhattandistance(i, j)==1) {
if (sum(findstatedim(i)-findstatedim(j)) <...