# potts: Potts Models In potts: Markov Chain Monte Carlo for Potts Models

## Description

Simulate Potts model using Swendsen-Wang algorithm.

## Usage

 ```1 2 3``` ```potts(obj, param, nbatch, blen = 1, nspac = 1, boundary = c("torus", "free", "condition"), debug = FALSE, outfun = NULL, ...) ```

## Arguments

 `obj` an R vector of class `"raw"` that encodes a realization of a Potts model, typically the output of `packPotts`. Alternatively, an object of class `"potts"` from a previous invocation of this function can be supplied, in which case any missing arguments are taken from this object. `param` numeric, canonical parameter vector. Last component must nonnegative (see Details below). `nbatch` the number of batches. `blen` the length of batches. `nspac` the spacing of iterations that contribute to batches. `boundary` type of boundary conditions. The value of this argument can be abbreviated. `debug` return additional debugging information. `outfun` controls the output. If a function, then the batch means of `outfun(tt, ...)` are returned. The argument `tt` is the canonical statistic of the Potts model having the same length as the argument `param` of this function. If `NULL`, the batch means of the canonical statistic are returned. `...` additional arguments for `outfun`.

## Details

Runs a Swendsen-Wang algorithm producing a Markov chain with equilibrium distribution having the specified Potts model. The state of a Potts model is a collection of random variables taking values in a finite set. Here the finite set is 1, ..., `ncolor` and the elements are called “colors”. The random variables are associated with the nodes of a rectangular lattice, represented by `unpackPotts` as a matrix. In keeping with calling the values “colors”, the random variables themselves are often called “pixels”. The probability model is an exponential family with canonical statistic vector of length `ncolor + 1`. The first `ncolor` components are the counts of the number of pixels of each color. The last component is the number of pairs of neighboring pixels colored the same. The corresponding canonical parameter, last component of the canonical parameter vector (argument `param`) must be nonnegative for the Swendsen-Wang algorithm to work (Potts models are defined for negative dependence parameter, but can't be simulated using this algorithm).

In the default boundary specification (`"torus"`), also called toroidal or periodic boundary conditions, the vertical edges of the pixel matrix are considered glued together, as are the horizontal edges. Thus corresponding pixels in the first and last rows are considered neighbors, as are corresponding pixels in the first and last columns. In the other boundary specifications there is no such gluing: pixels in the the relative interiors of the first and last rows and first and last columns have only three neighbors, and the four corner pixels have only two neighbors.

In the `"torus"` and `"free"` boundary specifications, all pixels are counted in determining the color count canonical statistics, which thus range from zero to `nrow * ncol`, where `nrow` and `ncol` are the number of rows and columns of the pixel matrix. In the `"condition"` boundary specification, all pixels in the first and last rows and first and last columns are fixed (conditioned on), and only the random pixels are counted in determining the color count canonical statistics, which thus range from zero to `(nrow - 2) * (ncol - 2)`.

In the `"torus"` boundary specification, all pixels have four neighbors, so the neighbor pair canonical statistic ranges from zero to `2 * nrow * ncol`. In the `"free"` boundary specification, pixels in the interior have four neighbors, those in the relative interior of edges have three, and those in the corners have two, so the neighbor pair canonical statistic ranges from zero to `nrow * (ncol - 1) + (nrow - 1) * ncol`. In the `"condition"` boundary specification, only neighbor pairs in which at least one pixel is random are counted, so the neighbor pair canonical statistic ranges from zero to `(nrow - 2) * (ncol - 1) + (nrow - 1) * (ncol - 2)`.

## Value

an object of class `"potts"`, which is a list containing at least the following components:

 `initial` initial state of Markov chain in the format output by `packPotts`. `final` final state of Markov chain in the same format. `initial.seed` value of `.Random.seed` before the run. `final.seed` value of `.Random.seed` after the run. `time` running time of Markov chain from `system.time`. `param` canonical parameter vector. `nbatch` the number of batches. `blen` the length of batches. `nspac` the spacing of iterations that contribute to batches. `boundary` the argument `boundary`. `batch` an `nbatch` by `nout` matrix, where `nout` is the length of the result returned by `outfun` or `length(param)` if `outfun == NULL`; each row is the batch means for the result of `outfun` or the canonical statistic vector for one batch of Markov chain iterations.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```ncolor <- as.integer(4) beta <- log(1 + sqrt(ncolor)) theta <- c(rep(0, ncolor), beta) nrow <- 100 ncol <- 100 x <- matrix(1, nrow = nrow, ncol = ncol) foo <- packPotts(x, ncolor) out <- potts(foo, theta, nbatch = 10) out\$batch ## Not run: image(out\$final) ```

potts documentation built on March 23, 2020, 5:07 p.m.