em: EM Algorithm (EM) Object

emR Documentation

EM Algorithm (EM) Object

Description

A concrete R6 object for EM Algorithm.

Value

Returns R6 object of class em.

Super classes

fmmr6::AbstractMethod -> fmmr6::EstimMethod -> em

Methods

Public methods

Inherited methods

Method fit()

Fit the model using the EM algorithm

Usage
em$fit(
  algo = "em",
  max_iter = 500,
  start = "random",
  rep = 1,
  div_tol = 10,
  verbose = F
)
Arguments
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.


Method em_start()

Generate the start value for the EM algorithm.

Usage
em$em_start(start = "kmeans")
Arguments
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.


Method em_algo()

Running the EM algorithm, given the start values, the data and number of classes.

Usage
em$em_algo(z, algo, max_iter, div_tol, verbose)
Arguments
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.


Method estep()

Given the data, start values, the number of latent classes, compute the expected value of the indicator variable.

Usage
em$estep(theta_update, pi_vector)
Arguments
theta_update

(matrix())
Updated coefficients

pi_vector

(matrix())
The matrix with the diagonal values representing the prior probability \pi.

Returns

return the probability matrix indicating the posterior probability of individual belonging to each class.


Method cstep()

Given the posterior probability, generate a matrix to assign each individual to a class. The assignment based on which probability is the largest.

Usage
em$cstep(hidden)
Arguments
hidden

(matrix())
The matrix of the posterior probability


Method 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.

Usage
em$sstep(hidden)
Arguments
hidden

(matrix())
The matrix of the posterior probability


Method 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.

Usage
em$mstep(hidden, theta, alpha = NULL, optim_method = "base")
Arguments
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.


Method clone()

The objects of this class are cloneable with this method.

Usage
em$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Author(s)

Dongjie Wu


wudongjie/fmmr6 documentation built on June 24, 2022, 2:48 p.m.