DynamicEdgeConv
¶
DynamicEdgeConv(mlp: Module, k: int, **kwargs)
Bases: EdgeConv
Dynamic edge convolution layer from the "Dynamic Graph CNN for Learning on Point Clouds" paper (see
EdgeConv), where the graph is dynamically constructed using the
nearest neighbors in the feature space.
where \(\mathcal{N}_k(i)\) are the \(k\) nearest neighbors of node \(i\) (including \(i\) itself) among the nodes of its graph, under the euclidean distance between the node features.
The layer also works on bipartite graphs: pass node_features as a
(src_features, dst_features) tuple (and batch_indices as a tuple of
two batch vectors); each destination node aggregates its \(k\) nearest
source nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mlp
|
Module
|
Callable |
required |
k
|
int
|
Number of nearest neighbors. |
required |
**kwargs
|
Arguments of |
{}
|
Example:
import mlx.core as mx
import mlx.nn as nn
from mlx_graphs.nn import DynamicEdgeConv
mlp = nn.Sequential(nn.Linear(2 * 3, 32), nn.ReLU(), nn.Linear(32, 32))
conv = DynamicEdgeConv(mlp, k=4)
points = mx.random.normal((10, 3))
batch_indices = mx.array([0] * 5 + [1] * 5)
h = conv(points, batch_indices)
>>> h.shape
(10, 32)
Methods:
| Name | Description |
|---|---|
__call__ |
Builds the k-NN graph of the node features and applies EdgeConv. |
Source code in mlx_graphs/nn/conv/dynamic_edge_conv.py
__call__
¶
__call__(
node_features: Union[array, Tuple[array, array]],
batch_indices: Optional[
Union[array, Tuple[Optional[array], Optional[array]]]
] = None,
) -> array
Builds the k-NN graph of the node features and applies EdgeConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
Union[array, Tuple[array, array]]
|
Input node features of shape |
required |
batch_indices
|
Optional[Union[array, Tuple[Optional[array], Optional[array]]]]
|
Graph of each node, of shape |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The computed node embeddings, one row per destination node |
Source code in mlx_graphs/nn/conv/dynamic_edge_conv.py
from mlx_graphs.nn import DynamicEdgeConv · mlx_graphs/nn/conv/dynamic_edge_conv.py