PyTorch Geometric Signed Directed Utils

Task-Specific Objectives and Evaluation Methods

class Prob_Balanced_Normalized_Loss(A_p: scipy.sparse.base.spmatrix, A_n: scipy.sparse.base.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.

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).

class Prob_Balanced_Ratio_Loss(A_p: scipy.sparse.base.spmatrix, A_n: scipy.sparse.base.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).

class Unhappy_Ratio(A_p: scipy.sparse.base.spmatrix, A_n: scipy.sparse.base.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).

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.

Given node embeddings z, classifies the link relation between node pairs edge_index to be either positive, negative or non-existent.

Parameters
  • x (Tensor) – The input node features.

  • edge_index (LongTensor) – The edge indices.

Computes the discriminator loss based on node embeddings z, and positive edges pos_edge_index and negative edges neg_edge_index.

Parameters
  • z (Tensor) – The node embeddings.

  • pos_edge_index (LongTensor) – The positive edge indices.

  • neg_edge_index (LongTensor) – The negative edge indices.

An implementation of the Product Loss used in the “Signed Graph Attention Networks” paper.

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

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.

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

An implementation of the Signed Entropy Loss used in “SDGNN: Learning Node Representation for Signed Directed Networks” paper.

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

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.

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.

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.

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

triplet_loss_node_classification(y: Union[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 [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}.

  • not given (If) –

  • classes are supposed to have weight one. Defaults to None. (all) –

Returns

The metrics for link sign prediction task. Tuple[float,float,float,float,float]: Accuracy, Binary-F1, Macro-F1, Micro-F1 and AUC.

Return type

[type]

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). :param embeddings: The embeddings for signed graph. :type embeddings: np.ndarray :param train_X: The indices for training data (e.g., [[0, 1], [0, 2]]) :type train_X: np.ndarray :param train_y: The sign for training data (e.g., [[1, -1]]) :type train_y: np.ndarray :param test_X: The indices for test data (e.g., [[1, 2]]) :type test_X: np.ndarray :param test_y: The sign for test data (e.g., [[1]]) :type test_y: np.ndarray :param class_weight: Weights associated with classes in the form {class_label: weight}. :type class_weight: Union[dict, str], optional :param If not given: :param all classes are supposed to have weight one.. Defaults to None.:

Returns

The metrics for link sign prediction task. Tuple[float,float,float]: Accuracy, Macro-F1, Micro-F1

Return type

[type]

class Prob_Imbalance_Loss(F: Optional[Union[int, numpy.ndarray]] = None)[source]

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: Union[torch.FloatTensor, None._VariableFunctions.sparse_coo_tensor], K: int, normalization: str = 'vol_sum', threshold: str = 'sort')torch.FloatTensor[source]

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

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.Data, train_size: Optional[Union[int, float]] = None, val_size: Optional[Union[int, float]] = None, test_size: Optional[Union[int, float]] = None, seed_size: Optional[Union[int, float]] = None, train_size_per_class: Optional[Union[int, float]] = None, val_size_per_class: Optional[Union[int, float]] = None, test_size_per_class: Optional[Union[int, float]] = None, seed_size_per_class: Optional[Union[int, float]] = None, seed: List[int] = [], data_split: int = 10)torch_geometric.data.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_size or train_size_per_class is 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: Optional[torch.FloatTensor] = None, device: str = 'cpu')Tuple[torch.LongTensor, torch.LongTensor, torch.FloatTensor, torch.LongTensor, torch.FloatTensor][source]

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 + 1 of edge_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: Optional[torch.Tensor] = None, normalization: Optional[str] = 'sym', dtype: Optional[int] = None, num_nodes: Optional[int] = None, q: Optional[float] = 0.25, return_lambda_max: bool = False)[source]

Computes the magnetic Laplacian of the graph given by edge_index and optional edge_weight from 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) -

    1. 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 + 1 of edge_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)[source]

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.

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_node(embeddings: torch.FloatTensor, y: torch.LongTensor, train_index: List[int], test_index: Optional[List[int]] = None)[source]

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: Optional[int], dtype: torch.dtype, edge_weight: Optional[torch.FloatTensor] = None)Tuple[torch.LongTensor, torch.FloatTensor][source]

Computes the fast approximate pagerank adjacency matrix of the graph given by edge_index and optional edge_weight from 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 + 1 of edge_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: Optional[int], dtype: torch.dtype, edge_weight: Optional[torch.FloatTensor] = None)Tuple[torch.LongTensor, torch.FloatTensor][source]

Computes the approximate pagerank adjacency matrix of the graph given by edge_index and optional edge_weight from 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 + 1 of edge_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: Optional[int], dtype: torch.dtype, edge_weight: Optional[torch.FloatTensor] = None)Tuple[torch.LongTensor, torch.FloatTensor][source]

Computes the second-order proximity matrix of the graph given by edge_index and optional edge_weight from 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 + 1 of edge_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[source]

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.base.spmatrix, labels: Optional[Union[numpy.array, torch.LongTensor]] = None, lowest_degree: int = 2, max_iter=10)Tuple[scipy.sparse.base.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.base.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: Optional[int] = None, signed: bool = False, edge_weight: Optional[torch.FloatTensor] = 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:
  • degree (Torch.Tensor) - The degree matrix (|V|*2) when signed=False, otherwise the degree matrix (|V|*4) with in-pos, in-neg, out-pos, out-neg degrees.

get_magnetic_signed_Laplacian(edge_index: torch.LongTensor, edge_weight: Optional[torch.Tensor] = None, normalization: Optional[str] = 'sym', dtype: Optional[int] = None, num_nodes: Optional[int] = None, q: Optional[float] = 0.25, return_lambda_max: bool = False, absolute_degree: bool = True)[source]

Computes the magnetic signed Laplacian of the graph given by edge_index and optional edge_weight from 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) -
    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)})\)

  • 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 + 1 of edge_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.