⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lvqcode.m

📁 这里包含了聚类的工具箱还有很详细的文档说明
💻 M
字号:
function [centro,nvoro] = lvqcode(X,centri,iter)

[N,d] = size(X);
[M,dc] = size(centri);

if dc ~= d
    disp('Dimensions from data and centroids is not equal?!')
    return;
end

% d = data dimension
% N = number of points
% L = number of iterations

centro = centri;

alph = 0.5/iter;

[dummy,pos] = sort(rand(1,N));
%pos = 1:N;
nvoro = zeros(M,1);
for n = 1:N

    datum = X(pos(n),:);

    diff = sqrt(sum((centro - ones(M,1)*datum).^2,2));
    minpos = find(diff==min(diff));
    minpos = minpos(1); % case there are two centroids, we choose the first one
    nvoro(minpos) = nvoro(minpos) + 1;

    centro(minpos,:) = (1-alph)*centro(minpos,:) + alph*datum;
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -