简介
冯·诺依曼图熵(VNGE)有助于测量图序列中图之间的信息差异和距离。
给定第一个无向图 , 其中 是对称的邻接矩阵。 度矩阵定义为 ,则它的拉普拉斯矩阵为 。其中后者的特征值 被称为拉普拉斯谱。 这里, 为冯诺依曼图熵(von Neumann graph entropy)。
图的容量为 。时间复杂度较高,是 。
我提供了Python版本代码来计算VNGE。应该注意的是陈等人给出了一种称为FINGER [1]的近似方法,该方法将VNGE的三次复杂度降低为节点和边的数量的线性复杂度。
VNGE和FINGER的代码如下。
代码
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# Name: VNGE # Author: Reacubeth # Time: 2021/1/25 16:01 # Mail: noverfitting@gmail.com # Site: www.omegaxyz.com # *_*coding:utf-8 *_* import time import numpy as np from scipy.sparse.linalg.eigen.arpack import eigsh def normalized_laplacian(adj_matrix): nodes_degree = np.sum(adj_matrix, axis=1) nodes_degree_sqrt = 1/np.sqrt(nodes_degree) degree_matrix = np.diag(nodes_degree_sqrt) eye_matrix = np.eye(adj_matrix.shape[0]) return eye_matrix - degree_matrix * adj_matrix * degree_matrix def unnormalized_laplacian(adj_matrix): nodes_degree = np.sum(adj_matrix, axis=1) degree_matrix = np.diag(nodes_degree) return degree_matrix - adj_matrix def VNGE_exact(adj_matrix): start = time.time() nodes_degree = np.sum(adj_matrix, axis=1) c = 1.0 / np.sum(nodes_degree) laplacian_matrix = c * unnormalized_laplacian(adj_matrix) eigenvalues, _ = np.linalg.eig(laplacian_matrix) eigenvalues[eigenvalues < 0] = 0 pos = eigenvalues > 0 H_vn = - np.sum(eigenvalues[pos] * np.log2(eigenvalues[pos])) print('H_vn exact:', H_vn) print('Time:', time.time() - start) def VNGE_FINGER(adj_matrix): start = time.time() nodes_degree = np.sum(adj_matrix, axis=1) c = 1.0 / np.sum(nodes_degree) edge_weights = 1.0 * adj_matrix[np.nonzero(adj_matrix)] approx = 1.0 - np.square(c) * (np.sum(np.square(nodes_degree)) + np.sum(np.square(edge_weights))) laplacian_matrix = unnormalized_laplacian(adj_matrix) ''' eigenvalues, _ = np.linalg.eig(laplacian_matrix) eig_max = c * max(eigenvalues) ''' eig_max, _ = eigsh(laplacian_matrix, 1, which='LM') eig_max = eig_max[0] * c H_vn = - approx * np.log2(eig_max) print('H_vn approx:', H_vn) print('Time:', time.time() - start) nodes_num = 3000 sparsity = 0.01 tmp_m = np.random.uniform(0, 1, (nodes_num, nodes_num)) pos1 = tmp_m > sparsity pos2 = tmp_m <= sparsity tmp_m[pos1] = 0 tmp_m[pos2] = 1 tmp_m = np.triu(tmp_m) adj_m = tmp_m + np.transpose(tmp_m) VNGE_exact(adj_m) VNGE_FINGER(adj_m) |
结果
H_vn exact: 11.496599468152386
Time: 13.172455072402954
H_vn approx: 10.63029083591871
Time: 0.23734617233276367
[1] Chen, Pin-Yu, et al. "Fast incremental von neumann graph entropy computation: Theory, algorithm, and applications." International Conference on Machine Learning. PMLR, 2019.
更多内容访问 [omegaxyz.com](https://www.omegaxyz.com/)
网站所有代码采用Apache 2.0授权
网站文章采用知识共享许可协议BY-NC-SA4.0授权
© 2021 • OmegaXYZ-版权所有 转载请注明出处