runme.m
来自「duke的tutorial on EM的matlab经典源码」· M 代码 · 共 45 行
M
45 行
% Number of points
N = 300;
% Number of mixture components
K = 3;
% Number of dimensions
D = 2;
% Generate random points from a mixture
[x, pTrue, mTrue, sigmaTrue, classTrue] = makeClusters(N, K, D);
% Assuming that the true value of K is known
K = K;
% See kmeans.m for other calling options
[mKM, classKM, niterKM] = kmeans(x, K);
% See emi.m and em.m for other calling options
[pEM, mEM, sigmaEM, pknEM, niterEM] = emi(x, K);
[dummy, classEM] = colmax(pknEM);
% Display
figure(1)
showClusters(x, mTrue, classTrue);
title('True Clusters')
figure(2)
showClusters(x, mKM, classKM);
if niterKM < 0
iterKM = 'Max Number of';
else
iterKM = sprintf('%d', niterKM);
end
title(sprintf('Clusters from %s Iterations of K Means', iterKM))
figure(3)
showClusters(x, mEM, classEM);
if niterEM < 0
iterEM = 'Max Number of';
else
iterEM = sprintf('%d', niterEM);
end
title(sprintf('Clusters Inferred from EM Probabilities (%s Iterations)', iterEM))
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?