composite.ll {potts}R Documentation

Composite Log Likelihood for Potts Models

Description

Calculate Composite Log Likelihood (CLL) and the gradient of the CLL for Potts models.

Usage

composite.ll(theta, t_stat, t_cache=NULL, fapply=lapply)
gr.composite.ll(theta, t_stat, t_cache=NULL, fapply=lapply) 

Arguments

theta

numeric canonical parameter vector. The CLL will be evaluated at this point. It is assumed that the component corresponding to the first color has been dropped.

t_stat

numeric, canonical statistic vector. The value of the canonical statistic for the full image.

t_cache

list of arrays. t_cache[[i]][j,] = the value of tt with window AiA_i replaced by the jthj^{th} element of CAC^A.

fapply

function. Expected to function as lapply does. Useful for enabling parallel processing. E.g. use the mclapply function from the multicore package.

Details

For the given value of theta composite.ll and gr.composite.ll calculate the CLL and the gradient of the CLL respectively for a realized Potts model represented by t_stat and t_cache.

A\mathcal{A} is the set of all windows to be used in calculating the Composite Log Likelihood (CLL) for a Potts model. A window is a collection of adjacent pixels on the lattice of the Potts model. AA is used to represent a generic window in A\mathcal{A}, the code in this package expects that all the windows in A\mathcal{A} have the same size and shape. A|A| is used to denote the size, or number of pixels in a window. Each pixel in a Potts takes on a value in CC, the set of possible colors. For simplicity, this implementation takes C={1,,ncolor}C = \{1,\dots,\texttt{ncolor}\}. Elements of CC will be referenced using cjc_j with j{1,,ncolor}j \in \{1,\dots,\texttt{ncolor}\}. CAC^A is used to denote all the permutations of CC across the window AA, and CA|C|^{|A|} is used to denote the size of CAC^A. In an abuse of notation, we use AaA_a to refer to the atha^{th} element of A\mathcal{A}. No ordinal or numerical properties of A\mathcal{A}, CC or CAC^A are used, only that each element in the sets are referenced by one and only one indexing value.

Value

composite.ll returns CLL evaluated at theta.

gr.composite.ll returns a numeric vector of length length(theta) containing the gradient of the CLL at theta.

See Also

generate_t_cache, calc_t.

Examples


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)
t_cache_two <- generate_t_cache(x, ncolor, t_stat, nrow*ncol/2, 2,
                                twopixel.nonoverlap)

composite.ll(theta[-1], t_stat, t_cache_mple)
gr.composite.ll(theta[-1], t_stat, t_cache_mple)

## Not run: 
optim.mple <- optim(theta.initial, composite.ll, gr=gr.composite.ll,
                    t_stat, t_cache_mple, method="BFGS",
                    control=list(fnscale=-1))
optim.mple$par

optim.two <- optim(theta.initial, composite.ll, gr=gr.composite.ll,
                   t_stat, t_cache_two, method="BFGS",
                   control=list(fnscale=-1))
optim.two$par

## End(Not run)

## Not run: 
# or use mclapply to speed things up.
library(multicore)
optim.two <- optim(theta.initial, composite.ll, gr=gr.composite.ll,
                   t_stat, t_cache_two, mclapply, method="BFGS",
                   control=list(fnscale=-1))
optim.two$par


## End(Not run)


[Package potts version 0.5-11 Index]