ChebConv
- class dgl.nn.pytorch.conv.ChebConv(in_feats, out_feats, k, activation=<function relu>, bias=True)[源码]
基类:
Module
来自 Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering 的 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\) 是可学习权重。
- 参数:
示例
>>> 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)[源码]
计算 ChebNet 层。
- 参数:
graph (DGLGraph) – 输入图。
feat (torch.Tensor) – 输入特征,形状为 \((N, D_{in})\),其中 \(D_{in}\) 是输入特征的大小,\(N\) 是节点数量。
lambda_max (list or tensor or None, 可选.) –
一个长度为 \(B\) 的列表(张量),存储
graph
中每个独立图的归一化 Laplacian 的最大特征值,其中 \(B\) 是输入图的批大小。默认值: None。如果为 None,此方法将把默认值设为 2。可以使用
dgl.laplacian_lambda_max()
计算该值。
- 返回值:
输出特征,形状为 \((N, D_{out})\),其中 \(D_{out}\) 是输出特征的大小。
- 返回值类型:
torch.Tensor