Single-Run Mixture Factor Analysis with a Preset Initial Assignment
Source:R/mfa_em_fit.R
mfa_em_fit_cpp_singleInit.RdThis 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(whereN=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 isTRUE.- 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:
zHard cluster assignments, length
N.piCluster mixing proportions, length
K.muList of length
K, each a mean vector (M x 1).LambdaList of length
K, each anM x rfactor loading matrix.PsiList of length
K, each anM x Mdiagonal noise matrix.logLikFinal log-likelihood computed in R.
respAn
N x Kmatrix 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
} # }