首页 > 数据库 > 数据库开发技术 > 图神经网络09-经典GCN论文解读与代码复现
论文名称:SEMI-SUPERVISED CLASSIFICATION WITH GRAPH CONVOLUTIONAL NETWORKS

图半监督分类问题:只有一小部分或者节点的子集存在标签,比如通过引用构建构建的文献分类,这种问题我们可以定义为基于图的半监督学习。
传统做法基本为图的正则化处理,比如 Laplacian regularization ,损失函数形式如下:
代表有监督损失(图中带有label的部分),
可以是一个神经网络,
是一个权重因子,
是一个节点特征向量矩阵
,
代表非规范图拉普拉斯算子[ unnormalized graph Laplacian],其中图
,具有
个节点
,边
,邻接矩阵为
,度矩阵
。
Eq 1 假设图中具有连接边的节点标签是一样的,这种假设一定程度上限制了模型。

reference:zhangxwww.github.io/pos
本文提出了layer-wise propagation (也就是layer by layer training)的GCN:
其中,:
(1)
,这里指无向图的邻接矩阵,但是添加了自连接,也就是每个节点也可以指向自己 ,
代表第N个节点矩阵实体,另外
,
是一个可训练的参数矩阵;
(2)
代表激活函数,比如
;
(3)
代表
层的隐向量矩阵,
;
图上的spectral convolutions 被定义为输入
与filter
傅里叶变换的乘积:

其中
为图的normalized 拉普拉斯矩阵
的特征向量,
。
即为xx在图上的傅里叶变换。
可以取为
的函数
。由于计算矩阵特征分解复杂度非常高,作者借助切比雪夫多项式进行近似:
,
其中
,
,为切比雪夫多项式的系数。
切比雪夫多项式定义为:

考虑到
,有:
,
其中
,
这就是原式的K阶近似,只考虑到了每个结点的K阶邻点。本文令
。
同时,作者将
,这个近似是因为作者认为网络可以通过学到的scale适应这个变化。这样就得到了下面的式子:

更进一步令
,有:

注意到
的特征值在
内,对于深度网络来说可能会发生梯度消失/爆炸的情况。作者介绍了一个trick,来避免这种情况的发生:

其中 
因此通过下式就可以将C个通道的输入
转化为F维的输出:

其中 
模型定义为以下形式:
计算所有带有标签的样本的交叉熵:

数据集:
实验结果:
我们可以看到GCN比传统的节点分类算法(例如DeepWalk)效果高出了好多。
Pytorch实现:github.com/tkipf/pygcn
Tensorflow实现:github.com/tkipf/gcn
GCN 层的实现:
import mathimport torchfrom torch.nn.parameter import Parameterfrom torch.nn.modules.module import Moduleclass GraphConvolution(Module):
""" Simple GCN layer, similar to https://arxiv.org/abs/1609.02907 """
def __init__(self, in_features, out_features, bias=True):
super(GraphConvolution, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.weight = Parameter(torch.FloatTensor(in_features, out_features))
if bias:
self.bias = Parameter(torch.FloatTensor(out_features))
else:
self.register_parameter('bias', None)
self.reset_parameters()
def reset_parameters(self):
stdv = 1. / math.sqrt(self.weight.size(1))
self.weight.data.uniform_(-stdv, stdv)
if self.bias is not None:
self.bias.data.uniform_(-stdv, stdv)
def forward(self, input, adj):
support = torch.mm(input, self.weight)
output = torch.spmm(adj, support)
if self.bias is not None:
return output + self.bias
else:
return output
def __repr__(self):
return self.__class__.__name__ + ' (' \ + str(self.in_features) + ' -> ' \ + str(self.out_features) + ')'两层GCN模型的实现
import torch.nn as nn
import torch.nn.functional as F
from pygcn.layers import GraphConvolution
class GCN(nn.Module):
def __init__(self, nfeat, nhid, nclass, dropout):
super(GCN, self).__init__()
self.gc1 = GraphConvolution(nfeat, nhid)
self.gc2 = GraphConvolution(nhid, nclass)
self.dropout = dropout
def forward(self, x, adj):
x = F.relu(self.gc1(x, adj))
x = F.dropout(x, self.dropout, training=self.training)
x = self.gc2(x, adj)
return F.log_softmax(x, dim=1)完成训练代码以及数据集下载可以参考Pytorch实现:github.com/tkipf/pygcn


[论文笔记 | Semi-Supervised Classification With Graph Convolutional Networks](zhangxwww.github.io/pos)
论文笔记之:Semi-supervised Classification with Graph Convolutional Networks
[【GCN】论文笔记:SEMI-SUPERVISED CLASSIFICATION WITH GRAPH CONVOLUTIONAL NETWORKS](blog.csdn.net/qq_417276)
机器学习论文笔记-Semi-Supervised Classification with Graph Convolutional Networks
GRAPH CONVOLUTIONAL NETWORKS
【Graph Neural Network】GCN: 算法原理,实现和应用
Tutorial: Implementing Layer-Wise Relevance Propagation
大家加左图进入微信群;右图有QQ学习交流群


原文作者:ChallengeHub;如有侵权,请联系管理员删除。