gammagl.layers.conv.GCNConv

class GCNConv(in_channels, out_channels, norm='both', add_bias=True)[source]

The graph convolutional operator from the “Semi-supervised Classification with Graph Convolutional Networks” paper

\[\mathbf{X}^{\prime} = \mathbf{\hat{D}}^{-1/2} \mathbf{\hat{A}} \mathbf{\hat{D}}^{-1/2} \mathbf{X} \mathbf{\Theta},\]

where \(\mathbf{\hat{A}} = \mathbf{A} + \mathbf{I}\) denotes the adjacency matrix with inserted self-loops and \(\hat{D}_{ii} = \sum_{j=0} \hat{A}_{ij}\) its diagonal degree matrix. The adjacency matrix can include other values than 1 representing edge weights via the optional edge_weight tensor.

Its node-wise formulation is given by:

\[\mathbf{x}^{\prime}_i = \mathbf{\Theta} \sum_{j \in \mathcal{N}(v) \cup \{ i \}} \frac{e_{j,i}}{\sqrt{\hat{d}_j \hat{d}_i}} \mathbf{x}_j\]

with \(\hat{d}_i = 1 + \sum_{j \in \mathcal{N}(i)} e_{j,i}\), where \(e_{j,i}\) denotes the edge weight from source node j to target node i (default: 1.0)

Parameters:
  • in_channels (int) – Size of each input sample.

  • out_channels (int) – Size of each output sample.

  • norm (str, optional) –

    How to apply the normalizer. Can be one of the following values:

    • right, to divide the aggregated messages by each node’s in-degrees, which is equivalent to averaging the received messages.

    • none, where no normalization is applied.

    • both (default), where the messages are scaled with \(1/c_{ji}\) above, equivalent to symmetric normalization.

    • left, to divide the messages sent out from each node by its out-degrees, equivalent to random walk normalization.

  • add_bias (bool, optional) – If set to False, the layer will not learn an additive bias. (default: True)

forward(x, edge_index, edge_weight=None, num_nodes=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 Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

message_aggregate(x, edge_index, edge_weight=None, aggr='sum')[source]

try to fuse message and aggregate to reduce expensed edge information.