LapPEEncoder
¶
LapPEEncoder(
pe_dim: int,
out_features_dim: int,
norm: Optional[str] = None,
random_sign_flip: bool = True,
)
Bases: RWSEEncoder
Projection of the Laplacian eigenvector positional encodings (LapPE)
of the nodes, as the linear LapPE node encoder of GraphGPS.
Eigenvectors are only defined up to their sign, so during training
(module.train()) the sign of every eigenvector of every graph is
flipped at random, which makes the model learn sign-invariant functions
of the encodings. The encodings (e.g. computed by
AddLaplacianEigenvectorPE) are then
normalized (optional) and linearly projected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pe_dim
|
int
|
Number of eigenvectors \(k\) in the input encodings. |
required |
out_features_dim
|
int
|
Size of the projected encodings. |
required |
norm
|
Optional[str]
|
Normalization of the input encodings: |
None
|
random_sign_flip
|
bool
|
Whether to flip signs at random during training.
Default: |
True
|
Example:
import mlx.core as mx
from mlx_graphs.nn import LapPEEncoder
encoder = LapPEEncoder(pe_dim=4, out_features_dim=8)
laplacian_pe = mx.random.normal((10, 4))
batch_indices = mx.array([0] * 6 + [1] * 4)
>>> encoder(laplacian_pe, batch_indices).shape
(10, 8)
References
Methods:
| Name | Description |
|---|---|
__call__ |
Projects the eigenvector encodings |
Source code in mlx_graphs/nn/encoding.py
__call__
¶
__call__(pe: array, batch_indices: Optional[array] = None)
Projects the eigenvector encodings pe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pe
|
array
|
Encodings of shape |
required |
batch_indices
|
Optional[array]
|
Graph of each node, so that each graph gets its own
random signs during training. Default: |
None
|
Source code in mlx_graphs/nn/encoding.py
from mlx_graphs.nn import LapPEEncoder · mlx_graphs/nn/encoding.py