FAConv
¶
FAConv(
node_features_dim: int,
eps: float = 0.1,
dropout: float = 0.0,
add_self_loops: bool = True,
normalize: bool = True,
**kwargs,
)
Bases: MessagePassing
The Frequency Adaptive Graph Convolution operator from the "Beyond Low-Frequency Information in Graph Convolutional Networks" paper.
where \(\mathbf{x}^{(0)}_i\) and \(d_i\) denote the initial feature representation and node degree of node \(i\), respectively. The attention coefficients \(\alpha_{i,j}\) are computed as
based on the trainable parameter vector \(\mathbf{a}\).
The normalization \(1 / \sqrt{d_i d_j}\) of a graph without edge
weights is cached per edge_index array (see
clear_norm_cache()), which replaces PyG's cached
argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of input (and output) node features |
required |
eps
|
float
|
\(\epsilon\)-value weighting the initial features.
Default: |
0.1
|
dropout
|
float
|
Dropout probability of the normalized attention coefficients.
Default: |
0.0
|
add_self_loops
|
bool
|
Whether to add self-loops to the input graph when
|
True
|
normalize
|
bool
|
Whether to add self-loops (if |
True
|
Example:
import mlx.core as mx
from mlx_graphs.nn import FAConv
conv = FAConv(16, eps=0.1)
edge_index = mx.array([[0, 1, 2, 3, 4], [0, 0, 1, 1, 3]])
x_0 = mx.random.uniform(low=0, high=1, shape=(5, 16))
h = conv(edge_index, x_0, x_0)
>>> h.shape
(5, 16)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of FAConv. |
Source code in mlx_graphs/nn/conv/fa_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: array,
initial_node_features: array,
edge_weights: Optional[array] = None,
return_attention_weights: bool = False,
) -> Union[array, Tuple[array, Tuple[array, array]]]
Computes the forward pass of FAConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
array
|
Input node features |
required |
initial_node_features
|
array
|
Initial node features \(\mathbf{x}^{(0)}\) (e.g. the output of the first layer of the model) |
required |
edge_weights
|
Optional[array]
|
Normalized edge weights, required if
|
None
|
return_attention_weights
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Union[array, Tuple[array, Tuple[array, array]]]
|
The computed node embeddings, and the attention weights if |
Union[array, Tuple[array, Tuple[array, array]]]
|
|
Source code in mlx_graphs/nn/conv/fa_conv.py
from mlx_graphs.nn import FAConv · mlx_graphs/nn/conv/fa_conv.py