GENConv
¶
GENConv(
node_features_dim: Union[int, Tuple[int, int]],
out_features_dim: int,
aggr: Union[GENAggregations, List[str]] = "softmax",
t: float = 1.0,
learn_t: bool = False,
p: float = 1.0,
learn_p: bool = False,
msg_norm: bool = False,
learn_msg_scale: bool = False,
norm: Optional[GENNorms] = "batch",
num_layers: int = 2,
expansion: int = 2,
eps: float = 1e-07,
bias: bool = False,
edge_features_dim: Optional[int] = None,
)
Bases: MessagePassing
The GENeralized Graph Convolution (GENConv) from the "DeeperGCN: All You Need to Train Deeper GCNs" paper.
The aggregation is, by default, the softmax aggregation of DeeperGCN, computed per feature channel with an (optionally learnable) inverse temperature \(t\):
With aggr="powermean" it is the power mean
\(\left(\frac{1}{|\mathcal{N}(i)|} \sum_j \mathbf{m}_j^p\right)^{1/p}\)
with an (optionally learnable) power \(p\), where the messages and the
mean are clamped to [1e-4, 100] (as in PyG) when \(p \neq 1\).
The layer also works on bipartite graphs: pass node_features as a
(src_features, dst_features) tuple and node_features_dim as a
(src_dim, dst_dim) tuple. The output has one row per destination node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
Union[int, Tuple[int, int]]
|
Size of input node features, or a |
required |
out_features_dim
|
int
|
Size of output node embeddings |
required |
aggr
|
Union[GENAggregations, List[str]]
|
Aggregation: |
'softmax'
|
t
|
float
|
Initial inverse temperature of the softmax aggregation.
Default: |
1.0
|
learn_t
|
bool
|
Whether to learn |
False
|
p
|
float
|
Initial power of the power mean aggregation. Default: |
1.0
|
learn_p
|
bool
|
Whether to learn |
False
|
msg_norm
|
bool
|
Whether to use message normalization (MsgNorm), i.e. rescale
the aggregated messages to the \(\ell_2\) norm of the
destination features. Default: |
False
|
learn_msg_scale
|
bool
|
Whether to learn the scale of the message
normalization. Default: |
False
|
norm
|
Optional[GENNorms]
|
Normalization of the hidden MLP layers: |
'batch'
|
num_layers
|
int
|
Number of MLP layers. Default: |
2
|
expansion
|
int
|
Expansion factor of the hidden MLP layers. Default: |
2
|
eps
|
float
|
Value added to every message. Default: |
1e-07
|
bias
|
bool
|
Whether the linear layers use a bias. Default: |
False
|
edge_features_dim
|
Optional[int]
|
Size of edge features. If set and different from
|
None
|
Example:
import mlx.core as mx
from mlx_graphs.nn import GENConv
conv = GENConv(16, 32, aggr="softmax", learn_t=True, edge_features_dim=4)
edge_index = mx.array([[0, 1, 2, 3, 4], [0, 0, 1, 1, 3]])
node_features = mx.random.uniform(low=0, high=1, shape=(5, 16))
edge_features = mx.random.uniform(low=0, high=1, shape=(5, 4))
h = conv(edge_index, node_features, edge_features)
>>> h.shape
(5, 32)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of GENConv. |
Source code in mlx_graphs/nn/conv/gen_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: Union[array, Tuple[array, array]],
edge_features: Optional[array] = None,
) -> array
Computes the forward pass of GENConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
node_features
|
Union[array, Tuple[array, array]]
|
Input node features, or a |
required |
edge_features
|
Optional[array]
|
Optional edge features of shape
|
None
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings, one row per destination node |
Source code in mlx_graphs/nn/conv/gen_conv.py
from mlx_graphs.nn import GENConv · mlx_graphs/nn/conv/gen_conv.py