gmdistribution.fit and gmdistribution help needed
Mostra commenti meno recenti
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 Commento
Daniel Shub
il 28 Nov 2012
Closed as doit4me, please show your what you have tried and where you are stuck.
Risposta accettata
Più risposte (1)
Wei Cai Law
il 29 Nov 2012
4 Commenti
Tom Lane
il 29 Nov 2012
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
il 4 Dic 2012
Tom Lane
il 12 Dic 2012
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
il 14 Dic 2012
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!