benedekrozemberczki / ClusterGCN

A PyTorch implementation of "Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks" (KDD 2019).
GNU General Public License v3.0
786 stars 135 forks source link

Why is the Feature Matrix (X) sparse instead of the Adjacency Matrix (A)? #13

Closed pyyush closed 4 years ago

pyyush commented 4 years ago

line 40 in utils.py features = coo_matrix((feature_values, (node_index, feature_index)), shape=(node_count, feature_count)).toarray()

EdisonLeeeee commented 4 years ago

line 40 in utils.py features = coo_matrix((feature_values, (node_index, feature_index)), shape=(node_count, feature_count)).toarray()

The feature matrix (x) isn't sparse, instead, it's a dense matrix (ndarray) due the .toarray() method.

And the adjacency matrix (A) is represented as edge_index and edge_weight.

pyyush commented 4 years ago

In that case, how to make a sparse adjacency matrix (A) given edge_index and edge_weight. My goal is to implement the GCNConv layer on my own by just using PyTorch.

EdisonLeeeee commented 4 years ago

You would like to call torch.sparse.FloatTensor(edge_index , edge_weight, shape), where shape denotes the dense shape of adjacancy matrix A.

For more details, you may refer to pygcn.