资源简介
Clustering by fast search and find of density peaks
代码片段和文件信息
clear all
close all
disp(‘The only input needed is a distance matrix file‘)
disp(‘The format of this file should be: ‘)
disp(‘Column 1: id of element i‘)
disp(‘Column 2: id of element j‘)
disp(‘Column 3: dist(ij)‘)
mdist=input(‘name of the distance matrix file (with single quotes)?\n‘);
disp(‘Reading input distance matrix‘)
xx=load(mdist);
ND=max(xx(:2));
NL=max(xx(:1));
if (NL>ND)
ND=NL;
end
N=size(xx1);
for i=1:ND
for j=1:ND
dist(ij)=0;
end
end
for i=1:N
ii=xx(i1);
jj=xx(i2);
dist(iijj)=xx(i3);
dist(jjii)=xx(i3);
end
percent=2.0;
fprintf(‘average percentage of neighbours (hard coded): %5.6f\n‘ percent);
position=round(N*percent/100);
sda=sort(xx(:3));
dc=sda(position);
fprintf(‘Computing Rho with gaussian kernel of radius: %12.6f\n‘ dc);
for i=1:ND
rho(i)=0.;
end
%
% Gaussian kernel
%
for i=1:ND-1
for j=i+1:ND
rho(i)=rho(i)+exp(-(dist(ij)/dc)*(dist(ij)/dc));
rho(j)=rho(j)+exp(-(dist(ij)/dc)*(dist(ij)/dc));
end
end
%
% “Cut off“ kernel
%
%for i=1:ND-1
% for j=i+1:ND
% if (dist(ij) % rho(i)=rho(i)+1.;
% rho(j)=rho(j)+1.;
% end
% end
%end
maxd=max(max(dist));
[rho_sortedordrho]=sort(rho‘descend‘);
delta(ordrho(1))=-1.;
nneigh(ordrho(1))=0;
for ii=2:ND
delta(ordrho(ii))=maxd;
for jj=1:ii-1
if(dist(ordrho(ii)ordrho(jj)) delta(ordrho(ii))=dist(ordrho(ii)ordrho(jj));
nneigh(ordrho(ii))=ordrho(jj);
end
end
end
delta(ordrho(1))=max(delta(:));
disp(‘Generated file:DECISION GRAPH‘)
disp(‘column 1:Density‘)
disp(‘column 2:Delta‘)
fid = fopen(‘DECISION_GRAPH‘ ‘w‘);
for i=1:ND
fprintf(fid ‘%6.2f %6.2f\n‘ rho(i)delta(i));
end
disp(‘Select a rectangle enclosing cluster centers‘)
scrsz = get(0‘ScreenSize‘);
figure(‘Position‘[6 72 scrsz(3)/4. scrsz(4)/1.3]);
for i=1:ND
ind(i)=i;
gamma(i)=rho(i)*delta(i);
end
subplot(211)
tt=plot(rho(:)delta(:)‘o‘‘MarkerSize‘5‘MarkerFaceColor‘‘k‘‘MarkerEdgeColor‘‘k‘);
title (‘Decision Graph‘‘FontSize‘15.0)
xlabel (‘\rho‘)
ylabel (‘\delta‘)
subplot(211)
rect = getrect(1);
rhomin=rect(1);
deltamin=rect(4);
NCLUST=0;
for i=1:ND
cl(i)=-1;
end
for i=1:ND
if ( (rho(i)>rhomin) && (delta(i)>deltamin))
NCLUST=NCLUST+1;
cl(i)=NCLUST;
icl(NCLUST)=i;
end
end
fprintf(‘NUMBER OF CLUSTERS: %i \n‘ NCLUST);
disp(‘Performing assignation‘)
%assignation
for i=1:ND
if (cl(ordrho(i))==-1)
cl(ordrho(i))=cl(nneigh(ordrho(i)));
end
end
%halo
for i=1:ND
halo(i)=cl(i);
end
if (NCLUST>1)
for i=1:NCLUST
bord_rho(i)=0.;
end
for i=1:ND-1
for j=i+1:ND
if ((cl(i)~=cl(j))&& (dist(ij)<=dc))
rho_aver=(rho(i)+rho(j))/2.;
if (rho_aver>bord_rho(cl(i)))
bord_rho(cl(i))=rho_aver;
end
if (rho_aver>bord_rho(cl(j)))
bord_rho(cl(j))=rho_aver;
end
end
end
end
for i=1:ND
if (rho(i) halo(i)=0;
end
end
end
for i=1:NCLUST
nc=0;
nh=0;
for j=1:N
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1938924 2016-05-27 15:27 Clustering-by-fast-search-and-find-of-density-peaks.pdf
文件 4525 2014-04-30 10:32 cluster_dp.m
文件 29771107 2014-04-30 15:20 example_distances.dat
文件 6110 2016-05-27 15:32 fast_cluster.cpp
文件 1606000 2016-05-27 15:41 Rodriguez.SM.pdf
评论
共有 条评论