@HaomingJiang
2018-04-17T00:22:07.000000Z
字数 2331
阅读 1290
Haoming Jiang
We have ,
, which means
n=10a = 10b = 5rec = rep(0, 11)for(i in 0:10){rec[i+1] = choose(n, i)*beta(a+i, b+n-i) / beta(a, b)}m = 100theta = x = rep(0, m)x[1] = 0theta[1] = rbeta(1, a+x[1], b+n-x[1])for(i in 2:m){x[i] = rbinom(1, n, prob = theta[i-1])theta[i] = rbeta(1, a+x[i-1], b+n-x[i-1])}plot(x, theta)

## dq = function(x, u, v) qbinom(v, n, qbeta(u, a+x, b+n-x) )ss = 0:10start_times = c()X0s = c()for(i in 1:100){a = 10b = 5n = 10xx = ssU = runif(2)u = U[1]; v = U[2]for(i in 1:(n+1)) xx[i] = q(ss[i], u, v)while( length(table(xx)) != 1 ){U = rbind(U, runif(2))path = xx = ssfor(tau in (dim(U)[1]:1) ){u = U[tau, 1]; v = U[tau, 2]for(i in 1:length(ss) ) xx[i] = q(xx[i], u, v)path = rbind(xx, path)}path}l = dim(path)[1]plot( rep((-l:-1 +1), 11), rep(rep(0:10), each = l), cex = 0.3, xlab = "tau", ylab = "sample space" )for(k in 1:11) points((-l:-1 +1), rev(path[, k]), "l")X0s = c(X0s, xx[1])start_times = c(start_times,-l+1)}hist(start_times)hist(X0s)


## fa = 10b = 5n = 10k=11set.seed(k)xx = ssU = runif(2)u = U[1]; v = U[2]for(i in 1:(n+1)) xx[i] = q(ss[i], u, v)while( length(table(xx)) != 1){U = rbind(U, runif(2))path = xx = ssfor(tau in (dim(U)[1]:1) ){u = U[tau, 1]; v = U[tau, 2]for(i in 1:length(ss) ) xx[i] = q(xx[i], u, v)path = rbind(xx, path)}#path}#paththeta = gibbs = perfect = rep(0, 20)gibbs[1] = perfect[1] = 0theta[1] = rbeta(1, a+gibbs[1], b+n-gibbs[1])for(i in 2:20){## perfectu = runif(1); v = runif(1)perfect[i] = q(perfect[i-1], u, v)## gibbsgibbs[i] = rbinom(1, n, prob = theta[i-1])theta[i] = rbeta(1, a+gibbs[i-1], b+n-gibbs[i-1])}plot(rep((0:19), 11), rep(rep(0:10), each = 20), cex = 0.3, xlab = "tau", ylab = "sample space" )points(0:19, perfect, "l")points(0:19, gibbs, lty = 2, "l")legend("topleft", legend = c("CFTP", "Gibbs"), lty=1:2)

i Yes
ii CFTP