Discovering Symmetry Invariants and Conserved Quantities by Interpreting Siamese Neural Networks

In this paper, we introduce interpretable Siamese Neural Networks (SNN) for similarity detection to the field of theoretical physics. More precisely, we apply SNNs to events in special relativity, the transformation of electromagnetic fields, and the motion of particles in a central potential. In these examples, the SNNs learn to identify datapoints belonging to the same events, field configurations, or trajectory of motion. It turns out that in the process of learning which datapoints belong to the same event or field configuration, these SNNs also learn the relevant symmetry invariants and conserved quantities. These SNNs are highly interpretable, which enables us to reveal the symmetry invariants and conserved quantities without prior knowledge.

Even though ML in theoretical physics is a young discipline, it has so far been successful in reproducing results in many complicated systems in just a few years.The success comes at the cost of a lack of understanding of what ML algorithms intrinsically learn.Physics, as a scientific discipline, benefits from a "deeper understanding" of the underlying models used for making predictions.
The question of whether ML models can "understand" physics is a deeply philosophical one, and we don't pretend to address it in all its complexity.Assuming that an ML algorithm is successfully trained to predict the outcome of a physical experiment or calculation, it is not always clear whether the algorithm has deduced physical concepts or has merely managed to perform some basic pattern matching.However, if the ML model is "interpretable" in the sense that we can recover a compact and simple mathematical representation of a physical law by analyzing the said model, then we take the position that such a model has indeed learned to "understand" the underlying physics.
The most successful ML algorithms are artificial neural networks (ANNs), which are famously inscrutable.Having said that, there have been many recent attempts at interpreting the learned features of a fully trained ANN.The simplest way to interpret a neural network is to examine the weights and biases of individual neurons, which can only yield successful results in shallow ANN.In the field of explainable AI (xAI), there are different methods that determine which features of the given input were responsible for the learned model's classification [26,27].Similarly, in the field of computer vision, there have been many developments to examine the contribution of the pixels in an image to the ANN prediction [28][29][30][31][32].One of the most popular methods is feature visualization by enhancing learned patterns on input images [33].
In physics, we have a distinct advantage when it comes to interpreting ANNs.In the field of computer vision or natural language processing, it is very hard to come up with mathematical equations uniquely describing the "ground truth".By contrast, many physicists have worked for hundreds of years to formulate their theories and experimental measurements in terms of mathematical equations.This means that if we can recover such an equation by analyzing an ANN, we have an immediate access to its interpretation.This also opens up the possibility to check for consistency and reveal new concepts.A few recent works have presented a successful interpretation of ANNs in physics [21,[34][35][36].
In this article, we propose a change in traditional SNN architectures that makes them easier to interpret.Specifically, the key feature is a bottleneck layer, where the SNN is forced to compress all available information from previous layers.The output of this bottleneck can be analyzed, for example, by applying known regression methods.A similar approach has been taken in [21].While there does not exist a related interpretation procedure in computer vision, the idea of interpreting bottleneck layers is also seen in disentangling autoencoders [37].
The ANNs we are considering in this work are a variant of the previously proposed Siamese Neural Networks (SNNs), a class of ANNs that have been applied to object tracking, face recognition, and image similarity detection [38][39][40][41].An SNN consists of two (identical) ANNs that are applied to a pair of input data points.The two networks share their weights and biases, which are updated simultaneously while training.The goal of the network is to map the input pairs to a set of latent variables that determine the similarity of the pair.
The general problem an SNN attempts to solve can be stated as follows: given two data points x and y related by an equivalence relation (e.g., the same event in a relativistic setting measured by two observers in different reference frames), is it possible to correctly and automatically classify them as "related"?Further, if x and y are not related, then we require the ANN to classify them as not related.
SNNs can solve an extension of a classification problem with relatively little training data per class.Instead of training a traditional neural network to distinguish between a fixed number of classes, an SNN can probe the similarity of one datapoint with another prototypical datapoint for a certain class.This reformulation bears many advantages.First, the number of classes does not need to be fixed.Further, it is no longer necessary to train on all of the classes.A successfully trained SNN might be able to share its learned representation to distinguish between classes that are not in the training set.These properties become important in the limits of many (possibly infinitely many) classes or in the case where only a few data points are available in each class.

Contributions
The contributions we make in this paper are: 1. We introduce the SNN to the field of theoretical physics.
2. We demonstrate its usage in the well known contexts of special relativity, electromagnetism, and the motion of particles in a central potential.In the case of special relativity, these SNNs learn whether or not two different observations of physical phenomena correspond to the same event.In the case of electromagnetism, these SNNs learn whether or not given two field configurations, one can be transformed into the other via a Lorentz transformation.
In the case of motion of particles, these SNNs discover whether or not two observations of position and momenta describe the same particle.
3. Further, we successfully interpret the intermediate output representations of the SNN and recover the mathematical formulations of known physical conserved quantities and invariants, e.g., the spacetime interval or the angular momentum.
4. Since the interpretation of the SNN yields signatures of known physical equations, we can argue that our SNN has indeed learned to "understand" physical concepts instead of merely performing basic pattern matching.

II. NEURAL NETWORK ARCHITECTURE
In this work, we employ Siamese neural networks (SNN) to determine whether or not two samples belong to the same class.In this context, our input data is a pair of samples X i = (x i , x ′ i ).In order to formulate a supervised learning problem, we associate the label y i = 0 to pairs that correspond to the same class (i.e., x i and x ′ i are related via an equivalence relation) and y i = 1 to pairs that belong to different classes (i.e., the input pairs are not related).In this sense, we can reformulate a classification problem with many, possibly infinitely many classes, into a traditional binary classification problem.

Loss
For this purpose, we construct the SNN consisting of several building blocks.The first building block is composed of a pair of identical neural networks.This pair of networks is applied simultaneously to each of the samples in a data point pair x i and x ′ i .The last layer of the network pair only contains a single neuron, this layer we refer to as the bottleneck.The output of the bottleneck layer is the intermediate output of the SNN.The intermediate output is merged by performing appropriate algebraic operations.Let us denote f (x i ) and f (x ′ i ) the output of each of the neural networks.Then the algebra layer calculates (f (x i ) − f (x ′ i )) 2 before supplying it to a sigmoid neuron such that the output of the full SNN can be written as The SNN outputs a probability whether the two samples belong to the same class or not.
For the purpose of training, we minimize the binary cross-entropy loss function between the SNN F (X i ) and the label y i on the training set, while the generalization performance is eventually measured on the test set.While training the SNN, we enforce weight sharing in the network pair to make sure these networks learn the same function.
After having successfully trained the SNN, our goal is to answer the question on which features this neural network bases its decision.In general, there is no easy answer to this question, since analyzing even small neural networks can become prohibitive.So far, there does not exist a comprehensive theory of what is learned by artificial neural networks.
One of our crucial insights is that in order to interpret what our SNN learns, we have designed the SNN to include a bottleneck at the output of the first building block before merging (see Fig. 1).We see later that our SNN learns conserved quantities and invariants at the bottleneck to make its decision if two samples belong to the same class.Further, by interpreting the network, we can predict conserved quantities and invariants without prior knowledge.
We note that, in the context of our physical examples, a natural minimization of the binary cross-entropy loss function is achieved if f (x i ) learns a symmetry invariant or a conserved quantity.If the number of neurons in the bottleneck layer increases, one can achieve better accuracy at the cost of interpretability.The interpretability can, in principle, be retained if one enforces decorrelated intermediate outputs.
More details about our neural network architecture and the learning procedure can be found in Appendix B.

Introduction
The first physical system we consider in this work is the Minkowski spacetime in special relativity.An event is a four vector (t, x, y, z) ∈ R 4 that combines spatial coordinates and a moment in time.Minkowki spacetime is R 4 with a scalar product induced by the metric where we have used x µ = η µν x ν .Thereby we define the spacetime interval s by The Lorentz Group is the set of transformations which preserve the scalar product on Minkowksi spacetime and thus also preserve the spacetime interval.

SNN Training
In this section, we discuss how to teach the neural network to identify if two observations in special relativity by different observers correspond to the same event.These observers are at the same position but move with a relative velocity in some direction.For this purpose, we prepare positive training data of pairs of observations that correspond to the same event and negative data where a pair of measurements does not describe the same event.
More specifically, in order to train our neural networks with data we prepare a training dataset consisting of pairs of measurements of the same event in Minkowski spacetime seen from two different observers , where Λ is a random Lorentz transformation which is sampled from all possible Lorentz transformations, more details can be found in Appendix A. We sample 50000 spacetime events x µ and Lorentz transformations Λ to create pairs of events that form the positive dataset.We associate with each pair the label y = 0. Further, we create a negative dataset where each pair of spacetime coordinates is not related by a Lorentz transformation.In practice, we implement this by randomly permuting among all second elements of all pairs of spacetime events in the positive dataset.Each pair in the negative dataset is labeled with y = 1.In addition to this training set, we prepare a similar test dataset of 5000 positive pairs and 5000 negative pairs.
The SNN is trained to predict if a pair of observations describe the same event or not correctly.This is done by optimizing the weights of the neural network via backpropagation to minimize the binary cross-entropy loss between network output y p and true label y t .After  We perform ridge regression with polynomial features of the input on the intermediate output of the SNN.We start with polynomials of degree 1 and increase the degree of the polynomial features until the polynomial regression becomes accurate.From Table I one can immediately infer that the optimal degree of the polynomial features is 2.
The result of the regression is in an ordered manner is f (x) ≈ − 87.41t We can see that four nontrivial features dominate all others.If we assume that the regression includes small approximation errors, we can infer that the SNN has learned the invariant quantity s 2 = −t 2 + x 2 + y 2 + z 2 .This quantity is the spacetime interval, a known invariant of the Lorentz group.In cases where the regression does not yield a clear result, one can cross-check the secondorder regression result with higher orders of regression, and observe if the dominant features stay the same.Another option is to do the whole training procedure with a different random seed and see what parts of the results keep the same ratio.
To summarize, as long as the ANN is only able to use one single scalar function to decide if two events are the same, it calculates the spacetime interval.If the spacetime interval is the same, the ANN predicts that both coordinates in a pair belong to the same event.While it is often difficult to decide if neural networks learn to "understand" physical concepts to make decisions, here we argue that our SNN does so.To confirm our derivation, we draw a scatter plot for a subset of our data points of the intermediate output versus the spacetime interval in Fig. 2 and observe a nearly perfect non-linear correlation between these two.Note that we have cross-checked the second-order regression result with higher orders of regression where the dominant features stay the same.
In the following, we examine if the SNN can also learn a different quantity to decide whether two observations from different observers belong to the same event.For this purpose, we again prepare a training and a test dataset, as explained before.However, in the preparation of the dataset, we keep the spacetime interval fixed.We try to train the SNN to learn to associate corresponding observations.However, we failed to train the ANN in this case.After the best training cycle, the ANN could only predict if two observations belong to the same event with an accuracy of 58% on the training set or 57% on the testing set, which is barely better than random.This fact leads to the conclusion that the SNN cannot find another invariant of the Lorentz group besides the spacetime interval.

Introduction
As a second system we consider the motion of a particle in a central potential similar to the movement of a planet in the gravitational potential of the sun.We constrain the motion to a two-dimensional plane.Newtonian gravity can be formulated via the Hamiltonian Here p is the momentum, r = (x 2 + y 2 ) is the distance from the potential centre, m is the mass of the planet, M is the mass of the sun, and G is Newton's constant of gravitation.Given an initial position x and velocity v one can calculate the trajectory of motion by solving Hamilton's equations There are conserved quantities in this system, the energy E the components of the angular momentum L and the components of the Laplace-Runge-Lenz vector A. They are related by two equations which effectively reduces the number of scalar conserved quantities to five.When examining the motion of particles in a central potential, the SNN is tasked with figuring out if two observations of the same particle correspond to the same particle trajectory.We simulate particles of fixed mass m moving in a Newtonian static gravitational potential produced by a stationary mass M by solving the Hamiltons equations for a set of random initial positions and velocities.For simplicity we set m = 1 and GmM = 1.We measure the position and the velocity of the particle at two different times to get pairs of inputs X = (x, x ′ ) = ((x, y, v x , v y ), (x ′ , y ′ , v ′ x , v ′ y )).We generate 50000 pairs  belonging to the same particle trajectories to form the positive training dataset labelled by y i = 0.By permuting the second entry in the pairs, we create a negative dataset labeled with y i = 1.Similarly, a testing set is produced with 5000 positive and 5000 negative examples.
The SNN is then trained to correctly predict if a pair of coordinates belong to the same trajectory.After being successfully trained, the network achieves an accuracy of ≈ 98% on the training set and ≈ 97% on the test set.
In order to interpret on what quantity the neural network bases its decision we again examine the bottleneck at the intermediate output.We again perform a hierarchy of linear regressions with increasing polynomial features on the intermediate output.The optimal degree of the regression is two, see Table II.
The result of the regression is in an ordered manner is This quantity is an approximation to the angular momentum L x = m(x v y − y v x ).A confirmation of this result is visualized in the very good correlation between the angular momentum and the intermediate output Fig. 3  (a).This means the SNN learns to distinguish between pairs originating from the same trajectory and different trajectories by calculating the angular momentum.Another conserved quantity in this system is the energy.In Fig. 3 (b), we see that the intermediate prediction is not correlated with the energy.
We now fix the angular momentum and perform the simulation again to produce 50000 positive and 50000 negative data pairs.We train the SNN again to distinguish if a pair of observations belong to the same trajectory.Even though the neural network cannot use the angular momentum to determine if the pair corresponds to the same trajectory, it still manages to perform well on this task.The SNN achieves an accuracy of ≈ 99% on both the training and the test set.
We now interpret what the SNN has learned in order to make its prediction and find that the regression is unsuccessful in revealing a suitable expression for the feature that was learned by the SNN.On the one hand, there is no clear optimal degree of the polynomial regression, see Table III.On the other hand, all the regression results do not yield a clear dominant feature.If we compare the intermediate output to the remaining invariants in the system, we find that the square of the intermediate output is strongly correlated with the energy of the system, see Fig. 4.This means that the SNN probes the pair of observations for energy conservation.However, the energy cannot be well approximated by a polynomial function with which we perform our regression.This is probably the main why the regression cannot reveal the energy in this case.In future studies, this caveat could be resolved by employing symbolic regression.One might ask whether the SNN is able to find the Laplace-Runge-Lenz vector, which remains open for further investigation.

Introduction
Finally, we consider electric E and magnetic fields this purpose we incorporate the fields in the electromagnetic field strength tensor The Lorentz transformation of the field strength tensor defines the transformations for the electric and magnetic fields.The known Lorentz invariants of the electromagnetic fields are the determinant of the field strength tensor

SNN Training
In this section, we study the behaviour of electromagnetic fields under Lorentz transformations with SNNs.For this purpose, we again produce 200000 true pairs ) of electric and magnetic field configurations which are connected by a Lorentz transformation, and 200000 negative pairs of fields by permuting the positive pairs.
We again train the SNN to predict if the two measurements belong to the same field configuration.After having successfully trained the neural network, we find that the neural network can fulfill the task to the high accuracy of ≈ 95% on the training set and ≈ 94% on the test set.
In order to find out what the neural network has learned, we perform polynomial regression on the intermediate output of the neural network.The function which approximates the output best is of degree two, see This function is an approximation to a known invariant, the determinant of the field strength tensor B ⋅ E = det F .A confirmation of this deduction is the correlation between det F and the intermediate output as depicted in Fig. 5.
Let us perform the same experiment again, this time we fix the determinant of the field strength tensor, when sampling the pairs of electromagnetic field configurations.The neural network still trains successfully and performs well in identifying between pairs of data belonging to the same fields with an accuracy of ≈ 93% on the training set an ≈ 92% on the test set.Performing the bottleneck regression on the intermediate output of the neural network reveals the remaining invariant to be of degree two, see This function is another known invariant of the field strength tensor B 2 − E 2 = 1 2F µν F µν , confirmed in Fig. 6 .To summarize, in the context of electromagnetism, we have revealed the two invariants of the electric and magnetic fields which are preserved under Lorentz transformations.

IV. CONCLUSIONS AND FUTURE DIRECTIONS
We have introduced siamese neural networks (SNNs) to the field of theoretical physics.They are successful in predicting whether two data instances are connected by a deterministic transformation.We examined spacetime events and electromagnetic fields which transform under Lorentz transformations, as well as the movement of particles in a central potential.By interpreting our neural network, we find that it learns the underlying symmetry invariants and conserved quantities to perform its prediction.Most interestingly, we were able to interpret our SNNs via the use of polynomial regression.This procedure revealed an excellent approximation of the underlying symmetry invariants and conserved quantities.These invariants range from the spacetime interval over angular momentum conservation to the determinant of the field strength tensor.If the underlying system does not contain human readable invariants, the neural network could act as an approximation to such an invariant.
Future directions of this work include an upgrade of the polynomial regression to symbolic regression [42].Another exciting direction is to combine interpretable SNNs with semi-automated mathematical reasoning tools, e.g., solvers or theorem provers.The idea is to check the physical law learned by the SNN for consistency against known laws and invariants by leveraging such reasoning tools [43].It does not take much imagination to envision how this technology can be used in quantum error correction or in particle tracking at the LHC.
It remains to be seen if SNNs will ever find an invariant or conserved quantity unknown to modern physics.Even if this does not happen, the contribution of this work is the introduction of SNNs as a useful tool in theoretical physics.Furthermore, we challenged the black box nature of artificial neural networks by a very clear interpretation that reveals polynomial quantities without prior knowledge.The interpretation procedure might also be adopted into the field of computer science, where the interpretability of neural networks poses a major problem.where y t denotes the true label, while y p is the neural network prediction.Our neural networks are trained using the Adadelta optimizer.We found that starting learning rates of lr = 100 are needed to train the neural network, this learning rate is a lot higher than normally used in traditional classification problems.Each update is performed by calculating the gradient on a batch of size 256.We employ learning rate decay callbacks which reduce the learning rate by a factor of 2 if the training loss has not improved for 50 epochs.We train our networks for 10000 epochs however, we employ an early stopping callback which aborts the training process if the training loss has not improved over 200 epochs.We do not use any kind of regularization in our neural networks.The evolution of the losses and accuracies during training are depicted in Fig. 8

