-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBScanModule.py
More file actions
33 lines (28 loc) · 893 Bytes
/
DBScanModule.py
File metadata and controls
33 lines (28 loc) · 893 Bytes
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
from pointClass import Point
def RangeQuery(DB, Q, eps):
Neighbors = set()
for P in DB:
if Point.getMetric(Q, P) <= eps:
Neighbors.add(P)
return Neighbors
def Scan(DB, eps, minPTS):
C = 0
N = set()
for P in DB:
if P.label == 'Undefined':
N = RangeQuery(DB, P, eps)
if len(N) < minPTS:
P.setLabel('Noise')
else:
C = C + 1
P.setLabel(str(C))
S = N.difference(P)
for Q in S:
if Q.label == 'Noise':
Q.setLabel(str(C))
if Q.label == 'Undefined':
Q.setLabel(str(C))
N = RangeQuery(DB, Q, eps)
if len(N) >= minPTS:
S = S | N
print('County of clusters = ', C)