def create_laplacian_dict(self): # 拉普拉斯字典 def symmetric_norm_lap(adj): # rowsum = np.array(adj.sum(axis=1)) d_inv_sqrt = np.power(rowsum, -0.5).flatten() d_inv_sqrt[np.isinf(d_inv_sqrt)] = 0 d_mat_inv_sqrt = sp.diags(d_inv_sqrt) norm_adj = d_mat_inv_sqrt.dot(adj).dot(d_mat_inv_sqrt) return norm_adj.tocoo() def random_walk_norm_lap(adj): # 传入邻接矩阵 rowsum = np.array(adj.sum(axis=1)) # 行总和 d_inv = np.power(rowsum, -1.0).flatten() d_inv[np.isinf(d_inv)] = 0 d_mat_inv = sp.diags(d_inv) norm_adj = d_mat_inv.dot(adj) return norm_adj.tocoo() # 归一化的邻接稀疏矩阵 if self.laplacian_type == 'symmetric': # 解释器默认的是random—walk norm_lap_func = symmetric_norm_lap elif self.laplacian_type == 'random-walk': norm_lap_func = random_walk_norm_lap # 拉普拉斯的功能就用这个 else: raise NotImplementedError self.laplacian_dict = {} for r, adj in self.adjacency_dict.items(): self.laplacian_dict[r] = norm_lap_func(adj) A_in = sum(self.laplacian_dict.values()) self.A_in = self.convert_coo2tensor(A_in.tocoo())
时间: 2024-03-28 18:39:03 浏览: 95
Laplacian.rar_laplacian_matlab laplacian_拉普拉斯滤波
可以看出这段代码是用来创建拉普拉斯字典的。其中使用了两种不同的归一化方法,分别是对称归一化和随机游走归一化。如果选择对称归一化,就使用函数symmetric_norm_lap,如果选择随机游走归一化,就使用函数random_walk_norm_lap。然后遍历邻接矩阵字典,对每一个邻接矩阵都进行相应的归一化操作,最后将所有的归一化邻接矩阵相加,得到A_in,并将其转换为张量格式。
阅读全文