最近在学习GCN的模型,看了下pytorch源码,模型结构很清晰,非常适合学习,但是数据处理过程中关于邻接矩阵的求法,看了很久才明白,这里记录一下思路作为学习笔记,给有同感的小伙伴一些参考。
作者关于模型实现中的邻接矩阵也做了一些解释,按照作者的解释,实现中使用
详情请看链接:
http://tkipf.github.io/graph-convolutional-networks/
我们重点看一下源码中怎么实现的
一开始看到了下面这段代码中build symmetric adjacency matrix下面那句就懵了
edges = np.array(list(map(idx_map.get, edges_unordered.flatten())),
dtype=np.int32).reshape(edges_unordered.shape)
adj = sp.coo_matrix((np.ones(edges.shape[0]), (edges[:, 0], edges[:, 1])),
shape=(labels.shape[0], labels.shape[0]),
dtype=np.float32)
# build symmetric adjacency matrix
adj = adj &