calct: Calculate Canonical Statistic for Potts Model In potts: Markov Chain Monte Carlo for Potts Models

Description

Calculate the canonical statistic 't' for a realization of a Potts Model

Usage

 ```1 2 3``` ```calc_t_full(x,ncolor) calc_t_innergrid(x, ncolor, grid, i, j) calc_t(x, ncolor, grid=NULL, i=NULL, j=NULL) ```

Arguments

 `x` 2 dimensional matrix, elements in 1, ..., `ncolor`, representing a Potts model `ncolor` numeric. Number of colors in this Potts Model. `grid` numeric. 2 dimensional matrix, elements in 1, ..., `ncolor`. If non-NULL it is placed into `x` at the location `x[i,j]`. `i` numeric. Row to place the grid. `j` numeric. Column to place the grid.

Details

For a description of notation and terminology, see `composite.ll`.

Calculates the canonical statistics for a realized Potts Model. `calc_t` calls `calc_t_full` if `grid` is `NULL` and `calc_t_innergrid` otherwise.

`calc_t_full` calculates the canonical statistics for the full image.

`calc_t_innergrid` calculates the canonical statistics for the a window of the image, but with that window replaced by `grid`, with the upper left corner of `grid` located at `x[i,j]`.

Value

For a description of notation and terminology, see `composite.ll`.

All functions return a vector of length `ncolor+1`. Elements 1,...,`ncolor` contain the number of pixels of each color. Element `ncolor+1` contains the number of matching neighbor pairs for the image.

`calc_t_full` returns the values for the whole image.

`calc_t_innergrid` returns the value for just the selected window, but this includes the number of matching pairs from the replaced window to it's neighbors. E.g. if `X` is the full image, and A(a) is the value of some window in the image and we want to know the value of \code{t( y union X \ A(a))} this would be ```calc_t_full(X, ncolor) + calc_t_innergrid(X, ncolor, y, i, j) - calc_t_innergrid(X, ncolor, A(a), i, j)```

`generate_t_cache`, `composite.ll`.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14``` ```ncolor <- 4 beta <- log(1+sqrt(ncolor)) theta <- c(rep(0,ncolor), beta) nrow <- 32 ncol <- 32 x <- matrix(sample(ncolor, nrow*ncol, replace=TRUE), nrow=nrow, ncol=ncol) foo <- packPotts(x, ncolor) out <- potts(foo, theta, nbatch=10) x <- unpackPotts(out\$final) t_stat <- calc_t(x, ncolor) t_stat_inner <- calc_t(x, ncolor, matrix(1, nrow=2, ncol=2), 1, 1) ```