GMM Utility Functions

gmmUtils.py - Gaussian Mixture Model Utilities

Gaussian mixture model utility functions for fitting approximations to posterior probability distributions.

approxposterior.gmmUtils.fitGMM(samples, maxComp=3, covType='full', useBic=True, gmmKwargs=None)[source]

Fit a Gaussian Mixture Model to the posterior samples to derive an approximation of the posterior density. Fit for the number of components by either minimizing the Bayesian Information Criterior (BIC) or via cross-validation.

Parameters
  • samples (numpy array) – sampler.flatchain MCMC chain array of dimensions (nwalkers x nsteps, ndim)

  • maxComp (int (optional)) – Maximum number of mixture model components to fit for. Defaults to 3.

  • covType (str (optional)) – GMM covariance type. Defaults to “full”. See the documentation here: http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html for more info

  • useBic (bool (optional)) – Minimize the BIC to pick the number of GMM components or use 5-fold cross validation? Defaults to True (aka, use the BIC)

  • gmmKwargs (dict (optional)) – keyword arguments for sklearn.mixture.GaussianMixture. Defaults to None

Returns

GMM – fitted Gaussian mixture model

Return type

sklearn.mixture.GaussianMixture