With a dataset containing only edge features. This graph has nodes with no X features. This dataset is a set of edges about a network and its network flow. Ex: ip-address1, ip-address2 are the source & target nodes ... the edge_attr
To build a model in pytorch geometric (pyg) how do I pass the x (features) to the Data object?
Here is what I do now, but is not working:
X = np.zeros(shape=(len(node_indices),0))
x = torch.tensor(X, dtype=torch.double)
...
data = Data(x=x, edge_index=edge_index, edge_attr=edge_attr, y=y)
print data:
Data(x=[1784, 0], edge_index=[2, 1087823], edge_attr=[1087823, 6], y=[1087823, 1])
A straightforward way to deal with graphs without node features is to give all the nodes the same feature, as shown in the following code. Here I suggest using
torch.ones
instead oftorch.zeros
as in some GNNs the message is multiplied with node embeddings.You also can create some node features based on the graph information, for example, using the Positional Encoding methods. In pytorch geometric, you can directly apply these methods by using transforms
AddLaplacianEigenvectorPE
andAddRandomWalkPE
.