gmdistribution.fit and gmdistribution help needed
2 次查看(过去 30 天)
显示 更早的评论
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.
采纳的回答
Tom Lane
2012-11-28
I don't know if your code is correct, but:
1. The text seems not to declare that the covariance is diagonal, and does use notation to suggested that it may not be shared across mixture components.
2. Unless I'm just not seeing something, you seem to compute pdf(objx,x(k,:)) twice inside the log, and the same for U, but I don't know why you would want that.
3. Your text describes U as multivariate, but you seem to create U1 with just one row and index into it repeatedly, getting scalar values each time.
4. It may be possible to avoid the loops and compute the pdf on an entire array in one call, then sum the log of the result.
0 个评论
更多回答(1 个)
Wei Cai Law
2012-11-29
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cloud Integrations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!