-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcitcles_DBSCAN.m
51 lines (44 loc) · 895 Bytes
/
citcles_DBSCAN.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
clear;clc;close all;
addpath('algorithm');
%% load data and normalization
load data/3circle.mat
c = length(unique(Y));
%%
%using euclidean distance measurement
distmat=zeros(size(X,1),size(X,1));
for i=1:size(X,1)
for j=i:size(X,1)
distmat(i,j)=sqrt((X(i,1:2)-X(j,1:2))*(X(i,1:2)-X(j,1:2))');
end
end
for i=1:size(X,1)
for j=i:size(X,1)
distmat(j,i)=distmat(i,j);
end
end
% k_dist=zeros(size(data,1),1);
% figure
% for k=3:5
% for i=1:size(data,1)
% tmp=sort(distmat(:,i),'ascend');
% k_dist(i)=tmp(k);
% end
% hold on
% plot(1:size(data,1),k_dist);
% end
%%
Eps=0.7;
MinPts=5;
Clust = DBSCAN(distmat,Eps,MinPts);
x=X(:,1);
y=X(:,2);
%plot different clusters
figure
for i=1:max(Clust)
hold on
scatter(x(Clust==i),y(Clust==i),'filled');
end
%plot the noise
hold on
scatter(x(Clust==0),y(Clust==0),'*')
title('DBSCAN')