Computes responsibilities \(\gamma_{ik}\) given current parameters. Expects params$invSigma and params$logdet to be precomputed (see init_cov_cache_fast()).

Updates mixture parameters given responsibilities, optionally with a quadratic prior penalty on stacked means via Q_prior. Supports covariance models: "VVV", "VII", "EII", "EEI".

Fits a Gaussian mixture model with optional quadratic prior penalty on the stacked mean vector mu. The algorithm alternates E-steps and penalized M-steps and records both a penalized observed-data objective and a penalized ELBO trace.

compute_log_joint_observed(
  X,
  params,
  Q_prior = NULL,
  eigen_tol = NULL,
  rank_deficiency = 0,
  Q_base = NULL,
  lambda = NULL
)

compute_penalized_ELBO(
  X,
  Gamma,
  params,
  Q_prior = NULL,
  eigen_tol = NULL,
  rank_deficiency = 0,
  Q_base = NULL,
  lambda = NULL
)

ESTEP(data, params)

MSTEP(
  data,
  gamma,
  params,
  Q_prior = NULL,
  relative_lambda = FALSE,
  modelName = "VVV",
  iterate_once = TRUE,
  nugget = 0,
  rank_deficiency = 0,
  tol_inner = 1e-06,
  max_inner = 20,
  verbose = FALSE
)

EM_algorithm(
  data,
  init_params,
  Q_prior = NULL,
  iterate_once = TRUE,
  max_inner = 10,
  modelName = "VVV",
  max_iter = 100,
  tol = 1e-04,
  inner_tol = 1e-06,
  eigen_tol = NULL,
  rank_deficiency = 0,
  nugget = 0,
  relative_lambda = FALSE,
  verbose = TRUE,
  include.data = TRUE
)

Arguments

params

Current parameter list (used mainly for starting sigma).

Q_prior

Optional precision matrix on stacked means (d*K x d*K).

eigen_tol

Optional tolerance passed to generalized_logdet().

rank_deficiency

Rank deficiency for pseudo-determinant correction (commonly q*d).

data

Numeric matrix (n x d) of observations.

gamma

Numeric matrix (n x K) responsibilities.

relative_lambda

Logical; if TRUE, rescales Q_prior by current marginal variances.

modelName

Covariance model: one of "VVV", "VII", "EII", "EEI".

iterate_once

Logical; if TRUE, stop after one EM iteration (often used inside wrappers).

nugget

Nonnegative diagonal jitter added to covariance estimates.

tol_inner, max_inner

Inner-loop controls when iterating mu <-> sigma.

max_inner

Maximum number of inner iterations inside the M-step.

verbose

Logical; print progress.

init_params

Initial parameters as a list with pi, mu, sigma.

max_iter

Maximum number of EM iterations.

tol

Convergence tolerance on ELBO changes.

inner_tol

Tolerance for inner iterations inside the M-step.

include.data

Logical; if TRUE, include data in the returned list.

Value

Numeric matrix (n x K) of responsibilities.

List with updated pi, mu, sigma.

A list with:

  • params: final parameters (including cached invSigma and logdet).

  • gamma: responsibility matrix (n x K).

  • elbo_trace: numeric vector.

  • loglik_trace: numeric vector.