NodeCentricConv(in_channels, out_channels, model_weights=(), lamb=0.2, aggr='mean', **kwargs)

Bases: MessagePassing

Node-centric graph convolution layer.

This layer implements a node-centric message passing mechanism with attention and weight-based feature transformation. It combines neighbor aggregation with learnable attention mechanisms and feature transformations.

Parameters:
  • in_channels (Union[int, Tuple[int, int]]) –

    Size of input features. If tuple, specifies different sizes for source and target nodes. If int, same size is used for both.

  • out_channels (int) –

    Size of output features

  • model_weights (tuple, default: () ) –

    Tuple of model weights for feature transformation (default is ())

  • lamb (float, default: 0.2 ) –

    Scaling factor for the base transformation (default is 0.2)

  • aggr (str, default: 'mean' ) –

    Aggregation scheme to use ('mean', 'sum', 'max') (default is 'mean')

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

    Additional arguments for MessagePassing base class

Attributes:
  • in_channels (Union[int, Tuple[int, int]]) –

    Input feature dimensions

  • out_channels (int) –

    Output feature dimension

  • weights_list (list) –

    List of transposed weight matrices for feature transformation

  • lamb (float) –

    Scaling factor for base transformation

  • att (Parameter) –

    Attention weight matrix of shape (out_channels, 1)

  • weight (Parameter) –

    Transform weight matrix of shape (in_channels, out_channels)

  • neigh_aggr (SimpleConv) –

    Neighbor aggregation layer with mean aggregation

  • sparse_attention (Sparsemax) –

    Sparsemax attention mechanism for dimension 1

Notes

The forward pass consists of several steps:

  1. Adds self-loops to the input graph
  2. Aggregates neighbor features
  3. Applies feature transformation with attention mechanism
  4. Combines transformed features with base transformation
forward(x, edge_index, edge_type=None)

Forward pass of the layer.

Parameters:
  • x (Union[Tensor, PairTensor]) –

    Node feature matrix of shape (num_nodes, in_channels) or pair of node feature matrices

  • edge_index (Adj) –

    Graph connectivity in COO format of shape (2, num_edges)

  • edge_type (OptTensor, default: None ) –

    Edge type information (default is None)

Returns:
  • Tensor

    Updated node features of shape (num_nodes, out_channels)

Notes

The forward pass performs these operations:

  1. Adds self-loops to edge_index
  2. Aggregates neighbor features using SimpleConv
  3. Applies multiple feature transformations with attention
  4. Combines transformed features with base transformation
message(x_j, gamma_i, edge_weight)

Compute messages between nodes.

Parameters:
  • x_j (Tensor) –

    Features of source nodes of shape (num_edges, in_channels)

  • gamma_i (Tensor) –

    Transformation coefficient for target nodes of shape (num_edges, in_channels)

  • edge_weight (OptTensor) –

    Optional edge weights of shape (num_edges,)

Returns:
  • Tensor

    Computed messages of shape (num_edges, in_channels)

Notes

The message function performs element-wise multiplication between source node features and transformation coefficients.

NodeCentricMLP(num_classes, model_list)

Bases: Module

Node-centric multi-layer perceptron.

This module implements a node-centric MLP with attention-based model ensemble.

Parameters:
  • num_classes (int) –

    Number of classes

  • model_list (list) –

    List of models to ensemble

Attributes:
  • att (Parameter) –

    Attention weight matrix

  • sparse_attention (Sparsemax) –

    Sparsemax attention mechanism

forward(x, edge_index, edge_weight=None)

Forward pass of the module.

Parameters:
  • x (Tensor) –

    Input node features

Returns:
  • Tensor

    Ensemble output after attention-weighted combination

Sparsemax(dim=0)

Bases: Module

Sparsemax activation function module.

A sparse alternative to softmax that produces sparse probability distributions.

Parameters:
  • dim (int, default: 0 ) –

    Dimension along which to apply sparsemax (default is 0)

SparsemaxFunction

Bases: Function

Custom autograd function for sparsemax operation.

Implements the forward and backward passes for the sparsemax normalization, which is a sparse alternative to softmax.

backward(ctx, grad_output) staticmethod

Backward pass of sparsemax.

Parameters:
  • ctx (_ContextMethodMixin) –

    Context object with saved variables

  • grad_output (Tensor) –

    Gradient of the loss with respect to sparsemax output

Returns:
  • tuple

    (gradient with respect to input, None)

forward(ctx, input, dim=0) staticmethod

Forward pass of sparsemax.

Parameters:
  • ctx (_ContextMethodMixin) –

    Context object to save variables for backward

  • input (Tensor) –

    Input tensor of any shape

  • dim (int, default: 0 ) –

    Dimension along which to apply sparsemax (default is 0)

Returns:
  • Tensor

    Output tensor with same shape as input