Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advice on inconsistent graph sizes? #59

Closed
JackMaguire opened this issue May 11, 2020 · 2 comments
Closed

Advice on inconsistent graph sizes? #59

JackMaguire opened this issue May 11, 2020 · 2 comments

Comments

@JackMaguire
Copy link
Contributor

JackMaguire commented May 11, 2020

Hi @danielegrattarola ,

I just found this library and am excited to start using it! I really appreciate the examples and great documentation. After reading, I still have one question: do you have any advice on modeling dynamically sized graphs (where the node count varies from graph to graph)?

My naive instinct is to train a network with a large N and zero-pad the unused elements when the number of nodes is < N. I am not sure if the zeros should be at the beginning, end, or just anywhere. I am interested to hear your input.

Thanks in advance for any advice!
-Jack

@danielegrattarola
Copy link
Owner

Hi,

there are a couple of solutions that you can try.

If the graphs are small enough to be zero-padded, then you can use spektral.utils.numpy_to_batch to do exactly what you suggest (this is called "batch mode" in the documentation). Note that this will waste a lot of memory because you will have dense arrays with a lot of zeros.

Another possibility is to use "disjoint mode", where you take the disjoint union of your graphs as if they were a single graph. This saves more memory because the adjacency matrix can be a sparse tensor, and also avoids the zero-padding.
Use spektral.utils.numpy_to_disjoint to convert your graphs to the single graph.

Hope this is what you were looking for.

Cheers,
Daniele

@JackMaguire
Copy link
Contributor Author

Thanks for the quick feedback, Daniele! I will try out your suggestions.

Best,
-Jack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants