FastRGCNConv
¶
FastRGCNConv(
node_features_dim: Union[int, Tuple[int, int]],
out_features_dim: int,
num_relations: int,
num_bases: Optional[int] = None,
root_weight: bool = True,
bias: bool = True,
**kwargs,
)
Bases: RGCNConv
Relational graph convolution layer with the same semantics as
RGCNConv, from the "Modeling Relational Data with Graph Convolutional Networks" paper.
Unlike RGCNConv, which aggregates the neighbors of each relation
before applying the relation weights, this layer applies the weight of its
relation to every edge (one batched matmul over the edges, as PyG's
FastRGCNConv). This avoids aggregating per (node, relation) pair, at
the cost of gathering one [node_features_dim, out_features_dim] weight
matrix per edge, so it is best suited to small graphs and feature sizes.
Only the "add" and "mean" aggregations are supported.
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 |
num_relations
|
int
|
Number of relations (edge types) |
required |
num_bases
|
Optional[int]
|
If set, uses basis decomposition with this number of bases.
Default: |
None
|
root_weight
|
bool
|
Whether to add the transformed features of the node itself
to the output. Default: |
True
|
bias
|
bool
|
Whether to add a learnable bias to the output. Default: |
True
|
**kwargs
|
Arguments of |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn import FastRGCNConv
conv = FastRGCNConv(16, 32, num_relations=3, num_bases=2)
edge_index = mx.array([[0, 1, 2, 3, 4], [0, 0, 1, 1, 3]])
edge_type = mx.array([0, 0, 1, 2, 2])
node_features = mx.random.uniform(low=0, high=1, shape=(5, 16))
h = conv(edge_index, node_features, edge_type)
>>> h.shape
(5, 32)
Source code in mlx_graphs/nn/conv/fast_rgcn_conv.py
from mlx_graphs.nn import FastRGCNConv · mlx_graphs/nn/conv/fast_rgcn_conv.py