Skip to content

Matlab script to fit univariate Gaussian Mixture Model (GMM) to a distribution of an observable

License

Notifications You must be signed in to change notification settings

Fluorescence-Tools/1D_GaussianFit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1D_GaussianFit

Matlab script to fit univariate Gaussian Mixture Model (GMM) to a distribution of an observable

General description

This script uses fitgmdist function to fit the univariate Gaussian Mixture Model (GMM) to data, using a maximum likelihood estimator (MLE). GMM uses a superposition of k normal distributions, with mixing proportion xk, mean value µk and variance σk2. fitgmdist operates on raw and not on histogrammed data, and is therefore independent on the bin settings later used in the visualization of the results. As an otput, fitgmdist function returns GModel object, which contains the following properties:

  • number of compoenent in a mixture model
  • mean, variance and proportion of the components
  • negative log likelihood at the found minimum
  • information criteria, i.e. Akaike Information Criterion (AIC) and Bayesian Information Criterion (BIC)

Script is made to be used in interactive/explorative manner, and runs in sections. In the first section, no assumption on the fit model are made. Tested are GMM models with up to Ngaussians components, and the model with the minimum BIC value is taken as the one that describes data the best.

GMM_fit_Ng3

Alternatively, if there are presumptions about the distribution, in the following three code sections it also possible to fit specific GMM models to data, with up to three components. Script saves png and svg file of a histogram, overlayed with fit model as well as individual components in the mixture model. Fit results can be easily transfered to a spreadsheet: in the workspace right-clik on the observable of interest and select Copy. Alternatively a line of a code can be added to automatize export of the fit results, or an entire workspace can be saved for convenient handling of data at later point.

Input data

Currently script load a .txt file of a size Nx1 using importdata function. For input file extensions which are not compatible with importdata, consider other import functions. Exemplary input file is provided in example_data directory.

Dependencies

Fit_1D_GMM.m is a MATLAB script built on MATLAB R2019a, which requires fitgmdist function introduced in R2014a.

References

  1. McLachlan, G., and D. Peel. Finite Mixture Models. Hoboken, NJ: John Wiley & Sons, Inc., 2000.

Authors

  • Milana Popara

About

Matlab script to fit univariate Gaussian Mixture Model (GMM) to a distribution of an observable

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • MATLAB 100.0%