DenseSAGEConv
- class dgl.nn.pytorch.conv.DenseSAGEConv(in_feats, out_feats, feat_drop=0.0, bias=True, norm=None, activation=None)[source]
Bases:
Module
来自大型图上的归纳表示学习的GraphSAGE层
我们建议在密集图上应用GraphSAGE时使用此模块。
请注意,我们仅在DenseSAGEConv中支持gcn聚合器。
- Parameters:
in_feats (int) – 输入特征大小;即,\(h_i^{(l)}\)的维度数。
out_feats (int) – Output feature size; i.e, the number of dimensions of \(h_i^{(l+1)}\).
feat_drop (float, optional) – 特征的丢弃率。默认值:0。
bias (bool) – If True, adds a learnable bias to the output. Default:
True
.norm (可调用的激活函数/层 或 无, 可选) – 如果不为None,则对更新的节点特征应用归一化。
activation (callable activation function/layer or None, optional) – If not None, applies an activation function to the updated node features. Default:
None
.
示例
>>> import dgl >>> import numpy as np >>> import torch as th >>> from dgl.nn import DenseSAGEConv >>> >>> feat = th.ones(6, 10) >>> adj = th.tensor([[0., 0., 1., 0., 0., 0.], ... [1., 0., 0., 0., 0., 0.], ... [0., 1., 0., 0., 0., 0.], ... [0., 0., 1., 0., 0., 1.], ... [0., 0., 0., 1., 0., 0.], ... [0., 0., 0., 0., 0., 0.]]) >>> conv = DenseSAGEConv(10, 2) >>> res = conv(adj, feat) >>> res tensor([[1.0401, 2.1008], [1.0401, 2.1008], [1.0401, 2.1008], [1.0401, 2.1008], [1.0401, 2.1008], [1.0401, 2.1008]], grad_fn=<AddmmBackward>)
另请参阅
- forward(adj, feat)[source]
Description
计算(密集)图SAGE层。
- param adj:
应用SAGE卷积的图的邻接矩阵,当应用于单向二分图时,
adj
的形状应为\((N_{out}, N_{in})\);当应用于同构图时,adj
的形状应为\((N, N)\)。在这两种情况下,一行代表一个目标节点,而一列代表一个源节点。- type adj:
torch.Tensor
- param feat:
如果给定一个 torch.Tensor,输入特征的形状为 \((N, D_{in})\),其中 \(D_{in}\) 是输入特征的大小,\(N\) 是节点的数量。 如果给定一对 torch.Tensor,这对张量必须包含两个形状为 \((N_{in}, D_{in})\) 和 \((N_{out}, D_{in})\) 的张量。
- type feat:
torch.Tensor 或一对 torch.Tensor
- returns:
The output feature of shape \((N, D_{out})\) where \(D_{out}\) is size of output feature.
- rtype:
torch.Tensor