#212GCN layer (message passing)MediumNeural Networks
GCN layer (message passing)
Background
A Graph Convolutional Network (GCN) layer updates each node's features by mixing in its neighbors'. Kipf & Welling's formulation uses the symmetrically normalized adjacency with self-loops: where . One layer is then — propagate (aggregate neighbors), transform (linear), activate.
Problem statement
Implement gcn_layer(A, H, W) for one GCN propagation step (no activation):
Input
A— adjacency matrix(n, n)(0/1, symmetric, no self-loops).H— node features(n, f_in).W— weight matrix(f_in, f_out).
Output
An np.ndarray (n, f_out): the propagated, transformed node features.
Examples
Example 1
Input: A = [[0,1],[1,0]] (two connected nodes), H = [[1],[3]], W = [[1]]
Output: [[2.0], [2.0]]
Explanation: with self-loops each node has degree 2, so . Each node's new feature is the average of both, , then multiplied by .
Constraints
- Add self-loops () before normalizing.
- Use symmetric normalization , not row normalization.
- Apply the linear transform
Wafter propagation (no activation here).
Notes
- Self-loops ensure a node keeps its own features; without them a node would see only its neighbors.
- Symmetric normalization keeps the scale of features stable across nodes of very different degree, avoiding exploding/vanishing signals in deep GCNs.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: two symmetric nodes mix features
- •Sample: 3-node path graph, 2 in-features, 2 out-features
- •Reference: 4-node graph, f_in=1, f_out=3 output