# Quaternion-based machine learning on topological quantum systems

Min-Ruei Lin<EMAIL_ADDRESS>Department of Physics, National
Sun Yat-sen University, Kaohsiung 80424, Taiwan  Wan-Ju Li  Department of
Physics, National Sun Yat-sen University, Kaohsiung 80424, Taiwan  Shin-Ming
Huang<EMAIL_ADDRESS>Department of Physics, National Sun Yat-sen
University, Kaohsiung 80424, Taiwan  Center of Crystal Research, National Sun
Yat-sen University, Kaohsiung 80424, Taiwan

###### Abstract

Topological phase classifications have been intensively studied via machine-
learning techniques where different forms of the training data are proposed in
order to maximize the information extracted from the systems of interests. Due
to the complexity in quantum physics, advanced mathematical architecture
should be considered in designing machines. In this work, we incorporate
quaternion algebras into data analysis either in the frame of supervised and
unsupervised learning to classify two-dimensional Chern insulators. For the
unsupervised-learning aspect, we apply the principal component analysis (PCA)
on the quaternion-transformed eigenstates to distinguish topological phases.
For the supervised-learning aspect, we construct our machine by adding one
quaternion convolutional layer on top of a conventional convolutional neural
networks. The machine takes quaternion-transformed configurations as inputs
and successfully classify all distinct topological phases, even for those
structures that are not seen by the machine during the training process. Our
work demonstrates the power of quaternion algebras on extracting crucial
features from the targeted data and the advantages of quaternion-based neural
networks than conventional ones in the tasks of topological phase
classifications.

##  I Introduction

The phase classification using machine-learning (ML) based techniques has been
attracting intense attentions since the pioneering work in 2017[1]. In
addition to the classical phase detections[2, 3] where each phase is well
defined by the corresponding order parameters, detecting topological phase
transitions[2] is interesting and challenging[4] due to the lack of local
order parameters. Recently, the phase detections and classifications have been
performed via different ML techniques for classifying various topological
invariants[5, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, 15, 16, 17, 6, 18, 19, 10,
20, 21, 22, 23, 24, 16, 25, 21, 18, 26, 18, 17, 27, 28, 29, 30, 6, 10, 4, 31,
32, 33, 34, 35, 26, 36], including the Chern number[14, 15, 16, 17, 6, 18, 19,
10, 20, 21, 22, 23], winding number[24, 16, 25, 21, 18, 26, 18],
$\mathbb{Z}_{2}$ index[17, 27, 28, 29, 30, 6, 10, 4, 31, 32, 33, 34, 35, 26,
36], to name a few. In addition to the applied ML architectures, the forms of
the inputs for training the machine also play a crucial role in determining
the resulting performance of the topological phase detections[4].

For the topological systems with the Chern numbers or the winding numbers as
the topological invariants, various types of inputs are used to perform the
phase classifications. For instance, researchers in Kim’s group introduced
quantum loop topography (QLT) to construct multi-dimensional images from raw
Hamiltonians or wave functions as inputs[14, 17]. Zhai’s group collected the
Bloch Hamiltonians into an arrays to feed their machines[24, 16]. The real-
space particle densities and local density of states were used as inputs by
Cheng et al.[15]. Carvalho et al. fed the local projections of the density
matrix to the machine [6]. From cold-atom experiments, momentum-space density
images were generated as inputs by Rem et al.[20]. The time-of-flight
images[10, 19], spatial correlation function[10] and density–density
correlation function[10] were also used as inputs. The density profiles formed
in quantum walks were proposed as appropriate inputs for training in Ming et
al’s work[23]. Furthermore, several works had tried the spin
configurations[18] and the Bloch Hamiltonians over the Brillouin zone (BZ) as
inputs[21, 18]. For these forms of inputs mentioned above, various ML
techniques with distinct real-valued neural networks have been applied to
discriminate different topological phases.

As the development of artificial neural networks becomes mature,
generalization from real-valued neural networks to complex-valued ones is
undertaken that anticipates a raise of representation capability of machines
[37, 38]. Specifically, a quaternion contains one real part and three
imaginary parts so that a quaternion-based neural network[39, 40, 41, 42] is
expected to have remarkable performance on handling the processing of data
with more than two degrees of freedom such as the color images (RGB channels)
and the descriptions of 3D systems (xyz coordinates). There have been various
proposals about quaternion-based neural networks in ML techniques and
applications in computer science, such as the quaternion convolutional neural
network (qCNN)[43, 44, 38], quaternion recurrent neural network[45],
quaternion generative adversarial networks[46], quaternion-valued variational
autoencoder[47], quaternion graph neural networks[48], quaternion capsule
networks[49] and quaternion neural networks for the speech recognitions[50].
However, the ML-related applications of the quaternion-based neural networks
on solving problems in physics are still limited, especially in the
topological phase detections, even though the quaternion-related concepts have
been applied in some fields in physics [51, 52, 53].

Figure 1: Spin vectors in the Brillouin zone, $k_{x},k_{y}\in(-\pi,\pi]$, with
Chern number (a) $C=1$, (b) $C=2$, (c) $C=3$ and (d) $C=4$.

In this work, we perform the Chern-insulator classifications from both
supervised- and unsupervised-learning aspects based on the inputs transformed
via the quaternion algebra. For the unsupervised learning, we firstly encode
the quaternion-transformed eigenstates of Chern insulators via a convolution
function as inputs and study them using the principal component analysis. We
found that using only the first two principal elements is not enough to fully
classify the Chern insulators, consistent with Ming’s work[23]. Further
studies show that the performance can be improved by including more principal
components. For the supervised learning, we construct a quaternion-based
neural network in which the first layer is a quaternion convolutional layer.
We then show that this quaternion-based machine has better performance than a
conventional CNN machine. Our machine is good not only at testing but also at
identifying data that have no common structures as in training data. The good
performance can be partially attributed to the similarities between the
formula of the Berry curvatures and the quaternion algebra. Therefore, our
work demonstrates the power of the quaternion algebra on extracting relevant
information from data, paving the way to applications of quaternion-based
algorithm ML techniques in topological phase classifications.

The outline of the remaining part of this work is as follows. In section II,
we introduce the model Hamiltonian, generating the training data for our
classification tasks, and the quaternion convolution layer used in this work.
PCA analysis of the quaternion-transformed eigenstates is discussed in Sec.
III. The data preparations, the network structures and the performance of the
quaternion-based supervised learning task are given in Sec. IV. Some further
discussions on our neural networks are given in Sec. V. Finally, a conclusion
is provided in Sec. VI.

##  II Model and quaternion convolutional layer

###  II.1 Model

A generic two-band Bloch Hamiltonian with the aid of the identity matrix
$\sigma_{0}$ and Pauli matrices
$\boldsymbol{\sigma}=(\sigma_{1},\sigma_{2},\sigma_{3})$ is written as

$\mathcal{H}(\vec{k})=h_{0}(\vec{k})\sigma_{0}+\mathbf{h}(\vec{k})\cdot\boldsymbol{\sigma},$
(1)

where $\vec{k}=(k_{x},k_{y})$ is the crystal momentum in the 2D
BZ($={k_{x},k_{y}\in(-\pi,\pi]}$), and the vector
$\mathbf{h}=(h_{1},h_{2},h_{3})$ acts as an external magnetic field. Sometimes
we will omit arguments $\vec{k}$ when writing $\mathbf{h}(\vec{k})$ for
brevity in $k$-space. The eigenstate of the upper (lower) band will represent
the spin pointing antiparallel (parallel) to
$\mathbf{n}=\mathbf{h}/\absolutevalue{\mathbf{h}}$. Since $h_{0}(\vec{k})$
does not affect the pointing direction, it will be ignored in the remaining
part of this section. The function $\mathbf{n}$ embeds the topology of the
system, and we firstly discuss the topological structure in $\mathbf{n}$.
Here, the topological invariant is the Chern number $C\in\mathbb{Z}$ with the
formula:

$C=\frac{1}{4\pi}\int_{\text{BZ}}\mathbf{n}\cdot(\partial_{k_{x}}\mathbf{n}\times\partial_{k_{y}}\mathbf{n})d\vec{k},$
(2)

where the integrand is the Berry curvature and the integration is over the
first BZ.

