Be the first to rate this file! 15 Downloads (last 30 days) File Size: 20.6 KB File ID: #17560
image thumbnail




16 Nov 2007 (Updated )

Fast implementation of EM algorithm for multivariate gaussian mixture

| Watch this File

File Information

Mex implementation of EM algorithm for multivariate Gaussian mixture. Multiple data/initial parameters are allowed by ND slices definition

 em_mvgm : Expectation-Maximization algorithm for Multivariate Gaussian Mixtures


 [logl , M , S , P] = em_mvgm(Z , M0 , S0 , P0 , [nbite]);


 Z Measurements (m x K x [n1] x ... x [nl])
 M0 Initial mean vector. M0 can be (m x 1 x p x [v1] x ... x [vr])
 S0 Initial covariance matrix. S0 can be (m x m x p x [v1] x ... x [vr])
 P0 Initial mixture probabilities (1 x 1 x p) : P0 can be (1 x 1 x d x [v1] x ... x [vr])
 nbite Number of iteration (default = 10)


 logl Final loglikelihood (n1 x ... x nl x v1 x ... x vr)
 M Estimated mean vector (d x 1 x p x n1 x ... x nl v1 x ... x vr)
 S Estimated covariance vector (d x d x p x n1 x ... x nl v1 x ... x vr)
 P Estimated initial probabilities (1 x 1 x p x n1 x ... x nl v1 x ... x vr)

Please run mexme_em_mvgm for compile mex file on your own systems.

Run test_em_mvgm.m for a demo


Fast Nd Multidimensional Gaussian Mixture Random Generator inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Other requirements A C compiler
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
24 Feb 2010 Gayathri

Works like charm after running the mex compilation code and the test program included. Will post more comments after checking the correctness of the program.

17 Dec 2008 Florian


thank you very much for the fast reply!

Unfortunately I still get NaNs in all elements of the em_ghmm results (command: [logl , PIest , Aest , Mest , Sest] = em_ghmm(Ztrain , PI0 , A0 , M0 , S0 , options);).

Maybe these information are also useful:
I needed to add

#define max(a,b) ( (a) >= (b) ? (a) : (b) )

in some of the files (also in em_ghmm.c) to overcome the error

undefined reference to `max'

With this addition, everything compiles fine, with a warning when I compile ndellipse.c:

ndellipse.c:138: warning: assignment discards qualifiers from pointer target type
ndellipse.c:165: warning: assignment discards qualifiers from pointer target type
ndellipse.c:205: warning: assignment discards qualifiers from pointer target type

But as far I can see, the ndellipse function is not used until the first call of em_ghmm in the fest file test_em_ghmm.m.

17 Dec 2008 Sebastien PARIS

Have you tried by recompiling as this script below ?

echo on
mex em_ghmm.c
mex -Dbetanormalize forward_backward.c
mex likelihood_mvgm.c
mex ndellipse.c
mex -DranSHR3 sample_ghmm.c
echo off

Never tried on 64 bits system

17 Dec 2008 Florian

I am using R2008a on a 64bit machine under Linux. I made the files compile, but unfortunately, when I run the test_em_mvgm.m, I get NaN as results of the em_mvgm-function. Do I have to set specific options when compiling the files? Did anyone else have similar problems and solve this problem?

18 Nov 2007 Sebastien PARIS

Please recompile the mex-File by following command :

mex -output em_mvgm.dll em_mvgm.c

17 Nov 2007 Scott Miller

Hmm. Seems to crash my machine after the first pause with a minidump. I'm running 2007b

17 Nov 2007 Dimitri Shvorob

How is your implementation different from
apart from yours being in C rather than Matlab?

17 Dec 2008

- add mexme_em_mvgm to build mex files and compatible with LCC compiler.

19 Jan 2009

Fixed bug in the likelihood constant computation

04 Feb 2009

Correct a bug in likelihood_mvgm.c when d=1

19 Oct 2010

-Fixed a bug for Linux64 & GCC

03 Jan 2011

-Fix a compilation error for Linux and // comments

12 Oct 2011

-Minor update for Linux

19 Jan 2012

-Fix a bug introduced in the last update

27 Nov 2012

-Fix 2 bugs (thanks to Jonathan for reporting)

Contact us