def _create_clusterings(self,dendrogram):
clusterings = [[(-(dendrogram.distance),dendrogram)]]
for threshold in np.linspace(-self._max_dist,-self._min_dist,self.number_of_steps)[1:]:
new_clustering = clusterings[-1][:] # set new clustering to be equivalent to previous
# Expand previous clustering
while new_clustering[0][0] < threshold and new_clustering[0][1].is_cluster():
expanded_cluster = heapq.heappop(new_clustering)[1]
left = expanded_cluster.left
right = expanded_cluster.right
if left.is_cluster():
heapq.heappush(new_clustering,(-left.distance,left))
else:
heapq.heappush(new_clustering,(-(self._min_dist-1),left))
if right.is_cluster():
heapq.heappush(new_clustering,(-right.distance,right))
else:
heapq.heappush(new_clustering,(-(self._min_dist-1),right))
clusterings.append(new_clustering)
return clusterings
评论列表
文章目录