Figure 2 :
Figure 2: Special Relativity: Correlation between the intermediate output of the siamese neural network at the bottleneck layer an the spacetime interval.

Figure 3 :
Figure 3: Particle in central potential: correlation between the intermediate output and (a) the angular momentum or (b) the energy.

Figure 4 :
Figure 4: Particle in central potential with fixed angular momentum: correlation between the intermediate output and the energy.
Regression scores of the Regression on the intermediate output in the case of the motion of a particle in a central potential.

Figure 5 :
Figure 5: Electromagnetism: Correlation between the intermediate output and (a) the determinant of the field strength tensor or (a) a specific contraction of two field strength tensors.

Figure 7 :
Figure 7: Detailed architecture of an interpretable siamese neural network.

Table I :
having trained the neural network, it is able to correctly predict Regression scores of the regression on the intermediate output in the case of special relativity, measures normalized distance between regression and data.The score metric is known as the coefficient of determination or R 2 score.Best possible score is 1, higher is better.ifapair of observations belong to the same event with an accuracy of ≈ 94% on the training dataset and ≈ 92% on the test dataset.The training and testing accuracies during training can be seen in Fig.8.Following the successful training of our SNN, we want to understand what the neural network has learned.This can be achieved by examining the intermediate output of the neural network, which acts as an interpretable bottleneck.We perform a hierarchy of linear regressions with polynomial features (aka polynomial regression) on the intermediate output with respect to the input.If we assume the Taylor expansion of the decision function to be sufficiently accurate at the decision boundary, we can hope to get insightful results.

Table III :
Regression scores of the Regression on the intermediate output in the case of the motion of a particle in a central potential with fixed angular momentum.
Table IV and given by

Table IV :
Regression scores of the Regression on the intermediate output in the case of Electromagnetism.

Table V :
Regression scores of the Regression on the intermediate output in the case of Electromagnetism with fixed determinant of the field strength tensor.