GiRaF-package: A toolbox for Gibbs Random Fields analysis

Description Details Author(s) References See Also Examples

Description

GiRaF is a package for calculations on, and sampling from Gibbs (or discrete Markov) random fields.

Details

GiRaF offers various tools for the analysis of Gibbs random fields and more precisely general homogeneous Potts model with possible anisotropy and potential on singletons (cliques composed of single vertex). GiRaF substantially lowers the barrier for practitioners aiming at analysing such Gibbs random fields. GiRaF contains exact methods for small lattices and several approximate methods for larger lattices that make the analysis easier for practitioners.

The “GiRaF-introduction” vignette gives a detailled introduction on the package.

For a complete list of functions, use library(help = "GiRaF").

Author(s)

Julien Stoehr, Pierre Pudlo and Nial Friel.

Maintainer: Julien Stoehr <julien.stoehr@ucd.ie>

References

Friel, N. and Rue, H. (2007). Recursive computing and simulation-free inference for general factorizable models. Biometrika, 94(3):661–672.

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.

Reeves, R. and Pettitt, A. N. (2004). Efficient recursions for general factorisable models. Biometrika, 91(3):751–757.

Swendsen, R. H. and Wang, J.-S. (1987). Nonuniversal critical dynamics in Monte Carlo simulations. Pysical Review Letters, 58(2):86-88.

See Also

The “GiRaF-introduction” vignette

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Dimension of the lattice
height <- 8
width <- 10

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

# Partition function for the default setting
NC.mrf(h = height, w = width, param = Beta)

# When specifying the number of colors and neighbors
NC.mrf(h = height, w = width, ncolors = K, nei = G, param = Beta)

# When specifying an optional potential on sites
NC.mrf(h = height, w = width, ncolors = K, nei = G, param = Beta, 
       pot = potential)
       
# When specifying possible borders. The users will omit to mention all
# the non-existing borders
NC.mrf(h = height, w = width, ncolors = K, nei = G, param = Beta, 
       top = Top, left = Left, bottom = Bottom, right = Right, corner = Corner)
       
# Exact sampling for the default setting
exact.mrf(h = height, w = width, param = Beta, view = TRUE)

# When specifying the number of colors and neighbors
exact.mrf(h = height, w = width, ncolors = K, nei = G, param = Beta, 
          view = TRUE)
          
# When specifying an optional potential on sites
exact.mrf(h = height, w = width, ncolors = K, nei = G, param = Beta, 
       pot = potential, view = TRUE)
       
# When specifying possible borders. The users will omit to mention all
# the non-existing borders
exact.mrf(h = height, w = width, ncolors = K, nei = G, param = Beta, 
       top = Top, left = Left, bottom = Bottom, right = Right, corner = Corner, view = TRUE)
       
# Algorithm settings
n <- 200
method <- "Gibbs"

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

Example output

[1] 3.541494e+45
[1] 3.541494e+45
[1] 5.210387e+21
[1] 9.42418e+50
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    0    1    1    0    0    0    0    0    0     0
[2,]    1    1    1    0    0    0    0    0    0     0
[3,]    1    1    1    1    0    0    0    0    0     0
[4,]    1    1    1    0    0    0    0    0    0     0
[5,]    1    1    1    1    0    0    0    0    0     1
[6,]    1    1    1    1    1    0    1    1    0     1
[7,]    1    1    1    1    1    0    1    1    0     1
[8,]    0    0    0    1    1    0    0    1    1     1
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    0    0    0    1    1    0    0    1    0     1
[2,]    1    1    1    0    1    0    0    0    1     1
[3,]    1    1    0    1    1    1    1    0    0     0
[4,]    1    1    1    1    1    1    1    0    0     1
[5,]    0    0    1    1    0    1    1    1    1     1
[6,]    0    1    1    1    1    1    1    1    1     1
[7,]    0    1    1    1    1    1    1    1    1     0
[8,]    0    1    1    1    0    1    1    1    0     1
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    0    1    1    1    1    0    1    1     1
[2,]    0    0    0    1    1    1    1    1    1     1
[3,]    0    0    1    1    0    0    0    1    1     0
[4,]    0    0    1    1    1    1    1    1    1     0
[5,]    0    1    1    1    1    1    1    1    1     1
[6,]    1    1    1    1    1    1    1    0    1     0
[7,]    1    1    1    1    1    1    1    1    1     1
[8,]    1    0    1    1    1    1    1    1    0     0
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1    1    0    0    0    1    1    1     1
[2,]    1    1    1    0    1    0    1    1    1     0
[3,]    1    1    1    0    1    1    1    1    1     1
[4,]    0    0    1    0    1    1    1    1    1     1
[5,]    1    0    1    1    1    1    1    1    1     0
[6,]    0    0    0    0    0    1    1    1    0     0
[7,]    0    0    0    0    0    1    1    1    1     1
[8,]    0    0    0    0    1    1    1    1    1     1
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    0    0    0    0    1    1    1    0    1     1
[2,]    0    1    1    1    1    0    1    0    0     0
[3,]    1    1    1    1    1    1    1    0    0     0
[4,]    1    1    1    1    1    1    1    0    0     0
[5,]    1    1    1    1    1    1    0    1    0     0
[6,]    1    1    1    1    1    0    0    1    0     1
[7,]    1    1    1    1    0    0    0    1    0     0
[8,]    1    1    1    0    0    0    0    0    0     0
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    0    1    1    0    0    0    0    0     1
[2,]    1    0    1    1    0    0    1    0    0     0
[3,]    1    0    1    1    0    1    1    0    0     0
[4,]    1    1    1    0    0    0    0    1    0     0
[5,]    1    1    1    0    0    1    0    1    1     1
[6,]    1    0    1    0    0    0    1    1    1     1
[7,]    0    0    0    0    1    1    1    1    1     1
[8,]    0    0    0    1    1    1    1    1    0     0
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1    0    0    1    1    1    1    1     0
[2,]    1    1    0    0    1    1    1    1    1     1
[3,]    1    1    0    1    1    1    1    0    1     1
[4,]    0    1    1    1    1    1    1    0    1     1
[5,]    1    0    0    1    1    1    1    0    1     1
[6,]    1    1    0    0    1    1    1    1    1     1
[7,]    0    0    0    0    1    1    1    1    0     0
[8,]    0    1    1    1    1    1    1    1    0     0
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1    1    0    1    0    1    0    0     0
[2,]    1    1    1    0    0    0    1    0    1     1
[3,]    1    1    1    0    0    0    0    0    0     1
[4,]    1    1    0    0    0    0    0    0    1     1
[5,]    0    1    1    0    0    0    0    0    0     1
[6,]    0    1    1    1    0    0    0    0    0     0
[7,]    1    1    1    0    0    1    0    0    0     1
[8,]    1    1    0    0    0    1    1    0    1     1

GiRaF documentation built on Oct. 23, 2020, 6:07 p.m.