FiLMConv
¶
FiLMConv(
node_features_dim: Union[int, Tuple[int, int]],
out_features_dim: int,
num_relations: int = 1,
mlp: Optional[Module] = None,
act: Optional[Callable[[array], array]] = relu,
aggr: str = "mean",
**kwargs,
)
Bases: MessagePassing
Feature-wise linear modulation (FiLM) graph convolution layer from the "GNN-FiLM: Graph Neural Networks with Feature-wise Linear Modulation" paper.
where \(\boldsymbol{\beta}_{r,i}, \boldsymbol{\gamma}_{r,i} =
g_r(\mathbf{x}_i)\), with \(g_r\) a linear layer by default (or a copy of
mlp) whose output is split in two halves, and \(\mathcal{N}_r(i)\)
the neighbours of \(i\) through edges of relation \(r\).
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). Default: |
1
|
mlp
|
Optional[Module]
|
Module mapping destination node features to |
None
|
act
|
Optional[Callable[[array], array]]
|
Activation function \(\sigma\), or |
relu
|
aggr
|
str
|
Aggregation \(\bigoplus\) within each relation.
Default: |
'mean'
|
**kwargs
|
Arguments of |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.nn import FiLMConv
edge_index = mx.array([[0, 1, 2, 3, 4], [1, 0, 3, 2, 0]])
edge_type = mx.array([0, 1, 0, 1, 1])
node_features = mx.random.normal((5, 16))
conv = FiLMConv(16, 32, num_relations=2)
h = conv(edge_index, node_features, edge_type)
>>> h.shape
(5, 32)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the forward pass of FiLMConv. |
Source code in mlx_graphs/nn/conv/film_conv.py
__call__
¶
__call__(
edge_index: array,
node_features: Union[array, Tuple[array, array]],
edge_type: Optional[array] = None,
) -> array
Computes the forward pass of FiLMConv.
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_type
|
Optional[array]
|
Relation of each edge, of shape |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings, one row per destination node |
Source code in mlx_graphs/nn/conv/film_conv.py
from mlx_graphs.nn import FiLMConv · mlx_graphs/nn/conv/film_conv.py