Figure 2: The Chern number with various $m$ and $c$.

We construct the normalized spin configurations $\mathbf{n}(\vec{k})$ based on
the following models. For topological systems, we choose the Hamiltonian with
$\mathbf{h}=\mathbf{h}^{(c)}$, where

$\mathbf{h}^{(c)}(\vec{k})=\begin{pmatrix}\
\mathrm{Re}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
-\mathrm{Im}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
\cos{k_{x}}+\cos{k_{y}}+m\end{pmatrix}$ (3)

with positive integer $c$ and real parameter $m$ to control the Chern number.
For $c=1$, the model is the Qi-Wu-Zhang (QWZ) model [54]. For a given $c$, the
Chern number $C$ can be either $0,~{}c,\text{ or}-c$ depending on the value of
$m$:

$C=\begin{cases}\mathrm{sgn}(m)c,&0<|m|<2,\\\ 0,&|m|>2.\end{cases}$ (4)

The Chern numbers with different c’s and m’s are shown in Fig. 1. Note that
$C=0$ stands for a topologically trivial phase and nonzero $C$’s are for
nontrivial phases. The topological phase diagram is shown in Fig. 2.

In this work, the unsupervised learning involves seven topological phases
($C=0,\pm 1,\pm 2,\pm 3$) in Sec. III, and the supervised learning involves
nine topological phases ($C=0,\pm 1,\pm 2,\pm 3,\pm 4$) in Sec. IV.

###  II.2 Quaternion convolutional layer

A quaternion number has four components, the first of which stands for the
real part and the other three of which stand for the imaginary parts. Given
two quaternions $q_{1}=(r_{1},a_{1},b_{1},c_{1})$ and
$q_{2}=(r_{2},a_{2},b_{2},c_{2})$, their product $Q=q_{1}q_{2}=(R,A,B,C)$ is
given by

$\begin{pmatrix}R\\\ A\\\ B\\\
C\end{pmatrix}=\begin{pmatrix}r_{1}r_{2}-a_{1}a_{2}-b_{1}b_{2}-c_{1}c_{2}\\\
a_{1}r_{2}+r_{1}a_{2}-c_{1}b_{2}+b_{1}c_{2}\\\
b_{1}r_{2}+c_{1}a_{2}+r_{1}b_{2}-a_{1}c_{2}\\\
c_{1}r_{2}-b_{1}a_{2}+a_{1}b_{2}+r_{1}c_{2}\end{pmatrix},$ (5)

which can be written as the matrix product form

$\begin{pmatrix}R\\\ A\\\ B\\\
C\end{pmatrix}=\begin{pmatrix}[r]r_{1}&-a_{1}&-b_{1}&-c_{1}\\\
a_{1}&r_{1}&-c_{1}&b_{1}\\\ b_{1}&c_{1}&r_{1}&-a_{1}\\\
c_{1}&-b_{1}&a_{1}&r_{1}\end{pmatrix}\begin{pmatrix}r_{2}\\\ a_{2}\\\ b_{2}\\\
c_{2}\end{pmatrix}.$ (6)

To implement a quaternion convolutional (q-Conv) layer in numerical
programming, we will regard the two quaternions as a $4\times 4$ matrix and a
$4\times 1$ column matrix, respectively:

$q_{1}\doteq\begin{pmatrix}[r]r_{1}&-a_{1}&-b_{1}&-c_{1}\\\
a_{1}&r_{1}&-c_{1}&b_{1}\\\ b_{1}&c_{1}&r_{1}&-a_{1}\\\
c_{1}&-b_{1}&a_{1}&r_{1}\end{pmatrix}\quad\mathrm{and}\quad
q_{2}\doteq\begin{pmatrix}[r]r_{2}\\\ a_{2}\\\ b_{2}\\\ c_{2}\end{pmatrix}.$
(7)

More details of quaternion algebra are described in Appendix B.

A conventional CNN contains a real-valued convolutional layer to execute the
convolution of the input and the kernel. Let the input $F$ have the shape:
$H_{i}\times W_{i}\times C_{i}$ (Height $\times$ Width $\times$ Channel) and
the shape of the kernel $K$ be $H_{k}\times W_{k}\times C_{i}\times C_{f}$.
The convolution will produce an output $O$, $O=F\ast K$, whose elements are

$O_{i^{\prime},j^{\prime},t^{\prime}}=\sum_{i}^{H_{k}}\sum_{j}^{W_{k}}\sum_{t}^{C_{i}}F_{i^{\prime}+i-1,j^{\prime}+j-1,t}\cdot
K_{i,j,t,t^{\prime}}.$ (8)

Here the stride is assumed to be $1$ both in the width and the height
directions. The indices $i$ and $j$ are spatial indicators, $t$ is the index
of channel in the input feature map and $t^{\prime}$ is the kernel index. The
shape of the output will be $(H_{i}-H_{k})\times(W_{i}-W_{k})\times C_{f}$.

Assume that the input has four components. To uncover the entanglement among
components through CNN, we will utilize the quaternion product. Now, we
introduce another dimension–Depth–which is four, as a quaternion number of
four components. Both of the input $F$ and the kernel $K$ have Depth of four
as two quaternion numbers. The product of $F$ and $K$ will have Depth of four
as a quaternion in Eq. (5). Referring to Eq. (7) where we show a matrix
representation to implement quaternion algebra and thinking of $F$ as $q_{1}$
and $K$ as $q_{2}$ in Eq. (7), we transform the Depth-four input $F$ into a
4x4 matrix, $F^{(l,s)}$, and keep the kernel $K$ still of Depth 4, $K^{(l)}$,
where $l,s=1,…,4$. The product of $F$ and $K$, say $O$, will have Depth of
four as shown in Eq. (9). We remark that the products between components of
$F$ and $K$ are convolution operations as Eq. (8).

$O_{i^{\prime},j^{\prime},t^{\prime}}^{(s)}=\sum_{l}^{4}\sum_{i,j,t}F^{(s,l)}_{i^{\prime}+i-1,j^{\prime}+j-1,t}\cdot
K^{(l)}_{i,j,t,t^{\prime}},$ (9)

Figure 3: Illustration of a quaternion convolutional layer. On the left, we
start with the input $q_{1}$ having four quaternion components ((yellow, red,
green, blue) stands for ($r_{1}$, $a_{1}$, $b_{1}$, $c_{1}$)). In the middle,
$q_{1}$ is permuted to construct $\\{F^{(\cdot,l)}\\}_{l=1}^{4}$ on which the
convolution with four kernels $\\{K^{(l)}\\}_{l=1}^{4}$ is performed. A
summation is taken for each Depth dimension to obtain the output feature map
$O$ on the right.

More specifically, we consider an input data as $q_{1}$ (four color squares on
the left of Fig. 3) and four kernels encoded in $q_{2}$, given in the
following

