pyg_spectral.utils

load_import(class_name, module_name)[source]

Simple dynamic import for module.class

class CallableDict[source]

Bases: dict

A dictionary subclass that allows its values to be called as functions.

classmethod to_callableVal(dct, keys: list | None = None, reckeys: list = [])[source]

Converts the sub-dictionaries of the specified keys in the dictionary to CallableDict.

Parameters:
  • dct (dict) – The dictionary to convert.

  • keys (list[str]) – The keys to convert. If None, converts all sub-dictionaries.

  • reckeys (list[str]) – The keys to recursively convert sub-sub-dictionaries.

Returns:

dct (dict) – The dictionary with the specified keys converted to CallableDict.

Examples:

dct = {'key0': Dict0, 'key1': Dict1, 'key2': Dict2}
dct = CallableDict.to_callableVal(dct, keys=['key1'], reckeys=['key2'])
# dct = {'key0': Dict0, 'key1': CallableDict1, 'key2': Dict2},
# and each sub-dictionary in 'key2' is converted to CallableDict.
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.