pyg_spectral.utils
- 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 toCallableDict
.
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 optionaledge_weight
. Remove the normalization of graph adjacency matrix intorch_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 caseedge_weight=None
.num_nodes (
int
|None
, default:None
) – The number of nodes, i.e.max_val + 1
ofedge_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 probabilityp
using samples from a Bernoulli distribution. Expandtorch_geometric.utils.dropout_edge()
with type support.- Parameters:
- Returns:
edge_index, edge_mask (
LongTensor, BoolTensor
) – The edge indices and the edge mask.