gcn_norm
¶
gcn_norm(
edge_index: array,
num_nodes: int,
edge_weights: Optional[array] = None,
add_self_loops: bool = True,
fill_value: float = 1.0,
) -> Tuple[array, array]
Symmetric GCN normalization of a graph.
Degrees are the (weighted) in-degrees, computed after the self-loops are added. Nodes with a degree of 0 get a normalization of 0.
With add_self_loops, a self-loop of weight fill_value (1 by
default, 2 for PyG's improved=True) is added to every node that does
not have one. Existing self-loops keep their weight, as in PyG.
The returned edge_index always has num_edges + num_nodes columns in
that case: the loop appended to a node that already has one has weight 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Graph connectivity of shape |
required |
num_nodes
|
int
|
Number of nodes in the graph |
required |
edge_weights
|
Optional[array]
|
Optional scalar weight per edge, of shape |
None
|
add_self_loops
|
bool
|
Whether to add self-loops before normalizing |
True
|
fill_value
|
float
|
Weight of the added self-loops. Default: |
1.0
|
Returns:
| Type | Description |
|---|---|
array
|
The edge index (with self-loops if requested) and one normalized weight |
array
|
per edge, of shape |
Source code in mlx_graphs/nn/conv/_norm.py
from mlx_graphs.nn import gcn_norm · mlx_graphs/nn/conv/_norm.py