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

Merging multiple feature arrays #102

Closed
casper2002casper opened this issue Jan 18, 2022 · 2 comments
Closed

Merging multiple feature arrays #102

casper2002casper opened this issue Jan 18, 2022 · 2 comments

Comments

@casper2002casper
Copy link

casper2002casper commented Jan 18, 2022

I'm a bit confused about using multiple node feature arrays per graph. Using multiple node feature arrays allows keeping apart different features of the node (i.e. x and y values) however when trying to pass it through a layer it outputs an error. Is the intended use to keep all features in a single array? Couldn't all features arrays be merged?

This works

julia> l = GCNConv(2=>1)
julia> g = rand_graph(4, 6, ndata=(x = ones(2,4)))
julia> l(g)`
GNNGraph:
    num_nodes = 4
    num_edges = 6
    ndata:
        x => (1, 4)

This doesn't

julia> g = rand_graph(4, 6, ndata=(x = ones(4), y = zeros(4)))  
julia> l(g)  
┌ Error: Multiple feature arrays, access directly through g.ndata
└ @ GraphNeuralNetworks.GNNGraphs ~/.julia/packages/GraphNeuralNetworks/KNr8R/src/GNNGraphs/query.jl:321
ERROR: MethodError: no method matching (::GCNConv{Matrix{Float32}, Vector{Float32}, typeof(identity)})(::GNNGraph{Tuple{Vector{Int64}, Vector{Int64}, Nothing}}, ::Nothing)
@CarloLucibello
Copy link
Member

CarloLucibello commented Jan 18, 2022

Yes, typically one keeps all features in a single array (e.g. one matrix of size num_features x num_nodes).

julia> g = rand_graph(4, 6, ndata= vcat(ones(1,4), zeros(1,4)))
GNNGraph:
    num_nodes = 4
    num_edges = 6
    ndata:
        x => (2, 4)

julia> l = GCNConv(2=>1)
GCNConv(2 => 1)

julia> l(g)
GNNGraph:
    num_nodes = 4
    num_edges = 6
    ndata:
        x => (1, 4)

julia> l(g, g.ndata.x)
1×4 Matrix{Float64}:
 -1.65217  -1.07596  -1.07596  -1.07596

We allow the possibility to store separate feature arrays since in some applications they are handled in a different way (see equivariant graph neural networks for instance).

PS using julia code blocks will make your code mode readable

@casper2002casper
Copy link
Author

I see, thank you

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