torch_geometric_signed_directed.nn.general.MSGNN ================================================ .. py:module:: torch_geometric_signed_directed.nn.general.MSGNN Classes ------- .. autoapisummary:: torch_geometric_signed_directed.nn.general.MSGNN.MSGNN_link_prediction torch_geometric_signed_directed.nn.general.MSGNN.MSGNN_node_classification Module Contents --------------- .. py:class:: MSGNN_link_prediction(num_features: int, hidden: int = 2, q: float = 0.25, K: int = 2, label_dim: int = 2, activation: bool = True, trainable_q: bool = False, layer: int = 2, dropout: float = 0.5, normalization: str = 'sym', cached: bool = False, conv_bias: bool = True, absolute_degree: bool = True) Bases: :py:obj:`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 :math:`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: :obj:`True`) * **trainable_q** (*bool, optional*) -- whether to set q to be trainable or not. (default: :obj:`False`) * **layer** (*int, optional*) -- Number of MSConv layers. Deafult: 2. * **dropout** (*float, optional*) -- Dropout value. (default: :obj:`0.5`) * **normalization** (*str, optional*) -- The normalization scheme for the signed directed Laplacian (default: :obj:`sym`): 1. :obj:`None`: No normalization :math:`\mathbf{L} = \bar{\mathbf{D}} - \mathbf{A} Hadamard \exp(i \Theta^{(q)})` 2. :obj:`"sym"`: Symmetric normalization :math:`\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 :obj:`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 :obj:`True` in transductive learning scenarios. (default: :obj:`False`) * **conv_bias** (*bool, optional*) -- Whether to use bias in the convolutional layers, default :obj:`True`. * **absolute_degree** (*bool, optional*) -- Whether to calculate the degree matrix with respect to absolute entries of the adjacency matrix. (default: :obj:`True`) .. py:attribute:: normalization :value: 'sym' .. py:attribute:: activation :value: True .. py:attribute:: Chebs .. py:attribute:: linear .. py:attribute:: dropout :value: 0.5 .. py:method:: reset_parameters() .. py:method:: forward(real: torch.FloatTensor, imag: torch.FloatTensor, edge_index: torch.LongTensor, query_edges: torch.LongTensor, edge_weight: Optional[torch.LongTensor] = 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. * 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). .. py: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: :py:obj:`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: :obj:`False`) * **trainable_q** (*bool, optional*) -- whether to set q to be trainable or not. (default: :obj:`False`) * **layer** (*int, optional*) -- Number of MSConv layers. Deafult: 2. * **dropout** (*float, optional*) -- Dropout value. (default: :obj:`False`) * **normalization** (*str, optional*) -- The normalization scheme for the signed directed Laplacian (default: :obj:`sym`): 1. :obj:`None`: No normalization :math:`\mathbf{L} = \bar{\mathbf{D}} - \mathbf{A} \odot \exp(i \Theta^{(q)})` 2. :obj:`"sym"`: Symmetric normalization :math:`\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 :obj:`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 :obj:`True` in transductive learning scenarios. (default: :obj:`False`) * **conv_bias** (*bool, optional*) -- Whether to use bias in the convolutional layers, default :obj:`True`. * **absolute_degree** (*bool, optional*) -- Whether to calculate the degree matrix with respect to absolute entries of the adjacency matrix. (default: :obj:`True`) .. py:attribute:: normalization :value: 'sym' .. py:attribute:: activation :value: False .. py:attribute:: Chebs .. py:attribute:: Conv .. py:attribute:: dropout :value: False .. py:method:: reset_parameters() .. py:method:: forward(real: torch.FloatTensor, imag: torch.FloatTensor, edge_index: torch.LongTensor, edge_weight: Optional[torch.LongTensor] = 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).