Skip to contents

This helper function calls the C++ routine mfaTimeseriesCpp() with a user-specified cluster assignment (z_init) and then computes the final log-likelihood and responsibilities in R.

Usage

mfa_em_fit_cpp_singleInit(
  list_of_data,
  K,
  r,
  z_init,
  max_iter = 50,
  nIterFA = 20,
  tol = 0.001,
  verbose = TRUE,
  n_threads = 0,
  seed = 0,
  progress_callback = NULL,
  em_type = c("hard", "soft")
)

Arguments

list_of_data

A list of (T_i x M) matrices, one for each subject.

K

Number of clusters.

r

Factor dimension in each cluster.

z_init

An integer vector of length N (where N=length(list_of_data)), giving the initial cluster label (1..K) for each subject.

max_iter

Maximum EM iterations in C++.

nIterFA

Number of sub-iterations for the factor analyzer update in C++.

tol

Convergence tolerance used in C++.

verbose

Logical; if TRUE, print progress messages. Default is TRUE.

n_threads

Integer; number of OpenMP threads to use (0 = auto). Default is 0.

seed

Integer; random seed for C++ RNG (0 = default/no seed). Default is 0.

progress_callback

Optional function to report progress from C++. Should accept two arguments: current iteration and total iterations.

em_type

Character; type of EM algorithm to use. Either "hard" (classification EM with hard assignments) or "soft" (standard EM with responsibility-weighted updates). Default is "hard".

Value

A list with elements:

z

Hard cluster assignments, length N.

pi

Cluster mixing proportions, length K.

mu

List of length K, each a mean vector (M x 1).

Lambda

List of length K, each an M x r factor loading matrix.

Psi

List of length K, each an M x M diagonal noise matrix.

logLik

Final log-likelihood computed in R.

resp

An N x K matrix of responsibilities.

Examples

if (FALSE) { # \dontrun{
# Suppose we have list_of_data, K=3, r=2:
z_init <- sample.int(3, size=length(list_of_data), replace=TRUE)
fit_one <- mfa_em_fit_cpp_singleInit(list_of_data, K=3, r=2,
                                     z_init=z_init)
fit_one$logLik
} # }