Cache T | R Documentation |
Variety of functions to support caching of calculated canonical statistics for Potts Models. There is some attempt at being 'smart' with when to regenerate the statistics.
generate_t_cache(x, ncolor, t_stat, sizeA, npixel, f, fapply=lapply, gridcache=NULL) gengridcache(ncolor, sizeCA, ncol) gensingleton(ncolor) singleton(x, ncolor, a, idx, gridcache=NULL) gentwopixel(ncolor) twopixel(x, ncolor, a, idx, gridcache=NULL) twopixel.nonoverlap(x, ncolor, a, idx, gridcache=NULL) genfourpixel(ncolor) fourpixel(x, ncolor, a, idx, gridcache=NULL) fourpixel.nonoverlap(x, ncolor, a, idx, gridcache=NULL) genthreebythree(ncolor) ninepixel.nonoverlap(x, ncolor, a, idx, gridcache=NULL) genfourbyfour(ncolor) sixteenpixel.nonoverlap(x, ncolor, a, idx, gridcache=NULL)
t_stat |
numerical vector of length |
sizeA |
numerical. The number of elements in sA. |
sizeCA |
numerical. The number of elements in C^A. |
npixel |
numerical. The number of pixels in one element of sA. |
f |
function. Takes arguments |
fapply |
function. It should behave exactly as lapply does. You can use this argument to enable parallel computing. |
gridcache |
list. Optional. If non-null, it is a list of the elements of C^A. |
x |
numeric, 2 dimensional matrix, elements in 1, ..., |
ncolor |
numeric. Number of colors in this Potts Model. |
ncol |
numeric. Gives the number of columns in a rectangular window. |
a |
numeric. Indicates which member of sA is being referenced. |
idx |
numeric. Indicates which element of C^A is being referenced. |
For a description of notation and terminology, see
composite.ll
.
This set of functions is used to generate cached calculations of the
canonical statistic of a Potts model suitable for passing into
composite.ll
or gr.composite.ll
.
All of the calculations using composite.ll
and these
caching functions need one of the color components to be dropped for
the model to be identifiable. For simplicity, the first color is
dropped by generate_t_cache
. In computing the composite log
likelihood for a Potts model with ncolor
colors, we are
interested in many calculations across C^A, the set of all
permutations of colors across a window. These functions facilitate
those calculations. gridcache
is a list of C^A.
generate_t_cache
is the main function, and the others are
intended to be used in conjunction with it. generate_t_cache
creates a list of arrays. Each array represents one window in the
image, and each row of the array contains the value of
t(x) (with one component dropped) found by replacing the
pixels in that window with one of the elements of C^A.
gengridcache
can generate the gridcache
for any rectangular
window, give the number of colors, size of C^A, and number
of columns in the window. gensingleton
, gentwopixel
,
genfourpixel
, genthreebythree
and genfourbyfour
are all just simple wrappers for gengridcache
.
singleton
, twopixel
, twopixel.nonoverlap
,
fourpixel
, fourpixel.nonoverlap
,
ninepixel.nonoverlap
and sixteenpixel.nonoverlap
are
intended to be passed to generate_t_cache
in the argument
f
. They are used to calculate \code{t( ca(idx) union X \ A(a) )} for the
idx-th element of C^A(a).
Functions that have overlap
and nonoverlap
versions
generate a overlapping and nonoverlapping set of windows respectively.
singleton
is for a single pixel window (Besag or MPLE).
twopixel
does a two horizontal pixel window.
fourpixel
does a two by two pixel window.
ninepixel
does a three by three pixel window.
sixteenpixel
does a four by four pixel window.
Functions that start with gen
return a list
of the
elements of C^A.
The other functions (e.g. twopixel
, fourpixel
, ...)
return the result of replacing the a
-th window of x
with
the idx
-th element of C^A and calculating
calc_t_innergrid
for that window.
composite.ll
, calc_t
.
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_cache_mple <- generate_t_cache(x, ncolor, t_stat, nrow*ncol, 1, singleton) ## Not run: # use multicore to speed things up. library(multicore) t_cache_mple <- generate_t_cache(x, ncolor, t_stat, nrow*ncol, 1, singleton, fapply=mclapply) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.