# Graph neural networks

A recent development in the field of machine learning are graph neural networks. Their unique feature is that they process data provided in the form of graphs.

Particularly high energy physics with the well-structured anatomy of collision events provides a fruitful playground to apply graph neural networks (GNN).

A gentle introduction is provided here:

{% embed url="https://towardsdatascience.com/a-gentle-introduction-to-graph-neural-network-basics-deepwalk-and-graphsage-db5d540d50b3" %}

A very nice overview showcasing  possible applications of GNNs in particle physics is provided in the review by Shlomi et al.:

{% embed url="https://arxiv.org/abs/2007.13681" %}

**Graphs**

A graph is a pair of nodes and edges. The nodes have no particular order and are consequently invariant under permutations. Edges denote connections between two nodes. A node does not necessarily have to be connected with all other nodes.

Graphs can be directed or undirected. If they are directed, then each edge has a certain direction. An example of directed graphs are Feynman diagrams. Here, the edges denote the type of particle, while the direction denotes particles and/or antiparticles. The nodes denote vertices. As the vertices are associated with the coupling strength of the interaction, we encounter an additional property of graphs: graphs can be either weighted or unweighted. Feynman graphs are weighted, as the nodes carry further information (to wit, the coupling strength).

&#x20;Mathematically, graphs can be represented using an [_adjacancy matrix_](https://en.wikipedia.org/wiki/Adjacency_matrix). It describes the relationship of _n_ nodes and is a _n_ x _n_ matrix. The entry in row _i_ and column _j_ denotes the weight of the edge connecting the _i_-th node and the _j_-th node. Consequently, undirected graphs have symmetric adjacency matrices. All operations on graphs can be described via operations on the adjacency matrix. The adjacency matrix can be used to store features associated with the edges which can be used in training graph neural networks.

Another matrix describing graphs is the [_degree matrix_](https://en.wikipedia.org/wiki/Degree_matrix). It describes how many connections each nodes has (the "degree" of a node).

Finally, also the nodes can store features which can be used in training graph neural networks.

**Graph neural networks**

A graph neural network (GNN) is a special kind of neural network which directly operates on the graph structure. A typical application of GNNs is node classification. Every node in the graph is associated with a label (resonance or no resonance), and we want to predict the label of the nodes without ground-truth.

We will be working with pyTorch and the pyTorch-Geometric libraries.

{% embed url="https://github.com/rusty1s/pytorch_geometric" %}

{% embed url="https://pytorch-geometric.readthedocs.io/en/latest/index.html" %}

**Tutorials**

Tutorial 1: essentials about graph neural networks (run tutorial in browser)

{% embed url="https://colab.research.google.com/drive/1h3-vJGRVloF5zStxL5I0rSy4ZUPNsjy8?usp=sharing" %}

Tutorial 2: node classification with neural networks (run tutorial in browser)

{% embed url="https://colab.research.google.com/drive/14OvFnAXggxB8vM4e8vSURUp1TaKnovzX?usp=sharing" %}

