SwendsenWangAlg: Simulate a Potts model using the Swendsen-Wang algorithm

Description Usage Arguments References Examples

View source: R/SwendsenWangAlg.R

Description

This function allows you to simulate a Potts model using the Swendsen-Wang algorithm.

Usage

1
2
SwendsenWangAlg(beta, Coord = NULL, Neigh_Bonds = NULL, col.obs,
  Nrun = 10, sampling = "else")

Arguments

beta

parameters of the Potts model.

Coord

Matrix of coordinates.

col.obs

Binary matrix of colors.

Nrun

Number of MCMC runs.

sampling

Choice of sampling for the components.

References

Wang, J. and Swendsen, R. (1990) Cluster Monte Carlo algorithms. Physica A: Statistical Mechanics and its Applications 167 565–579.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
beta = c(0.5,0.5,0.5)
Obs.loc = expand.grid(1:50,1:50)
id.pos = sample(1:3, 2500, replace = T)
Res20 = SwendsenWangAlg(beta, Coord = as.matrix(Obs.loc), col.obs = id.pos, Nrun = 20)
Res50 = SwendsenWangAlg(beta, Coord = as.matrix(Obs.loc), col.obs = id.pos, Nrun = 50)
Res500 = SwendsenWangAlg(beta, Coord = as.matrix(Obs.loc), col.obs = id.pos, Nrun = 500)
par(mfrow = c(2,2))
col = grey.colors(3)
image(matrix(Res20$col.old, ncol = 50), col = col)
image(matrix(Res20$col.new, ncol = 50), col = col)
image(matrix(Res50$col.new, ncol = 50), col = col)
image(matrix(Res500$col.new, ncol = 50), col = col)

ick003/SpTMixture documentation built on May 18, 2019, 2:32 a.m.