cll: Composite Log Likelihood for Potts Models

Description Usage Arguments Details Value See Also Examples

Description

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

Usage

1
2
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 \code{t} with window A(i) replaced by the j-th element of C^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.

sA 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. A is used to represent a generic window in sA -- meaning `script A', the code in this package expects that all the windows in sA have the same size and shape. |A| is used to denote the size, or number of pixels in a window. Each pixel in a Potts takes on a value in C, the set of possible colors. For simplicity, this implementation takes C = {1,…,\code{ncolor}}. Elements of C will be referenced using c(j) with j in {1,…,\code{ncolor}}. C^A is used to denote all the permutations of C across the window A, and |C|^|A| is used to denote the size of C^A. In an abuse of notation, we use A(a) to refer to the a-th element of sA. No ordinal or numerical properties of sA, C or C^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

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

potts documentation built on March 23, 2020, 5:07 p.m.