graphstorm.model.RelGraphConvLayer
- class graphstorm.model.RelGraphConvLayer(in_feat, out_feat, rel_names, num_bases, *, weight=True, bias=True, activation=None, self_loop=False, dropout=0.0, num_ffn_layers_in_gnn=0, ffn_activation=<function relu>, norm=None)
Relational graph convolution layer from Modeling Relational Data with Graph Convolutional Networks.
A generic module for computing convolution on heterogeneous graphs.
The relational graph convolution layer applies GraphConv on the relation graphs, which reads the features from source nodes and writes the updated ones to destination nodes. If multiple relations have the same destination node types, their results are aggregated by the specified method. If the relation graph has no edge, the corresponding module will not be called.
Mathematically for the GraphConv it is defined as follows:
\[h_i^{(l+1)} = \sigma(b^{(l)} + \sum_{j\in\mathcal{N}(i)}\frac{1}{c_{ji}}h_j^{(l)}W^{(l)})\]where \(\mathcal{N}(i)\) is the set of neighbors of node \(i\), \(c_{ji}\) is the product of the square root of node degrees (i.e., \(c_{ji} = \sqrt{|\mathcal{N}(j)|}\sqrt{|\mathcal{N}(i)|}\)), and \(\sigma\) is an activation function.
If a weight tensor on each edge is provided, the weighted graph convolution is defined as:
\[h_i^{(l+1)} = \sigma(b^{(l)} + \sum_{j\in\mathcal{N}(i)}\frac{e_{ji}}{c_{ji}}h_j^{(l)}W^{(l)})\]where \(e_{ji}\) is the scalar weight on the edge from node \(j\) to node \(i\). This is NOT equivalent to the weighted graph convolutional network formulation in the paper.
Note:
In the RelGraphConvLayer, the implementation select ‘right’ or the default option for the norm
to divide the aggregated messages by each node’s in-degrees, which is equivalent to averaging the received messages.
Examples:
# suppose graph and input_feature are ready from graphstorm.model.rgcn_encoder import RelGraphConvLayer layer = RelGraphConvLayer( h_dim, h_dim, g.canonical_etypes, num_bases, activation, self_loop, dropout, num_ffn_layers_in_gnn, ffn_activation, norm) h = layer(g, input_feature)
Parameters
- in_featint
Input feature size.
- out_featint
Output feature size.
- rel_nameslist[str]
Relation names.
- num_basesint
Number of bases. If is none, use number of relations. Default: None.
- weightbool, optional
True if a linear layer is applied after message passing. Default: True
- biasbool, optional
True if bias is added. Default: True
- activationcallable, optional
Activation function. Default: None
- self_loopbool, optional
True to include self loop message. Default: False
- dropoutfloat, optional
Dropout rate. Default: 0.0
- num_ffn_layers_in_gnn: int, optional
Number of layers of ngnn between gnn layers
- ffn_actication: torch.nn.functional
Activation Method for ngnn
- normstr, optional
Normalization Method. Default: None