fit_ghm {mrf2d} | R Documentation |
EM estimation for Gaussian Hidden Markov field
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 (Zhang et al. 2001), which is described in (Freguglia et al. 2020).
Usage
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 |
theta |
A 3-dimensional array describing potentials. Slices represent
interacting positions, rows represent pixel values and columns represent
neighbor values. As an example: |
fixed_fn |
A list of functions |
equal_vars |
|
init_mus |
Optional. A |
init_sigmas |
Otional. A |
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 |
icm_cycles |
Number of steps used in the Iterated Conditional Modes algorithm executed in each interaction. Defaults to 6. |
verbose |
|
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 (\mu
and \sigma
) parameters
in consecutive iterations is less than max_dist
.
Value
A hmrfout
containing:
-
par
: Adata.frame
with\mu
and\sigma
estimates for each component. -
fixed
: Amatrix
with the estimated fixed effect in each pixel. -
Z_pred
: Amatrix
with the predicted component (highest probability) in each pixel. -
predicted
: Amatrix
with the fixed effect + the\mu
value for the predicted component in each pixel. -
iterations
: Number of EM iterations done.
Author(s)
Victor Freguglia
References
Freguglia V, Garcia NL, Bicas JL (2020).
“Hidden Markov random field models applied to color homogeneity evaluation in dyed textile images.”
Environmetrics, 31(4), e2613.
Zhang Y, Brady M, Smith S (2001).
“Segmentation of brain MR images through a hidden Markov random field model and the expectation-maximization algorithm.”
IEEE transactions on medical imaging, 20(1), 45–57.
See Also
A paper with detailed description of the package can be found at doi: 10.18637/jss.v101.i08.
Examples
# 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)