potts | R Documentation |

Simulate Potts model using Swendsen-Wang algorithm.

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

`obj` |
an R vector of class |

`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 |

`...` |
additional arguments for |

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)`

.

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 |

`final` |
final state of Markov chain in the same format. |

`initial.seed` |
value of |

`final.seed` |
value of |

`time` |
running time of Markov chain from |

`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 |

`batch` |
an |

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)

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.