Skip to content

Commit a0c0736

Browse files
authored
Merge pull request #317 from FluxML/new_features
New features: positional encoding
2 parents 0a42497 + 9e2c938 commit a0c0736

21 files changed

+637
-30
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ DataStructures = "0.18"
3131
FillArrays = "0.13"
3232
Flux = "0.12 - 0.13"
3333
GraphMLDatasets = "0.1"
34-
GraphSignals = "0.4 - 0.5"
34+
GraphSignals = "0.6"
3535
Graphs = "1"
3636
NNlib = "0.8"
3737
NNlibCUDA = "0.2"

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
4+
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
45

56
[compat]
67
Documenter = "0.27"

docs/bibliography.bib

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,29 @@ @inproceedings{Hamilton2017
184184
year = {2017},
185185
}
186186

187+
@inproceedings{Satorras2021,
188+
abstract = {This paper introduces a new model to learn graph neural networks equivariant to rotations, translations, reflections and permutations called E(n)-Equivariant Graph Neural Networks (EGNNs). In contrast with existing methods, our work does not require computationally expensive higher-order representations in intermediate layers while it still achieves competitive or better performance. In addition, whereas existing methods are limited to equivariance on 3 dimensional spaces, our model is easily scaled to higher-dimensional spaces. We demonstrate the effectiveness of our method on dynamical systems modelling, representation learning in graph autoencoders and predicting molecular properties.},
189+
author = {Victor Garcia Satorras and Emiel Hoogeboom and Max Welling},
190+
editor = {Marina Meila and Tong Zhang},
191+
booktitle = {Proceedings of the 38th International Conference on Machine Learning},
192+
month = {2},
193+
pages = {9323-9332},
194+
publisher = {PMLR},
195+
title = {E(n) Equivariant Graph Neural Networks},
196+
volume = {139},
197+
url = {http://arxiv.org/abs/2102.09844},
198+
year = {2021},
199+
}
200+
201+
@article{Dwivedi2021,
202+
abstract = {Graph neural networks (GNNs) have become the standard learning architectures for graphs. GNNs have been applied to numerous domains ranging from quantum chemistry, recommender systems to knowledge graphs and natural language processing. A major issue with arbitrary graphs is the absence of canonical positional information of nodes, which decreases the representation power of GNNs to distinguish e.g. isomorphic nodes and other graph symmetries. An approach to tackle this issue is to introduce Positional Encoding (PE) of nodes, and inject it into the input layer, like in Transformers. Possible graph PE are Laplacian eigenvectors. In this work, we propose to decouple structural and positional representations to make easy for the network to learn these two essential properties. We introduce a novel generic architecture which we call LSPE (Learnable Structural and Positional Encodings). We investigate several sparse and fully-connected (Transformer-like) GNNs, and observe a performance increase for molecular datasets, from 2.87% up to 64.14% when considering learnable PE for both GNN classes.},
203+
author = {Vijay Prakash Dwivedi and Anh Tuan Luu and Thomas Laurent and Yoshua Bengio and Xavier Bresson},
204+
month = {10},
205+
title = {Graph Neural Networks with Learnable Structural and Positional Representations},
206+
url = {http://arxiv.org/abs/2110.07875},
207+
year = {2021},
208+
}
209+
187210
@article{Battaglia2018,
188211
abstract = {Artificial intelligence (AI) has undergone a renaissance recently, making major progress in key domains such as vision, language, control, and decision-making. This has been due, in part, to cheap data and cheap compute resources, which have fit the natural strengths of deep learning. However, many defining characteristics of human intelligence, which developed under much different pressures, remain out of reach for current approaches. In particular, generalizing beyond one's experiences--a hallmark of human intelligence from infancy--remains a formidable challenge for modern AI. The following is part position paper, part review, and part unification. We argue that combinatorial generalization must be a top priority for AI to achieve human-like abilities, and that structured representations and computations are key to realizing this objective. Just as biology uses nature and nurture cooperatively, we reject the false choice between "hand-engineering" and "end-to-end" learning, and instead advocate for an approach which benefits from their complementary strengths. We explore how using relational inductive biases within deep learning architectures can facilitate learning about entities, relations, and rules for composing them. We present a new building block for the AI toolkit with a strong relational inductive bias--the graph network--which generalizes and extends various approaches for neural networks that operate on graphs, and provides a straightforward interface for manipulating structured knowledge and producing structured behaviors. We discuss how graph networks can support relational reasoning and combinatorial generalization, laying the foundation for more sophisticated, interpretable, and flexible patterns of reasoning. As a companion to this paper, we have released an open-source software library for building graph networks, with demonstrations of how to use them in practice.},
189212
author = {Peter W. Battaglia and Jessica B. Hamrick and Victor Bapst and Alvaro Sanchez-Gonzalez and Vinicius Zambaldi and Mateusz Malinowski and Andrea Tacchetti and David Raposo and Adam Santoro and Ryan Faulkner and Caglar Gulcehre and Francis Song and Andrew Ballard and Justin Gilmer and George Dahl and Ashish Vaswani and Kelsey Allen and Charles Nash and Victoria Langston and Chris Dyer and Nicolas Heess and Daan Wierstra and Pushmeet Kohli and Matt Botvinick and Oriol Vinyals and Yujia Li and Razvan Pascanu},

docs/make.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ makedocs(
4242
"Dynamic Graph Update" => "dynamicgraph.md",
4343
"Manual" => [
4444
"FeaturedGraph" => "manual/featuredgraph.md",
45-
"Graph Convolutional Layers" => "manual/conv.md",
45+
"Graph Convolutional Layers" => "manual/graph_conv.md",
4646
"Graph Pooling Layers" => "manual/pool.md",
47+
"Group Convolutional Layers" => "manual/group_conv.md",
48+
"Positional Encoding Layers" => "manual/positional.md",
4749
"Embeddings" => "manual/embedding.md",
4850
"Models" => "manual/models.md",
4951
"Linear Algebra" => "manual/linalg.md",

docs/src/manual/featuredgraph.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ GraphSignals.edge_feature
99
GraphSignals.has_edge_feature
1010
GraphSignals.global_feature
1111
GraphSignals.has_global_feature
12+
GraphSignals.positional_feature
13+
GraphSignals.has_positional_feature
1214
GraphSignals.subgraph
1315
GraphSignals.ConcreteFeaturedGraph
1416
```
File renamed without changes.

docs/src/manual/group_conv.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Group Convolutional Layers
2+
3+
## ``E(n)``-equivariant Convolutional Layer
4+
5+
It employs message-passing scheme and can be defined by following functions:
6+
7+
- message function (Eq. 3 from paper): ``m_{ij} = \phi_e(h_i^l, h_j^l, ||x_i^l - x_j^l||^2, a_{ij})``
8+
- aggregate (Eq. 5 from paper): ``m_i = \sum_j m_{ij}``
9+
- update function (Eq. 6 from paper): ``h_i^{l+1} = \phi_h(h_i^l, m_i)``
10+
11+
where ``h_i^l`` and ``h_j^l`` denotes the node feature for node ``i`` and ``j``, respectively, in ``l``-th layer, as well as ``x_i^l`` and ``x_j^l`` denote the positional feature for node ``i`` and ``j``, respectively, in ``l``-th layer. ``a_{ij}`` is the edge feature for edge ``(i,j)``. ``\phi_e`` and ``\phi_h`` are neural network for edges and nodes.
12+
13+
```@docs
14+
EEquivGraphConv
15+
```
16+
17+
Reference: [Satorras2021](@cite)
18+
19+
---

docs/src/manual/positional.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Positional Encoding
2+
3+
## Positional Encoding Methods
4+
5+
```@docs
6+
AbstractPositionalEncoding
7+
RandomWalkPE
8+
LaplacianPE
9+
positional_encode
10+
```
11+
12+
## Positional Encoding Layers
13+
14+
### ``E(n)``-equivariant Positional Encoding Layer
15+
16+
It employs message-passing scheme and can be defined by following functions:
17+
18+
- message function: ``y_{ij}^l = (x_i^l - x_j^l)\phi_x(m_{ij})``
19+
- aggregate: ``y_i^l = \frac{1}{M} \sum_{j \in \mathcal{N}(i)} y_{ij}^l``
20+
- update function: ``x_i^{l+1} = x_i^l + y_i^l``
21+
22+
where ``x_i^l`` and ``x_j^l`` denote the positional feature for node ``i`` and ``j``, respectively, in ``l``-th layer, ``\phi_x`` is the neural network for positional encoding and ``m_{ij}`` is the edge feature for edge ``(i,j)``. ``y_{ij}^l`` and ``y_i^l`` represent the encoded positional feature and aggregated positional feature, respectively, and ``M`` denotes number of neighbors of node ``i``.
23+
24+
```@docs
25+
EEquivGraphPE
26+
```
27+
28+
Reference: [Satorras2021](@cite)
29+
30+
---
31+
32+
### Learnable Structural Positional Encoding layer
33+
34+
(WIP)
35+
36+
```@docs
37+
LSPE
38+
```
39+
40+
Reference: [Dwivedi2021](@cite)
41+
42+
---
43+

src/GeometricFlux.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ export
3030
# layers/msgpass
3131
MessagePassing,
3232

33-
# layers/conv
33+
# layers/positional
34+
AbstractPositionalEncoding,
35+
RandomWalkPE,
36+
LaplacianPE,
37+
positional_encode,
38+
EEquivGraphPE,
39+
LSPE,
40+
41+
# layers/graph_conv
3442
GCNConv,
3543
ChebConv,
3644
GraphConv,
@@ -44,6 +52,9 @@ export
4452
MeanAggregator, MeanPoolAggregator, MaxPoolAggregator,
4553
LSTMAggregator,
4654

55+
# layers/group_conv
56+
EEquivGraphConv,
57+
4758
# layer/pool
4859
GlobalPool,
4960
LocalPool,
@@ -71,7 +82,9 @@ include("layers/graphlayers.jl")
7182
include("layers/gn.jl")
7283
include("layers/msgpass.jl")
7384

74-
include("layers/conv.jl")
85+
include("layers/positional.jl")
86+
include("layers/graph_conv.jl")
87+
include("layers/group_conv.jl")
7588
include("layers/pool.jl")
7689
include("models.jl")
7790

src/layers/gn.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ aggregate_vertices(::GraphNet, aggr, V) = aggregate(aggr, V)
165165
@inline aggregate_vertices(::GraphNet, ::Nothing, V) = nothing
166166

167167
function propagate(gn::GraphNet, sg::SparseGraph, E, V, u, naggr, eaggr, vaggr)
168-
el = to_namedtuple(sg)
168+
el = GraphSignals.to_namedtuple(sg)
169169
return propagate(gn, el, E, V, u, naggr, eaggr, vaggr)
170170
end
171171

@@ -179,14 +179,11 @@ function propagate(gn::GraphNet, el::NamedTuple, E, V, u, naggr, eaggr, vaggr)
179179
return E, V, u
180180
end
181181

182-
WithGraph(fg::AbstractFeaturedGraph, gn::GraphNet) = WithGraph(to_namedtuple(fg), gn)
183-
WithGraph(gn::GraphNet; dynamic=nothing) = WithGraph(DynamicGraph(dynamic), gn)
182+
WithGraph(fg::AbstractFeaturedGraph, gn::GraphNet) =
183+
WithGraph(GraphSignals.to_namedtuple(fg), gn, positional_feature(fg))
184184

185-
to_namedtuple(fg::AbstractFeaturedGraph) = to_namedtuple(graph(fg))
185+
WithGraph(gn::GraphNet; dynamic=nothing) =
186+
WithGraph(DynamicGraph(dynamic), gn, GraphSignals.NullDomain())
186187

187-
function to_namedtuple(sg::SparseGraph)
188-
es, nbrs, xs = collect(edges(sg))
189-
return (N=nv(sg), E=ne(sg), es=es, nbrs=nbrs, xs=xs)
190-
end
191-
192-
@non_differentiable to_namedtuple(x...)
188+
WithGraph(fg::AbstractFeaturedGraph, gn::GraphNet, pos::GraphSignals.AbstractGraphDomain) =
189+
WithGraph(GraphSignals.to_namedtuple(fg), gn, pos)

0 commit comments

Comments
 (0)