precluster.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:texta 作者: texta-tk 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号