def merge_candidates_scan(candidates, seriesuid, distance=5.):
distances = pdist(candidates, metric='euclidean')
adjacency_matrix = squareform(distances)
# Determine nodes within distance, replace by 1 (=adjacency matrix)
adjacency_matrix = np.where(adjacency_matrix<=distance,1,0)
# Determine all connected components in the graph
n, labels = connected_components(adjacency_matrix)
new_candidates = np.zeros((n,3))
# Take the mean for these connected components
for cluster_i in range(n):
points = candidates[np.where(labels==cluster_i)]
center = np.mean(points,axis=0)
new_candidates[cluster_i,:] = center
x = new_candidates[:,0]
y = new_candidates[:,1]
z = new_candidates[:,2]
labels = [seriesuid]*len(x)
class_name = [0]*len(x)
data= zip(labels,x,y,z,class_name)
new_candidates = pd.DataFrame(data,columns=CANDIDATES_COLUMNS)
return new_candidates
评论列表
文章目录