ChebConv
- class dgl.nn.pytorch.conv.ChebConv(in_feats, out_feats, k, activation=<function relu>, bias=True)[source]
Bases:
Module
来自图上的快速局部谱滤波卷积神经网络的Chebyshev谱图卷积层
\[ \begin{align}\begin{aligned}h_i^{l+1} &= \sum_{k=0}^{K-1} W^{k, l}z_i^{k, l}\\Z^{0, l} &= H^{l}\\Z^{1, l} &= \tilde{L} \cdot H^{l}\\Z^{k, l} &= 2 \cdot \tilde{L} \cdot Z^{k-1, l} - Z^{k-2, l}\\\tilde{L} &= 2\left(I - \tilde{D}^{-1/2} \tilde{A} \tilde{D}^{-1/2}\right)/\lambda_{max} - I\end{aligned}\end{align} \]其中 \(\tilde{A}\) 是 \(A\) + \(I\),\(W\) 是可学习的权重。
- Parameters:
示例
>>> import dgl >>> import numpy as np >>> import torch as th >>> from dgl.nn import ChebConv >> >>> g = dgl.graph(([0,1,2,3,2,5], [1,2,3,4,0,3])) >>> feat = th.ones(6, 10) >>> conv = ChebConv(10, 2, 2) >>> res = conv(g, feat) >>> res tensor([[ 0.6163, -0.1809], [ 0.6163, -0.1809], [ 0.6163, -0.1809], [ 0.9698, -1.5053], [ 0.3664, 0.7556], [-0.2370, 3.0164]], grad_fn=<AddBackward0>)
- forward(graph, feat, lambda_max=None)[source]
计算ChebNet层。
- Parameters:
graph (DGLGraph) – The graph.
feat (torch.Tensor) – 输入特征的形状为 \((N, D_{in})\),其中 \(D_{in}\) 是输入特征的大小,\(N\) 是节点的数量。
lambda_max (list 或 tensor 或 None, 可选.) –
一个长度为 \(B\) 的列表(tensor),存储每个单独图的归一化拉普拉斯矩阵的最大特征值, 其中 \(B\) 是输入图的批量大小。默认值:None。
如果为 None,此方法将默认值设置为 2。 可以使用
dgl.laplacian_lambda_max()
来计算此值。
- Returns:
The output feature of shape \((N, D_{out})\) where \(D_{out}\) is size of output feature.
- Return type:
torch.Tensor