tkipf / pygcn

Graph Convolutional Networks in PyTorch
MIT License
5.16k stars 1.23k forks source link

load own adjacency matrix and features #21

Open xypan1232 opened 6 years ago

xypan1232 commented 6 years ago

I have my own array for adjacency matrix and features, thus i did not use the load function in utils.py Could I ask is it right for me to generate adjacency and feature data for training graph cnn. features and adj are full numpy array:

features = sp.csr_matrix(features, dtype=np.float32) features = normalize(features) features = np.array(features.todense()) adj = sp.csr_matrix(adj) adj = normalize(adj + sp.eye(adj.shape[0])) adj = sparse_mx_to_torch_sparse_tensor(adj)

Another question is that why need "adj + sp.eye(adj.shape[0])" if adj is an adjacency matrix? thanks.

JTunis commented 5 years ago

To take a crack at your second question: we want to add the identity matrix to our adjacency matrix in order to add self-loops onto each node. If we did not do this, at each propagation we would only be aggregating the features of each node's neighborhood without accounting for the features of the node itself. Adding self-loops allows us to aggregate a node's features with its neighbor's features (because it acts as its own neighbor).