GCNNorm
¶
GCNNorm(add_self_loops: bool = True)
Bases: BaseTransform
Applies the GCN normalization from "Semi-supervised Classification with Graph Convolutional Networks"
to the edges of a graph and stores the result in edge_weights:
where \(\hat{D}_{ii} = \sum_{j} (\mathbf{A} + \mathbf{I})_{ji}\) is the
weighted in-degree. The edge_weights attribute of the graph is used as
\(\mathbf{A}\) if it exists.
With add_self_loops, every node gets exactly one self-loop, placed
after the other edges: a node that already has a self-loop keeps its
weight, the others get a self-loop of weight 1. The other per-edge
attributes (e.g. edge_features) are kept aligned with the new
edge_index: existing self-loops keep their values and the added ones
get zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
add_self_loops
|
bool
|
Whether to add self-loops before normalizing.
Default: |
True
|
Example:
graph = GraphData(edge_index=mx.array([[0, 1], [1, 0]]))
graph = GCNNorm()(graph)
graph.edge_index
# mx.array([[0, 1, 0, 1], [1, 0, 0, 1]])
graph.edge_weights
# mx.array([0.5, 0.5, 0.5, 0.5])
Methods:
| Name | Description |
|---|---|
process |
Normalizes the edges of |
Source code in mlx_graphs/transforms/features.py
process
¶
Normalizes the edges of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph with the normalized |
GraphData
|
if requested). |
Source code in mlx_graphs/transforms/features.py
from mlx_graphs.transforms import GCNNorm · mlx_graphs/transforms/features.py