# spatial field
## Not run:
# n <- 30
# iter_max <- 500
# ## End(Not run)
G <- 3
coords <- data.frame(which(matrix(0, nrow = n * G, ncol = n * G) == 0, arr.ind = TRUE), 1)
optionsMRIaggr(quantiles.legend = FALSE, axes = FALSE, num.main = FALSE)
# neighbourhood matrix
resW <- calcW(coords, range = sqrt(2), row.norm = TRUE, calcBlockW = TRUE)
W <- resW$W
# with no initial sample
res1 <- simulPotts(W, G = 3, rho = 3, iter_max = iter_max)
multiplot(coords,
apply(res1$simulation, 1, which.max),
breaks=seq(0.5, 3.5, 1))
res2 <- simulPotts(W, G = 4, rho = 3, iter_max = iter_max)
multiplot(coords,
apply(res2$simulation, 1, which.max),
breaks = seq(0.5, 4.5, 1))
res3 <- simulPotts(W, G = 4, rho = 6, iter_max = iter_max)
multiplot(coords,
apply(res3$simulation, 1, which.max),
breaks = seq(0.5, 4.5, 1))
# with specific initialisation
res3.bis <- simulPotts(W, rho = 6, initialization = res3$simulation, iter_max = iter_max / 2)
multiplot(coords,
apply(res3.bis$simulation, 1, which.max),
breaks=seq(0.5, 4.5, 1))
res3.ter <- simulPotts(W, rho = 6, initialization = res3$simulation, iter_max = iter_max)
multiplot(coords,
apply(res3.ter$simulation, 1, which.max),
breaks=seq(0.5, 4.5, 1))
#### defining site order save time
site_order <- unlist(resW$blocks$ls_groups) - 1
system.time(
res <- simulPotts(W, iter_max = 100, G = 3, rho = 6, site_order = NULL,
fast = TRUE, verbose = FALSE)
)
system.time(
res <- simulPotts(W, iter_max = 100, G = 3, rho = 6, site_order = site_order,
fast = TRUE, verbose = FALSE)
)
system.time(
res <- simulPotts(W, iter_max = 100, G = 3, rho = 6, site_order = NULL,
fast = FALSE, verbose = FALSE)
)
system.time(
res <- simulPotts(W, iter_max = 100, G = 3, rho = 6, site_order = site_order,
fast = FALSE, verbose = FALSE)
)
Run the code above in your browser using DataLab