PyTorch Geometric Signed Directed Utils
Task-Specific Objectives and Evaluation Methods
- class Prob_Balanced_Normalized_Loss(A_p: scipy.sparse.spmatrix, A_n: scipy.sparse.spmatrix)[source]
An implementation of the probabilistic balanced normalized cut loss function from the SSSNET: Semi-Supervised Signed Network Clustering paper.
- Parameters:
A_p (scipy sparse matrices) – Positive part of adjacency matrix A.
A_n (scipy sparse matrices) – Negative part of adjacency matrix A.
- D_bar
- forward(prob: torch.FloatTensor) torch.Tensor[source]
Making a forward pass of the probabilistic balanced normalized cut loss function.
- Arg types:
prob (PyTorch FloatTensor) - Prediction probability matrix made by the model
- Return types:
loss value (torch.Tensor).
- mat
- class Prob_Balanced_Ratio_Loss(A_p: scipy.sparse.spmatrix, A_n: scipy.sparse.spmatrix)[source]
An implementation of the probabilistic balanced ratio cut loss function from the SSSNET: Semi-Supervised Signed Network Clustering paper.
- Parameters:
A_p (scipy sparse matrices) – Positive part of adjacency matrix A.
A_n (scipy sparse matrices) – Negative part of adjacency matrix A.
- forward(prob: torch.FloatTensor) torch.Tensor[source]
Making a forward pass of the probabilistic balanced ratio cut loss function.
- Arg types:
prob (PyTorch FloatTensor) - Prediction probability matrix made by the model
- Return types:
loss value (torch.Tensor).
- mat
- class Unhappy_Ratio(A_p: scipy.sparse.spmatrix, A_n: scipy.sparse.spmatrix)[source]
A calculation of the ratio of unhappy edges among all edges from the SSSNET: Semi-Supervised Signed Network Clustering paper.
- Parameters:
A_p (scipy sparse matrices) – Positive part of adjacency matrix A.
A_n (scipy sparse matrices) – Negative part of adjacency matrix A.
- forward(prob: torch.FloatTensor) torch.Tensor[source]
Making a forward pass of the calculation of the ratio of unhappy edges among all edges. Arg types:
prob (PyTorch FloatTensor) - Prediction probability matrix made by the model
- Return types:
loss value (torch.Tensor).
- mat
- num_edges
- class Sign_Triangle_Loss(emb_dim: int, edge_weight: scipy.sparse.csc_matrix)
- An implementation of the Signed Triangle Loss used in
“SDGNN: Learning Node Representation for Signed Directed Networks” paper.
- Parameters:
emb_dim (int) – The embedding size.
- edge_weight
- forward(z: torch.Tensor, pos_edge_index: torch.LongTensor, neg_edge_index: torch.LongTensor) torch.Tensor
- lin
- class Sign_Direction_Loss(emb_dim: int)
- An implementation of the Signed Direction Loss used in
“SDGNN: Learning Node Representation for Signed Directed Networks” paper.
- Parameters:
emb_dim (int) – The embedding size.
- forward(z: torch.Tensor, pos_edge_index: torch.LongTensor, neg_edge_index: torch.LongTensor) torch.Tensor
- score_function1
- score_function2
- class Sign_Product_Entropy_Loss
An implementation of the Signed Entropy Loss used in “SDGNN: Learning Node Representation for Signed Directed Networks” paper.
- forward(z: torch.Tensor, pos_edge_index: torch.LongTensor, neg_edge_index: torch.LongTensor) torch.Tensor
- class Link_Sign_Product_Loss
An implementation of the Product Loss used in the “Signed Graph Attention Networks” paper.
- forward(z: torch.Tensor, pos_edge_index: torch.LongTensor, neg_edge_index: torch.LongTensor) torch.Tensor
- class Link_Sign_Entropy_Loss(emb_dim: int)
An implementation of the Entropy Loss used in the “Signed Graph Convolutional Network” paper. and “Learning Signed Network Embedding via Graph Attention” paper
- Parameters:
emb_dim (int) – The embedding size.
- discriminate(z: torch.Tensor, edge_index: torch.LongTensor) torch.FloatTensor
Given node embeddings
z, classifies the link relation between node pairsedge_indexto be either positive, negative or non-existent.- Parameters:
x (Tensor) – The input node features.
edge_index (LongTensor) – The edge indices.
- forward(z: torch.Tensor, pos_edge_index: torch.LongTensor, neg_edge_index: torch.LongTensor) torch.Tensor
Computes the discriminator loss based on node embeddings
z, and positive edgespos_edge_indexand negative edgesneg_edge_index.- Parameters:
z (Tensor) – The node embeddings.
pos_edge_index (LongTensor) – The positive edge indices.
neg_edge_index (LongTensor) – The negative edge indices.
- lin
- reset_parameters()
- class Sign_Structure_Loss
- forward(z: torch.Tensor, pos_edge_index: torch.LongTensor, neg_edge_index: torch.LongTensor) torch.Tensor
- neg_embedding_loss(z: torch.Tensor, neg_edge_index: torch.LongTensor) torch.Tensor
Computes the triplet loss between negative node pairs and sampled non-node pairs.
- Parameters:
z (Tensor) – The node embeddings.
neg_edge_index (LongTensor) – The negative edge indices.
- pos_embedding_loss(z: torch.Tensor, pos_edge_index: torch.LongTensor) torch.Tensor
Computes the triplet loss between positive node pairs and sampled non-node pairs.
- Parameters:
z (Tensor) – The node embeddings.
pos_edge_index (LongTensor) – The positive edge indices.
- triplet_loss_node_classification(y: numpy.array | torch.Tensor, Z: torch.FloatTensor, n_sample: int, thre: float)[source]
Triplet loss function for node classification.
- Arg types:
y (np.array or torch.Tensor) - Node labels.
Z (torch.FloatTensor) - Embedding matrix for nodes.
n_sample (int) - Number of samples.
thre (float) - Threshold value for the triplet differences to be counted.
- Return types:
loss (torch.FloatTensor) - Loss value.
- link_sign_prediction_logistic_function(embeddings: numpy.ndarray, train_X: numpy.ndarray, train_y: numpy.ndarray, test_X: numpy.ndarray, test_y: numpy.ndarray, class_weight: dict | str = None) Tuple[float, float, float, float, float]
link_sign_prediction_logistic_function [summary] Link sign prediction is a binary classification machine learning task. It will return the metrics for link sign prediction (i.e., Accuracy, Binary-F1, Macro-F1, Micro-F1 and AUC).
- Parameters:
embeddings (np.ndarray) – The embeddings for signed graph.
train_X (np.ndarray) – The indices for training data (e.g., [[0, 1], [0, 2]])
train_y (np.ndarray) – The sign for training data (e.g., [[1, -1]])
test_X (np.ndarray) – The indices for test data (e.g., [[1, 2]])
test_y (np.ndarray) – The sign for test data (e.g., [[1]])
class_weight (Union[dict, str], optional) – Weights associated with classes in the form
{class_label: weight}.If not given, all classes are supposed to have weight one. Defaults to None.
- Returns:
[type] – The metrics for link sign prediction task. Tuple[float,float,float,float,float]: Accuracy, Binary-F1, Macro-F1, Micro-F1 and AUC.
- link_sign_direction_prediction_logistic_function(embeddings: numpy.ndarray, train_X: numpy.ndarray, train_y: numpy.ndarray, test_X: numpy.ndarray, test_y: numpy.ndarray, class_weight: dict | str = None) Tuple[float, float, float, float, float]
link_sign_prediction_logistic_function [summary] Link sign prediction is a multi-class classification machine learning task. It will return the metrics for link sign direction prediction (i.e., Accuracy, Macro-F1, and Micro-F1). :Parameters: * embeddings (np.ndarray) – The embeddings for signed graph.
train_X (np.ndarray) – The indices for training data (e.g., [[0, 1], [0, 2]])
train_y (np.ndarray) – The sign for training data (e.g., [[1, -1]])
test_X (np.ndarray) – The indices for test data (e.g., [[1, 2]])
test_y (np.ndarray) – The sign for test data (e.g., [[1]])
class_weight (Union[dict, str], optional) – Weights associated with classes in the form
{class_label: weight}.If not given, all classes are supposed to have weight one.. Defaults to None.
- Returns:
[type] – The metrics for link sign prediction task. Tuple[float,float,float]: Accuracy, Macro-F1, Micro-F1
- class Prob_Imbalance_Loss(F: int | numpy.ndarray | None = None)
An implementation of the probabilistic imbalance loss function from the DIGRAC: Digraph Clustering Based on Flow Imbalance paper.
- Parameters:
F (int or NumPy array, optional)
- forward(P: torch.FloatTensor, A: torch.FloatTensor | torch.sparse_coo_tensor, K: int, normalization: str = 'vol_sum', threshold: str = 'sort') torch.FloatTensor
Making a forward pass of the probabilistic imbalance loss function from the DIGRAC: Digraph Clustering Based on Flow Imbalance” paper.
- Arg types:
prob (PyTorch FloatTensor) - Prediction probability matrix made by the model
A (PyTorch FloatTensor, can be sparse) - Adjacency matrix A
K (int) - Number of clusters
normalization (str, optional) - normalization method:
‘vol_sum’: Normalized by the sum of volumes, the default choice.
‘vol_max’: Normalized by the maximum of volumes.
‘vol_min’: Normalized by the minimum of volumes.
‘plain’: No normalization, just CI.
threshold: (str, optional) normalization method:
‘sort’: Picking the top beta imbalnace values, the default choice.
‘std’: Picking only the terms 3 standard deviation away from null hypothesis.
‘naive’: No thresholding, suming up all K*(K-1)/2 terms of imbalance values.
- Return types:
loss (torch.Tensor) - loss value, roughly in [0,1].
Utilities and Preprocessing Methods
- link_class_split(data: torch_geometric.data.Data, size: int = None, splits: int = 2, prob_test: float = 0.15, prob_val: float = 0.05, task: str = 'direction', seed: int = 0, maintain_connect: bool = True, ratio: float = 1.0, device: str = 'cpu') dict[source]
Get train/val/test dataset for the link prediction task. Arg types:
data (torch_geometric.data.Data or DirectedData object) - The input dataset.
prob_val (float, optional) - The proportion of edges selected for validation (Default: 0.05).
prob_test (float, optional) - The proportion of edges selected for testing (Default: 0.15).
splits (int, optional) - The split size (Default: 2).
size (int, optional) - The size of the input graph. If none, the graph size is the maximum index of nodes plus 1 (Default: None).
task (str, optional) - The evaluation task: three_class_digraph (three-class link prediction); direction (direction prediction); existence (existence prediction); sign (sign prediction); four_class_signed_digraph (directed sign prediction); five_class_signed_digraph (directed sign and existence prediction) (Default: ‘direction’)
seed (int, optional) - The random seed for positve edge selection (Default: 0). Negative edges are selected by pytorch geometric negative_sampling.
maintain_connect (bool, optional) - If maintaining connectivity when removing edges for validation and testing. The connectivity is maintained by obtaining edges in the minimum spanning tree/forest first. These edges will not be removed for validation and testing (Default: True).
ratio (float, optional) - The maximum ratio of edges used for dataset generation. (Default: 1.0)
device (int, optional) - The device to hold the return value (Default: ‘cpu’).
- Return types:
- datasets - A dict include training/validation/testing splits of edges and labels. For split index i:
datasets[i][‘graph’] (torch.LongTensor): the observed edge list after removing edges for validation and testing.
datasets[i][‘train’/’val’/’testing’][‘edges’] (List): the edge list for training/validation/testing.
- datasets[i][‘train’/’val’/’testing’][‘label’] (List): the labels of edges:
If task == “existence”: 0 (the directed edge exists in the graph), 1 (the edge doesn’t exist). The undirected edges in the directed input graph are removed to avoid ambiguity.
If task == “direction”: 0 (the directed edge exists in the graph), 1 (the edge of the reversed direction exists). The undirected edges in the directed input graph are removed to avoid ambiguity.
If task == “three_class_digraph”: 0 (the directed edge exists in the graph), 1 (the edge of the reversed direction exists), 2 (the edge doesn’t exist in both directions). The undirected edges in the directed input graph are removed to avoid ambiguity.
- If task == “four_class_signed_digraph”: 0 (the positive directed edge exists in the graph),
1 (the negative directed edge exists in the graph), 2 (the positive edge of the reversed direction exists), 3 (the edge of the reversed direction exists). The undirected edges in the directed input graph are removed to avoid ambiguity.
- If task == “five_class_signed_digraph”: 0 (the positive directed edge exists in the graph),
1 (the negative directed edge exists in the graph), 2 (the positive edge of the reversed direction exists), 3 (the edge of the reversed direction exists), 4 (the edge doesn’t exist in both directions). The undirected edges in the directed input graph are removed to avoid ambiguity.
If task == “sign”: 0 (negative edge), 1 (positive edge). This is the link sign prediction task for signed networks.
- node_class_split(data: torch_geometric.data.Data, train_size: int | float = None, val_size: int | float = None, test_size: int | float = None, seed_size: int | float = None, train_size_per_class: int | float = None, val_size_per_class: int | float = None, test_size_per_class: int | float = None, seed_size_per_class: int | float = None, seed: List[int] = [], data_split: int = 10) torch_geometric.data.Data[source]
Train/Val/Test/Seed split for node classification tasks. The size parameters can either be int or float. If a size parameter is int, then this means the actual number, if it is float, then this means a ratio.
train_sizeortrain_size_per_classis mandatory, with the former regardless of class labels. Validation and seed masks are optional. Seed masks here masks nodes within the training set, e.g., in a semi-supervised setting as described in the SSSNET: Semi-Supervised Signed Network Clustering paper. If test_size and test_size_per_class are both None, all the remaining nodes after selecting training (and validation) nodes will be included.- Arg types:
data (Data or DirectedData, required) - The data object for data split.
train_size (int or float, optional) - The size of random splits for the training dataset. If the input is a float number, the ratio of nodes in each class will be sampled.
val_size (int or float, optional) - The size of random splits for the validation dataset. If the input is a float number, the ratio of nodes in each class will be sampled.
test_size (int or float, optional) - The size of random splits for the validation dataset. If the input is a float number, the ratio of nodes in each class will be sampled. (Default: None. All nodes not selected for training/validation are used for testing)
seed_size (int or float, optional) - The size of random splits for the seed nodes within the training set. If the input is a float number, the ratio of nodes in each class will be sampled.
train_size_per_class (int or float, optional) - The size per class of random splits for the training dataset. If the input is a float number, the ratio of nodes in each class will be sampled.
val_size_per_class (int or float, optional) - The size per class of random splits for the validation dataset. If the input is a float number, the ratio of nodes in each class will be sampled.
test_size_per_class (int or float, optional) - The size per class of random splits for the testing dataset. If the input is a float number, the ratio of nodes in each class will be sampled. (Default: None. All nodes not selected for training/validation are used for testing)
seed_size_per_class (int or float, optional) - The size per class of random splits for seed nodes within the training set. If the input is a float number, the ratio of nodes in each class will be sampled.
seed (An empty list or a list with the length of data_split, optional) - The random seed list for each data split.
data_split (int, optional) - number of splits (Default : 10)
- Return types:
data (Data or DirectedData) - The data object includes train_mask, val_mask and test_mask.
- directed_features_in_out(edge_index: torch.LongTensor, size: int, edge_weight: torch.FloatTensor | None = None, device: str = 'cpu') Tuple[torch.LongTensor, torch.LongTensor, torch.FloatTensor, torch.LongTensor, torch.FloatTensor]
Computes directed in-degree and out-degree features.
- Arg types:
edge_index (PyTorch LongTensor) - The edge indices.
size (int or None) - The number of nodes, i.e.
max_val + 1ofedge_index.edge_weight (PyTorch Tensor, optional) - One-dimensional edge weights. (default:
None)device (str, optional) - The device to store the returned values. (default: :str:`cpu`)
- Return types:
index_undirected (PyTorch LongTensor) - Undirected edge_index.
edge_in (PyTorch LongTensor) - Inwards edge indices.
in_weight (PyTorch Tensor) - Inwards edge weights.
edge_out (PyTorch LongTensor) - Outwards edge indices.
out_weight (PyTorch Tensor) - Outwards edge weights.
- get_magnetic_Laplacian(edge_index: torch.LongTensor, edge_weight: torch.Tensor | None = None, normalization: str | None = 'sym', dtype: int | None = None, num_nodes: int | None = None, q: float | None = 0.25, return_lambda_max: bool = False)
Computes the magnetic Laplacian of the graph given by
edge_indexand optionaledge_weightfrom the MagNet: A Neural Network for Directed Graphs. paper.- Arg types:
edge_index (PyTorch LongTensor) - The edge indices.
edge_weight (PyTorch Tensor, optional) - One-dimensional edge weights. (default:
None)normalization (str, optional) - The normalization scheme for the magnetic Laplacian (default:
sym) -None: No normalization \(\mathbf{L} = \mathbf{D} - \mathbf{A} Hadamard \exp(i \Theta^{(q)})\)
2.
"sym": Symmetric normalization \(\mathbf{L} = \mathbf{I} - \mathbf{D}^{-1/2} \mathbf{A} \mathbf{D}^{-1/2} Hadamard \exp(i \Theta^{(q)})\)dtype (torch.dtype, optional) - The desired data type of returned tensor in case
edge_weight=None. (default:None)num_nodes (int, optional) - The number of nodes, i.e.
max_val + 1ofedge_index. (default:None)q (float, optional) - The value q in the paper for phase.
return_lambda_max (bool, optional) - Whether to return the maximum eigenvalue. (default:
False)
- Return types:
edge_index (PyTorch LongTensor) - The edge indices of the magnetic Laplacian.
edge_weight.real, edge_weight.imag (PyTorch Tensor) - Real and imaginary parts of the one-dimensional edge weights for the magnetic Laplacian.
lambda_max (float, optional) - The maximum eigenvalue of the magnetic Laplacian, only returns this when required by setting return_lambda_max as True.
- drop_feature(x: torch.FloatTensor, drop_prob: float)
Drop feature funciton from the Directed Graph Contrastive Learning paper.
- Arg types:
x (PyTorch FloatTensor) - Node features.
drop_prob (float) - Feature drop probability.
- Return types:
x (PyTorch FloatTensor) - Node features.
- pred_digcl_node(embeddings: torch.FloatTensor, y: torch.LongTensor, train_index: List[int], test_index: List[int] = None)
Generate predictions from embeddings from the Directed Graph Contrastive Learning paper.
- Arg types:
embeddings (PyTorch FloatTensor) - Node embeddings.
y (PyTorch LongTensor) - Labels.
train_index (NumPy array) - Training index.
test_index (NumPy array) - Testing index.
- Return types:
y_pred (NumPy array) - Predicted labels.
- pred_digcl_link(embeddings: torch.FloatTensor, y: torch.LongTensor, train_index: List[int], test_index: List[int])
Generate predictions from embeddings from the Directed Graph Contrastive Learning paper.
- Arg types:
embeddings (PyTorch FloatTensor) - Node embeddings.
y (PyTorch LongTensor) - Labels.
train_index (NumPy array) - Training index.
test_index (NumPy array) - Testing index.
- Return types:
y_pred (NumPy array) - Predicted labels.
- cal_fast_appr(alpha: float, edge_index: torch.LongTensor, num_nodes: int | None, dtype: torch.dtype, edge_weight: torch.FloatTensor | None = None) Tuple[torch.LongTensor, torch.FloatTensor]
Computes the fast approximate pagerank adjacency matrix of the graph given by
edge_indexand optionaledge_weightfrom the Directed Graph Contrastive Learning paper.- Arg types:
alpha (float) -alpha used in approximate personalized page rank.
edge_index (PyTorch LongTensor) -The edge indices.
num_nodes (int or None) -The number of nodes, i.e.
max_val + 1ofedge_index.dtype (torch.dtype) -The desired data type of returned tensor in case
edge_weight=None.edge_weight (PyTorch Tensor, optional) -One-dimensional edge weights. (default:
None)
- Return types:
edge_index (PyTorch LongTensor) -The edge indices of the approximate page-rank matrix.
edge_weight (PyTorch Tensor) -One-dimensional edge weights of the approximate page-rank matrix.
- get_appr_directed_adj(alpha: float, edge_index: torch.LongTensor, num_nodes: int | None, dtype: torch.dtype, edge_weight: torch.FloatTensor | None = None) Tuple[torch.LongTensor, torch.FloatTensor]
Computes the approximate pagerank adjacency matrix of the graph given by
edge_indexand optionaledge_weightfrom the Digraph Inception Convolutional Networks paper.- Arg types:
alpha (float) -alpha used in approximate personalized page rank.
edge_index (PyTorch LongTensor) -The edge indices.
num_nodes (int or None) -The number of nodes, i.e.
max_val + 1ofedge_index.dtype (torch.dtype) -The desired data type of returned tensor in case
edge_weight=None.edge_weight (PyTorch Tensor, optional) -One-dimensional edge weights. (default:
None)
- Return types:
edge_index (PyTorch LongTensor) -The edge indices of the approximate page-rank matrix.
edge_weight (PyTorch Tensor) -One-dimensional edge weights of the approximate page-rank matrix.
- get_second_directed_adj(edge_index: torch.LongTensor, num_nodes: int | None, dtype: torch.dtype, edge_weight: torch.FloatTensor | None = None) Tuple[torch.LongTensor, torch.FloatTensor]
Computes the second-order proximity matrix of the graph given by
edge_indexand optionaledge_weightfrom the Digraph Inception Convolutional Networks paper.- Arg types:
edge_index (PyTorch LongTensor) -The edge indices.
num_nodes (int or None) -The number of nodes, i.e.
max_val + 1ofedge_index.dtype (torch.dtype) -The desired data type of returned tensor in case
edge_weight=None.edge_weight (PyTorch Tensor, optional) -One-dimensional edge weights. (default:
None)
- Return types:
edge_index (PyTorch LongTensor) -The edge indices of the approximate page-rank matrix.
dge_weight (PyTorch Tensor) -One-dimensional edge weights of the approximate page-rank matrix.
- meta_graph_generation(F_style: str = 'cyclic', K: int = 4, eta: float = 0.05, ambient: bool = False, fill_val: float = 0.5) numpy.array
The meta-graph generation function from the DIGRAC: Digraph Clustering Based on Flow Imbalance paper.
- Arg types:
F_style (str) - Style of the meta-graph: ‘cyclic’, ‘path’, ‘complete’, ‘star’ or ‘multipartite’.
K (int) - Number of clusters.
eta (float) - Noise parameter, 0 <= eta <= 0.5.
ambient (bool) - Whether there are ambient nodes.
fill_val (float) - Value to fill in the ambient locations.
- Return types:
F (NumPy array) - The resulting meta-graph adjacency matrix.
- extract_network(A: scipy.sparse.spmatrix, labels: numpy.array | torch.LongTensor | None = None, lowest_degree: int = 2, max_iter=10) Tuple[scipy.sparse.spmatrix, numpy.array][source]
Find the largest connected component and iteratively only include nodes with degree at least lowest_degree, for at most max_iter iterations, from the DIGRAC: Digraph Clustering Based on Flow Imbalance paper.
- Arg types:
A (scipy sparse matrix) - Adjacency matrix.
labels (numpy array or torch.LongTensor, optional) - Node labels, default None.
lowest_degree (int, optional) - The lowest degree for the output network, default 2.
max_iter (int, optional) - The maximum number of iterations.
- Return types:
A (scipy sparse matrix) - Adjacency matrix after fixing degrees and obtaining a connected netework.
labels (numpy array) - Node labels after fixing degrees and obtaining a connected netework.
- scipy_sparse_to_torch_sparse(A: scipy.sparse.spmatrix) torch.Tensor[source]
Convert scipy.sparse.spmatrix to torch sparse coo tensor
- Arg types:
A (sparse.spmatrix): The scipy sparse matrix to be converted.
- Return types:
obj (torch.sparse_coo_tensor): The returned torch.sparse_coo_tensor.
- in_out_degree(edge_index: torch.LongTensor, size: int | None = None, signed: bool = False, edge_weight: torch.FloatTensor | None = None) torch.Tensor[source]
Get the in degrees and out degrees of nodes
- Arg types:
edge_index (torch.LongTensor) The edge index from a torch geometric data / DirectedData object .
size (int) - The node number.
signed (bool, optional) - Whether to take into account signed edge weights and to return signed 4D features. Defualt is False and to only account for absolute degrees.
edge_weight (PyTorch Tensor, optional) - One-dimensional edge weights. (default:
None)
- Return types:
- get_magnetic_signed_Laplacian(edge_index: torch.LongTensor, edge_weight: torch.Tensor | None = None, normalization: str | None = 'sym', dtype: int | None = None, num_nodes: int | None = None, q: float | None = 0.25, return_lambda_max: bool = False, absolute_degree: bool = True)[source]
Computes the magnetic signed Laplacian of the graph given by
edge_indexand optionaledge_weightfrom the MSGNN: A Spectral Graph Neural Network Based on a Novel Magnetic Signed Laplacian paper.- Arg types:
edge_index (PyTorch LongTensor) - The edge indices.
edge_weight (PyTorch Tensor, optional) - One-dimensional edge weights. (default:
None)- normalization (str, optional) - The normalization scheme for the magnetic Laplacian (default:
sym) - 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)})\)
- normalization (str, optional) - The normalization scheme for the magnetic Laplacian (default:
dtype (torch.dtype, optional) - The desired data type of returned tensor in case
edge_weight=None. (default:None)num_nodes (int, optional) - The number of nodes, i.e.
max_val + 1ofedge_index. (default:None)q (float, optional) - The value q in the paper for phase.
return_lambda_max (bool, optional) - Whether to return the maximum eigenvalue. (default:
False)absolute_degree (bool, optional) - Whether to calculate the degree matrix with respect to absolute entries of the adjacency matrix. (default:
True)
- Return types:
edge_index (PyTorch LongTensor) - The edge indices of the magnetic signed Laplacian.
edge_weight.real, edge_weight.imag (PyTorch Tensor) - Real and imaginary parts of the one-dimensional edge weights for the magnetic signed Laplacian.
lambda_max (float, optional) - The maximum eigenvalue of the magnetic signed Laplacian, only returns this when required by setting return_lambda_max as True.