mixle.stats.latent.gaussian_mixture module¶
Multivariate Gaussian mixtures built on the generic mixture machinery.
The Gaussian mixture classes are thin specializations of
mixle.stats.latent.mixture. They construct multivariate-Gaussian
components from packed (mu, sig2) arrays and reuse the generic mixture
scoring, posterior, EM, fused-likelihood, keying, and stability behavior.
A K-component multivariate Gaussian mixture has density
P(x) = sum_{k=1}^{K} w_k * N(x; mu_k, sigma_k),
where each observation is a length-d real vector. sig2 may be supplied as
full (K, d, d) covariance matrices or as per-component diagonal variances
with shape (K, d).
- class GaussianMixtureDistribution(mu, sig2, w=MISSING, name=None, weights=MISSING)[source]
Bases:
MixtureDistributionFinite mixture of full-covariance multivariate Gaussian components.
The constructor packs each
(mu[k], sig2[k])pair into aMultivariateGaussianDistribution. Density, posterior responsibility, and vectorized scoring behavior are inherited fromMixtureDistribution.- Parameters:
mu (Sequence[Sequence[float]] | ndarray) – Component means with shape
(K, d).sig2 (Sequence[Any] | ndarray) – Component covariance matrices with shape
(K, d, d)or diagonal variances with shape(K, d).w (Sequence[float] | ndarray) – Mixture weights with length
K.name (str | None) – Optional diagnostic name.
- mu
Component means as a
(K, d)NumPy array.
- sig2
Component covariance matrices as a
(K, d, d)NumPy array.
- dim
Observation dimension.
- density_semantics()[source]
Return exact-or-approximate density semantics joined from Gaussian components.
- sampler(seed=None)[source]
Return a sampler that draws vectors from this Gaussian mixture.
- Parameters:
seed (int | None) – Optional seed for reproducible component and Gaussian draws.
- Returns:
GaussianMixtureSamplerbound to this distribution.- Return type:
GaussianMixtureSampler
- estimator(pseudo_count=None)[source]
Return an estimator with matching Gaussian component structure.
- Parameters:
pseudo_count (float | None) – Optional smoothing mass for mixture weights.
- Returns:
GaussianMixtureEstimatorsuitable for fitting length-d vectors.- Return type:
GaussianMixtureEstimator
- dist_to_encoder()[source]
Return the Gaussian mixture encoder for iid vector observations.
- Return type:
GaussianMixtureDataEncoder
- class GaussianMixtureSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSampler for iid draws from a Gaussian mixture.
- Parameters:
dist (GaussianMixtureDistribution) – Gaussian mixture distribution to sample from.
seed (int | None) – Optional seed for reproducible component and Gaussian draws.
- rng
Random state used for component labels.
- compSamplers
Per-component Gaussian samplers.
- sample(size=None, *, batched=True)[source]
Draw iid samples from the Gaussian mixture.
If size is None, a single length-d numpy array is returned. Otherwise a numpy array with shape (size, d) containing ‘size’ iid samples is returned. With
batched=True(default) component draws are grouped and scattered – bit-identical to the per-draw loop (batched=False) but far faster, since each component sampler owns an independent RNG.
- class GaussianMixtureAccumulator(accumulators, keys=(None, None))[source]
Bases:
MixtureAccumulatorEM accumulator for Gaussian mixture responsibilities and component stats.
Vectorized E-step, fused-likelihood tracking, scalar update/initialize, combine/value/from_value, and key merge/replace behavior are inherited from
MixtureAccumulator. The specialization only supplies the Gaussian mixture encoder.- Parameters:
- acc_to_encoder()[source]
Return an encoder compatible with the component accumulators.
- Return type:
GaussianMixtureDataEncoder
- class GaussianMixtureEstimatorAccumulatorFactory(factories, dim, keys=(None, None))[source]
Bases:
MixtureAccumulatorFactoryFactory for Gaussian mixture EM accumulators.
- Parameters:
- make()[source]
Return a fresh Gaussian mixture accumulator.
- Return type:
GaussianMixtureAccumulator
- class GaussianMixtureEstimator(estimators, name=None, conj_prior_params=None, suff_stat=None, pseudo_count=None, keys=(None, None))[source]
Bases:
MixtureEstimatorEM estimator for a multivariate Gaussian mixture.
The weight M-step and robustness options are inherited from
MixtureEstimator. The specialization repacks fitted Gaussian components into(mu, sig2, w)arrays for aGaussianMixtureDistribution.- Parameters:
estimators (Sequence[ParameterEstimator]) – Component estimators, typically multivariate Gaussian estimators.
name (str | None) – Optional diagnostic name.
conj_prior_params (Any | None) – Reserved compatibility slot.
suff_stat (ndarray | None) – Optional prior component-count vector used with
pseudo_count.pseudo_count (float | None) – Optional smoothing mass for mixture weights.
keys (tuple[str | None, str | None]) – Optional shared-statistic keys for weights and components.
- accumulator_factory()[source]
Return a Gaussian mixture accumulator factory.
- Return type:
GaussianMixtureEstimatorAccumulatorFactory
- accumulatorFactory()[source]
Backward-compatible alias for
accumulator_factory().New code should call
accumulator_factory. The camelCase name remains available for older callers and returns the same factory.- Return type:
GaussianMixtureEstimatorAccumulatorFactory
- estimate(nobs, suff_stat)[source]
Estimate a Gaussian mixture from aggregated EM sufficient statistics.
The component M-step and weight estimate reuse the generic mixture estimator path. The fitted component means and covariances are then repacked into a
GaussianMixtureDistribution.
- class GaussianMixtureDataEncoder(encoder=None)[source]
Bases:
MixtureDataEncoderEncoder for iid vector observations in a Gaussian mixture.
- Parameters:
encoder (DataSequenceEncoder | None) – Optional component encoder. Defaults to
MultivariateGaussianDataEncoder.
- GaussianMixtureAccumulatorFactory
alias of
GaussianMixtureEstimatorAccumulatorFactory