torch_geometric_signed_directed.nn.general.MSGNN

Classes

MSGNN_link_prediction

The MSGNN model for link prediction from the

MSGNN_node_classification

The MSGNN model for node classification from the

Module Contents

Bases: torch.nn.Module

The MSGNN model for link prediction from the MSGNN: A Spectral Graph Neural Network Based on a Novel Magnetic Signed Laplacian paper.

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

  • hidden (int, optional) – Number of hidden channels. Default: 2.

  • K (int, optional) – Order of the Chebyshev polynomial plus 1, i.e., Chebyshev filter size \(K\). Default: 2.

  • q (float, optional) – Initial value of the phase parameter, 0 <= q <= 0.25. Default: 0.25.

  • label_dim (int, optional) – Number of output classes. Default: 2.

  • activation (bool, optional) – whether to use activation function or not. (default: True)

  • trainable_q (bool, optional) – whether to set q to be trainable or not. (default: False)

  • layer (int, optional) – Number of MSConv layers. Deafult: 2.

  • dropout (float, optional) – Dropout value. (default: 0.5)

  • normalization (str, optional) – The normalization scheme for the signed directed Laplacian (default: sym): 1. None: No normalization \(\mathbf{L} = \bar{\mathbf{D}} - \mathbf{A} Hadamard \exp(i \Theta^{(q)})\) 2. "sym": Symmetric normalization \(\mathbf{L} = \mathbf{I} - \bar{\mathbf{D}}^{-1/2} \mathbf{A} \bar{\mathbf{D}}^{-1/2} Hadamard \exp(i \Theta^{(q)})\)

  • cached (bool, optional) – If set to True, the layer will cache the __norm__ matrix on first execution, and will use the cached version for further executions. This parameter should only be set to True in transductive learning scenarios. (default: False)

  • conv_bias (bool, optional) – Whether to use bias in the convolutional layers, default True.

  • absolute_degree (bool, optional) – Whether to calculate the degree matrix with respect to absolute entries of the adjacency matrix. (default: True)

Making a forward pass of the MagNet node classification model.

Arg types:
  • real, imag (PyTorch Float Tensor) - Node features.

  • edge_index (PyTorch Long Tensor) - Edge indices.

  • query_edges (PyTorch Long Tensor) - Edge indices for querying labels.

  • edge_weight (PyTorch Float Tensor, optional) - Edge weights corresponding to edge indices.

Return types:
  • log_prob (PyTorch Float Tensor) - Logarithmic class probabilities for all nodes, with shape (num_nodes, num_classes).

class MSGNN_node_classification(num_features: int, hidden: int = 2, q: float = 0.25, K: int = 2, label_dim: int = 2, activation: bool = False, trainable_q: bool = False, layer: int = 2, dropout: float = False, normalization: str = 'sym', cached: bool = False, conv_bias: bool = True, absolute_degree: bool = True)

Bases: torch.nn.Module

The MSGNN model for node classification from the MSGNN: A Spectral Graph Neural Network Based on a Novel Magnetic Signed Laplacian paper.

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

  • hidden (int, optional) – Number of hidden channels. Default: 2.

  • K (int, optional) – Order of the Chebyshev polynomial. Default: 2.

  • q (float, optional) – Initial value of the phase parameter, 0 <= q <= 0.25. Default: 0.25.

  • label_dim (int, optional) – Number of output classes. Default: 2.

  • activation (bool, optional) – whether to use activation function or not. (default: False)

  • trainable_q (bool, optional) – whether to set q to be trainable or not. (default: False)

  • layer (int, optional) – Number of MSConv layers. Deafult: 2.

  • dropout (float, optional) – Dropout value. (default: False)

  • normalization (str, optional) – The normalization scheme for the signed directed Laplacian (default: sym): 1. None: No normalization \(\mathbf{L} = \bar{\mathbf{D}} - \mathbf{A} \odot \exp(i \Theta^{(q)})\) 2. "sym": Symmetric normalization \(\mathbf{L} = \mathbf{I} - \bar{\mathbf{D}}^{-1/2} \mathbf{A} \bar{\mathbf{D}}^{-1/2} \odot \exp(i \Theta^{(q)})\) odot denotes the element-wise multiplication.

  • cached (bool, optional) – If set to True, the layer will cache the __norm__ matrix on first execution, and will use the cached version for further executions. This parameter should only be set to True in transductive learning scenarios. (default: False)

  • conv_bias (bool, optional) – Whether to use bias in the convolutional layers, default True.

  • absolute_degree (bool, optional) – Whether to calculate the degree matrix with respect to absolute entries of the adjacency matrix. (default: True)

normalization = 'sym'
activation = False
Chebs
Conv
dropout = False
reset_parameters()
forward(real: torch.FloatTensor, imag: torch.FloatTensor, edge_index: torch.LongTensor, edge_weight: torch.LongTensor | None = None) torch.FloatTensor

Making a forward pass of the MagNet node classification model.

Arg types:
  • real, imag (PyTorch Float Tensor) - Node features.

  • edge_index (PyTorch Long Tensor) - Edge indices.

  • edge_weight (PyTorch Float Tensor, optional) - Edge weights corresponding to edge indices.

Return types:
  • z (PyTorch FloatTensor) - Embedding matrix, with shape (num_nodes, 2*hidden) for undirected graphs and (num_nodes, 4*hidden) for directed graphs.

  • output (PyTorch FloatTensor) - Log of prob, with shape (num_nodes, num_clusters).

  • predictions_cluster (PyTorch LongTensor) - Predicted labels.

  • prob (PyTorch FloatTensor) - Probability assignment matrix of different clusters, with shape (num_nodes, num_clusters).