szemeredi_regularity_lemma.py 文件源码

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

项目:dense_graph_reducer 作者: MarcoFiorucci 项目源码 文件源码
def reconstruct_original_mat(self, thresh, intracluster_weight=0):
        """
        reconstruct a similarity matrix with size equals to the original one, from the reduced similarity matrix
        :param thresh: a threshold parameter to prune the edges of the graph
        :param intracluster_weight: the weight to assign at each connection generated by the expansion of a cluster
        :return: the reconstructed graph
        """
        reconstructed_mat = np.zeros((self.N, self.N))

        r_nodes = self.classes > 0

        reconstructed_mat[np.ix_(r_nodes, r_nodes)] = intracluster_weight

        for r in range(2, self.k + 1):
            r_nodes = self.classes == r
            reconstructed_mat[np.ix_(r_nodes, r_nodes)] = intracluster_weight
            for s in range(1, r):
                if self.is_weighted:
                    cl_pair = WeightedClassesPair(self.sim_mat, self.adj_mat, self.classes, r, s, self.epsilon)
                else:
                    cl_pair = ClassesPair(self.adj_mat, self.classes, r, s, self.epsilon)

                s_nodes = self.classes == s
                if cl_pair.bip_density > thresh:
                    reconstructed_mat[np.ix_(r_nodes, s_nodes)] = reconstructed_mat[np.ix_(s_nodes, r_nodes)] = cl_pair.bip_density
        np.fill_diagonal(reconstructed_mat, 0.0)
        return reconstructed_mat
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号