📄 loglike_mvgm.c
字号:
/* loglike_mvgm.c
Compute the loglikelihood of mixture of Multivariate Gaussian pdf.
Usage: logl = loglike_mvgm(Z , mu , sigma , p);
------
Inputs
------
Z Measure (d x K x [s1] x ....x [sn])
mu Mean parameters (d x 1 x [v1] x ... x [vp])
sigma Covariance parameters (d x d x [v1] x ... x [vp])
p Weight parameters (1 x 1 x [v1] x ... x [vp]), sum(p) = 1
Outputs
-------
logl Loglikelihood ([s1] x ... x [sn] x [v1] x ... x [vp]) matrix.
Example
--------
N = 200;
V = 90;
OV = ones(1 , V);
mu = cat(3 , [-5 ; -5] , [0 ; 0] ,[ 5 ; 5]); %(d x 1 x M)
sigma = cat(3 , [2 0; 0 1] , [2 -.2; -.2 2] , [1 .9; .9 1] ); %(d x d x M)
p = cat(3 , [0.3] , [0.1] , [0.6]); %(1 x 1 x M)
M = mu(: , : , : , OV) + 0.5*randn(2 , 1 , 3 , V);
S = sigma(: , : , : , OV) + 0.01*randn(2 , 2 , 3 , V);
P = p(: , : , : , OV);
Z = mvgmmrnd(N , mu , sigma , p);
[x , y] = ndellipse(mu , sigma);
[X , Y] = ndellipse(M , S);
logl = loglike_mvgm(Z , M , S , P);
logltrue = loglike_mvgm(Z , mu , sigma , p);
figure(1)
plot(Z(1 , :) , Z(2 , :) , 'k+',reshape(permute(X , [1 3 2]) , 50*V , 3) , reshape(permute(Y , [1 3 2]) , 50*V , 3) , 'markersize' , 2 , 'linewidth' , 1);
hold on
plot( x , y , 'g' , reshape(mu(1 , : , :) , 1 , 3) , reshape(mu(2 , : , :) , 1 , 3) , 'r+' , 'markersize' , 6 , 'linewidth' , 2);
hold off
figure(2),plot(1:V , logl , 1:V , logltrue(: , ones(1 , V))),grid on
To compile :
-----------
mex -output loglike_mvgm.dll loglike_mvgm.c
Myself, I use Intel CPP compiler as :
mex -f mexopts_intel10amd.bat -output loglike_mvgm.dll loglike_mvgm.c
Ver 1.1 (03/26/05)
Changle Log
1.0 Initial release
1.1 New Feature : nd slices measurements is now accepted
Author : S閎astien PARIS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -