Tropical neural networks and its applications to classifying
  phylogenetic trees
Deep neural networks show great success when input vectors are in an
Euclidean space. However, those classical neural networks show a poor
performance when inputs are phylogenetic trees, which can be written as vectors
in the tropical projective torus. Here we propose tropical embedding to
transform a vector in the tropical projective torus to a vector in the
Euclidean space via the tropical metric. We introduce a tropical neural network
where the first layer is a tropical embedding layer and the following layers
are the same as the classical ones. We prove that this neural network with the
tropical metric is a universal approximator and we derive a backpropagation
rule for deep neural networks. Then we provide TensorFlow 2 codes for
implementing a tropical neural network in the same fashion as the classical
one, where the weights initialization problem is considered according to the
extreme value statistics. We apply our method to empirical data including
sequences of hemagglutinin for influenza virus from New York. Finally we show
that a tropical neural network can be interpreted as a generalization of a
tropical logistic regression.
Ruriko Yoshida, Georgios Aliatimis, Keiji Miura
# Tropical neural networks and its applications to classifying phylogenetic trees

###### Abstract

Deep neural networks show great success when input vectors are in an Euclidean space. However, those classical neural networks show a poor performance when inputs are phylogenetic trees, which can be written as vectors in the tropical projective torus. Here we propose tropical embedding to transform a vector in the tropical projective torus to a vector in the Euclidean space via the tropical metric. We introduce a tropical neural network where the first layer is a tropical embedding layer and the following layers are the same as the classical ones. We prove that this neural network with the tropical metric is a universal approximator and we derive a backpropagation rule for deep neural networks. Then we provide TensorFlow 2 codes for implementing a tropical neural network in the same fashion as the classical one, where the weights initialization problem is considered according to the extreme value statistics. We apply our method to empirical data including sequences of hemagglutinin for influenza virus from New York. Finally we show that a tropical neural network can be interpreted as a generalization of a tropical logistic regression.

## 1 Introduction

A neural network is a learning method, called deep learning, to learn data in a way to mimic a brain system, i.e., which interconnects nodes, called neurons, in a layered structure like a human brain system [13, 8, 15]. Recent years deep neural networks show great success to process input data which lay in the Euclidean space [11]. However, when input data are phylogenetic trees or the time series with trends, represented as vectors in the _tropical projective torus_[26, 27, 23, 38, 39, 40, 29, 42, 35], classical neural networks show a poor performance. Therefore in this paper, we propose neural networks which process an input data as vectors over the tropical projective torus. The tropical projective torus denoted by \(\mathbb{R}^{d}/\mathbb{R}\mathbf{1}\) is the \(d\)-dimensional real numbers, \(\mathbb{R}^{d}\), mod by the vector with all ones, i.e., \(\mathbf{1}:=(1,1,\ldots,1)\in\mathbb{R}^{d}\). Over the tropical projective torus denoted by \(\mathbb{R}^{d}/\mathbb{R}\mathbf{1}\), we define \(x:=(x_{1},x_{2},\ldots,x_{d})=(x_{1}+c,x_{2}+c,\ldots,x_{d}+c)\in\mathbb{R}^{d} /\mathbb{R}\mathbf{1}\) where \(c\in\mathbb{R}\)[20]. Here we consider the _tropical metric_, also known as
the _generalized Hilbert projective metric_, over the tropical projective torus as activation functions in a hidden layer of a neural network. It is important to keep the invariance of the input vector under the one-vector which is innate in the tropical projective torus [20, 17, 33, 18, 41, 30]. Our strategy is to embed an input vector in the tropical projective torus into a vector in the classical Euclidean space in the first layer. This is analogous to the word embedding in the field of natural language processing [37, 28]. Then the following layers can be the same as the classical ones.

Although some previous works analyzed ReLU neural networks by using the tropical geometry, the neural networks themselves are defined on a classical Euclidean space [43, 1, 24]. In this paper, on the other hand, we consider a tropical projective torus as an input space and keep the invariance under the one-vector. That is, our work is truly tropical.

In this paper, we first introduce a tropical embedding layer. We use the tropical embedding layer as the first layer of the classical neural networks to keep the invariance in the tropical projective space. To check if this tropical neural network has enough flexibility, we next prove that this tropical neural network is a universal approximator. Then we derive a backpropagation rule for the tropical neural networks. We provide TensorFlow 2 codes for implementing a tropical neural network in the same fashion as the classical one, where the weights initialization problem is considered according to the extreme value statistics. We show its applications to phylogenomics, a new field in evolutionary biology which applies tools from phylogenetic trees to genome data. Applications includes simulated data under the multi-species coalescent model which is the most popular model to analyze gene tree analysis on a genome data [21], and empirical data of influenza virus data set collected from the state of New York [27]. Finally we briefly show that a tropical neural network can be interpreted as a generalization of a tropical logistic regression.

## 2 Tropical Embedding for Tropical Neural Networks

The classical neural networks only accept a input vector in an Euclidean space in its original form. Thus they cannot accept a phylogenetic tree as an input since a space of phylogenetic trees is not Euclidean [33, 3, 6], for example. Therefore, we first consider a tropical embedding layer, which is analogous to the word embedding in natural language processing [37, 28]. Once a phylogenetic tree is embedded in an Euclidean space, a classical neural network can is applied to analyzing it.

**Definition 1** (tropical neural networks).: _A tropical neural network is a network where a tropical embedding layer as the first hidden layer is followed by a classical neural network (classical layers)._

**Definition 2** (tropical embedding layer).: _Let \(x\) in \(\mathbb{R}^{d}/\mathbb{R}\mathbf{1}\) be an input vector to the tropical embedding layer. the activity of \(j\)-th neuron as an output of the
tropical embedding layer is given by_

\[z_{j}=\max_{i}(x_{i}+w^{(1)}_{ji})-\min_{i}(x_{i}+w^{(1)}_{ji}). \tag{1}\]

**Remark 3**.: _Note that no activation function is executed for \(z\) as "max - min" operation is somehow regarded as the activation function of the neurons in the first hidden layer._

**Remark 4**.: _There is a geometric interpretation: "max - min" operation measures the distance between the points \(x\) and \(w^{(1)}_{j}\). Therefore \(z(x)\) is invariant along one vectors \(\mathbf{1}\)._

**Remark 5**.: _There are alternative ways to attain the invariance such as_

\[z_{j}=\max_{i}(x_{i}+w^{(1)}_{ji})-2\text{nd}\max_{i}(x_{i}+w^{(1)}_{ji}). \tag{2}\]

_There is a geometric interpretation: "max - 2nd max" operation measures the distance between a point \(x\) and the tropical hyperplane whose normal vector is \(w^{(1)}\)[17]. Therefore \(z(x)\) is invariant along one vectors \(\mathbf{1}\). You could even use \(j\)-th max in general. However, the repertoire of functions never increase by using alternative ones. That is, from the view point of universal approximation theorem, using Eq. (1) suffices. In addition, Eq. (1) seems to perform better than the alternative ones according to our numerical experiments (not shown). Therefore we solely use Eq. (1) as a tropical embedding layer in what follows._

**Remark 6**.: _Suppose \(A\in\mathbb{Z}_{+}^{N\times d}\). Then we consider the ReLU such that_

\[\max\{Ax+b,0\}.\]

_Assume that \(A\mathbf{1}\neq 0\). Suppose \(x\in\mathbb{R}^{d}/\mathbb{R}\mathbf{1}\). Then we have \(x:=x+c\cdot(1,\ldots,1)=x+c\cdot\mathbf{1}\in\mathbb{R}^{d}/\mathbb{R}\mathbf{1}\). Then for \(c\ll 0\) and fixed \(x\), we have:_

\[\max\{Ax+cA\mathbf{1}+b,0\} = 0.\]

_As \(c\to-\infty\), we have_

\[\frac{1}{1+\exp(-\max\{Ax+cA\mathbf{1}+b,0\})}\to\frac{1}{1+1}=1/2\]

_for any \(x\in\mathbb{R}^{d}/\mathbb{R}\mathbf{1}\). Also for \(c\gg 0\) and fixed \(x\), we have:_

\[\max\{Ax+cA\mathbf{1}+b,0\} = Ax+cA\mathbf{1}+b.\]

_As \(c\to\infty\), we have_

\[\frac{1}{1+\exp(-(Ax+cA\mathbf{1}+b))}\to 1\]

_for any \(x\in\mathbb{R}^{d}/\mathbb{R}\mathbf{1}\). Therefore, neural networks with the ReLU cannot learn from observation in these cases. However, with the activator function defined in Eq. (1), we have_

\[\max_{i}(x_{i}+c\cdot\mathbf{1}+w^{(1)}_{ji})-\min_{i}(x_{i}+c\cdot\mathbf{1}+ w^{(1)}_{ji})=\max_{i}(x_{i}+w^{(1)}_{ji})-\min_{i}(x_{i}+w^{(1)}_{ji}).\]
**Remark 7**.: _Classical neural networks are not well-defined in the tropical projective torus, since the neuron values are not invariant under transformations of the form \(x\to x+(c,\ldots,c)\). Meanwhile, the tropical embedding layer of Eq. (1) is invariant under such transformations._

## 3 Universal Approximation Theorems for Tropical Neural Networks

It is very important to check if the tropical embedding layer as in Eq. (1) followed by classical layers has enough varieties to represent considerable input-output relations [8]. In this section, we show that the tropical neural network can approximate enough variety of functions so that we can safely use it.

**Definition 8**.: _The norm \(\|\cdot\|_{q}\) for \(q\geq 1\) is defined by_

\[\|f(x)\|_{q}=\int_{\mathbb{R}^{n}}|f(x)|^{q}dx \tag{3}\]

_The space \(L^{q}(\mathbb{R}^{d}),(1<q<\infty),\) is the set of Lebesgue integrable functions \(f\) from \(\mathbb{R}^{d}\) to \(\mathbb{R}\) for which \(\|f(x)\|_{q}<\infty\)._

**Definition 9**.: _The space \(C^{0}(\mathbb{R}^{d})\) is the set of continuous, compactly suppported functions from \(\mathbb{R}^{d}\) to \(\mathbb{R}\)._

**Remark 10**.: _Note that \(C^{0}(\mathbb{R}^{d})\subset L^{q}(\mathbb{R}^{d})\)._

For the classical case, a universal approximation theorem for ReLU feedforward neural networks has been proved in [4].

**Theorem 11** (classical universal approximation theorem [4]).: _Any function of \(x_{j}\) for \(j=1,\ldots,d\) in \(L^{q}(\mathbb{R}^{d}),(1<q<\infty),\) can be arbitrarily well approximated in the \(\|\cdot\|_{q}\) by a ReLU feedforward neural network with at most \(L=2(\lfloor\log_{2}d\rfloor+2)\) layers._

As the \(d-1\) neurons in the tropical embedding layer can easily represent \((x_{j}-x_{d})\) for \(j=1,\ldots,d-1\) and Theorem 11 can be applied to the second and later layers of a tropical neural network (that is equivalent to a classical neural network), we can prove the following theorem.

**Theorem 12** (tropical universal approximation theorem).: _Any function of \((x_{j}-x_{d})\) for \(j=1,\ldots,d-1\) in \(L^{q}(\mathbb{R}^{d}/\mathbb{R}\mathbf{1})\simeq L^{q}(\mathbb{R}^{d-1}),(1<q <\infty),\) can be arbitrarily well approximated in the \(\|\cdot\|_{q}\) by a tropical neural network with at most \(L=2(\lfloor\log_{2}d\rfloor+2)+1\) layers (which include an tropical embedding layer as the first layer)._

Proof.: For any \(f\in L^{q}(\mathbb{R}^{d-1})\), \(\exists g\in C_{0}(\mathbb{R}^{d-1})\) such that \(\|f-g\|_{q}<\epsilon/2\)[8]. Let \(K\) be the support of \(g\) and let \(M\) be \(\max_{x\in K}\|x\|\). For \(x\in K\), we can set \(w^{(1)}_{jj}=-w^{(1)}_{jd}=2M\) and \(w^{(1)}_{ji}=0\) for \(i\neq j,d\) to obtain \(z_{j}=x_{j}-x_{d}+4M\)
for \(j=1,\ldots,d-1\). This means that a neuron in the first tropical embedding layer can represent \(x_{j}-x_{d}\). Then \(d-1\) neurons can represent \(z_{1}\), \(z_{2}\),..., \(z_{d-1}\). Finally, simply apply Theorem 11 to the classical neural network \(F(z_{1},\ldots,z_{d-1})\) consisting of the second and later layers of a tropical neural network to obtain \(\|g-F\|_{q}<\epsilon/2\). Taken together, \(\|f-F\|_{q}<\|f-g\|_{q}+\|g-F\|_{q}<\epsilon\). 

There is another type of classical universal approximation theorems.

**Definition 13**.: _The width \(d_{m}\) of a neural network is defined to be the maximal number of neurons in a layer._

**Theorem 14** (classical universal approximation theorem for width-bounded ReLU networks [19]).: _For any \(f\in L^{1}(\mathbb{R}^{d})\) and any \(\epsilon>0\), there exists a classical neural networks \(F(x)\) with ReLU activation functions with width \(d_{m}\leq d+4\) that satisfies_

\[\int_{\mathbb{R}^{d}}|f(x)-F(x)|dx<\epsilon. \tag{4}\]

Again, as the \(d-1\) neurons in the tropical embedding layer can easily represent \((x_{j}-x_{d})\) for \(j=1,\ldots,d-1\) and Theorem 14 can be applied to the second and later layers of a tropical neural network (that is equivalent to a classical neural network), we can prove the following theorem.

**Theorem 15** (tropical universal approximation theorem with bounded width).: _For any function \(f\) of \((x_{j}-x_{d})\) for \(j=1,\ldots,n-1\) in \(L^{1}(\mathbb{R}^{d}/\mathbb{R}\mathbf{1})\simeq L^{1}(\mathbb{R}^{d-1})\) and any \(\epsilon>0\), there exists a tropical neural networks \(F(x)\) with width \(d_{m}\leq d+4\) that satisfies_

\[\int_{\mathbb{R}^{d-1}}|f(x)-F(x)|dx<\epsilon. \tag{5}\]

Proof.: For any \(f\in L^{1}(\mathbb{R}^{d-1})\), \(\exists g\in C_{0}(\mathbb{R}^{d-1})\) such that \(\|f-g\|_{1}<\epsilon/2\)[8]. Let \(K\) be the support of \(g\) and let \(M\) be \(\max_{x\in K}\|x\|\). For \(x\in K\), we can set \(w^{(1)}_{jj}=-w^{(1)}_{jd}=2M\) and \(w^{(1)}_{ji}=0\) for \(i\neq j,d\) to obtain \(z_{j}=x_{j}-x_{d}+4M\) for \(j=1,\ldots,d-1\). This means that a neuron in the first tropical embedding layer can represent \(x_{j}-x_{d}\). Then \(d-1\) neurons can represent \(z_{1}\), \(z_{2}\),..., \(z_{d-1}\). Finally, simply apply Theorem 14 to the classical neural network \(F(z_{1},\ldots,z_{d-1})\) consisting of the second and later layers of a tropical neural network to obtain \(\|g-F\|_{q}<\epsilon/2\). Taken together, \(\|f-F\|_{q}<\|f-g\|_{q}+\|g-F\|_{q}<\epsilon\). 

## 4 Backpropagation Rule for Simplest Tropical Neural Networks

Here we demonstrate that the gradients of the loss function with respect to weights exist for tropical neural networks. The gradient is computable through the chain rule for differentials called backpropagation rule in the similar fashion to the classical case. The gradients obtained in this way can guarantee the successful update of the weights at each iteration of learning.
We consider a simplest three layer network whose weights in the first and the second layers are denoted as \(w^{(1)}\in\mathbb{R}^{d\times N}\) and \(w^{(2)}\in\mathbb{R}^{N\times 1}\). Suppose the activity in the first hidden layer is given by Eq. 1 and the output of the network is given as

\[y=\sum_{j}^{N}w_{j}^{(2)}z_{j}. \tag{6}\]

Note that although here we derive a backpropagation rule for this regression setting just for simplicity, the backpropagation rule can be derived in a similar manner for the classification setting with a sigmoid function, too.

Below is the summary of parameters of the neural network.

* \(w^{(1)}\), \(w^{(2)}\): weights in the first and second layers;
* \(z_{j}\): activation of \(j\)-th neuron in the hidden layer; and
* \(y\): activation of the output neuron.

**Theorem 16**.: _The partial derivatives of the cost function \(Q:=\frac{1}{2}(y-y^{\text{true}})^{2}\) with respect to weights for the above tropical neural network \(y=f(x)\) are given by_

\[\frac{\partial Q}{\partial w_{ji}^{(1)}}=(y-y^{\text{true}})w_{j}^{(2)}(\delta (i=i_{j}^{\text{max}})-\delta(i=i_{j}^{\text{min}})), \tag{7}\]

_where \(i_{j}^{\text{max}}\) (or \(i_{j}^{\text{min}}\)) is the index \(i\) for which \((x_{i}+w_{ji}^{(1)})\) takes the maximum (or

Figure 1: architecture of a simplest neural networks that accept a vector in \(\mathbb{R}^{d}/\mathbb{R}\mathbf{1}\)
minimum) and_

\[\frac{\partial Q}{\partial w_{j}^{(2)}}=(y-y^{true})z_{j}. \tag{8}\]

Proof.: Direct calculations. 

**Example 17**.: _As a simplest example of Eq. (7), let us consider the three dimensional input case \((d=3)\). Suppose the number of neurons in the middle layer is one and its activity is z, for simplicity. Assume \(x_{1}=1\), \(x_{2}=2\) and \(x_{3}=3\) and \(w_{1}^{(1)}=w_{2}^{(1)}=w_{3}^{(1)}=0\). Then \((x_{i}+w_{1}^{(1)})<(x_{i}+w_{2}^{(1)})<(x_{i}+w_{3}^{(1)})\) and \(i_{\text{max}}=3\) and \(i_{\text{min}}=1\). Therefore,_

\[\frac{\partial Q}{\partial w_{i}^{(1)}}=\left\{\begin{array}{ll}-(y-y^{true })w^{(2)}&(i=1)\\ 0&(i=2)\\ (y-y^{true})w^{(2)}&(i=3).\end{array}\right. \tag{9}\]

_In this case we have \(z=3-1=2\) If, furthermore, \(w^{(2)}=1\), then, \(y=w^{(2)}z=2\) and_

\[\frac{\partial Q}{\partial w_{i}^{(1)}}=\left\{\begin{array}{ll}-(2-y^{true }),&(i=1)\\ 0,&(i=2)\\ 2-y^{true}.&(i=3),\end{array}\right. \tag{10}\]

\(w_{i}^{(1)}\) _can be, for example, updated by the SGD rule: \(\Delta w_{i}^{(1)}=-\eta\frac{\partial Q}{\partial w_{i}^{(1)}}\), where \(\eta>0\) is a learning rate. Then, \(w_{3}^{(1)}\) increases (and \(w_{1}^{(1)}\) decreases) if \(2>y^{\text{true}}\)._

**Remark 18**.: _It is interesting that only two of \(w_{i}^{(1)}\) are modified while the others remains. Note that \(\Delta w^{(1)}\) is orthogonal to the one vector, \(\mathbf{1}:=(1,1,\ldots,1)\in\mathbb{R}^{d}\). It is interesting to elucidate how this learning rule works as a dynamical system._

## 5 TensorFlow2 Codes for Tropical Neural Networks

In order to boost computing with GPUs, we implement tropical neural networks in TensorFlow 2 [9]. As is the case for the classical neural networks, the auto-differential is the key for the GPU implementation of tropical neural networks. In order to guarantee fast auto-differentials, all the calculations must be implemented only with the math functions in TensorFlow2 such as top_k(\(v\),\(d\)), which returns the maximum and the minimum of a vector \(v\).

In practice, it is essential to create a user-friendly class for the tropical embedding as the first layer of the tropical neural networks, that is scalable for big data. The following code defines a hand-made class called TropEmbed(), which enables us to easily implement the tropical neural networks in the Keras/Tensorflow style.
class TropEmbed(Layer):  def__init__(self,units=2,input_dim=3):  super(TropEmbed,self).__init__()  self.w = self.add_weight(shape=(units,input_dim), \  initializer="random_normal")  self.units = units  self.input_dim = input_dim

 def call(self, x):  x_reshaped = tf.reshape(x,[-1, 1, self.input_dim])  Bcast = repeat_elements(x_reshaped, self.units, 1)  val, i = tf.math.top_k(Bcast + self.w, self.input_dim)  returnval[:,:,0] - val[:,:,-1]

# usage model = Sequential([TropEmbed(10, d), Dense(1)])

The codes for TropEmbed() class and for reproducing all the figures in this paper are available at [https://github.com/keiji-miura/TropicalNN](https://github.com/keiji-miura/TropicalNN).

## 6 Weight Initialization Based on Extreme Value Statistics

Weight initializations are important for avoiding the divergence and vanishment of neural activities after propagating many layers. For the classical neural networks, Xavier's and He's initializations are famous [12, 16]. Here we consider a tropical analogue.

**Definition 19** (Generalized Hilbert Projective Metric).: _For any points \(v:=(v_{1},\ldots,v_{d}),\,w:=(w_{1},\ldots,w_{d})\in\mathbb{R}^{d}/\mathbb{R} \mathbf{1}\), the tropical distance (also known as tropical metric) \(d_{\mathrm{tr}}\) between \(v\) and \(w\) is defined as:_

\[d_{\mathrm{tr}}(v,w):=\max_{i\in\{1,\ldots,d\}}\bigl{\{}v_{i}-w_{i}\bigr{\}}- \min_{i\in\{1,\ldots,d\}}\bigl{\{}v_{i}-w_{i}\bigr{\}}.\]

**Lemma 20**.: _Suppose \(x_{i},w_{i}\sim N(0,1)\) for \(i=1,\ldots,d\). Then the expectation and variance of \(d_{\mathrm{tr}}(x,-w)\) can be approximated by \(2\sqrt{2}(a_{d}\gamma+b_{d})\) and \(\frac{\pi^{2}}{3\log d}\), respectively, where \(a_{d}=\frac{1}{\sqrt{2\log d}}\) and \(b_{d}=\sqrt{2\log d}-\frac{\log\log d+\log(4\pi)}{2\sqrt{2}\log d}\)._

Proof.: As \(x_{i}+w_{i}\sim N(0,2)\), \(Z:=\frac{\max\{x+w\}/\sqrt{2}-b_{d}}{a_{d}}\sim Gumbel(0,1)\) as \(d\rightarrow\infty\). Therefore, \(\mathrm{Ex}[d_{\mathrm{tr}}(x,-w)]=\mathrm{Ex}[2\max\{x+w\}]\xrightarrow[d \rightarrow\infty]{}2\sqrt{2}(a_{d}\mathrm{Ex}[Z]+b_{d})\). \(\mathrm{Var}[d_{\mathrm{tr}}(x,-w)]=\mathrm{Var}[\max\{x+w\}-\min\{x+w\}]=2 \mathrm{Var}[\max\{x+w\}]+2\mathrm{Cov}[\max\{x+w\},-\min\{x+w\}]\xrightarrow[d \rightarrow\infty]{}2\times 2a_{d}^{2}\mathrm{Var}[Z]=2\times 2a_{d}^{2}\frac{\pi^{2}}{6}\) where \(\mathrm{Cov}[\max\{x+w\},-\min\{x+w\}]\xrightarrow[d\rightarrow\infty]{}0\) was assumed. 

Here we confirm that the above scaling holds actually by numerical calculations.
One way for better weight initialization is to choose the scale of \(w\) so that the variance of the neural activity in the embedding layer becomes \(1\).

**Lemma 21**.: _Suppose \(x_{i}\sim N(0,1)\) and \(w_{i}\sim N(0,\frac{6\log d}{\pi^{2}}-1)\) for \(i=1,\ldots,d\). Then the expectation and variance of \(d_{\mathrm{tr}}(x,-w)\) can be approximated by \(2\sqrt{\frac{6\log d}{\pi^{2}}}(a_{d}\gamma+b_{d})\) and \(1\), respectively._

Proof.: As \(x_{i}+w_{i}\sim N(0,\frac{6\log d}{\pi^{2}})\), \(Z:=\frac{\max\{x+w\}/\sqrt{\frac{6\log d}{\pi^{2}}-b_{d}}}{a_{d}}\sim Gumbel(0,1)\). Therefore, \(\mathrm{Ex}[d_{\mathrm{tr}}(x,-w)]=\mathrm{Ex}[2\max\{x+w\}]\xrightarrow[d \rightarrow\infty]{}2\sqrt{\frac{6\log d}{\pi^{2}}}(a_{d}\mathrm{Ex}[Z]+b_{d})\). \(\mathrm{Var}[d_{\mathrm{tr}}(x,-w)]\xrightarrow[d\rightarrow\infty]{}2\times \frac{6\log d}{\pi^{2}}a_{d}^{2}\mathrm{Var}[Z]=2\frac{6\log d}{\pi^{2}}a_{d}^ {2}\frac{\pi^{2}}{6}=1\). 

To control the standard deviation of the weights, you can customize an initializer (instead of simply specifying initializer = "random_normal") in the definition of TropEmbed class.

> ini = tf.keras.initializers.RandomNormal(mean=0., stddev=1.) > self.w = self.add_weight(shape=(units, input_dim), \(\backslash\) initializer=ini) However, as the weight initialization should be done together with the data preprocessing, in this paper we entirely use the default value of stddev=0.05 for "random_normal" for simplicity.

> self.w = self.add_weight(shape=(units, input_dim), \(\backslash\) initializer="random_normal")

Figure 2: histogram of simulated \(d_{\mathrm{tr}}(x,-w)\) for the same situation as in Lemma 20 with \(d=10000\). For the histogram, \(100000\) samples of \(d_{\mathrm{tr}}(x,-w)\) are used. The simulated mean is \(10.893\) while the theoretical prediction is \(10.954\). The simulated std is \(0.604\) while the theoretica prediction is \(0.598\). The mean and std are the same as predicted from the theory.
Computational Experiments

In this section, we apply tropical neural networks with one hidden layer (the tropical embedded layer) to simulated data as well as empirical data. Then later we compare its performance against neural networks with one hidden layer with ReLU activator.

### Small simulated data

First we illustrate our tropical neural networks with one hidden layer with \(16\) neurons and with one output Sigmoid function using a small example. First we generate two dimensional \(16+16\) random points from the Gaussian distributions with means \((0.5,-0.5)\) and \((-0.5,0.5)\) with the unit covariance matrix. Then these points are randomly translated by \((c,c)\) where \(c\) is a Gaussian random variable whose standard deviation is \(4\). The left and right figures in Figure 3 show the actual test labels and the predicted probabilities of the test data by the tropical neural networks with one hidden layer with \(16\) neurons.

### High-dimensional simulated data

Second we demonstrate that a tropical neural network with one hidden layer with \(8\) neurons and with one output sigmoid function works against the curse of dimensionality, where the most of the variables in this high dimensional data are rather just noises [42]. We generate \(d\) dimensional \(16+16\) random points from the Gaussian distributions with means \((0.5,-0.5,0,\ldots,0)\) and \((-0.5,0.5,0,\ldots,0)\) with the unit covariance matrix. Then these points are randomly translated by \((c,c,c,\ldots,c)\) where \(c\) is a Gaussian random variable whose standard deviation is \(6\). The result demonstrates that the tropical neural networks work robustly against the curse of dimensionality.

Figure 3: Predicted probabilities by the tropical neural networks on a small example.
### simulated data generated from the multi-species coalescent model

In this subsection we apply the tropical neural networks to a sample of phylogenetic trees generated under the _multi-species coalescent model_.

A phylogenetic tree is a weighted tree whose leaves are labeled with \([m]:=\{1,2,\ldots,m\}\), where \(m\) is the number of leaves, and whose internal nodes are unlabeled. A weight on each edge of a phylogenetic tree is considered as a distance from a node to another node on the tree and in evolutionary biology, a weight on an edge can be considered as a product of an evolutionary time and mutationa rate [32]. On this paper we consider a rooted phylogenetic tree with a leaf label set \([m]\). An equidistant tree with \(m\) leaves is called _equidistant tree_ if the total weights on the unique path from its room to each leaf is the same for all leaf in \([m]\). Under the multi-species coalescent model which can be used to analyze gene trees, which are phylogenetic trees reconstructed from genes in a genome, we assume that gene trees are all equidistant trees. Therefore in this paper we assume that all phylogenetic trees are equidistant trees.

To conduct a statistical analysis on a set of phylogenetic trees, we consider a _space of phylogenetic trees_ with fixed \([m]\). A space of phylogenetic trees on \([m]\) is a set of all possible phylogenetic trees with \([m]\) and it is well-known that it is not Euclidean [33]. It is also well-known that the space of all possible equidistant trees on \([m]\) with the _tropical metric_ under the max-plus algebra is a subspace of the tropical projective space [3, 39]. In order to define the space of equidistant trees, first we define _ultrametrics_. COnsider a map \(u:[m]\times[m]\rightarrow\mathbb{R}\) such that \(u(i,j)=u(j,i)\) and \(u(i,i)=0\). This map is called a _dissimilarity map_ on \([m]\). If a dissimilarity map \(u\) satisfies that

\[\max\{u(i,j),u(i,k),u(j,k)\}\]

Figure 4: Application of the tropical neural networks to a high-dimensional example. The test accuracy averaged over 100 trials is plotted. The tropical neural networks work robustly against the curse of dimensionality.
achieve at least twice, then we call \(u\) an _ultrametric_.

**Example 22**.: _Suppose \(m=3\), i.e., \([3]=\{1,2,3\}\) and suppose_

\[u(1,2)=u(2,1)=1,u(1,3)=u(3,1)=1,u(2,3)=u(3,2)=0.5\]

_and \(u(i,i)=0\) for all \(i=1,2,3\). Since_

\[\max\{u(1,2),u(1,3),u(2,3)\}=1\]

_and it achieves twice, i.e., \(u(1,2)=u(1,3)=1\). Thus, \(u\) is an ultrametric._

Consider dissimilarity maps \(u_{T}\) on a phylogenetic tree \(T\) on \([m]\) such that \(u(i,j)\) is the total weights on the unique path from a leaf \(i\) to a leaf \(j\) for all \(i,j\in[m]\). Then we have the following theorem:

**Theorem 23** ([7]).: _Consider an equidistant tree \(T\) on \([m]\). Then \(u_{T}\) realizes an equidistant tree \(T\) on \([m]\) if and only if a dissimilarity map \(u_{T}\) is ultrametric._

**Example 24**.: _Suppose we have an ultrametric from Example 22. An equidistant tree whose dissimilarity maps are ultrametric in Example 22 is a rooted phylogenetic tree with leaves \([3]=\{1,2,3\}\) shown in Figure 5._

Therefore, we consider the space of all possible ultrametrics on \([m]\) as the space of equidistant trees on \([m]\). Then we have the following theorem:

**Theorem 25** ([3]).: _The space of ultrametrics on \([m]\) is the tropicalization of the linear subspace defined by linear equations_

\[x_{ij}-x_{ik}+x_{jk}=0\]

_for \(1\leq i\leq j\leq k\leq m\) by replacing sum with max operation and replacing multiplication by a classical summation._

Figure 5: An equidistant tree with the dissimilarity maps which are ultrametric shown in Example 22.
The space of ultrametrics on \([m]\) is a subspace of the tropical projective space \((\mathbb{R}^{e}\cup\{-\infty\})/\mathbb{R}\mathbf{1}\) where \(e=\binom{m}{2}\). Therefore, we apply our method, tropical neural networks, to simulated data generated from the multi-species coalescent model using a software Mesquite [21].

The multi-species coalescent model has two parameters: species depth and effective population size. Here we fix the effective population size \(N_{e}=100000\) and we vary

\[R=\frac{SD}{N_{e}}\]

where \(SD\) is the species depth. We generate species trees using the Yule process. Then we use the multi-species coalescent model to generate gene trees with a given species tree. In this experiment, for each \(R\), we generate two different set of \(1000\) gene trees: In each set of gene tree, we have a different species tree so that each set of gene trees is different from the other. We conduct experiments with \(R=0.25,0.5,1,2,5,10\).

Note that when we have a small ratio \(R\), then gene trees become more like random trees since the species tree constrains less on tree topologies of gene trees. Thus it is more difficult when we have a small \(R\) while if we have a large \(R\), then it is easier to classify since the species tree constrains more on tree topologies of gene trees.

In this experiment, we set one hidden layer for each neural network: neural network with ReLU activators and neural network with tropical activators. We set the Sigmoid function in the output node in both neural networks. In each neural network, we set \(1000\) neurons in the hidden layer.

Figure 6 shows ROC curves for neural networks with ReLU and tropical

Figure 6: ROC curves for neural networks with ReLU and tropical neural networks with one hidden layer. We conduct experiments with \(R=0.25,0.5,1,2,5,10\).
neural networks. In general tropical neural networks perform better than neural networks with ReLU activator function.

### Influenza data

In this subsection we apply our method to genomic data for 1089 full length sequences of hemagglutinin (HA) for influenza A H3N2 from 1993 to 2017 collected in the state of New York obtained from the GI-SAID EpiFlu database (www.gisaid.org). These collected data were aligned using muscle developed by [10] with the default settings. Then we apply the neighbor-joining method with the p-distance [31] to reconstruct a tree from each sequenced data. Each year corresponds to the first season. We also apply KDETrees [38] to remove outliers and a sample size of each year is about 20,000 trees.

We apply tropical neural networks and neural networks with ReLU with one hidden layer with 10 neurons to all pairs of different years to see if they are significantly different one year to the other. Heatmaps of accuracy rates with the probability threshold 0.5 and AUC values are shown in Figure 7. Again, tropical neural networks outperform classical neural networks.

Tropical Neural Network as a Generalization of Tropical Logistic Regression for Classification of Gene Trees

A tropical neural network can be interpreted as a generalization of a tropical logistic regression. The tropical logistic regression model [2] is developed for binary classification on gene trees and it has been proven to have higher predictive power than classical logistic regression to classify phylogenetic trees. It assumes that if \(X\) is the covariate (gene tree), the binary response random variable is \(Y\sim\text{Bernoulli}(p(X))\), with

\[p(x)=S\left(\lambda_{0}d_{\text{tr}}(x,\omega_{0})-\lambda_{1}d_{\text{tr}}(x,\omega_{1})+C\right),\]

where \(m\) is the number of leaves in each phylogenetic tree in the given sample, \(e:=\binom{m}{2}\), \(S\) is the sigmoid function, \(\omega_{0},\,\omega_{1}\in\mathbb{R}^{e}/\mathbb{R}\mathbf{1}\), and \(\lambda_{0},\lambda_{1},C\in\mathbb{R}\) with \(\lambda_{0}\lambda_{1}\geq 0\). Note that this model is a special case for Eq. (6), with the sigmoid function as the link, and two neurons in the hidden layer whose weights are \(w_{0}^{(2)}=\lambda_{0},w_{1}^{(2)}=-\lambda_{1}\) and \(w_{0}^{(1)}=-\omega_{0},w_{1}^{(1)}=-\omega_{1}\). Therefore, tropical logistic regression is almost identical to a tropical neural network consisting of one tropical embedding layer with two neurons and a classical layer, with the additional assumption that \(w_{0}^{(2)}w_{1}^{(2)}\leq 0\).

The one-species model described in [2] can be considered to be a neural network with \(e\) neurons in the input layer, no hidden layers and a unique output neuron. The activation function is the logistic function and the inner product used is tropical defined as

\[\langle x,-\omega\rangle:=d_{\text{tr}}(x,\omega)-C, \tag{11}\]
where \(C\) can be considered to be a bias variable, similarly to the intercept variable in classical models. Tropical logistic regression returns the sigmoid of the tropical inner product. We define the tropical generalised linear model as an extension to tropical logistic regression, where instead of the sigmoid function, we may use a different link/activation function. If there are multiple outputs (multivariate generalized linear model (GLM)) and if we treat the output layer as the new input layer and iterate this \(L\) times, then we have an \(L\)-layer neural network. In the same way that classical neural networks are a stack/recursive application of classical multivariate GLMs, tropical neural networks can be a stack of tropical multivariate GLMs. Effectively, all is identical to classical networks, but instead of applying classical inner products, we apply tropical inner products as defined in Eq. (11). The \(i\)-th neuron of the \(l\)-th layer is

Figure 7: Heat maps for (top) classification rates with threshold 0.5 and (bottom) AUC values for classical neural networks with ReLU (left) and tropical neural networks (right).
defined as \(x_{i}^{(l)}\) and computed through the recursive formula,

\[x_{i}^{(l)}=d_{\mathrm{tr}}\left(x_{i}^{(l-1)},\omega_{i}^{(l)}\right)-C_{i}^{(l )}, \tag{12}\]

where \(\Omega^{(l)}=(\omega_{1}^{(l)},\omega_{2}^{(l)},\ldots,\omega_{N_{l}}^{(l)})\in \mathbb{R}^{N_{l-1}\times N_{l}}\) is the weight matrix between layer \((l-1)\) and \(l\) for the number \(N_{s}\) of neurons in layer \(s\), and \(C^{(l)}\in\mathbb{R}^{N_{l}}\). By assuming that all neurons share the same bias variable \(c=C_{i}^{(l)}\) for all \(i\in[N_{l}]\), Eq. (12) reduces to Eq. (1), since vectors are defined up to an additive constant vector \((c,\ldots,c)\) in the tropical projective torus. When the last tropical embedding layer connects to the first classical layer, the constant bias vector is incorporated in the bias term of the classical layer. Hence, tropical bias terms are redundant and not considered in the development of tropical neural networks. Thus, the tropical neural network which we propose in this paper follows naturally as an extension of the tropical logistic regression model.

## 8 Summary and Discussion

In this paper, we first developed a tropical embedding layer. We used the tropical embedding layer as the first layer of the classical neural networks to keep the invariance in the tropical projective space. To check if this tropical neural network has enough flexibility, we next proved that this tropical neural network is a universal approximator. After we derived a backpropagation rule for the tropical neural networks, we provided TensorFlow 2 codes for implementing a tropical neural network in the same fashion as the classical one, where the weights initialization problem is considered according to the extreme value statistics. Finally we showed some applications as examples.

The tropical neural networks with the tropical metric worked better than the classical neural networks when the input data are phylogenetic trees which is included in the tropical projective torus. This is partly because only the tropical neural network can keep the invariance of the input vector under the one-vector which is innate in the tropical projective torus.

One of the nice properties of tropical neural networks is its tractability and interpretability in analysis. The tropical embedding can be interpreted as taking the tropical distance to a point in the space of the tropical projective torus. The activities of neurons in the tropical neural networks with the randomized weights and inputs can be analyzed by using the extreme value statistics. The backpropagation rule of the tropical neural networks can be derived and interpreted rather easily.

The TensorFlow 2 codes for the Python class for tropical embedding was provided in the paper. This makes it possible to implement a tropical neural network in the same familiar fashion as the classical one. This facilitates, for example, to compare tropical and classical neural networks for the same data by using a common code.

Recent work shows that neural networks are vulnerable against adversarial attacks (for example, [5, 25, 34, 22]). However, our initial computational
experiments on image data from computer vision show that tropical neural networks are robust against gradient based methods, such as the Fast Gradient Sign Method [14] and Ensemble Adversarial Training [36]. It is interesting to investigate why tropical neural networks are robust against such attacks. In addition, it is interesting to develop adversarial attacks toward tropical neural networks.
