# 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>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://philipp-gadow.gitbook.io/bsm4tops-gnn/concepts/graph-neural-networks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
