Created
April 24, 2018 00:21
-
-
Save slwu89/80fed4086e514f9d9d7ede08ca79b706 to your computer and use it in GitHub Desktop.
walk on hypercube
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
n_iter = 100 | |
n_nodes = 10 | |
trace = vector(mode="list",length = n_iter) | |
trace[[1]] = sample(x = 1:n_nodes,size = n_nodes,replace = TRUE) | |
for(i in 2:n_iter){ | |
trace[[i]] = trace[[i-1]] | |
j = sample(x = 1:n_nodes,size = 1) # sample index | |
trace[[i]][j] = sample(x = 1:n_nodes,size = 1) # flip n-bit | |
} | |
allele_col = viridis::viridis(n = 10) | |
defaultPars = par() | |
par(mar=c(0,0,1,0),mgp=c(0,0,0)) | |
# std_AIC = (out[[100]]$AIC - mean(out[[100]]$AIC) ) / sd(out[[100]]$AIC) | |
# std_AIC = std_AIC * 3 | |
std_AIC = rep(0,p) | |
final_chromosomes = trace | |
ylim = c(-60,20) # for some breathing space | |
xlim = c(0,101) # one extra for 'true' chromosome | |
plot(1, type="n",axes=F,frame.plot=F,ann=T, xlim=xlim, ylim=ylim) | |
mtext(text = "Chromosome Population",side = 3,at=20,line=-2,cex=1.5) | |
box_ysize = 1 | |
# iterate over population of chromosomes | |
for(i in 1:p){ | |
final_chromosomes[[i]] | |
yctr = 5 | |
# make 49th box and 50 boxes above it (51 'upper' boxes) | |
yctr_up = yctr + (box_ysize/2) | |
yseq_up = seq(from = yctr_up + box_ysize,to = yctr_up + (box_ysize*50),by = box_ysize) # need 50 more boxes above | |
# make lower 48 boxes | |
yctr_dwn = yctr - (box_ysize/2) | |
yseq_dwn = seq(from = yctr_dwn - box_ysize,to = yctr_dwn - (box_ysize*49),by = -box_ysize) | |
yseq = c(rev(yseq_dwn),yctr_dwn,yctr_up,yseq_up) | |
# iterate over a chromosome | |
for(j in 1:100){ | |
# if(as.logical(final_chromosomes[[i]][j])){ | |
# c = allele_col[1] # 1 | |
# } else { | |
# c = allele_col[2] # 0 | |
# } | |
c = allele_col[final_chromosomes[[i]][j]] | |
if(j==1 | j==100){ | |
segments(x0 = i,y0 = yseq[j],x1 = i,y1 = yseq[j+1],col = c,lty = 1,lwd = 6.5,lend = 0) | |
} else { | |
segments(x0 = i,y0 = yseq[j],x1 = i,y1 = yseq[j+1],col = c,lty = 1,lwd = 6.5,lend = 2) | |
} | |
} | |
} | |
par(mar=defaultPars$mar,mgp=defaultPars$mgp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment