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!