DenseSAGEConv๏
- class dgl.nn.pytorch.conv.DenseSAGEConv(in_feats, out_feats, feat_drop=0.0, bias=True, norm=None, activation=None)[source]๏
Bases:
ModuleGraphSAGE layer from Inductive Representation Learning on Large Graphs
We recommend to use this module when appying GraphSAGE on dense graphs.
Note that we only support gcn aggregator in DenseSAGEConv.
- Parameters:
in_feats (int) โ Input feature size; i.e, the number of dimensions of \(h_i^{(l)}\).
out_feats (int) โ Output feature size; i.e, the number of dimensions of \(h_i^{(l+1)}\).
feat_drop (float, optional) โ Dropout rate on features. Default: 0.
bias (bool) โ If True, adds a learnable bias to the output. Default:
True.norm (callable activation function/layer or None, optional) โ If not None, applies normalization to the updated node features.
activation (callable activation function/layer or None, optional) โ If not None, applies an activation function to the updated node features. Default:
None.
Example
>>> 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>)
See also
- forward(adj, feat)[source]๏
Description๏
Compute (Dense) Graph SAGE layer.
- param adj:
The adjacency matrix of the graph to apply SAGE Convolution on, when applied to a unidirectional bipartite graph,
adjshould be of shape should be of shape \((N_{out}, N_{in})\); when applied to a homo graph,adjshould be of shape \((N, N)\). In both cases, a row represents a destination node while a column represents a source node.- type adj:
torch.Tensor
- param feat:
If a torch.Tensor is given, the input feature of shape \((N, D_{in})\) where \(D_{in}\) is size of input feature, \(N\) is the number of nodes. If a pair of torch.Tensor is given, the pair must contain two tensors of shape \((N_{in}, D_{in})\) and \((N_{out}, D_{in})\).
- type feat:
torch.Tensor or a pair of torch.Tensor
- returns:
The output feature of shape \((N, D_{out})\) where \(D_{out}\) is size of output feature.
- rtype:
torch.Tensor