pyg_spectral.utils

load_import(class_name, module_name)[source]

Simple dynamic import for ‘module.class’

get_laplacian(edge_index: Tensor | SparseTensor, edge_weight: Tensor | None = None, normalization: bool | None = None, diag: float = 1.0, dtype: dtype | None = None, num_nodes: int | None = None) Tuple[Tensor, Tensor] | SparseTensor[source]

Computes the graph Laplacian of the graph given by edge_index and optional edge_weight. Remove the normalization of graph adjacency matrix in torch_geometric.utils.get_laplacian().

Parameters:
  • edge_index (Tensor | SparseTensor) – The edge indices.

  • edge_weight (Tensor | None, default: None) – One-dimensional edge weights.

  • normalization (bool | None, default: None) –

    The normalization scheme for the graph Laplacian:

    1. False: No normalization \(\mathbf{L} = \mathbf{D} - \mathbf{A}\)

    2. "True": Normalization already applied \(\mathbf{L} = diag * \mathbf{I} - \mathbf{A}\)

  • diag (float, default: 1.0) – Weight of identity when normalization=True.

  • dtype (dtype | None, default: None) – The desired data type of returned tensor in case edge_weight=None.

  • num_nodes (int | None, default: None) – The number of nodes, i.e. max_val + 1 of edge_index.

dropout_edge(edge_index: Tensor, p: float = 0.5, force_undirected: bool = False, training: bool = True) Tuple[Tensor, Tensor][source]

Random inplace edge dropout for the adjacency matrix edge_index with probability p using samples from a Bernoulli distribution. Expand torch_geometric.utils.dropout_edge() with type support.

Parameters:
  • edge_index (Tensor) – The edge indices.

  • p (float, default: 0.5) – Dropout probability.

  • force_undirected (bool, default: False) – If set to True, will either drop or keep both edges of an undirected edge.

  • training (bool, default: True) – If set to False, this operation is a no-op.

Returns:

edge_index, edge_mask (LongTensor, BoolTensor) – The edge indices and the edge mask.