📄 240.txt
字号:
发信人: GzLi (笑梨), 信区: DataMining
标 题: [转载] Re: 聚类算法的源代码
发信站: 南京大学小百合站 (Sat Jul 6 16:10:36 2002), 站内信件
【 以下文字转载自 AI 讨论区 】
【 原文由 fascination 所发表 】
function [x,esq,j] = kmeans(d,k,x0)
%KMEANS Vector quantisation using K-means algorithm [X,ESQ,J]=(D,K,X0)
%Inputs:
% D contains data vectors (one per row)
% K is number of centres required
% X0 are the initial centres (optional)
%
%Outputs:
% X is output row vectors (K rows)
% ESQ is mean square error
% J indicates which centre each data vector belongs to
% Based on a routine by Chuck Anderson, anderson@cs.colostate.edu, 1996
% Copyright (C) Mike Brookes 1998
%
% Last modified Mon Jul 27 15:48:23 1998
%
% VOICEBOX home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebo
x.html
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You can obtain a copy of the GNU General Public License from
% ftp://prep.ai.mit.edu/pub/gnu/COPYING-2.0 or by writing to
% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%
[n,p] = size(d);
if nargin<3
x = d(ceil(rand(1,k)*n),:);
else
x=x0;
end
y = x+1;
while any(x(:) ~= y(:))
z = disteusq(d,x,'x');
[m,j] = min(z,[],2);
y = x;
for i=1:k
s = j==i;
if any(s)
x(i,:) = mean(d(s,:),1);
else
q=find(m~=0);
if isempty(q) break; end
r=q(ceil(rand*length(q)));
x(i,:) = d(r,:);
m(r)=0;
y=x+1;
end
end
end
esq=mean(m,1);
【 在 chdq135 (阿权) 的大作中提到: 】
: 在北大的搜索引擎去看看
: 有SOM、art聚类算法源代码
: 关键词可以是NerualNetworkSourcesCode
: 【 在 songmdm (songmdm) 的大作中提到: 】
: : 谁有聚类算法的源代码(任何一种)? 谢谢
: : MailTo: songhaiyu7719@sina.com
--
※ 来源:.南京大学小百合站 bbs.nju.edu.cn.[FROM: 202.120.118.48]
--
※ 转载:.南京大学小百合站 bbs.nju.edu.cn.[FROM: 211.80.38.29]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -