對於一個特定大小的矩陣,可以生成隨機行/列矩陣安排這樣
#create fake data
mydata.block1 <- matrix (rep(1, times=100), ncol=10)
mydata.block2 <- matrix (rep(0, times=900), ncol=90)
mydata.block3 <- matrix (rep(0, times=900), ncol=10)
mydata.block4 <- matrix (rep(1, times=8100), ncol=90)
mydata <- rbind(cbind (mydata.block1, mydata.block2), cbind (mydata.block3, mydata.block4))
#Mix mydata
mix.order <- sample(1:dim (mydata)[1])
mydata <- mydata[mix.order,mix.order]
#create 100 random orderings
##preallocate matrix
rand.samp <- matrix (rep(NA, times=10000), ncol=100)
##create orderings
for (i in 1:100){
rand.samp[i,] <- sample(1:dim (mydata)[1])
}
##Eliminate duplicate orderings (unlikely to occur)
rand.samp <- unique (rand.samp)
#Reorder and measure fitness
##preallocate fitness measure
fit.meas <- rep (NA, times=100)
for (i in 1:100){
mydata.reordered <- mydata[rand.samp[i,],rand.samp[i,]]
fit.meas[i] <- myfitnessfunc(mydata.reordered)
}
已經測量健身後,您將需要一些方法來確定哪些方面促進了健身並在修改其他區域(「品種」)的同時修復這些問題。也許dist()會有一些用處。也許熱圖或集羣hclust()也可以使用?你能提供更多關於如何確定本地化健身的細節嗎?
非常感謝答案,但是當我測試代碼時,它似乎是在矩陣中創建新條目。由於我正在處理一個鄰接矩陣,所以1的總和應該是常數,它只是應該重新排列的列和行。 – 2011-01-21 10:17:46