em | R Documentation |
A concrete R6 object for EM Algorithm.
Returns R6 object of class em.
fmmr6::AbstractMethod
-> fmmr6::EstimMethod
-> em
fit()
Fit the model using the EM algorithm
em$fit( algo = "em", max_iter = 500, start = "random", rep = 1, div_tol = 10, verbose = F )
algo
(character(1)
)
Specify the type of EM algorithm to use. Can choose em
stands for the
conventional EM algorithm, cem
stands for the classification EM algorithm,
and sem
stands for the stochastic EM algorithm.
The default algorithm is em
.
max_iter
(numeric(1)
)
Specify the maximum number of iterations for the E-step-M-step loop.
The default number is 500.
start
(character(1)
)
Specify the starting method of the EM algorithm.
Can either start from kmeans
or random
.
kmeans
use the K-mean methods to put samples into latent classes.
random
randomly assigns samples into latent classes.
The default method is kmeans
.
rep
(numeric(1)
)
Specify the number of reps EM-algorithm runs.
This parameter is designed for preventing the local maximum.
Each rep, the EM_algorithm generates a start.
It is only useful when start
is random
.
After all reps, the algorithm will pick the rep with maximum log likelihood.
The default value is 1
div_tol
(numeric(1)
)
Divergence tolerence: the convergence process stops if there are div_tol
number of
divergence ,i.e. the log-likelihood getting bigger.
verbose
(bool(1)
)
Print the converging log-likelihood for all steps.
em_start()
Generate the start value for the EM algorithm.
em$em_start(start = "kmeans")
start
(character(1)
)
Specify the starting method of the EM algorithm.
Can either start from kmeans
or random
.
kmeans
use the K-mean methods to put samples into latent classes.
random
randomly assigns samples into latent classes.
The default method is kmeans
.
em_algo()
Running the EM algorithm, given the start values, the data and number of classes.
em$em_algo(z, algo, max_iter, div_tol, verbose)
z
(matrix()
)
The matrix of the posterior probability.
algo
(character(1)
)
Specify the type of EM algorithm to use. Can choose em
stands for the
conventional EM algorithm, cem
stands for the classification EM algorithm,
and sem
stands for the stochastic EM algorithm.
The default algorithm is em
.
max_iter
(numeric(1)
)
Specify the maximum number of iterations for the E-step-M-step loop.
The default number is 500.
div_tol
(numeric(1)
)
Divergence tolerence: the convergence process stops if there are div_tol
number of
divergence ,i.e. the log-likelihood getting bigger.
verbose
(bool(1)
)
Print the converging log-likelihood for all steps.
estep()
Given the data, start values, the number of latent classes, compute the expected value of the indicator variable.
em$estep(theta_update, pi_vector)
theta_update
(matrix()
)
Updated coefficients
pi_vector
(matrix()
)
The matrix with the diagonal values representing the prior probability \pi
.
return the probability matrix indicating the posterior probability of individual belonging to each class.
cstep()
Given the posterior probability, generate a matrix to assign each individual to a class. The assignment based on which probability is the largest.
em$cstep(hidden)
hidden
(matrix()
)
The matrix of the posterior probability
sstep()
Given the posterior probability, generate a matrix to assign each individual to a class. The assignment is randomly sampled based on the posterior probability.
em$sstep(hidden)
hidden
(matrix()
)
The matrix of the posterior probability
mstep()
Given the data, start values, the number of latent classes, the indicator variable, the likelihood function, solve the maximum value of the likelihood function and update the parameter vectors theta.
em$mstep(hidden, theta, alpha = NULL, optim_method = "base")
hidden
(matrix()
)
The matrix of the posterior probability.
theta
(matrix()
)
The matrix of the coefficients to fit.
optim_method
(character(1)
)
The optimization method to use to fit the model.
The default is base
.
clone()
The objects of this class are cloneable with this method.
em$clone(deep = FALSE)
deep
Whether to make a deep clone.
Dongjie Wu
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.