CachedGCNConv(in_channels, out_channels, weight=None, bias=None, improved=False, use_bias=True, **kwargs)

Bases: MessagePassing

Implementation of the GCN layer from "Semi-supervised Classification with Graph Convolutional Networks" (Kipf & Welling, 2017) with caching capabilities.

Parameters:
  • in_channels (int) –

    Dimension of input features.

  • out_channels (int) –

    Dimension of output features.

  • weight (Tensor, default: None ) –

    Pre-initialized weight matrix. If None, weights are initialized using Glorot.

  • bias (Tensor, default: None ) –

    Pre-initialized bias vector. If None, bias is initialized to zeros.

  • improved (bool, default: False ) –

    If True, uses A + 2I instead of A + I for self-loops. Default is False.

  • use_bias (bool, default: True ) –

    Whether to use bias term. Default is True.

  • **kwargs (dict, default: {} ) –

    Additional arguments for MessagePassing base class.

forward(x, edge_index, cache_name='default_cache', edge_weight=None)

Forward pass of the layer.

Parameters:
  • x (Tensor) –

    Node feature matrix (num_nodes, in_channels).

  • edge_index (Tensor) –

    Edge indices (2, num_edges).

  • cache_name (str, default: 'default_cache' ) –

    Identifier for cached normalization. Default is "default_cache".

  • edge_weight (Tensor, default: None ) –

    Edge weights. Default is None.

Returns:
  • Tensor

    Output feature matrix (num_nodes, out_channels).

Notes

Caches the normalized adjacency computation for efficiency in transductive settings.

message(x_j, norm)

Message computation for message passing.

Parameters:
  • x_j (Tensor) –

    Features of neighboring nodes.

  • norm (Tensor) –

    Normalization coefficients.

Returns:
  • Tensor

    Normalized messages.

norm(edge_index, num_nodes, edge_weight=None, improved=False, dtype=None) staticmethod

Compute normalized adjacency matrix.

Parameters:
  • edge_index (Tensor) –

    Edge indices (2, num_edges).

  • num_nodes (int) –

    Number of nodes in the graph.

  • edge_weight (Tensor, default: None ) –

    Edge weights. Default is None (all ones).

  • improved (bool, default: False ) –

    Whether to use improved normalization. Default is False.

  • dtype (dtype, default: None ) –

    Data type for computations.

Returns:
  • tuple

    (edge_index, normalized_weights) where normalized_weights contains the symmetric normalization coefficients.

Notes

Implements D^(-1/2) * A * D^(-1/2) normalization with self-loops.

update(aggr_out)

Update node embeddings after message aggregation.

Parameters:
  • aggr_out (Tensor) –

    Aggregated messages.

Returns:
  • Tensor

    Updated node features with optional bias.