All problems
GCN Layer Output
Problem
Compute the output of one graph convolutional layer: H = ReLU(D~^-1/2 (A + I) D~^-1/2 X W).
features is an n by dim input matrix and weights is a dim by out_dim parameter matrix. Return the n by out_dim hidden matrix after the ReLU nonlinearity. edges is a list of [u, v] pairs.
Hint
Self-loops inside the normalized adjacency keep a node's own features in the mix.
Test cases
case 1
in: [3,[[0,1],[1,2]],[[1,0],[0,1],[1,1]],[[1,-1],[2,1]]]
expected: [[1.3164965809277263,0],[2.299659828522119,0],[2.3164965809277263,0.40824829046386313]]
case 2
in: [2,[[0,1]],[[1,1],[2,0]],[[1],[1]]]
expected: [[2],[2]]
case 3
in: [3,[],[[1,0],[0,1],[1,1]],[[1,-1],[2,1]]]
expected: [[1,0],[2,1],[3,0]]
Starter codePython
import math
def gcn_layer_output(n, edges, features, weights):
# Your code here
pass3 test cases · run your code against them in the editor