fit_ghm: EM estimation for Gaussian Hidden Markov field

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/fit_ghm.R

Description

fit_ghm fits a Gaussian Mixture model with hidden components driven by a Markov random field with known parameters. The inclusion of a linear combination of basis functions as a fixed effect is also possible.

The algorithm is a modification of of \insertCitezhang2001segmentationmrf2d, which is described in \insertCitefreguglia2020hiddenmrf2d.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
fit_ghm(
  Y,
  mrfi,
  theta,
  fixed_fn = list(),
  equal_vars = FALSE,
  init_mus = NULL,
  init_sigmas = NULL,
  maxiter = 100,
  max_dist = 10^-3,
  icm_cycles = 6,
  verbose = interactive(),
  qr = NULL
)

Arguments

Y

A matrix of observed (continuous) pixel values.

mrfi

A mrfi object representing the interaction structure.

theta

A 3-dimensional array describing potentials. Slices represent interacting positions, rows represent pixel values and columns represent neighbor values. As an example: theta[1,3,2] has the potential for the pair of values 0,2 observed in the second relative position of mrfi.

fixed_fn

A list of functions fn(x,y) to be considered as a fixed effect. See basis_functions.

equal_vars

logical indicating if the mixture model has the same variances in all mixture components.

init_mus

Optional. A numeric with length (C+1) with the initial mean estimate for each component.

init_sigmas

Otional. A numeric with length (C+1) with initial sample deviation estimate for each component.

maxiter

The maximum number of iterations allowed. Defaults to 100.

max_dist

Defines a stopping condition. The algorithm stops if the maximum absolute difference between parameters of two consecutive iterations is less than max_dist.

icm_cycles

Number of steps used in the Iterated Conditional Modes algorithm executed in each interaction. Defaults to 6.

verbose

logical indicating wheter to print the progress or not.

qr

The QR decomposition of the design matrix. Used internally.

Details

If either init_mus or init_sigmas is NULL an EM algorithm considering an independent uniform distriburion for the hidden component is fitted first and its estimated means and sample deviations are used as initial values. This is necessary because the algorithm may not converge if the initial parameter configuration is too far from the maximum likelihood estimators.

max_dist defines a stopping condition. The algorithm will stop if the maximum absolute difference between (μ and σ) parameters in consecutive iterations is less than max_dist.

Value

A hmrfout containing:

Author(s)

Victor Freguglia

References

\insertAllCited

See Also

A paper with detailed description of the package can be found at https://arxiv.org/abs/2006.00383

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Sample a Gaussian mixture with components given by Z_potts
# mean values are 0, 1 and 2 and a linear effect on the x-axis.

set.seed(2)
Y <- Z_potts + rnorm(length(Z_potts), sd = 0.4) +
      (row(Z_potts) - mean(row(Z_potts)))*0.01
# Check what the data looks like
cplot(Y)

fixed <- polynomial_2d(c(1,0), dim(Y))
fit <- fit_ghm(Y, mrfi = mrfi(1), theta = theta_potts, fixed_fn = fixed)
fit$par
cplot(fit$fixed)

mrf2d documentation built on Oct. 30, 2020, 1:07 a.m.