GraphUNet
¶
GraphUNet(
node_features_dim: int,
hidden_features_dim: int,
out_features_dim: int,
depth: int,
pool_ratios: Union[float, List[float]] = 0.5,
sum_res: bool = True,
act: Union[str, Callable] = "relu",
)
Bases: Module
The Graph U-Net model from the "Graph U-Nets" paper, which implements a U-Net like architecture with graph pooling and unpooling operations.
The encoder alternates GCNConv layers
(improved=True) and TopKPooling. Before each
pooling step, the graph is augmented with its 2-hop edges (the edges of
\((\mathbf{A} + \mathbf{I})^2\) without self-loops, weighted), so that
the pooled graph stays connected. The decoder puts the pooled features
back at their positions and adds (sum_res) or concatenates them to
the features of the encoder at the same depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of the input node features. |
required |
hidden_features_dim
|
int
|
Size of the hidden node features. |
required |
out_features_dim
|
int
|
Size of the output node features. |
required |
depth
|
int
|
The depth of the U-Net (number of pooling steps). |
required |
pool_ratios
|
Union[float, List[float]]
|
Pooling ratio of each depth, or one ratio for all.
Default: |
0.5
|
sum_res
|
bool
|
Whether the skip connections are summed ( |
True
|
act
|
Union[str, Callable]
|
The non-linearity, a name (e.g. |
'relu'
|
Example:
import mlx.core as mx
from mlx_graphs.nn import GraphUNet
model = GraphUNet(16, 32, 4, depth=2)
edge_index = mx.array([[0, 1, 1, 2, 2, 3, 3, 4], [1, 0, 2, 1, 3, 2, 4, 3]])
node_features = mx.random.normal((5, 16))
>>> model(edge_index, node_features).shape
(5, 4)
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the node embeddings. |
augment_adj |
Edges of \((\mathbf{A} + \mathbf{I})^2\) without self-loops |
Source code in mlx_graphs/nn/models/graph_unet.py
__call__
¶
__call__(
edge_index: array,
node_features: array,
batch_indices: Optional[array] = None,
edge_weights: Optional[array] = None,
) -> array
Computes the node embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Edges of shape |
required |
node_features
|
array
|
Node features of shape |
required |
batch_indices
|
Optional[array]
|
Graph of each node, of shape |
None
|
edge_weights
|
Optional[array]
|
Optional weight of each edge, of shape
|
None
|
Returns:
| Type | Description |
|---|---|
array
|
The node embeddings, of shape |
Source code in mlx_graphs/nn/models/graph_unet.py
augment_adj
¶
Edges of \((\mathbf{A} + \mathbf{I})^2\) without self-loops (where the self-loops of \(\mathbf{A}\) are replaced by \(\mathbf{I}\)), sorted by source then target node.
Source code in mlx_graphs/nn/models/graph_unet.py
from mlx_graphs.nn import GraphUNet · mlx_graphs/nn/models/graph_unet.py