gammagl.layers.conv.SimpleHGNConv¶
- class SimpleHGNConv(in_feats, out_feats, num_etypes, edge_feats, heads=1, negative_slope=0.2, feat_drop=0.0, attn_drop=0.0, residual=False, activation=None, bias=False, beta=0.0)[source]¶
The SimpleHGN layer from the “Are we really making much progress? Revisiting, benchmarking, and refining heterogeneous graph neural networks” paper
The model extend the original graph attention mechanism in GAT by including edge type information into attention calculation.
Calculating the coefficient:
\[\alpha_{ij} = \frac{exp(LeakyReLU(a^T[Wh_i||Wh_j||W_r r_{\psi(<i,j>)}]))}{\Sigma_{k\in\mathcal{E}}{exp(LeakyReLU(a^T[Wh_i||Wh_k||W_r r_{\psi(<i,k>)}]))}} (1)\]Residual connection including Node residual:
\[h_i^{(l)} = \sigma(\Sigma_{j\in \mathcal{N}_i} {\alpha_{ij}^{(l)}W^{(l)}h_j^{(l-1)}} + h_i^{(l-1)}) (2)\]and Edge residual:
\[\alpha_{ij}^{(l)} = (1-\beta)\alpha_{ij}^{(l)}+\beta\alpha_{ij}^{(l-1)} (3)\]Multi-heads:
\[h^{(l+1)}_j = \parallel^M_{m = 1}h^{(l + 1, m)}_j (4)\]Residual:
\[h^{(l+1)}_j = h^{(l)}_j + \parallel^M_{m = 1}h^{(l + 1, m)}_j (5)\]- Parameters:
in_feats (int) – the input dimension
out_feats (int) – the output dimension
num_etypes (int) – the number of the edge type
edge_feats (int) – the edge dimension
heads (int, optional) – the number of heads in this layer
negative_slope (float, optional) – the negative slope used in the LeakyReLU
feat_drop (float, optional) – the feature drop rate
attn_drop (float, optional) – the attention score drop rate
residual (bool, optional) – whether we need the residual operation
activation (, optional) – the activation function
bias (bool, optional) – whether we need the bias
beta (float, optional) – the hyperparameter used in edge residual
- message(x, edge_index, edge_feat, num_nodes, res_alpha=None)[source]¶
Function that construct message from source nodes to destination nodes.
- Parameters:
x (tensor) – input node feature.
edge_index (tensor) – edges from src to dst.
edge_weight (tensor, optional) – weight of each edge.
- Returns:
tensor – output message
Returns – the message matrix, and the shape is [num_edges, message_dim]
- propagate(x, edge_index, aggr='sum', **kwargs)[source]¶
Function that perform message passing.
- Parameters:
x – input node feature.
edge_index – edges from src to dst.
aggr – aggregation type, default=’sum’, optional=[‘sum’, ‘mean’, ‘max’].
kwargs – other parameters dict.
- forward(x, edge_index, edge_feat, res_attn=None)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.