AddLaplacianEigenvectorPE
¶
AddLaplacianEigenvectorPE(
k: int,
attr_name: Optional[str] = "laplacian_eigenvector_pe",
is_undirected: bool = False,
**kwargs: Any,
)
Bases: BaseTransform
Adds the Laplacian eigenvector positional encoding from "Benchmarking Graph Neural Networks" to each node,
as PyG's AddLaplacianEigenvectorPE.
The encoding holds the eigenvectors of the k smallest non-trivial
eigenvalues of the symmetrically normalized Laplacian
\(\mathbf{L} = \mathbf{I} - \mathbf{D}^{-1/2} \mathbf{A}
\mathbf{D}^{-1/2}\) (the eigenvector of the smallest eigenvalue is
skipped). The edge_weights attribute is used as \(\mathbf{A}\) if
it exists. As eigenvectors are only defined up to their sign, the sign of
each one is flipped at random (from mx.random, so reproducible with
mx.random.seed), as in PyG.
The eigenvectors are computed on the host: with NumPy for graphs of less
than SPARSE_THRESHOLD nodes, and with scipy.sparse.linalg (which
is then required) otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of non-trivial eigenvectors, which is the size of the encoding. Must be smaller than the number of nodes. |
required |
attr_name
|
Optional[str]
|
Name of the attribute in which the |
'laplacian_eigenvector_pe'
|
is_undirected
|
bool
|
If |
False
|
**kwargs
|
Any
|
Additional arguments of |
{}
|
Example:
graph = GraphData(edge_index=mx.array([[0, 1, 1, 2], [1, 0, 2, 1]]))
graph = AddLaplacianEigenvectorPE(k=1, is_undirected=True)(graph)
graph.laplacian_eigenvector_pe
# mx.array([[0.7071], [0.0], [-0.7071]]) (up to the sign)
Methods:
| Name | Description |
|---|---|
process |
Adds the Laplacian eigenvector positional encoding to |
Source code in mlx_graphs/transforms/spectral.py
process
¶
Adds the Laplacian eigenvector positional encoding to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph with the encoding. |
Source code in mlx_graphs/transforms/spectral.py
from mlx_graphs.transforms import AddLaplacianEigenvectorPE · mlx_graphs/transforms/spectral.py