how to model multivariate normal distribution in matlab?

8 views (last 30 days)
I have a data set of ut, control input which i would like to model it as a mixture with K component Gaussian densities. p(ut) = sum(pi*(N(ut;mean;covariance)). Sum from 1 to the K. Pi is the mixing parameter. N denotes the multivariate normal density function. With only data set ut, i have to estimate the mean, covariance and the mixing parameter with expectation maximisation algorithm. Below is the code that i wrote trying to model it. i wonder if they are correct or did i miss out anything?
obju = gmdistribution.fit(U1',K,'SharedCov',true,'CovType','diagonal');
sigmau = obju.Sigma;
muu = obju.mu;
pu=0;
for k=1:T-m
pu = mvnpdf(U1(:,k),muu(1),sigmau)+mvnpdf(U1(:,k),muu(2),sigmau)+pu;
end

Answers (1)

Peter Perkins
Peter Perkins on 27 Nov 2012
Wei, unless you want to evaluate each component's pdf separately, I think you want to use the pdf method of the gaussian mixture distribution that you've created with gmdistributin.fit:
Hope this helps.
  1 Comment
Wei Cai Law
Wei Cai Law on 28 Nov 2012
Edited: Wei Cai Law on 28 Nov 2012
I tried to model a multivariate gaussian density with just a data set to estimate the mean, covariance and mixing parameter using gmdistribution.fit. But i dont know whether its correct. Here is my code:
function Ecc = Econtrol(O,K,m,T,n,q1,p2)
x = reshape(O(1:2*n),2,n);
U1 = reshape(O(2*n+1:q1),1,p2);
x=x';
obju = gmdistribution.fit(U1',K,'SharedCov',true,'CovType','diagonal');
objx = gmdistribution.fit(x,K,'SharedCov',true,'CovType','diagonal');
px=0;
for k=1:m
px = log(pdf(objx,x(k,:))+pdf(objx,x(k,:)))+px;
end
pu=0;
for k=1:T-m
pu = log(pdf(obju,U1(:,k))+pdf(obju,U1(:,k)))+pu;
end
Ecc = -px -pu;
end
below is the equation i wanna model. is it correct?
%

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!