ChebConv
¶
ChebConv(
node_features_dim: int,
out_features_dim: int,
K: int,
normalization: Optional[Literal["sym", "rw"]] = "sym",
bias: bool = True,
**kwargs,
)
Bases: MessagePassing
Chebyshev spectral graph convolution layer from "Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering" paper.
where the \(\mathbf{Z}^{(k)}\) are computed recursively by
and \(\mathbf{\hat{L}} = \frac{2 \mathbf{L}}{\lambda_{\max}} - \mathbf{I}\) is the scaled graph Laplacian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of input node features |
required |
out_features_dim
|
int
|
Size of output node embeddings |
required |
K
|
int
|
Number of Chebyshev terms, i.e. the filter reaches |
required |
normalization
|
Optional[Literal['sym', 'rw']]
|
Normalization of the graph Laplacian
\(\mathbf{L}\), with \(\mathbf{D}\) the (weighted) degree
matrix (default:
|
'sym'
|
bias
|
bool
|
Whether to add a bias to the output |
True
|
**kwargs
|
Arguments of |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn import ChebConv
edge_index = mx.array([[0, 1, 1, 2, 2, 3], [1, 0, 2, 1, 3, 2]])
node_features = mx.ones((5, 16))
conv = ChebConv(16, 32, K=3)
h = conv(edge_index, node_features)
>>> h.shape
(5, 32)
# Largest eigenvalue of the Laplacian, if it is known
h = conv(edge_index, node_features, lambda_max=1.8)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of ChebConv. |
Source code in mlx_graphs/nn/conv/cheb_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: array,
edge_weights: Optional[array] = None,
batch: Optional[array] = None,
lambda_max: Optional[Union[float, array]] = None,
) -> array
Computes the forward pass of ChebConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
array
|
Input node features |
required |
edge_weights
|
Optional[array]
|
Optional scalar weight per edge, of shape |
None
|
batch
|
Optional[array]
|
Graph index of every node, of shape |
None
|
lambda_max
|
Optional[Union[float, array]]
|
Largest eigenvalue of the graph Laplacian, either one
value or an array with one value per graph of the batch. If
|
None
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings |
Source code in mlx_graphs/nn/conv/cheb_conv.py
from mlx_graphs.nn import ChebConv · mlx_graphs/nn/conv/cheb_conv.py