AddRandomWalkPE
¶
Bases: BaseTransform
Adds the random walk positional encoding of each node, from "Graph Neural Networks with Learnable Structural and Positional Representations".
The encoding of a node holds its probabilities of being back at its
starting point after \(1, 2, \ldots,\) walk_length steps of a
random walk, i.e. the diagonals of the powers of the transition matrix
\(\mathbf{D}^{-1} \mathbf{A}\), where \(\mathbf{D}\) is the
out-degree. The edge_weights attribute of the graph is used as
\(\mathbf{A}\) if it exists: the walk then follows an edge with a
probability proportional to its weight. Duplicate edges are summed.
The encoding is computed on the host with NumPy: with dense matrices for
graphs of up to DENSE_THRESHOLD nodes, and otherwise with scipy
sparse products on blocks of nodes, which keeps the memory bounded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
walk_length
|
int
|
Number of random walk steps, which is the size of the encoding. |
required |
attr_name
|
Optional[str]
|
Name of the attribute in which the |
'random_walk_pe'
|
Example:
graph = GraphData(edge_index=mx.array([[0, 1, 1, 2], [1, 0, 2, 1]]))
graph = AddRandomWalkPE(walk_length=2)(graph)
graph.random_walk_pe
# mx.array([[0, 0.5], [0, 1], [0, 0.5]])
Methods:
| Name | Description |
|---|---|
process |
Adds the random walk positional encoding to |
Source code in mlx_graphs/transforms/features.py
process
¶
Adds the random walk 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/features.py
from mlx_graphs.transforms import AddRandomWalkPE · mlx_graphs/transforms/features.py