gmdistribution.fit and gmdistribution help needed
Afficher commentaires plus anciens
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 commentaire
Daniel Shub
le 28 Nov 2012
Closed as doit4me, please show your what you have tried and where you are stuck.
Réponse acceptée
Plus de réponses (1)
Wei Cai Law
le 29 Nov 2012
4 commentaires
Tom Lane
le 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
le 4 Déc 2012
Tom Lane
le 12 Déc 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
le 14 Déc 2012
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!