Training the adjacency matrix(weights) as a learnable parameter for graph classification #8191
-
Hello all,
As you can see, I have applied a linear transformation to the feature vectors using nn.Linear and the weights of this layer are learnable parameters. I have used this adjacency matrix to create a data object. However, I am not sure if I can indeed treat a learnable parameter as a data object in PyG.
My concerns regarding my approach are as follows:
Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
That's interesting. I do not see why it should fail, but you will have I guess to remove
otherwise the parameters of your
because this is not a parameter of your model. |
Beta Was this translation helpful? Give feedback.
-
Now I understand the problem. If you go for a batch size of 1, the following works:
The idea is to load one graph at a time, and for that graph create the adjacency matrix and edge weights based on the features. Actually, you can put all the |
Beta Was this translation helpful? Give feedback.
-
You can use more than a single graph per batch but then you will have to adapt |
Beta Was this translation helpful? Give feedback.
-
You can adapt your |
Beta Was this translation helpful? Give feedback.
You can adapt your
calculate_inverse_distances
by using the information in the batch. See the documentation.batch
is a vector of int. It has as many elements as the number of rows of the data tensorx
and indicates for each elementx[i]
which graph it belongs to. With this information you can avoid computing the distance between two nodes that are not from the same graph. Some methods from PyG might be here of help, I do not know.