Covariance matrix Kmeans in matlab

4 views (last 30 days)
amj
amj on 8 Sep 2017
Hi, I would like to generate the covariance matrix using kmeans algorithm in Matlab as initial parameter estimation. Later on, i want to use the parameter estimation in gaussian mixture model.
This is the code in matlab:
[idx,C] = kmeans(Faithful,2);
theta.mu = C';
theta.tau = hist(idx,2)/length(idx);
for j = 1:K
theta.Sigma(:,:,j) = cov(Faithful(idx==j,:));
end
Is that the correct way to estimate the covariance matrix? The result yielded:
(:,:,1) =
0.1722 0.7471
0.7471 31.7966
(:,:,2) =
0.1543 1.0129
1.0129 35.5095
This is because, when i checked from mixtools package in R, the results are bit different whereas the covariance elements in second covariance matrix are more than 1 as shown in above compared to the answer below:
[[1]]
[,1] [,2]
[1,] 0.06916788 0.4351698
[2,] 0.43516975 33.6972966
[[2]]
[,1] [,2]
[1,] 0.1699681 0.9406057
[2,] 0.9406057 36.0461700
If i want to compute the pdf, can i simply recall the parameter estimate for theta.Sigma like this?:
densEst(pointsObserved,j) = mvnpdf(X(pointsObserved,:),theta.mu(:,j)',theta.Sigma(:,:,j));

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!