GRADEBase(in_dim, hid_dim, num_classes, num_layers=1, dropout=0.1, act=F.relu, disc='JS', mode='node', **kwargs)

Bases: Module

Base class for GRADE.

Parameters:
  • in_dim (int) –

    Input dimension of model.

  • hid_dim (int) –

    Hidden dimension of model.

  • num_classes (int) –

    Number of classes.

  • num_layers (int, default: 1 ) –

    Total number of layers in model. Default: 4.

  • dropout (float, default: 0.1 ) –

    Dropout rate. Default: 0..

  • act (callable activation function or None, default: relu ) –

    Activation function if not None. Default: torch.nn.functional.relu.

  • disc (str, default: 'JS' ) –

    Discriminator. Default: JS.

  • mode (str, default: 'node' ) –

    Mode for node or graph level tasks. Default: node.

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

    Other parameters for the backbone.

feat_bottleneck(x, edge_index, batch)

Feature extraction through GNN layers.

Parameters:
  • x (Tensor) –

    Node feature matrix.

  • edge_index (Tensor) –

    Edge indices.

  • batch (Tensor or None) –

    Batch indices for graph-level tasks.

Returns:
  • tuple

    Contains: - torch.Tensor: Final layer features - list: Features from each layer

Notes

Process:

  1. Sequential GCN layer application
  2. Activation and dropout
  3. Feature collection per layer
  4. Graph pooling (if graph-level task)
feat_classifier(x)

Classification layer.

Parameters:
  • x (Tensor) –

    Input features.

Returns:
  • Tensor

    Classification logits.

Notes

Simple linear transformation for classification.

forward(data)

Forward pass of the GRADE model.

Parameters:
  • data (Data) –

    Input graph data object containing: - x: Node features - edge_index: Edge indices - batch: Batch indices (for graph-level tasks)

Returns:
  • tuple

    Contains: - torch.Tensor: Classification logits - torch.Tensor: Concatenated features from all layers

Notes

Process:

  1. Extract features through GNN layers
  2. Apply classification layer
  3. Concatenate features for discrimination
one_hot_embedding(labels)

Convert labels to one-hot encoding.

Parameters:
  • labels (Tensor) –

    Input labels as indices.

Returns:
  • Tensor

    One-hot encoded labels.

Notes

Creates a one-hot encoding matrix of shape (num_samples, num_classes).