zhengchuanpan / GMAN

GMAN: A Graph Multi-Attention Network for Traffic Prediction (GMAN, https://fanxlxmu.github.io/publication/aaai2020/) was accepted by AAAI-2020.
Apache License 2.0
403 stars 105 forks source link

The code snippet to create SE file #2

Open tanwimallick opened 4 years ago

tanwimallick commented 4 years ago

Could you please share the code snippet to create the SE file?

tijsmaas commented 4 years ago

According to the paper, the spatial embeddings (SE file) are bootstrapped with node2vec and then trained together with the model.

import networkx as nx
from node2vec import Node2Vec

graph = nx.from_numpy_matrix(adj_mx)
# Precompute probabilities and generate walks
node2vec = Node2Vec(graph, dimensions=64, walk_length=30, num_walks=200, workers=1) 
# Embed nodes
model = node2vec.fit(window=10, min_count=1, batch_words=4)
model.wv.save_word2vec_format('SE_new.txt')

In practise however, you could also use a coordinate-based initialisation, since training the spatial embedding is part of the training procedure.

Edit: This script is less optimal than the results of the authors.

This was before the authors published their results on METR-LA dataset (+source). Additionally, I'm using another node2vec implementation with slightly different params.

zhengchuanpan commented 4 years ago

I have uploaded the code