sampler.mrf {GiRaF} | R Documentation |
sampler.mrf gives approximate sample from the likelihood of a general Potts model defined on a rectangular h x w lattice (h ≤ w) with either a first order or a second order dependency structure. Available options are the Gibbs sampler (Geman and Geman (1984)) and the Swendsen-Wang algorithm (Swendsen and Wang (1987)).
sampler.mrf(iter, sampler = "Gibbs" , h, w, param, ncolors = 2, nei = 4, pot = NULL, top = NULL, left = NULL, bottom = NULL, right = NULL, corner = NULL, initialise = TRUE, random = TRUE, view = FALSE)
iter |
Number of iterations of the algorithm. |
sampler |
The method to be used. The latter must be one of "Gibbs" or "SW" corresponding respectively to the Gibbs sampler and the Swendsen-Wang algorithm. |
h |
the number of rows of the rectangular lattice. |
w |
the number of columns of the rectangular lattice. |
param |
numeric entry setting the interaction parameter (edges parameter) |
ncolors |
the number of states for the discrete random variables. By default, ncolors = 2. |
nei |
the number of neighbors. The latter must be one of nei = 4 or nei = 8, which respectively correspond to a first order and a second order dependency structure. By default, nei = 4. |
pot |
numeric entry setting homogeneous potential on singletons (vertices parameter). By default, pot = NULL |
top, left, bottom, right, corner |
numeric entry setting constant borders for the lattice. By default, top = NULL, left = NULL, bottom = NULL, right = NULL, corner = NULL. |
initialise |
Logical value indicating whether initial guess should be randomly drawn. |
random |
Logical value indicating whether the sites should be updated sequentially or randomdly. Used only with the "Gibbs" option. |
view |
Logical value indicating whether the draw should be printed. Do not display the optional borders. |
Geman, S. and Geman, D. (1984). Stochastic Relaxation, Gibbs Distributions, and the Bayesian Restoration of Images. IEEE Transactions on Pattern Analysis and Machine Intellignence, 6(6):721-741.
Swendsen, R. H. and Wang, J.-S. (1987). Nonuniversal critical dynamics in Monte Carlo simulations. Pysical Review Letters, 58(2):86-88.
The “GiRaF-introduction” vignette
# Algorithm settings n <- 200 method <- "Gibbs" # Dimension of the lattice height <- width <- 100 # Interaction parameter Beta <- 0.6 # Isotropic configuration # Beta <- c(0.6, 0.6) # Anisotropic configuration when nei = 4 # Beta <- c(0.6, 0.6, 0.6, 0.6) # Anisotropic configuration when nei = 8 # Number of colors K <- 2 # Number of neighbors G <- 4 # Optional potential on sites potential <- runif(K,-1,1) # Optional borders. Top <- Bottom <- sample(0:(K-1), width, replace = TRUE) Left <- Right <- sample(0:(K-1), height, replace = TRUE) Corner <- sample(0:(K-1), 4, replace = TRUE) # Sampling method for the default setting sampler.mrf(iter = n, sampler = method, h = height, w = width, param = Beta, view = TRUE) # Sampling using an existing configuration as starting point sampler.mrf(iter = n, sampler = method, h = height, w = width, ncolors = K, nei = G, param = Beta, initialise = FALSE, view = TRUE) # Specifying optional arguments. The users may omit to mention all # the non-existing borders sampler.mrf(iter = n, sampler = method, h = height, w = width, ncolors = K, nei = G, param = Beta, pot = potential, top = Top, left = Left, bottom = Bottom, right = Right, corner = Corner, view = TRUE) # Gibbs sampler with sequential updates of the sites. sampler.mrf(iter = n, sampler = "Gibbs", h = height, w = width, ncolors = K, nei = G, param = Beta, random = FALSE, view = TRUE)