# Simple GCN: https://towardsdatascience.com/how-to-do-deep-learning-on-graphs-with-graph-convolutional-networks-7d2250723780
import numpy as np
import torch.nn.functional
A = np.matrix([
[0, 1, 0, 0],
[0, 0, 1, 1],
[0, 1, 0, 0],
[1, 0, 1, 0]],
dtype=float
)
I = np.matrix(np.eye(A.shape[0]))
A_hat = A + I
D_hat = np.array(np.sum(A_hat, axis=0))[0] # count the in degree as D
D_hat = np.matrix(np.diag(D_hat))
X = np.matrix([
[i, -i]
for i in range(A.shape[0])
], dtype=float)
W1 = np.matrix([
[1, -1],
[-1, 1]
])
W2 = np.matrix([
[1],
[-1]
])
X1 = D_hat**-1*A_hat*X*W1
print("X",X)
print("X1",X1)
act = torch.nn.functional.relu_(torch.tensor(X1))
print(act)
手写简单的GCN
最新推荐文章于 2024-07-30 21:09:58 发布