$\left\\{\begin{matrix}q_{1}\doteq&(r_{1}~{}a_{1}~{}b_{1}~{}c_{1})^{T}&\\\
q_{2}\doteq&(r_{2}~{}a_{2}~{}b_{2}~{}c_{2})^{T}&=:K^{(\cdot)}.\end{matrix}\right.$
(10)

The output feature maps $O\doteq(R~{}A~{}B~{}C)^{T}$ is then calculated based
on Eq. (5). As the first step, we permute the order of $q_{1}$ to obtain

$\displaystyle F^{(\cdot,1)}=:\begin{pmatrix}r_{1}\\\ a_{1}\\\ b_{1}\\\
c_{1}\end{pmatrix},F^{(\cdot,2)}=:\begin{pmatrix}[r]-a_{1}\\\ r_{1}\\\
c_{1}\\\ -b_{1}\end{pmatrix},$ (11) $\displaystyle
F^{(\cdot,3)}=:\begin{pmatrix}[r]-b_{1}\\\ -c_{1}\\\ r_{1}\\\
a_{1}\end{pmatrix},F^{(\cdot,4)}=:\begin{pmatrix}[r]-c_{1}\\\ b_{1}\\\
-a_{1}\\\ r_{1}\end{pmatrix}$

(see the four sets of sqaures in the middle of Fig. 3). We then convolute
those four quaternions ($F^{(\cdot,l)}$ with $l=1,2,3$ and 4) with four
kernels ($K^{(l)}$ with $l=1,2,3$ and 4) in the following way:

$\left\\{\begin{matrix}F^{(\cdot,1)}K^{(1)}&\doteq&\begin{pmatrix}r_{1}r_{2}&a_{1}r_{2}&b_{1}r_{2}&c_{1}r_{2}\end{pmatrix}^{T}\\\
F^{(\cdot,2)}K^{(2)}&\doteq&\begin{pmatrix}-a_{1}a_{2}&r_{1}a_{2}&c_{1}a_{2}&-b_{1}a_{2}\end{pmatrix}^{T}\\\
F^{(\cdot,3)}K^{(3)}&\doteq&\begin{pmatrix}-b_{1}b_{2}&-c_{1}b_{2}&r_{1}b_{2}&a_{1}b_{2}\end{pmatrix}^{T}\\\
F^{(\cdot,4)}K^{(4)}&\doteq&\begin{pmatrix}-c_{1}c_{2}&b_{1}c_{2}&-a_{1}c_{2}&r_{1}c_{2}\end{pmatrix}^{T}\end{matrix}\right.$

, as shown in the middle of Fig. 3. Finally, we sum over the above four
quaternions to get the output feature maps $O$, as shown on the right of Fig.
3.

$O:=\begin{pmatrix}R\\\ A\\\ B\\\
C\end{pmatrix}=\begin{pmatrix}r_{1}r_{2}-a_{1}a_{2}-b_{1}b_{2}-c_{1}c_{2}\\\
a_{1}r_{2}+r_{1}a_{2}-c_{1}b_{2}+b_{1}c_{2}\\\
b_{1}r_{2}+c_{1}a_{2}+r_{1}b_{2}-a_{1}c_{2}\\\
c_{1}r_{2}-b_{1}a_{2}+a_{1}b_{2}+r_{1}c_{2}\end{pmatrix}.$

##  III principal component analysis

Principal component analysis (PCA) is a linear manifold learning that is to
find the relevant basis set among data[55, 56].

We prepare eigenstates $\ket{u_{\pm}}$ of Eq. (1), where $+\ (-)$ stands for
the upper (lower) band. For a topological state, the phase cannot be well-
defined over the whole BZ. Therefore, we can divide the whole BZ into two
parts, in each part of them the topological wave function has continuously
well-defined phase. We then choose two regions according to the sign of
$h_{3}$ in Eq. (3):

$\displaystyle\begin{split}\ket{u_{+}}&\doteq\frac{1}{\sqrt{2h_{+}(h_{+}+h_{3})}}\matrixquantity(h_{+}+h_{3}\\\
h_{1}+ih_{2})\\\
\ket{u_{-}}&\doteq\frac{1}{\sqrt{2h_{-}(h_{-}+h_{3})}}\matrixquantity(-h_{1}+ih_{2}\\\
h_{-}+h_{3})\end{split}\quad,~{}h_{3}\geq 0,$ (12)

and

$\displaystyle\begin{split}\ket{u_{+}}&\doteq\frac{1}{\sqrt{2h_{+}(h_{+}-h_{3})}}\matrixquantity(h_{1}-ih_{2}\\\
h_{+}-h_{3})\\\
\ket{u_{-}}&\doteq\frac{1}{\sqrt{2h_{-}(h_{-}-h_{3})}}\matrixquantity(h_{-}-h_{3}\\\
-h_{1}-ih_{2})\end{split}\quad,~{}h_{3}<0,$ (13)

where $h_{\pm}=\pm\sqrt{h_{1}^{2}+h_{2}^{2}+h_{3}^{2}}$. In this choice of
gauge, the first (second) component of $\ket{u_{+}}$ $(\ket{u_{-}})$ is real-
valued when $h_{3}\geq 0$, and the second (first) component of $\ket{u_{+}}$
$(\ket{u_{-}})$ is real-valued when $h_{3}<0$.

By translating $\ket{u_{\pm}}\doteq(\alpha_{\pm},\beta_{\pm})^{T}$ with
$\alpha_{\pm},\beta_{\pm}\in\mathbb{C}$, into a quaternion number of four
components, we have

$q_{\pm}:=\mathrm{Re}(\alpha_{\pm})+\mathrm{Im}(\alpha_{\pm})\hat{\mathbf{i}}+\mathrm{Re}(\beta_{\pm})\hat{\mathbf{j}}+\mathrm{Im}(\beta_{\pm})\hat{\mathbf{k}}.$
(14)

(a brief introduction of the quaternion number can be seen in Appendix B). To
see the correlation of states over $\vec{k}$, we define the quantity $F$ to be
the quaternion-based convolutions:

$\begin{split}F(\vec{p}):=q^{*}_{+}&\circledast
q_{+}[\vec{p}]-q^{*}_{-}\circledast q_{-}[\vec{p}]\quad\mathrm{with}\\\
q_{\pm}^{*}&\circledast
q_{\pm}[\vec{p}]:=\sum_{\vec{k}\in\mathrm{BZ}}q_{\pm}^{*}(\vec{k})q_{\pm}(\vec{p}-\vec{k}),\end{split}$
(15)

where $q^{*}$ is the conjugate of $q$. It can be proved that $F$ is real-
valued. Therefore, $F(\vec{p})$ of all $\vec{p}$ in the BZ based on a given
Hamiltonian can be analysed by using PCA.

Figure 4: The maps of the function $F$ without noise in the BZ. Three rows are
for $c=1,2\ \mathrm{and}\ 3$ in Eq. 3 from top to bottom; four columns from
left to right are for $m=-3,-1,1$ and 3. The corresponding Chern number $C$ is
tagged with each panel.

We collected various $F$ of all $\vec{k}\in$BZ within seven topological phases
as the dataset for PCA. For each topological phases, 30 $F$’s were prepared,
so the total amount of data was 210. The data for six non-trivial phases were
generated based on Eq. (3) with $m=\pm 1$ (the sign of $m$ determines the sign
of $C$). For the trivial phase, we prepared five data points from each of six
combinations of $\\{c,m\\}$, where $c\in\\{1,2,3\\}$ and $m\in\\{3,-3\\}$, and
then there are totally 30 data. To augment the number of data, we add Gaussian
noises $\delta\mathbf{h}$ at every $\vec{k}$ of the model [Eq. (3)] such that
$\mathbf{h}\to\mathbf{h}+\delta\mathbf{h}$ without closing the band gap.

In Fig. 4, we present various noiseless $F$ generated from Eq. (3) with
different $c$ and $m$.

Figure 5: PCA of seven topological phases with various noise. The symbols with
corresponding Chren numbers are marked in the legend.

It is notable that $F$ for $C=0$ are featureless, $F$ for $C=\pm 1$ have a
dipole moment, and $F$ for $C=\pm 2$ have a quadruple moment, and $F$ for
$C=\pm 3$ seemingly have a primary dipole and a secondary quadruple moment.
The remarkable features imply that the convolution function $F$ is a good
choice for topological classifications.

We examine data with the standard deviation (SD) equal to 0, 0.1, 0.2 and 0.3
respectively, and show the first two PCs of 210 pieces of data for each SD in
Fig. 5. In Fig. 5, it is evident that data are clustered into four groups and
their variances increase with SD. PCA is successful to separate different
topological phases into different clusters. However, some clusters contain two
topological phases of Chern numbers: $\\{+1,-3\\}$, $\\{-1,+3\\}$, and
$\\{+2,-2\\}$. The $C$ modulo 4 resemblance has also be observed in a previous
study [23].

Figure 6: Magnitude of projection (logarithmic scale) from non-trivial data
onto first six principal components. Inset: The first 16 principal values of
PCA. (normalized by maximal $\lambda_{1}$)

We find that including more PCs helps separate different classes in each
cluster. Figure 6 shows first six PCs of data in topologically non-trivial
phases, where PCx denotes the x-th PC component. One can find that PC1 and PC2
in each pair of $\\{+1,-3\\}$, $\\{-1,+3\\}$, and $\\{+2,-2\\}$ are nearly
identical, as also shown in Fig. 5. By including PC3 PC6 into the analysis,
all topological classes are completely classified. Via the proposed
convolution, topological states can be successfully classified by using PCA, a
linear machine for classification.

Figure 7: Framework of (a) the CNN and (b) the qCNN classifier. The shape of
data is $L_{x}\times L_{y}\times$ (number of channels). The number appended
after the symbol “@” stands for the number of filters convolved with the data,
and the number just above is the filter size. The number of tuneable network
parameters of CNN (qCNN) is 24,252 (19,350).

##  IV Supervised learning of CNN and the qCNN

###  IV.1 Datasets

The input data are normalized spin configurations $\mathbf{n}$, laying on a
$40\times 40$ square lattice with periodic boundary conditions, and their
corresponding topological phases are labels with one-hot encoding. We prepared
four datasets: training, validation, testing and prediction dataset. The first
three datasets are well known in conventional deep learning procedure [57]. To
understand whether our machine can also classify unseen spin configuration, we
prepare a prediction dataset that includes a few types of spin configurations
never seen by the machine during the training process.

The data pool containing training and validation datasets is constructed as
follows. Based on the Eq. (3), we firstly prepared 5760 data points of
$\mathbf{n}$ of nine topological phases with Chern number ranging from -4 to 4
so that each phase contain 640 data points. Additionally, we add 360 data
points for spin vortex which belongs to the trivial phase. A spin-vortex has
an in-plane spin texture that winds around a center, which is generated by
setting one of three components in Eq. (3) to be zero. By including spin
vortices, the machine learn the difference between 3D winding (non-trivial)
and 2D winding (trivial) spin configurations (more details are described in
the Appendix A). After the training process, the trained machine is scored by
a testing dataset with the same composition of nine phases as that in the
training (and validation) dataset. Importantly, without changing the
topologies, the Gaussian distributed random transition and random rotation
imposed on these three datasets can increase the diversity of dataset and
enhance the ability of generalization of the trained machine.

The prediction dataset contains six categories of spin configurations. The
first category is generated with $m$ uniformly distributed from $+3$ to $-3$.
In the second and the third categories, we change the sign of $n_{z}$ (the
second category) and swapping $n_{y}$ and $n_{z}$ of $\mathbf{n}$ (the third
category). Finally, we consider three categories for trivial states, which are
ferromagnetic (FM), conical $(\epsilon\neq 0)$ and helical $(\epsilon=0)$
states, based on the following formula:

$\mathbf{n}_{\mathrm{spiral/conical}}(\vec{k})=\begin{pmatrix}\sqrt{1-\epsilon^{2}}\cos{(k_{x}+k_{y})}\\\
\sqrt{1-\epsilon^{2}}\sin{(k_{x}+k_{y})}\\\ \epsilon\end{pmatrix}.$ (16)

FM can be viewed as 1D uncompleted winding configuration while conical and
helical can be viewed as 2D uncompleted ones. In total, we prepared six
categories for the prediction dataset. More details about data preparations
will be described in Appendix A.

For the conventional CNN, we use $\mathbf{n}$ as the input data. For the qCNN,
in order to feed the input data into the qCNN classifier, we transform the 3D
spin vector into an unit pure quaternion,

$(n_{x},n_{y},n_{z})\in\mathbb{R}^{3}\mapsto(0,n_{x},n_{y},n_{z})\in\mathbb{H},$
(17)

where the scalar part (the first component) is zero and the vector part is
$\mathbf{n}$.

###  IV.2 network structure and performance

We implement a qCNN classifier with a quaternion convolution (q-Conv) layer as
the first layer [see red dotted cube in Fig. 7(b)], and the operations in a
q-Conv layer are based on the quaternion algebra. Then the next three layers
are conventional 3D convolutional layers. Details of the quaternion algebra
and the keynote of a qCNN are explained in Appendix B. For comparison, we also
set up a conventional CNN classifier by replacing the q-Conv layer by a
conventional 2D convolutional layer, and appending three conventional 2D
convolutional layers to the first layer. The architecture of these two
classifiers are shown in Fig. 7. Note that the data in the qCNN has one more
rank than that in CNN, and in numerical programs, this extra dimension—
_Depth_ is used to store the quaternion [referred to Eq. (17)]. As you can see
in the Fig. 7, the architecture of the qCNN is one layer more than the CNN’s,
the total network parameters of the qCNN is however less than the CNN’s. This
is one advantage of the qCNN over the conventional CNN.

In order for classifiers to satisfy some physically reasonable conditions,
three special designs are needed. Firstly, we extend the $k$ points out of the
BZ by padding the input data according to the periodic boundary conditions
[58].

Figure 8: Schematic of “overlap” convolution (red solid) and “non-overlap”
convolution (blue solid) from a $3\times 3$ filter (black dotted) over data.
The blue solid square is a signal movement from the filter, and the size of
stride is the same as the length of filter, thus each movement of this filter
is “non-overlap”.

Secondly, a convolutional layer (q-Conv layer in the qCNN) with arctangent
activation function is then adopted, which contains 27 filters of kernel size
$2\times 2$. This layer executes an “overlapping” feature mapping. (Figure 8
illustrates how the “overlapping” and “non-overlapping” feature mapping can be
manipulated by varying the size of stride.) Thirdly. we shrink the $k$ space
of data into “a point” by three non-overlapping convolutional layers. In the
qCNN, three 3D convolutional layers are applied while keeping four Depths
independent. In particular, we additionally append a 2D convolutional layer to
make combination Depths-wisely. Specifically, this layer with 9 filters of
kernel size $4\times 1$ transforms data from $4\times 9$ to $1\times 9$, where
each of nine neurons corresponds to one topological class. In comparison, the
conventional CNN shrinks the $k$-space to a point in each of nine _Channels_ ,
where the dimension is integrated out after the convolution. More details and
descriptions are relative to the SEC. V.

Figure 9: Learning curves of the qCNN and CNN classifiers. By applied
_Dropout_ , the validation is greater than the training.

In the following, we perform both the qCNN and conventional CNN trainings. The
learning curves of both machines are shown in Fig. 9. The CNN machine (orange
and light orange lines) jumps over a big learning barrier at around the
$700^{th}$ epoch. After that, the training and the validation accuracy (orange
and light orange line respectively) are separated and do not converge up to
end of this training process. Even though the same training (and validation)
dataset is used in the training process, the learning curves of the qCNN
machine (blue and light blue lines) are qualitatively different. The training
and the validation accuracy are separated around $90^{th}$ epoch, but the
difference between these two accuracies decreases with increasing epochs.
After the training procedure finished, the qCNN (CNN) machine gets 99.67%
(94.12%) testing accuracy. This difference in accuracy results from the spin-
vortex dataset, where the qCNN works well but CNN dose not.

The trained machines are ready to do prediction, and the result is shown in
Fig. 10.

Figure 10: The performance of the qCNN (blue line) and CNN (red dashed line)
on the prediction datasets. Numbers tagged are the values of the accuracies.
Standard deviations (by error bars) are also provided. The qCNN outperforms
the conventional CNN on all prediction datasets, especially on three spin-
vortex ones

In Fig. 10, since the first category contains $\mathbf{n}$ of uniformly
distributed $m$, where a few data points are very close to the phase
boundaries $m\approx\\{0,\pm 2\\}$, the accurate rate of the the qCNN is
slightly low at $96\%$. For the second and third categories, we choose $m=\pm
1$, away from the phase transition points, and the performance is nearly
perfect. For the uncompleted winding configurations, the qCNN, different from
the conventional CNN, can accurately classifies FM, helical and conical states
after learning the spin-vortex states. This is the main advantage of the qCNN
over the conventional CNN, which is expected to result from the quaternion
algebra.

##  V discussions

On PCA the reason why we choose spinor state vector $\ket{u}$, not the spin
normalized vector $\mathbf{n}$ as data is that the gauge discontinuities exist
in the non-trivial $\ket{u}$, but not in $\mathbf{n}$’s. It turns out that the
function $F$ can detect the existence of this discontinuity so that trivial
and non-trivial states can be distinguished by PCA. Above statement is further
supported by the relation between $\ket{u}$ and $\mathbf{n}$ in pure state,
which is known as

$\mathbf{n}(\vec{k})=\bra{u_{+}(\vec{k})}\boldsymbol{\sigma}\ket{u_{+}(\vec{k})}.$
(18)

In Eq. (18), the $U(1)$ ambiguity of $\ket{u}$ is eliminated effectively,
thus, there is no discontinuities to be detected by PCA in $\mathbf{n}$. There
is another issue if we use n as the data in PCA. If we encode
$\mathbf{n}=(n_{x},n_{y},n_{z})$ into a quaternion in the following form,

$q:=(0,~{}n_{x},~{}n_{y},~{}n_{z}),$

the corresponding convolution [Eq. (15)] will not depend on the sign of $m$.
It can be shown that there exists one point
$\vec{k}^{\prime}\to\vec{p}_{0}-\vec{k}+\pi$ in BZ such that

$n_{z}(\vec{k},m_{0})n_{z}(\vec{p}_{0}-\vec{k},m_{0})=n_{z}(\vec{k}^{\prime},-m_{0})n_{z}(\vec{p}_{0}-\vec{k}^{\prime},-m_{0}).$

That is, for two spin configurations with opposite sign $m_{0}$, their $n_{z}$
products are equal at $\vec{k}$ and $\vec{k}^{\prime}$ respectively. As shown
in Eq. (3), m shows up only in the $n_{z}$ component. Therefore, after the
integration over the whole BZ, the convolution is independent of the sign of
$m$ and there is no feature for PCA to discriminate distinct topological
states.

Figure 11: (a) Three nearest neighborhood spin vectors will contribute a solid
angle, and (b) four nearest neighbors are enclosed by the filters in the first
convolutional layer.

On qCNN, there are several possible factors promoting the performance of our
supervised learning machine. The first one is that the size of filter in the
first convolutional layer is 2 × 2 with stride = 1, which means the machine
can collect spin information among four nearest neighbors [see Fig. 11(b)]. We
know that the Chern number is the integral of the Berry curvature in the BZ,
and the Berry curvature is twice of the solid angle. A solid angle $\Omega$
subtended by three normalized vectors $\vec{a}$, $\vec{b}$, $\vec{c}$, can be
calculated using the following equation:

$\tan{\frac{\boldsymbol{\Omega}}{2}}=\frac{\absolutevalue{\vec{a}\cdot(\vec{b}\times\vec{c})}}{1+\vec{a}\cdot\vec{b}+\vec{b}\cdot\vec{c}+\vec{c}\cdot\vec{a}}.$
(19)

Our choice of the size of the filter in the first hidden layer is the minimal
of $2\times 2$ that mixes only the nearest-neighboring spins. In this way, it
is very possible to enforce the machine to notice the solid angle extended in
this plaquette. The second factor is the quaternion product. Recall that the
conventional CNN might correlate spins $\mathbf{n}^{\prime}s$ in neighboring
$\vec{k}^{\prime}s$ due to the feature map through the kernel. However, the
map does not mix the components of spins. In comparison, the qCNN is more
efficient for it directly entangle spins via the quaternion product. It is
this entanglement of spin components by the quaternion product that makes the
scalar and vector products in calculating the solid angle (see Eq. (19))
become possible to be realized by the machine. As a solid angle involves at
least three spins and the feature map by the kernel is just linear, a
nonlinear transformation is crucial to create high-order (three spins) terms
in the expansion. Based on this argument, the third factor is the non-linear
activation function [59], which is an arctangent function in this work. Based
on Eq. (19), the calculation of a solid angle involves the arctan operation.
Therefore, we expect that using the arctangent function as the activation
function can further help the machine to learn correct representations. This
idea is further supported by the results shown in Fig. 12, where the
arctangent activation function outperforms the ReLU and tanh activation
functions over nine different datasets. In summary, several factors are
combined to enhance the performance of our machine as follows. The quaternion-
based operations in the q-Conv layer mix not only different components of a
spin $\mathbf{n}(\vec{k}_{0})$ but also neighbouring spins, say
$\mathbf{n}(\vec{k}_{0})$ and $\mathbf{n}(\vec{k}_{1})$. When these linear
combinations are fed into the non-linear activation functions in our qCNN, the
output can be viewed as an expansion of a non-linear function, which may
contain a term having both the scalar- and vector-product of neighboring
spins, similar to that in Eq. (19). Therefore, in the optimization process,
combined with the effect of choosing the size of filter to be $2\times 2$, the
machine may keep increasing the weight of a solid-angle-related term and
eventually learn to classify the topological phases based on the calculated
solid angles.

Also, adding some noises to the training dataset helped our supervised-
learning machine to learn the generic feature of our data. We found that when
the training data was generated directly from Eq. (3) without adding any
noise, the machine worked well for training and testing datasets but had poor
performance on all the prediction dataset. This could be understood by noting
that topology is determined by the sign of $m$, which appears only in the z
component in Eq. (3). By using the dataset without noises, the machine may
learn to classify states only by looking at the $z-$component but not
extracting the full information from the full configuration. When we gave
random transition and rotation to each training data, the machine had to
examine all three components in order to have correction predictions. From our
observations, the performance on the prediction dataset was remarkably
enhanced when the noise was added, which supports our ideas.

Figure 12: Comparison between three activation function applied in the first
layer of the qCNN classifier.

##  VI Conclusions

In summary, we classify topological phases with distinct Chern numbers via two
types of machine-learning algorithms. For the unsupervised part, we propose a
quaternion-based convolution to transform the topological states into the
input data. With this convolution, distinct topological states are
successfully classified by PCA, a linear machine for classification.

We then go to the supervised learning part where, in contrast to the
conventional CNN, we successfully use the qCNN to classify different
topological phases. This work demonstrates the power of quaternion-based
algorithm, especially for the topological systems with the Chern number as the
topological invariants.

###### Acknowledgements.

This study is supported by the Ministry of Science and Technology (MoST) in
Taiwan under grant No. 108-2112-M-110-013-MY3. M.R.L. and W.J.L. contributed
equally to this work.

##  Appendix A Data preparation

_Training dataset_ — The normalized spin configurations $\mathbf{n}(\vec{k})$
are given in the following [referred to the Eq. (3)]

$\begin{split}\mathbf{n}:=&\mathbf{h}/\absolutevalue{\mathbf{h}},\quad\textrm{where}\\\
&\mathbf{h}(\vec{k})[m,c]=\begin{pmatrix}\
\mathrm{Re}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
-\mathrm{Im}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
\cos{k_{x}}+\cos{k_{y}}+m\end{pmatrix}\end{split}$

in a $40\times 40$ square lattice with periodic boundary conditions. For each
$c(\in\\{1,2,3,4\\})$, we generated 1440 spin configurations. That is totally
5760 normalized spin configurations $\mathbf{n}(\vec{k})$ throughout nine
topological states of Chern number ranging from -4 to 4. For given $c$ and
$m$, each of spin configurations is under data augmentation and Gaussian
noise. The details are in the following. For a given spin configuration,
$\mathbf{n}(\vec{k})$, we produce its multiple derivatives through a random
translation ($\mathcal{T}$) and a random rotation ($\mathcal{R}$) in three
dimensions:

$\mathbf{n}(\vec{k})\xrightarrow{\mathcal{T}}\mathbf{n}(\vec{k}+\vec{p}_{0})\xrightarrow{\mathcal{R}}\mathbf{n}^{\prime}(\vec{k}+\vec{p}_{0})\xrightarrow{\mathcal{G}}\mathbf{n}^{\prime}(\vec{k}+\vec{p}_{0})+\Delta\mathbf{n}^{\prime}(\vec{k})$
(20)

where $\vec{p}_{0}$ is a random displacement in $k$ space, and the operation
$\mathcal{R}$ stands for applying the $3\times 3$ rotation matrix on whole
configuration with arbitrary Euler angles. After data augmentation, we further
applied three-component Gaussian noise ($\mathcal{G}$) with $0.1\pi$ standard
deviation (SD) at randomly chosen 30 out of 1600 spin vectors for each spin
configuration.

Here, we provide more details about the data generation. For each $c$ we
generated four sets $S_{1}^{(c)},S_{2}^{(c)}$, $S_{3}^{(c)}$ and
$S_{4}^{(c)}$. Each of the first-two sets contains 640 topologically
nontrivial states:

$\begin{matrix}S_{1}^{(c)}=&\big{\\{}\mathbf{n}\Big{|}m\in[-1.9,-0.1]\big{\\}},\\\
S_{2}^{(c)}=&\big{\\{}\mathbf{n}\Big{|}m\in[0.1,1.9]\big{\\}}.\end{matrix}$

Each of the rest two sets contains 80 topologically trivial states:

$\begin{matrix}S_{3}^{(c)}=&\big{\\{}\mathbf{n}\Big{|}m=-3\big{\\}},\\\
S_{4}^{(c)}=&\big{\\{}\mathbf{n}\Big{|}m=3\big{\\}}.\end{matrix}$

That is, for each $c$ we have 1280 nontrivial spin configurations and 160
trivial ones. Thus, the 5760 spin configurations are evenly divided into nine
topological phases, each of which contains 640 spin configurations. In the
training data, we also include 360 spin vortice states, which are $C=0$
states, according to the following models:

$\mathbf{h}_{yz}(\vec{k})=\begin{pmatrix}0\\\
-\mathrm{Im}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
\cos{k_{x}}+\cos{k_{y}}+m\end{pmatrix}$ (21)
$\mathbf{h}_{xz}(\vec{k})=\begin{pmatrix}\
\mathrm{Re}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\ 0\\\
\cos{k_{x}}+\cos{k_{y}}+m\end{pmatrix}$ (22)
$\mathbf{h}_{xy}(\vec{k})=\begin{pmatrix}\
\mathrm{Re}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
-\mathrm{Im}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\ 0\end{pmatrix}$
(23)

For each $c$, 30 spin configurations are generated using each of the models
above with uniformly distributed $m$ ranging from -3 to 3. We therefore have
totally 360 trivial states generated using different $c$ and $m$. After the
process, we have totally 6120 spin configurations as the training dataset.

After generating the training dataset, 25% of the training data are assigned
as the validation dataset (light color lines in Fig. 9). Therefore, two
dataset are prepared under data augmentation and noise for the supervised
learning procedure.

_Testing dataset_ — In addition to the training and validation dataset, we
prepare extra 1224 spin configurations as the testing dataset, with the same
composition as the training and validation datasets. This dataset is prepared
for scoring the trained classifiers.

_Prediction dataset_ — The prediction dataset is an extra dataset, different
from the aforementioned three datasets. It consists of six categories, each of
which is not seen by the machine during the training process. This dataset is
processed by the data augmentation but without adding the Gaussian noise. The
six categories are constructed as following. The First category, the “chern”
category, is a set $S$ which is generated from Eq. (3) with 30 $m$’s uniformly
ranging from -3 to 3 for $c$:

$S=\big{\\{}\mathbf{n}^{(c)}\Big{|}c=1,2,3,4,~{}m=-3+\frac{6i}{29},~{}i=0,...,29\big{\\}}$

As a reminder, this category is different from the training dataset. The
training data includes the specific $m=\pm 3$ at trivial phase, and two
intervals $\\{\left[-1.9,-0.1\right]$ and $\left[0.1,1.9\right]\\}$ at
nontrivial phases. Therefore, 20% of this category is close to the phase
transition $m\approx\\{0,+2,-2\\}$.

The next two categories are generated based on the Eq. (3) with $m=\pm 1$. The
first one is constructed by changing the sign of the $z$-component:

$\begin{split}\mathbf{h}(\vec{k})=\begin{pmatrix}\
\mathrm{Re}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
-\mathrm{Im}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
\cos{k_{x}}+\cos{k_{y}}+m\end{pmatrix}\\\ \to\begin{pmatrix}\
\mathrm{Re}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
-\mathrm{Im}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
-\cos{k_{x}}-\cos{k_{y}}-m\end{pmatrix}=\mathbf{h}^{\prime}(\vec{k}).\end{split}$

The second one is constructed by swapping the $y-$component and the
$z-$component:

$\begin{split}\mathbf{h}(\vec{k})=\begin{pmatrix}\
\mathrm{Re}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
-\mathrm{Im}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
\cos{k_{x}}+\cos{k_{y}}+m\end{pmatrix}\\\ \to\begin{pmatrix}\
\mathrm{Re}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\\\
\cos{k_{x}}+\cos{k_{y}}+m\\\
-\mathrm{Im}\big{[}(\sin{k_{x}}-i\sin{k_{y}})^{c}\big{]}\end{pmatrix}=\mathbf{h}^{\prime}(\vec{k}).\end{split}$

The next two categories, called conical and helical spin configurations, are
generated based on the following equation

$\mathbf{n}_{\mathrm{spiral/conical}}(\vec{k})=\begin{pmatrix}\sqrt{1-\epsilon^{2}}\cos{(k_{x}+k_{y})}\\\
\sqrt{1-\epsilon^{2}}\sin{(k_{x}+k_{y})}\\\ \epsilon\end{pmatrix}.$

Here $\epsilon=0$ is for the helical state and $0<|\epsilon|<1$ is for a
conical state. The last category contains the ferromagnetic spin
configurations where the z-component is a constant and x- and y-component are
zero.

##  Appendix B Quaternion

The quaternion number system were introduced by Irish mathematician William
Rowan Hamilton in 1843 as an extension of the complex numbers. A quaternion
number $q$ is composed of four real numbers $r,~{}a,~{}b$ and $c$ to be

$q=r+a\hat{\mathbf{i}}+b\hat{\mathbf{j}}+c\hat{\mathbf{k}},$ (24)

where
$\\{\boldsymbol{1},~{}\hat{\mathbf{i}},~{}\hat{\mathbf{j}},~{}\hat{\mathbf{k}}\\}$
is the basis. Sometimes it is written as $q=(r,\ \vec{v})$ or $q=(r,a,b,c)$ in
short. Here $r$ is called the scalar (or real) part of the quaternion and
$\vec{v}=(a,b,c)$ the vector (or imaginary) part. A quaternion without scalar
part $q=(0,a,b,c)$ is called _pure quaternion_. Similar to the imaginary
number,

$\hat{\mathbf{i}}^{2}=\hat{\mathbf{j}}^{2}=\hat{\mathbf{k}}^{2}=\hat{\mathbf{i}}\hat{\mathbf{j}}\hat{\mathbf{k}}=-\boldsymbol{1}.$
(25)

Importantly, the algebra of quaternions is noncommutative, based on

$\displaystyle\boldsymbol{1}\hat{\mathbf{i}}=\hat{\mathbf{i}}\boldsymbol{1}=\hat{\mathbf{i}},\quad\boldsymbol{1}\hat{\mathbf{j}}=\hat{\mathbf{j}}\boldsymbol{1}=\hat{\mathbf{j}},\quad\boldsymbol{1}\hat{\mathbf{k}}=\hat{\mathbf{k}}\boldsymbol{1}=\hat{\mathbf{k}},$
(26)
$\displaystyle\hat{\mathbf{i}}\hat{\mathbf{j}}=-\hat{\mathbf{j}}\hat{\mathbf{i}}=\hat{\mathbf{k}},\quad\hat{\mathbf{j}}\hat{\mathbf{k}}=-\hat{\mathbf{k}}\hat{\mathbf{j}}=\hat{\mathbf{i}},\quad\mathrm{and}\quad\hat{\mathbf{k}}\hat{\mathbf{i}}=-\hat{\mathbf{i}}\hat{\mathbf{k}}=\hat{\mathbf{j}}.$

The conjugate of the quaternion is defined to be

$q^{*}=r-a\hat{\mathbf{i}}-b\hat{\mathbf{j}}-c\hat{\mathbf{k}},$ (27)

and the norm is given by

$||q||=\sqrt{qq^{*}}=\sqrt{r^{2}+a^{2}+b^{2}+c^{2}}.$ (28)

Therefore the inverse of $q$ is defined as

$q^{-1}:=\frac{q^{*}}{\norm{q}^{2}}.$ (29)

If $q$ is unit quaternion, then their inverse is exactly their conjugate. The
multiplication (so-called Hamilton product) of two quaternions
$q_{1}=(r_{1},~{}a_{1},~{}b_{1},~{}c_{1})$ and
$q_{2}=(r_{2},~{}a_{2},~{}b_{2},~{}c_{2})$ is given by

$\begin{split}q_{1}q_{2}&=(r_{1}r_{2}-a_{1}a_{2}-b_{1}b_{2}-c_{1}c_{2})\\\
&\quad+(a_{1}r_{2}+r_{1}a_{2}-c_{1}b_{2}+b_{1}c_{2})\hat{\mathbf{i}}\\\
&\quad+(b_{1}r_{2}+c_{1}a_{2}+r_{1}b_{2}-a_{1}c_{2})\hat{\mathbf{j}}\\\
&\quad+(c_{1}r_{2}-b_{1}a_{2}+a_{1}b_{2}+r_{1}c_{2})\hat{\mathbf{k}}\\\
&=(r_{1}r_{2}-\vec{v}_{1}\cdot\vec{v}_{2},~{}r_{1}\vec{v}_{2}+r_{2}\vec{v}_{1}+\vec{v}_{1}\times\vec{v}_{2}).\end{split}$
(30)

To realize the algebra in Eqs. (25) and (26), one can choose the
$\mathcal{M}(4,\mathbb{R})$ representation for the quaternion numbers with

$\begin{split}\boldsymbol{1}\doteq&\begin{pmatrix}1&0&0&0\\\ 0&1&0&0\\\
0&0&1&0\\\ 0&0&0&1\end{pmatrix},\
\hat{\mathbf{i}}\doteq\begin{pmatrix}[r]0&-1&0&0\\\ 1&0&0&0\\\ 0&0&0&-1\\\
0&0&\ 1&0\end{pmatrix},\\\
&\hat{\mathbf{j}}\doteq\begin{pmatrix}[r]0&0&-1&0\\\ 0&0&0&\ 1\\\ 1&0&0&0\\\
0&-1&0&0\end{pmatrix},\ \mathrm{and}\
\hat{\mathbf{k}}\doteq\begin{pmatrix}[r]0&0&0&-1\\\ 0&0&-1&0\\\ 0&\ 1&0&0\\\
1&0&0&0\end{pmatrix},\end{split}$

so that

$q\doteq\begin{pmatrix}[r]r&-a&-b&-c\\\ a&r&-c&b\\\ b&c&r&-a\\\
c&-b&a&r\end{pmatrix}.$

Reversely,

$r=\frac{1}{4}\mathrm{tr}(q),~{}a=-\frac{1}{4}\mathrm{tr}(\hat{\mathbf{i}}q),~{}b=-\frac{1}{4}\mathrm{tr}(\hat{\mathbf{j}}q),~{}c=-\frac{1}{4}\mathrm{tr}(\hat{\mathbf{k}}q).$

It is evident that in terms of matrices the commutativity of multiplication of
quaternions dose not hold. Furthermore, in the matrix representation
$q^{*}=q^{T}$, conjugation of a quaternion being equal to its transposition.
More specifically, an unit quaternion have a property $q^{-1}=q^{*}=q^{T}$ in
the $\mathcal{M}(4,\mathbb{R})$ representations.

## References

  * Carrasquilla and Melko [2017] J. Carrasquilla and R. G. Melko, Machine learning phases of matter, Nature Physics 13, 431 (2017).
  * Bedolla  _et al._ [2020] E. Bedolla, L. C. Padierna, and R. Castañeda-Priego, Machine learning for condensed matter physics, Journal of Physics: Condensed Matter 33, 053001 (2020).
  * Mehta  _et al._ [2019] P. Mehta, M. Bukov, C.-H. Wang, A. G. Day, C. Richardson, C. K. Fisher, and D. J. Schwab, A high-bias, low-variance introduction to machine learning for physicists, Physics reports 810, 1 (2019).
  * Beach  _et al._ [2018] M. J. Beach, A. Golubeva, and R. G. Melko, Machine learning vortices at the kosterlitz-thouless transition, Physical Review B 97, 045207 (2018).
  * Yoshioka  _et al._ [2018] N. Yoshioka, Y. Akagi, and H. Katsura, Learning disordered topological phases by statistical recovery of symmetry, Physical Review B 97, 205110 (2018).
  * Carvalho  _et al._ [2018] D. Carvalho, N. A. García-Martínez, J. L. Lado, and J. Fernández-Rossier, Real-space mapping of topological invariants using artificial neural networks, Physical Review B 97, 115453 (2018).
  * Balabanov and Granath [2020a] O. Balabanov and M. Granath, Unsupervised learning using topological data augmentation, Physical Review Research 2, 013354 (2020a).
  * Balabanov and Granath [2020b] O. Balabanov and M. Granath, Unsupervised interpretable learning of topological indices invariant under permutations of atomic bands, Machine Learning: Science and Technology 2, 025008 (2020b).
  * Greplova  _et al._ [2020] E. Greplova, A. Valenti, G. Boschung, F. Schäfer, N. Lörch, and S. D. Huber, Unsupervised identification of topological phase transitions using predictive models, New Journal of Physics 22, 045003 (2020).
  * Ho and Wang [2021] C.-T. Ho and D.-W. Wang, Robust identification of topological phase transition by self-supervised machine learning approach, New Journal of Physics 23, 083021 (2021).
  * Zhang  _et al._ [2021] L.-F. Zhang, L.-Z. Tang, Z.-H. Huang, G.-Q. Zhang, W. Huang, and D.-W. Zhang, Machine learning topological invariants of non-hermitian systems, Physical Review A 103, 012419 (2021).
  * Narayan and Narayan [2021] B. Narayan and A. Narayan, Machine learning non-hermitian topological phases, Physical Review B 103, 035413 (2021).
  * Yu and Deng [2021] L.-W. Yu and D.-L. Deng, Unsupervised learning of non-hermitian topological phases, Physical Review Letters 126, 240402 (2021).
  * Zhang and Kim [2017] Y. Zhang and E.-A. Kim, Quantum loop topography for machine learning, Physical review letters 118, 216401 (2017).
  * Cheng  _et al._ [2018] Q.-Q. Cheng, W.-W. Luo, A.-L. He, and Y.-F. Wang, Topological quantum phase transitions of chern insulators in disk geometry, Journal of Physics: Condensed Matter 30, 355502 (2018).
  * Sun  _et al._ [2018] N. Sun, J. Yi, P. Zhang, H. Shen, and H. Zhai, Deep learning topological invariants of band insulators, Physical Review B 98, 085402 (2018).
  * Zhang  _et al._ [2020] Y. Zhang, P. Ginsparg, and E.-A. Kim, Interpreting machine learning of topological quantum phase transitions, Physical Review Research 2, 023283 (2020).
  * Kerr  _et al._ [2021] A. Kerr, G. Jose, C. Riggert, and K. Mullen, Automatic learning of topological phase boundaries, Physical Review E 103, 023310 (2021).
  * Käming  _et al._ [2021] N. Käming, A. Dawid, K. Kottmann, M. Lewenstein, K. Sengstock, A. Dauphin, and C. Weitenberg, Unsupervised machine learning of topological phase transitions from experimental data, Machine Learning: Science and Technology 2, 035037 (2021).
  * Rem  _et al._ [2019] B. S. Rem, N. Käming, M. Tarnowski, L. Asteria, N. Fläschner, C. Becker, K. Sengstock, and C. Weitenberg, Identifying quantum phase transitions using artificial neural networks on experimental data, Nature Physics 15, 917 (2019).
  * Che  _et al._ [2020] Y. Che, C. Gneiting, T. Liu, and F. Nori, Topological quantum phase transitions retrieved through unsupervised machine learning, Physical Review B 102, 134213 (2020).
  * Chung  _et al._ [2021] M.-C. Chung, T.-P. Cheng, G.-Y. Huang, and Y.-H. Tsai, Deep learning of topological phase transitions from the point of view of entanglement for two-dimensional chiral p-wave superconductors, Physical Review B 104, 024506 (2021).
  * Ming  _et al._ [2019] Y. Ming, C.-T. Lin, S. D. Bartlett, and W.-W. Zhang, Quantum topology identification with deep neural networks and quantum walks, npj Computational Materials 5, 1 (2019).
  * Zhang  _et al._ [2018] P. Zhang, H. Shen, and H. Zhai, Machine learning topological invariants with neural networks, Physical review letters 120, 066401 (2018).
  * Holanda and Griffith [2020] N. Holanda and M. Griffith, Machine learning topological phases in real space, Physical Review B 102, 054107 (2020).
  * Tsai  _et al._ [2021] Y.-H. Tsai, K.-F. Chiu, Y.-C. Lai, K.-J. Su, T.-P. Yang, T.-P. Cheng, G.-Y. Huang, and M.-C. Chung, Deep learning of topological phase transitions from entanglement aspects: An unsupervised way, Physical Review B 104, 165108 (2021).
  * Zhang  _et al._ [2017] Y. Zhang, R. G. Melko, and E.-A. Kim, Machine learning z 2 quantum spin liquids with quasiparticle statistics, Physical Review B 96, 245119 (2017).
  * Mano and Ohtsuki [2019] T. Mano and T. Ohtsuki, Application of convolutional neural network to quantum percolation in topological insulators, Journal of the Physical Society of Japan 88, 123704 (2019).
  * Su  _et al._ [2019] Z. Su, Y. Kang, B. Zhang, Z. Zhang, and H. Jiang, Disorder induced phase transition in magnetic higher-order topological insulator: A machine learning study, Chinese Physics B 28, 117301 (2019).
  * Lian  _et al._ [2019] W. Lian, S.-T. Wang, S. Lu, Y. Huang, F. Wang, X. Yuan, W. Zhang, X. Ouyang, X. Wang, X. Huang, _et al._ , Machine learning topological phases with a solid-state quantum simulator, Physical review letters 122, 210503 (2019).
  * Richter-Laskowska  _et al._ [2018] M. Richter-Laskowska, H. Khan, N. Trivedi, and M. M. Maśka, A machine learning approach to the berezinskii-kosterlitz-thouless transition in classical and quantum models, arXiv preprint arXiv:1809.09927 (2018).
  * Zhang  _et al._ [2019] W. Zhang, J. Liu, and T.-C. Wei, Machine learning of phase transitions in the percolation and x y models, Physical Review E 99, 032142 (2019).
  * Rodriguez-Nieva and Scheurer [2019] J. F. Rodriguez-Nieva and M. S. Scheurer, Identifying topological order through unsupervised machine learning, Nature Physics 15, 790 (2019).
  * Tsai  _et al._ [2020] Y.-H. Tsai, M.-Z. Yu, Y.-H. Hsu, and M.-C. Chung, Deep learning of topological phase transitions from entanglement aspects, Physical Review B 102, 054512 (2020).
  * Scheurer and Slager [2020] M. S. Scheurer and R.-J. Slager, Unsupervised machine learning and band topology, Physical review letters 124, 226401 (2020).
  * Caio  _et al._ [2019] M. D. Caio, M. Caccin, P. Baireuther, T. Hyart, and M. Fruchart, Machine learning assisted measurement of local topological invariants, arXiv preprint arXiv:1901.03346 (2019).
  * Trabelsi  _et al._ [2018] M. Trabelsi, P. Kakosimos, and H. Komurcugil, Mitigation of grid voltage disturbances using quasi-z-source based dynamic voltage restorer, in  _2018 IEEE 12th International Conference on Compatibility, Power Electronics and Power Engineering (CPE-POWERENG 2018)_ (IEEE, 2018) pp. 1–6.
  * Gaudet and Maida [2018] C. J. Gaudet and A. S. Maida, Deep quaternion networks, in  _2018 International Joint Conference on Neural Networks (IJCNN)_ (IEEE, 2018) pp. 1–8.
  * García-Retuerta  _et al._ [2020] D. García-Retuerta, R. Casado-Vara, A. Martin-del Rey, F. De la Prieta, J. Prieto, and J. M. Corchado, Quaternion neural networks: state-of-the-art and research challenges, in  _International Conference on Intelligent Data Engineering and Automated Learning_ (Springer, 2020) pp. 456–467.
  * Isokawa  _et al._ [2009] T. Isokawa, N. Matsui, and H. Nishimura, Quaternionic neural networks: Fundamental properties and applications, in  _Complex-valued neural networks: utilizing high-dimensional parameters_ (IGI global, 2009) pp. 411–439.
  * Parcollet  _et al._ [2020] T. Parcollet, M. Morchid, and G. Linarès, A survey of quaternion neural networks, Artificial Intelligence Review 53, 2957 (2020).
  * Matsui  _et al._ [2004] N. Matsui, T. Isokawa, H. Kusamichi, F. Peper, and H. Nishimura, Quaternion neural network with geometrical operators, Journal of Intelligent & Fuzzy Systems 15, 149 (2004).
  * Zhu  _et al._ [2018] X. Zhu, Y. Xu, H. Xu, and C. Chen, Quaternion convolutional neural networks, in  _Proceedings of the European Conference on Computer Vision (ECCV)_ (2018) pp. 631–647.
  * Hongo  _et al._ [2020] S. Hongo, T. Isokawa, N. Matsui, H. Nishimura, and N. Kamiura, Constructing convolutional neural networks based on quaternion, in  _2020 International Joint Conference on Neural Networks (IJCNN)_ (IEEE, 2020) pp. 1–6.
  * Parcollet  _et al._ [2018a] T. Parcollet, Y. Zhang, M. Morchid, C. Trabelsi, G. Linarès, R. De Mori, and Y. Bengio, Quaternion convolutional neural networks for end-to-end automatic speech recognition, arXiv preprint arXiv:1806.07789 (2018a).
  * Grassucci  _et al._ [2022] E. Grassucci, E. Cicero, and D. Comminiello, Quaternion generative adversarial networks, in  _Generative Adversarial Learning: Architectures and Applications_ (Springer, 2022) pp. 57–86.
  * Grassucci  _et al._ [2021] E. Grassucci, D. Comminiello, and A. Uncini, A quaternion-valued variational autoencoder, in  _ICASSP 2021-2021 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)_ (IEEE, 2021) pp. 3310–3314.
  * Nguyen  _et al._ [2021] T. D. Nguyen, D. Phung, _et al._ , Quaternion graph neural networks, in  _Asian Conference on Machine Learning_ (PMLR, 2021) pp. 236–251.
  * Özcan  _et al._ [2021] B. Özcan, F. Kinli, and F. Kiraç, Quaternion capsule networks, in  _2020 25th International Conference on Pattern Recognition (ICPR)_ (IEEE, 2021) pp. 6858–6865.
  * Parcollet  _et al._ [2018b] T. Parcollet, M. Ravanelli, M. Morchid, G. Linarès, and R. De Mori, Speech recognition with quaternion neural networks, arXiv preprint arXiv:1811.09678 (2018b).
  * Girard [1984] P. R. Girard, The quaternion group and modern physics, European Journal of Physics 5, 25 (1984).
  * Girard and Baylis [2008] P. R. Girard and W. E. Baylis, Quaternions, clifford algebras and relativistic physics, SIAM review 50, 382 (2008).
  * Girard  _et al._ [2018] P. R. Girard, P. Clarysse, R. Pujol, R. Goutte, and P. Delachartre, Hyperquaternions: a new tool for physics, Advances in Applied Clifford Algebras 28, 1 (2018).
  * Qi  _et al._ [2006] X.-L. Qi, Y.-S. Wu, and S.-C. Zhang, Topological quantization of the spin hall effect in two-dimensional paramagnetic semiconductors, Phys. Rev. B 74, 085308 (2006).
  * Jolliffe and Cadima [2016] I. T. Jolliffe and J. Cadima, Principal component analysis: a review and recent developments, Philosophical Transactions of the Royal Society A: Mathematical, Physical and Engineering Sciences 374, 20150202 (2016).
  * Ma and Fu [2012] Y. Ma and Y. Fu,  _Manifold learning theory and applications_ , Vol. 434 (CRC press Boca Raton, FL, 2012).
  * Chollet [2021] F. Chollet,  _Deep learning with Python_ (Simon and Schuster, 2021).
  * Efthymiou  _et al._ [2019] S. Efthymiou, M. J. S. Beach, and R. G. Melko, Super-resolving the ising model with convolutional neural networks, Phys. Rev. B 99, 075113 (2019).
  * Lin  _et al._ [2017] H. R. Lin, M. Tegmark, and D. Rolnick, Why does deep and cheap learning work so well?, Journal of Statistical Physics 168, 1223 (2017).