-
Notifications
You must be signed in to change notification settings - Fork 0
/
clusteringModule.py
36 lines (29 loc) · 972 Bytes
/
clusteringModule.py
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
# Euclidean Clustering Module
# author Aaron Brown
# modified by W.Jin and S.Lim
import numpy as np
from sklearn.neighbors import KDTree
def clusterHelper(index, points, cluster, processed, tree, distanceTol):
processed[index] = True
cluster.append(index)
nearest_index, nearest_distance = tree.query_radius([points[index]], r=distanceTol, return_distance=True)
for i in range(len(nearest_index[0])):
idx = nearest_index[0][i]
if processed[idx] == False:
clusterHelper(idx, points, cluster, processed, tree, distanceTol)
def euclideanCluster(points, tree, distanceTol):
clusters = []
processed = [False for i in range(len(points))]
i = 0
while i < len(points):
if processed[i] == True:
i += 1
continue
cluster = []
clusterHelper(i, points, cluster, processed, tree, distanceTol)
if(len(cluster) > 10):
clusters.append(cluster)
i += 1
return clusters
if __name__ == "__main__":
print("Error.. Why clusteringModule execute")