% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gaussian_mixture.R
\name{gaussian_mixture_em}
\alias{gaussian_mixture_em}
\title{Gaussian Mixture EM -- direct R port of GaussianMixture.m (Bowman CLUSTER)}
\usage{
gaussian_mixture_em(x, k = 2L)
}
\arguments{
\item{x}{Numeric vector of observations (the C_peak values in the window).}

\item{k}{Integer number of components (default 2).}
}
\value{
Named list:
  \describe{
    \item{mu}{Numeric vector length \code{k}: component means sorted
      ascending.}
    \item{sigma}{Numeric vector length \code{k}: component standard
      deviations (= sqrt of fitted variance), sorted to match \code{mu}.}
    \item{prop}{Numeric vector length \code{k}: mixing proportions, sorted
      to match \code{mu}.}
    \item{loglik}{Scalar: log-likelihood at convergence.}
  }
}
\description{
Fits a K-component univariate Gaussian mixture using the same EM algorithm
bundled with CharAnalysis v1.1 and v2.0 (Bowman CLUSTER implementation).
Replicates three key behaviours that distinguish it from \code{mclust}:
}
\details{
\enumerate{
  \item \strong{First/last-point initialisation}: for K = 2, component
    means are seeded at the first and last elements of the input data
    vector (not at sorted min/max; the data are in time order).  This is
    the \code{initMixture()} behaviour from MATLAB.
  \item \strong{Loose convergence criterion}: EM stops when the per-step
    log-likelihood gain falls to or below
    \eqn{\epsilon = 0.01 \times L_c \times \log N} where \eqn{L_c = 3}
    for univariate data.  This is much looser than the \code{mclust}
    default (\eqn{10^{-5}}) and causes MATLAB to freeze closer to the
    initial configuration.
  \item \strong{Variance regularisation}: a small floor
    \eqn{R_{\min} = \bar{\sigma}^2 / 10^5} is added to each component
    variance after every M-step, preventing degenerate (zero-variance)
    solutions.
}

Because CharAnalysis always calls \code{GaussianMixture(X, 2, 2, false)}
(i.e.\ \code{finalK = initK = 2}), the \code{MDLReduceOrder()} path is
never exercised and is therefore not implemented here.
}
\seealso{
[char_thresh_local()], [char_thresh_global()]
}
