FluxML / GeometricFlux.jl

Geometric Deep Learning for Flux
https://fluxml.ai/GeometricFlux.jl/stable/
MIT License
348 stars 30 forks source link

GCNConv fails on FeaturedGraphs from adjacency list #217

Closed CarloLucibello closed 2 years ago

CarloLucibello commented 3 years ago

Exposed in #214

julia> alist = [[2,3],[1],[1]];

julia> m = GCNConv(2=>2)
GCNConv(2 => 2)

julia> fg = FeaturedGraph(alist, nf=rand(2,3));

julia> m(fg)
ERROR: MethodError: no method matching normalized_laplacian(::Vector{Vector{Int64}}, ::Type{Float64}; selfloop=true)
Closest candidates are:
  normalized_laplacian(::AbstractMatrix{T} where T, ::DataType; selfloop) at /home/lucibello/.julia/packages/GraphLaplacians/HituL/src/adjmat.jl:125
  normalized_laplacian(::MetaGraphs.AbstractMetaGraph, ::DataType; selfloop) at /home/lucibello/.julia/packages/GraphLaplacians/HituL/src/graphs.jl:44
  normalized_laplacian(::AbstractGraph, ::DataType; selfloop) at /home/lucibello/.julia/packages/GraphLaplacians/HituL/src/graphs.jl:21
  ...
Stacktrace:
 [1] normalized_laplacian(fg::FeaturedGraph{Vector{Vector{Int64}}, Matrix{Float64}, FillArrays.Fill{Int64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, FillArrays.Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}}, T::DataType; selfloop::Bool)
   @ GraphSignals ~/.julia/packages/GraphSignals/SWYsC/src/featuredgraph.jl:266
 [2] (::GCNConv{Matrix{Float32}, Vector{Float32}, typeof(identity), NullGraph})(fg::FeaturedGraph{Vector{Vector{Int64}}, Matrix{Float64}, FillArrays.Fill{Int64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, FillArrays.Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}}, x::Matri
x{Float64})
   @ GeometricFlux ~/.julia/dev/GeometricFlux/src/layers/conv.jl:40
 [3] (::GCNConv{Matrix{Float32}, Vector{Float32}, typeof(identity), NullGraph})(fg::FeaturedGraph{Vector{Vector{Int64}}, Matrix{Float64}, FillArrays.Fill{Int64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, FillArrays.Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}})
   @ GeometricFlux ~/.julia/dev/GeometricFlux/src/layers/conv.jl:44
 [4] top-level scope
   @ REPL[39]:1
 [5] top-level scope
   @ ~/.julia/packages/CUDA/lwSps/src/initialization.jl:52
yuehhua commented 2 years ago

Should be fixed.

julia> using GraphSignals, GeometricFlux

julia> alist = [[2,3],[1],[1]];

julia> fg = FeaturedGraph(alist, nf=rand(2,3));

julia> m = GCNConv(2=>2)
GCNConv(2 => 2)

julia> m(fg)
FeaturedGraph(
    Undirected graph with (#V=3, #E=2) in adjacency matrix,
    Node feature:   ℝ^2 <Matrix{Float64}>,
)