Skip to contents

This helper function calls the updated C++ routine mpcaTimeseriesCpp() with a user-specified cluster assignment (z_init), then converts the returned W into (P, D) and constructs Psi, and finally computes the final log-likelihood and responsibilities in R.

Usage

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

Arguments

list_of_data

A list of matrices (each T_i x M).

K

Number of clusters.

r

Number of principal components (dimension).

max_iter

Maximum EM iterations (C++).

nIterPCA

Sub-iterations for updating each cluster's PPCA parameters in C++.

tol

Convergence tolerance (C++).

method

Either "EM" or "closed_form", passed to mpcaTimeseriesCpp.

z_init

An integer vector of length N giving initial cluster labels (1..K).

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 (1..K).

pi

Mixing proportions (length K).

mu

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

W

List of length K, each an (M x r) loading matrix (optional).

P

List of length K, each an (M x r) matrix of principal directions.

D

List of length K, each an (r x r) diagonal matrix of column norms.

Psi

List of length K, each an (M x M) diagonal matrix sigma2 * I.

logLik

Final log-likelihood computed in R.

sigma2

Numeric vector of length K, the final sigma2 for each cluster.

resp

An (N x K) matrix of responsibilities.

Examples

if (FALSE) { # \dontrun{
# Suppose we have list_of_data, K=3, r=2, method="EM", plus some z_init:
z_init <- sample.int(3, size=length(list_of_data), replace=TRUE)
fit_one <- mixture_pca_em_fit_cpp_singleInit(
  list_of_data, K=3, r=2, max_iter=50, nIterPCA=20, tol=1e-3,
  method="EM", z_init=z_init
)
print(fit_one$logLik)
# Now we can call compute_factor_scores_mpca(fit_one, list_of_data) because fit_one$W exists
} # }