FelixOpolka / STGCN-PyTorch

🚗 Implementation of spatio-temporal graph convolutional network with PyTorch
MIT License
331 stars 70 forks source link

About the Adjacent matrix #3

Open GreatWizard9519 opened 5 years ago

GreatWizard9519 commented 5 years ago

Hi,

I am confused with the Adjacency Matrix in your adj_mat.npy. It doesn't seem to be an adjacency matrix.

Best

FelixOpolka commented 5 years ago

Hey, Could you elaborate what you mean with "not an adjacency matrix"? Do you mean because it is not symmetric?

GreatWizard9519 commented 5 years ago

Hey, Could you elaborate what you mean with "not an adjacency matrix"? Do you mean because it is not symmetric?

Thanks for your reply.

I think an adjacency matrix always looks like this. image

But I found yours is more like a diagonal matrix A = np.load("data/adj_mat.npy") image

Maybe I am wrong and looking forward to your reply

FelixOpolka commented 5 years ago

Thanks for your reply! When the adjacency matrix contains non-zero elements, it means that the nodes have self-loops, which might be necessary for some algorithms (e.g. for graph convolutions). Also it might look like it is a diagonal matrix because it is extremely sparse but it should certainly contain non-zero off-diagonal elements. I think I visualised it with matplotlib's imshow before, which should make that visible.

GreatWizard9519 commented 5 years ago

Thanks for your reply! When the adjacency matrix contains non-zero elements, it means that the nodes have self-loops, which might be necessary for some algorithms (e.g. for graph convolutions). Also it might look like it is a diagonal matrix because it is extremely sparse but it should certainly contain non-zero off-diagonal elements. I think I visualised it with matplotlib's imshow before, which should make that visible.

Thanks. That is to say that you transform the adjacency matrix into a special form since the matrix is extremely sparse.

FelixOpolka commented 5 years ago

The non-zero diagonal entries are not necessary because of the sparsity of the matrix but because of the way it is used, i.e. for graph convolutions. If the diagonal was zero, due to the way graph convolutions are implemented, the central node's features would be ignored when aggregating features for a patch. You can have a look at the original GCN paper (https://arxiv.org/pdf/1609.02907.pdf), especially eq. 7 for more details.

The sparsity is not really a problem, it is a result of the specific problem at hand (and a design decision of the data set creators to some degree). Only the visualisation of the matrix is a bit tricky because it is large and mostly 0.

GreatWizard9519 commented 5 years ago

The non-zero diagonal entries are not necessary because of the sparsity of the matrix but because of the way it is used, i.e. for graph convolutions. If the diagonal was zero, due to the way graph convolutions are implemented, the central node's features would be ignored when aggregating features for a patch. You can have a look at the original GCN paper (https://arxiv.org/pdf/1609.02907.pdf), especially eq. 7 for more details.

The sparsity is not really a problem, it is a result of the specific problem at hand (and a design decision of the data set creators to some degree). Only the visualisation of the matrix is a bit tricky because it is large and mostly 0.

Thanks for your kind reply! Maybe I have some misunderstanding on the mathematical principle of GCN and will go back to have a look.

ThomasAFink commented 1 year ago

Here's how I created my own. It's not diagonal, but in list format: https://github.com/ThomasAFink/osmnx_adjacency_matrix_for_graph_convolutional_networks