ncolor <- 4
beta <- log(1+sqrt(ncolor))
theta <- c(rep(0,ncolor), beta)
nrow <- 32
ncol <- 32
x <- matrix(sample(ncolor, nrow*ncol, replace=TRUE), nrow=nrow, ncol=ncol)
foo <- packPotts(x, ncolor)
out <- potts(foo, theta, nbatch=10)
x <- unpackPotts(out$final)
t_stat <- calc_t(x, ncolor)
t_cache_mple <- generate_t_cache(x, ncolor, t_stat, nrow*ncol, 1,
singleton)
t_cache_two <- generate_t_cache(x, ncolor, t_stat, nrow*ncol/2, 2,
twopixel.nonoverlap)
composite.ll(theta[-1], t_stat, t_cache_mple)
gr.composite.ll(theta[-1], t_stat, t_cache_mple)
if (FALSE) {
optim.mple <- optim(theta.initial, composite.ll, gr=gr.composite.ll,
t_stat, t_cache_mple, method="BFGS",
control=list(fnscale=-1))
optim.mple$par
optim.two <- optim(theta.initial, composite.ll, gr=gr.composite.ll,
t_stat, t_cache_two, method="BFGS",
control=list(fnscale=-1))
optim.two$par
}
if (FALSE) {
# or use mclapply to speed things up.
library(multicore)
optim.two <- optim(theta.initial, composite.ll, gr=gr.composite.ll,
t_stat, t_cache_two, mclapply, method="BFGS",
control=list(fnscale=-1))
optim.two$par
}
Run the code above in your browser using DataLab