gmdistribution.fit and gmdistribution help needed
이전 댓글 표시
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?

%
댓글 수: 1
Daniel Shub
2012년 11월 28일
Closed as doit4me, please show your what you have tried and where you are stuck.
채택된 답변
추가 답변 (1개)
Wei Cai Law
2012년 11월 29일
댓글 수: 4
Tom Lane
2012년 11월 29일
An ill-conditioned matrix can result from various things. One might be a cluster with too few components to estimate a full-rank covariance. Sharing or forcing a diagonal would be possible ways to deal with that.
pdf(obj,x), where obj is a gmdistribution object, computes the full mixture distribution for you. So I think you want to revert back to the old code, but compute log(pdf()) rather than log(pdf()+pdf()). Furthermore, you don't need to loop over a single row at a time. Check this out, showing how you can compute the pdf for the entire array and get the same answer as if you did each row separately:
>> x = [0 0;0 1;1 1;10 10;10 11;11 11];
>> g = gmdistribution.fit(x,2);
>> pdf(g,[.4 .5]) + pdf(g,[.7 .7])
ans =
0.6487
>> pdf(g,[.4 .5;.7 .7])
ans =
0.3631
0.2856
>> sum(ans)
ans =
0.6487
Wei Cai Law
2012년 12월 4일
Tom Lane
2012년 12월 12일
I don't understand. The variable g represents both components. pdf(g,x) compute the sum over both. Are you asking how to get at each one individually?
Wei Cai Law
2012년 12월 14일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!