0% found this document useful (0 votes)
4 views

1 DQuantum Convolutional Neural Networkfor Time Series Forecastingand Classification

Uploaded by

madhumita mishra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

1 DQuantum Convolutional Neural Networkfor Time Series Forecastingand Classification

Uploaded by

madhumita mishra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/375518556

1D Quantum Convolutional Neural Network for Time Series Forecasting and


Classification

Chapter · November 2023


DOI: 10.1007/978-3-031-47765-2_2

CITATIONS READS

0 145

5 authors, including:

Mayra Alejandra Rivera-Ruiz Andres Mendez-Vazquez


Center for Research and Advanced Studies of the National Polytechnic Institute Center for Research and Advanced Studies of the National Polytechnic Institute
4 PUBLICATIONS 15 CITATIONS 39 PUBLICATIONS 208 CITATIONS

SEE PROFILE SEE PROFILE

Eduardo Rodriguez-Tello
Center for Research and Advanced Studies of the National Polytechnic Institute
76 PUBLICATIONS 660 CITATIONS

SEE PROFILE

All content following this page was uploaded by Andres Mendez-Vazquez on 08 December 2023.

The user has requested enhancement of the downloaded file.


1D Quantum Convolutional Neural
Network for Time Series Forecasting
and Classification

Mayra Alejandra Rivera-Ruiz1(B) , Sandra Leticia Juárez-Osorio1 ,


Andres Mendez-Vazquez1 , José Mauricio López-Romero2 ,
and Eduardo Rodriguez-Tello3
1
CINVESTAV Unidad Guadalajara, Av. del Bosque 1145, colonia el Bajı́o, C.P.
45019 Zapopan, Jalisco, Mexico
{mayra.rivera,sandra.juarez,andres.mendez}@cinvestav.mx
2
CINVESTAV Unidad Querétaro, Libramiento Norponiente 2000,
Fracc. Real de Juriquilla, C.P. 76230 Santiago de Querétaro, Querétaro, Mexico
[email protected]
3
CINVESTAV Unidad Tamaulipas, Km. 5.5 Carretera Victoria - Soto La Marina,
C.P. 87130 Victoria, Tamaulipas, Mexico
[email protected]

Abstract. The 1D Convolutional Neural Network (1D CNN) is a kind


of Artificial Neural Network (ANN) that has been shown to obtain state-
of-the-art performance levels on several applications with minimal com-
putational complexity and whose advantages are well established. In this
article, we propose a 1D quantum convolution, which extracts local fea-
tures by means of a quantum circuit in a way similar to the classical
convolution. In this work, we test the performance of the proposed 1D
quantum convolutional layer building a 1D Quantum Convolutional Neu-
ral Network (1D QCNN) that consists of the 1D quantum convolution
followed by classical layers. The proposed model is compared with classi-
cal models for both time series forecasting and classification tasks includ-
ing benchmark and real-world datasets. The obtained results show that
the 1D QCNN can successfully extract features from temporal data, and
in certain cases outperform classical models in terms of accuracy and
convergence.

Keywords: Quantum Neural Netwoks · Time Series

1 Introduction
Machine Learning refers to the use of statistics, mathematics, and computer
science to allow computers to learn from data. Those algorithms have been suc-
cessfully used in tasks such as classification, regression, image classification, and
forecasting, among others. On the other hand, Quantum Computing is the pro-
cessing of information in devices based on the laws of quantum theory and it
is a research field that in the last decades has had a rapid growth. It is a new
c The Author(s), under exclusive license to Springer Nature Switzerland AG 2024
H. Calvo et al. (Eds.): MICAI 2023, LNAI 14391, pp. 17–35, 2024.
https://doi.org/10.1007/978-3-031-47765-2_2
18 M. A. Rivera-Ruiz et al.

paradigm that comprises aspects of computer science and quantum mechanics,


it emerges as a solution to problems that classical computers struggle to solve
efficiently [17,25].
Recently both disciplines have been combined into hybrid algorithms of
Quantum Machine Learning (QML) with the objective of looking for advantages
such as a speed-up in the convergence of algorithms, recognizing new patterns
unable to appear in classical algorithms, obtaining better results in the usual
metrics, or dealing better with high levels of noise [11,20,25].
Different approaches exist on how to combine both disciplines according to
the type of data (classical or quantum data) and the information processing
device (classical or quantum) [25]. For the case of supervised learning problems
with classical data and a quantum device, many approaches are explored in
literature [11,20,26]. Quantum versions of classical algorithms such as support
vector machine [21], nearest neighbor [13], and decision tree [14] have been imple-
mented, exhibiting quadratic or even exponential speedups. Neural Networks are
a classical successful algorithm and, inspired in those architectures and inher-
iting some of its features [27], the Variational Quantum Circuits (VQC) have
been widely developed in recent years [4]. These VQC have also been used to
build the quantum version of Classical Convolutional Neural Networks (CNN)
[7,10,12]. Further explanation of VQC will be provided in Sect. 2.2.
In literature, many examples can be found in which the QML algorithms
outperformed or at least matched the results provided by their classical coun-
terparts, both in toy datasets [15,18,24] and in real applications such as clas-
sification of medical images [9,22,29], detection of defects in materials [32] and
time series forecasting [2]. In particular, Quantum Convolutional Neural Net-
works (QCNNs) have been applied in toy datasets such as MNIST and Fashion
MNIST [7,10] but also in real applications, for example, the detection of protein
distance prediction [8] and the recognition of patients infected by COVID-19 [9].
This work presents a 1D Quantum Convolutional Neural Network (1D QCNN).
Our contributions lie in designing and implementing the following novel
approaches:

– We propose a 1D quantum convolutional layer that fully resembles its classical


counterpart where a quantum circuit acts as a feature detector along the input
vector.
– We propose a hybrid Quantum-Classical model: 1D Quantum Convolutional
Neural Network (1D QCNN). This model incorporates the 1D Quantum Con-
volutional layer followed by classical layers.
– We conducted a series of time series forecasting and classification experiments
to compare the performance of the proposed model with classical models.

The rest of the paper is organized as follows. Section 2 gives a background


in quantum computing. In Sect. 3, the quantum convolution and the proposed
architectures are presented. The experimental setups and results are presented
in Sect. 4. Finally, the conclusions are presented in Sect. 5.
1D Quantum Convolutional Neural Network 19

2 Preliminaries
In this section, we discuss the necessary background on the basic concepts of
quantum computing.

2.1 Quantum Computation


The concept of quantum computers was proposed by Feynman in 1982 to sim-
ulate quantum systems, especially many body systems, which would be hard to
simulate in classical computers [5]. He claimed that nature is not classical and
that if a simulation is to be done, it was necessary to develop a computer based
on quantum mechanics rules and challenged computer scientists to study this
new model. 40 years after Feynman’s idea, quantum hardware has progressed,
but the accuracy of quantum processors is still limited [19]. Even with those lim-
itations, quantum algorithms demonstrate supremacy in certain problems, such
as Shor’s algorithm for factoring with polynomial complexity or Grover’s search
algorithm with quadratic speed up with respect to its classical counterpart [17].

Quantum vs. Classical. Macroscopical systems are well defined by the laws of
classical physics but a microscopic system isolated from its surroundings exhibits
non-classical features such as [17,19]:

– Uncertainty: There is a fundamental limit in the precision with which certain


pair of complementary observables can be simultaneously known due to the
Heisenberg’s uncertainty principle.
– Collapse: In quantum mechanics, a system is described by a wave function,
which exists in a superposition of multiple possible states and when a mea-
surement is performed, the system collapses to one of them.
– Entanglement: Two or more quantum systems can be correlated in a such a
way that the state of one system cannot be described independently of the
state of the other system, regardless of the spatial separation between them.

Qubits. Analogously to the bit in classical computing, the quantum bit or


qubit is the basic unit of information processing used in quantum computing.
The qubit is a two-level quantum system hence it can be in a superposition of
the two independent states |0 and |1 until it is observed. In other words, the
state of the qubit is a combination of being |0 and |1 at the same time [17].
The basis states {|0, |1} are given by
   
1 0
|0 = and |1 = . (1)
0 1
20 M. A. Rivera-Ruiz et al.

Using Dirac’s Bra-Ket notation the state of the qubit |Ψ  can be written as:

|Ψ  = α|0 + β|1 α, β ∈ C, (2)


2
When a qubit is measured, the state |0 is obtained with probability |α| , or
2
the state |1 is obtained with probability |β| . For example, for a qubit in the
state |φ = √12 |0 + √12 |1, when measured, gives |0 fifty percent of the times
and |1 fifty percent of the times. Because the sum of probabilities must be
2 2
one α and β satisfies the normalization condition: |α| + |β| = 1, which means
geometrically that the qubit’s state is normalized to length 1 [17].
In quantum mechanics, the interactions and dynamics of particles are math-
ematically represented within the framework of the Hilbert space. The space of
n qubits is given by the tensor product space of the qubits:

|Ψ  = Cq1 ,q2 ,...,qn |q1  ⊗ |q2  ⊗ ... ⊗ |qn . (3)
(q1 ,q2 ,...,qn )∈{0,1}

With: 
Cq1 ,q2 ,...,qn 2 = 1, Cq1 ,q2 ,...,qn ∈ C. (4)
(q1 ,q2 ,...,qn )∈{0,1}

Hereafter, n denotes the number of qubits.

2.2 Quantum Circuits


Quantum gates are unitary operators (they meet the property U † U = 1) that
perform a linear transformation in qubits. This unitarity allows operations to
be reversible [17]. Those quantum operations can be applied in sequence to a
certain number of qubits, generally initialized in the state |0. This sequence
is known as a quantum circuit and the state after passing the initialized state
through it is given by:
k

|Ψ  = Ui |0⊗n , (5)
i=1

where n is the number of qubits.


The Bloch sphere is a spherical representation of the possible states of a
qubit, showing pure states at the poles and superposition states on the equator,
allowing for a visual understanding of qubit behavior. Some of the most common
gates in Quantum Computing are Pauli’s matrices σx , which flip quantum bits
from |0 to |1 and vice-versa, σy which makes a π rotation around the y axis and
σz which makes also a π rotation around the z axis. By using those Pauli matri-
ces, a rotation of the qubit in the Bloch sphere can be performed by the Pauli
θ θ θ
rotations: Rx = e−i 2 σx , Ry = e−i 2 σy and Rz = e−i 2 σz . Another common gate
is the Hadamard gate, which creates a superposition state between two qubits
{ |0+|1

2
, |0−|1

2
}. Also, other gates are capable of performing a transformation in
two or more qubits. For example, a common gate is the CNOT, which performs
1D Quantum Convolutional Neural Network 21

the NOT operation on the target qubit only when the control qubit is |1 and
otherwise leaves it unchanged [17].
As in the classical case, quantum circuits can be represented graphically,
where two gates in parallel indicate their tensor product, and two gates in series
are equal to their matrix product, where the order of appearance in the circuit
is opposite to that of multiplication.

2.3 Variational Quantum Circuits

Variational Quantum Circuits (VQC) are trainable quantum circuits that are
widely used as quantum neural networks for different tasks. VQC are quantum
algorithms that capture correlations in data using entangling properties [24]. In
today’s noisy intermediate-scale quantum computers (NISQ), which suffer from
noise and qubit limitations, the VQC is the leading strategy due to their shallow
depth [4].
In Fig. 1 the general schema of a VQA is shown. The first step is to encode
the N -dimensional classical input x = (x1 , ..., xN ) into a vector in the Hilbert
space. This is accomplished by applying a unitary transformation Uin (x) to the
initial state, which is generally chosen as |0⊗n [4]. The method for doing this
encoding is still an open question but some of the strategies to perform this step
are:

– Amplitude Encoding: The classical N features are associated with the prob-
ability amplitudes of quantum states of log2 N qubits [25]:
N
1 
Uin (x) : x ∈ RN −→ |Ψin (x) = xi |0. (6)
x i=1
– Rotation Encoding: Embeds the classical vector x of N features into N qubits
in the following way:
N 
 x  x  
i i
Uin (x) : x ∈ RN −→ |Ψin (x) = cos |0 + sin |1 , (7)
i=1
2 2

where indicates the tensor product.

After encoding the classical input, the state vector is passed through a set
of quantum operations depending on an optimizable parameter θ [4]. Now, the
encoded vector |Ψin (x) is mapped to |Ψ  = U (θ)|Ψin (x), and U (θ) can be
decomposed as L layers:
22 M. A. Rivera-Ruiz et al.

Fig. 1. Illustration of a Variational Quantum Circuit (VQC). The classical input x is


encoded into a quantum state |Ψin (x) by applying a unitary transformation Uin (θ) to
the initial quantum state |0⊗n . Then, a unitary transformation U (θ) with trainable
parameters is applied. Finally, a measurement is made on the qubits.

U = UL ...Ul ...U1 , (8)


with each layer Ul is a combination of either a single qubit rotations and multiple
qubit gate to entangle two or more qubits [24].
When the state has passed through the circuit, an observable (a physical
quantity) M is measured. This measurement is given by the expectation value,
which is given by:

M  = Ψ |M |Ψ , (9)
which means that the operator M is applied to the output state |Ψ  that comes
out of the VQC and the result of that is multiplied with Ψ |. The usual choice for
this observable is the Pauli Z operator. The circuit is calculated a number of times
S and the expectation value is obtained by averaging over the measurements
of each run. One way to map this result to a label is for example to assign
the probability of obtaining a state of the computational basis to one of the
labels. With the prediction and the actual label is possible to calculate the cost
function to perform the optimization of the trainable parameters [3]. After that,
the derivative of the expectation value is calculated with respect to the trainable
parameters in order to minimize the cost function and optimize the parameters
[3,4,23].
Although the capacity of Quantum Neural Networks (QNNs) needs to be
further explored, there are several studies that show that in certain cases they
offer advantages in terms of the number of parameters and trainability [1,16,24].
Amira Abbas et al., demonstrate that QNNs have a higher effective dimension
than classical neural networks [1].
1D Quantum Convolutional Neural Network 23

Fig. 2. Illustration of the 1D quantum convolution. A VQC is used to extract features


from the data. A VQC of n qubits slides over input tensor subsections and outputs n
features maps.

3 1D Quantum Convolution

In order to propose an extension of the classical 1D CNN, we design a 1D quan-


tum convolution. The state |Ψ  of n qubits can be represented as a unit vector
in a Hilbert space H of dimension 2n (see Eq. 3), which is high dimensional
and difficult to simulate by a classical computer. We hypothesize that the large
dimensionality of the quantum Hilbert space can benefit the extraction of mean-
ingful features from data. Moreover, quantum circuits perform well even in the
presence of noise [6]. The proposed 1D Quantum Convolution is shown in Fig. 2.
The 1D quantum convolution works in a similar way to the 1D classical
convolution. The main difference lies in the way in which the 1D quantum con-
volution performs the operations. Instead of using element-wise matrix multi-
plication operations, the 1D quantum convolution takes as input subsections of
one-dimensional signals and utilizes a VQC to create a feature map. The VQC
slides over subsections of the input tensor extracting the features. First, the
considered part is encoded into an initialized quantum state and then a parame-
terized quantum circuit is applied. The parameterized quantum circuit involves
a unitary transformation U (θ) given by Eq. 8. The optimizable parameter θ
is determined during the training. Finally, the information is decoded making
measurements on all qubits. The measurements are real numbers given by Eq. 9.
Then, by performing quantum measurements on each qubit we get each output
channel. The number of output feature maps is equal to the number of qubits.
Since the outputs of the 1D quantum convolution are vectors with real compo-
nents, we can stack the proposed quantum layer with other quantum or classical
layers.
24 M. A. Rivera-Ruiz et al.

In order to evaluate the 1D quantum convolution, we propose a hybrid


Quantum-Classical model, called 1D Quantum Convolutional Neural Network
(1D QCNN) which consists of one 1D quantum convolutional layer followed by
classical layers. The 1D QCNN is applied to two tasks: time series forecasting and
time series classification. The forecasting and classification performance of the
proposed 1D QCNN is compared with two classical models: 1D CNN and Mul-
tilayer Perceptron (MLP). The overall architecture for each time series problem
is as follows:

– Forecasting: 1D QUANV-CONV1-ReLU-POOL1-FC1-ReLU-FC2
– Classification: 1D QUANV-ReLU-POOL1-CONV1-ReLU-POOL2-CONV2-
ReLU-POOL3-FC1-ReLU-FC2

The details of each model depend on each dataset and are described in the
next section.
In both cases, for the 1D quantum convolution, a kernel of size 3 is chosen,
so 3 values have to be encoded into the quantum circuit. The data encodings for
forecasting and classification task are respectively:
n−1

|Ψin (x1 , x2 , x3 ) = Rz (x1 )Ry (x2 )Rz (x3 )|0⊗n , (10)
i=0

and
n−1

|Ψin (x1 , x2 , x3 ) = Rx (xi )|0⊗n , (11)
i=0

with n = 8 and n = 3.
In the case of the forecasting task, Eq. 10 can be seen as the repetition of
the encoding in parallel that in [28] is shown to increase the expressivity of the
model. In [28] it is shown that a quantum circuit of this kind can be written
as a partial Fourier series and then repeating the encoding would extend the
frequency spectrum. The fact that the quantum circuit can be seen as Fourier
series suggests that this approach is suitable for problems related to time series
forecasting.
Once the encoding has been done, the state vector is passed through the
variational circuit, which in this case was chosen as in Fig. 3a for the forecast-
ing problem and Fig. 3b for the classification problem. The configurations were
chosen in this way following the intuition explained in [24] which indicates that
using rotations of trainable angles does not require extra conditions for the model
parameters and that the use of entangling gates improves the expressivity of the
model. Then, the expectation value of the variable σz is measured in each qubit.
1D Quantum Convolutional Neural Network 25

Fig. 3. Parameterized Quantum Circuits (U (θ)) used for time series forecasting and
classification. U (θ) is made up of Pauli rotations with trainable angles and CNOT
gates.
26 M. A. Rivera-Ruiz et al.

Fig. 4. Actual and forecasted outputs using the 1D QCNN.

4 Results and Discussion

4.1 Time Series Forecasting

In this section, the effectiveness of the proposed quantum machine learning archi-
tectures is assessed by employing them in three standard time series datasets:
Mackey-Glass time series, Lorenz attractor, and USD-to-euro currency exchange
rate forecasting. The experiments conducted for this research utilize the built-in
Pennylane simulator lighting.qubit and PyTorch.
To ensure a fair comparison, the same optimizers, learning rates, and the
number of epochs (50 for all cases) are applied to the MLP, CNN, and the
proposed models. Additionally, the time series data is scaled using the min-max
1D Quantum Convolutional Neural Network 27

normalization formula, which confines it within the range of [0, 1]. The Adam
optimizer is utilized with a learning rate of 5e − 4. The evaluated metrics are
Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), and Mean
Absolute Percentage Error (MAPE).

Mackey-Glass Time Series. The Mackey-Glass time series data is generated


from a differential equation with the form:

ẋ = αx(t − τ ) (1 + xγ (t − τ )) − βx(t) (19), (12)


where the parameter τ represents the time delay. To obtain a numerical solution,
the Runge-Kutta method was employed, starting with an initial condition x(0) =
1.2 and using an integration step of 0.1. The values of α, β, and γ are set to 0.2,
0.1, and 10, respectively.
For building our model, we use 1000 simulation data points defined as:

[x(t − 18), x(t − 12), x(t − 6), x(t); x(t + 6)] (20) (13)
Here, t ranges from 19 to 1018. The first 500 points are designated as train-
ing data, while the remaining points are reserved for testing. In the model, we
consider the vector x with components x(t − 18), x(t − 12), x(t − 6), and x(t) as
the input, and the last component x(t + 6) as the output variable.
The model is the 1D quantum convolutional layer described in Sect. 3 followed
by a classical convolutional layer with 8 input channels, 8 output channels, a
kernel size of 3, a stride of 1, and padding. The ReLU activation function is
applied after the convolutional layer. A max pooling operation with a kernel
size of 4 is performed. The features are then flattened and passed through a
fully connected layer with 8 input neurons and 16 output neurons. The ReLU
activation is applied after this layer, followed by a final fully connected layer
with 16 input neurons and 1 output neuron.
The model was tested against an MLP with input dimension 4, followed by
two hidden layers with sizes 8 and 16 respectively. The output layer consists of
a single neuron with ReLU activation. The model was also tested for a CNN in
which the quantum convolutional layer was substituted for a first layer with 1
input channel, 8 output channels, a kernel size of 3, a stride of 1, and padding
to maintain the input size.
Table 1 displays a comparison of the three models in terms of RMSE, MAE,
and MAPE. It is evident that all three models exhibit similar metrics, yet the 1D
QCNN model outperforms the classical models. The 1D QCNN model improved
the results of MLP, which was the best of the two tested classical models, by
66% in RMSE. Also a 57% improvement with respect to MLP was obtained in
MAE and MAPE.
28 M. A. Rivera-Ruiz et al.

Figure 4a provides a visual comparison of the actual and forecasted values


for both the training and testing phases. Additionally, Fig. 5a depicts the con-
vergence of the three models. It is noteworthy that the 1D QCNN exhibits faster
convergence compared to the classical convolutional model.

Exchange Rate USD/EURO. The data regarding the exchange rate between
USD and EUR is obtained from [31]. The data is collected for the period from
January 1, 2020, until July 8, 2021, with a daily time step. We utilize 376 sim-
ulation data points to construct the model, defined as:

[x(t − 4), x(t − 3), x(t − 2), x(t − 1), x(t); x(t + 1)] (25) (14)
where t ranges from 5 to 380. The initial 300 data points are employed for the
training phase, while the remaining data points are used for testing.
The model consists of the custom 1D quantum convolutional layer described
in Sect. 3 followed by a classical convolutional layer with 8 input channels, 8
output channels, a kernel size of 3, a stride of 1, and padding. ReLU activation
is applied after the convolutional layer. A max pooling operation with a kernel
size of 5 is performed. The features are then flattened and passed through a fully
connected layer with 8 input neurons and 16 output neurons. ReLU activation
is applied after this layer, followed by a final fully connected layer with 16 input
neurons and 1 output neuron.
Table 1. Comparison results among the proposed 1D QCNN, 1D CNN, and MLP for
the Mackey Glass, Exchange Rate USD/EURO, and Lorenz attractor.

Data Network Parameters RMSE MAE MAPE


Mackey Glass 1D QCNN 385 0.0091 0.0073 0.0080
MLP 473 0.022 0.017 0.019
1D CNN 393 0.027 0.023 0.026
Exchange Rate 1D QCNN 385 0.0028 0.0020 0.0025
MLP 385 0.0032 0.0025 0.0030
1D CNN 393 0.0031 0.0024 0.0030
Lorenz attractor 1D QCNN 419 0.4935 0.3440 0.1122
0.6996 0.5398 0.1929
0.7941 0.7063 0.0300
MLP 464 0.4902 0.3744 0.1435
0.7219 0.5719 0.1508
0.8666 0.7523 0.0325
1D CNN 427 0.4590 0.3651 0.1179
0.6288 0.4704 0.1980
0.8694 0.8041 0.0282
1D Quantum Convolutional Neural Network 29

The proposed model was tested against a 3-layer MLP with input dimension
5, two hidden layers of size 16 each, and a single output neuron. The ReLU
activation function was used for all layers. The model is also compared with 1D
CNN, which consists of substituting the quantum convolutional layer for a first
layer with 1 input channel, 8 output channels, a kernel size of 3, a stride of 1,
and padding to maintain the input size.
In Table 1 a comparison between the models is presented for RMSE, MAE,
and MAPE. As can be observed, the three models present comparable metrics
but the classical models are outperformed by the 1D QCNN. Compared with the
best result of the classical models, in this case, 1D CNN, the 1D QCNN model
showed an improvement of 9.6% in RMSE and a 16% improvement in both MAE
and MAPE.
In Fig. 4b the comparison between the actual and forecasted values can be
observed for both training and testing. Also, in Fig. 5b the convergence of the
three models is presented and it can be observed that both 1D QCNN and MLP
converge faster than the classical convolution.

Lorenz Time Series. The Lorenz equations are given by

ẋ = σ(y − x),
ẏ = − y − zx + ρx,
ż = − βz + xy.

The numerical solution is obtained with the Euler method taking parameter
settings σ = 10, ρ = 28 and β = 8/3, and using the initial conditions: x(0) = 0,
y(0) = −0.01 and z(0) = 9.
The 1D quantum convolutional layer described in Sect. 3 was utilized, fol-
lowed by a classical convolutional layer with 8 input channels, 8 output chan-
nels, a kernel size of 3, a stride of 1, and padding. ReLU activation is applied
after the convolutional layer. A max pooling operation with a kernel size of 3 is
performed. The features are then flattened and passed through a fully connected
layer with 8 input neurons and 16 output neurons. ReLU activation is applied
after this layer, followed by a final fully connected layer with 16 input neurons
and 3 output neurons.
This model was compared with an MLP consisting of an input dimension of
3, followed by two hidden layers with sizes 21 and 11 respectively. The output
layer consists of 3 neurons with ReLU activation. Also, a comparison was made
with a CNN consisting of replacing the quantum convolutional layer for a layer
with 1 input channel, 8 output channels, a kernel size of 3, a stride of 1, and
padding.
30 M. A. Rivera-Ruiz et al.

Fig. 5. MSE loss curves of the 1D QCNN, 1D CNN and MLP.

Table 2. Comparison results among the proposed 1D QCNN, 1D CNN, and MLP for
the PTB Diagnostic dataset.

Network Parameters Accuracy (%)


1D QCNN 1534216 98.125
1D CNN 1534222 98.062
MLP 97282 96.250

Table 3. Classification report from the confusion matrix.

Network Precision Recall F1-Score Support


1D QCNN N 0.9765 0.9862 0.9813 800
A 0.9861 0.9762 0.9812 800
Average 0.9813 0.9812 0.9812 1600
1D CNN N 0.9788 0.9825 0.9807 800
A 0.9824 0.9788 0.9806 800
Average 0.9806 0.9806 0.9806 1600
MLP N 0.9512 0.9750 0.9630 800
A 0.9744 0.9500 0.9620 800
Average 0.9628 0.9625 0.9625 1600
1D Quantum Convolutional Neural Network 31

In Table 1, we present a comparison of the three models for time series fore-
casting of the Lorenz attractor in the dimension x, y, z. The 1D QCNN model
demonstrates superior performance compared to the classical models in certain
metrics. Specifically, the 1D QCNN model achieves lower RMSE and MAE val-
ues in some cases, indicating its effectiveness in capturing the dynamics of the
Lorenz attractor. However, all models still exhibit comparable overall perfor-
mance. Compared with 1D CNN, which presented the best result of the two
classical models, the 1D QCNN model improved by 5.7% in MAE for the x
direction and in 12% for the z direction. In MAPE, 1D QCNN outperformed 1D
CNN by 4.8% and 2.5% in the directions x and y, but 1D CNN improved by 6%
in z. In RMSE, the 1D CNN presented a better performance of 6.8% in the x
direction, 10% in y, and 8.6% in z.
In Figs. 4c–4e the actual points are compared with the forecasted outputs
obtained using the 1D QCNN model in the training and validation phases for
the dimension x, y, and z respectively. In Fig. 4f the actual and forecasted values
for the validation phase are compared in a three-dimensional plot. Finally, in
Fig. 5c the loss curves are presented for the three models and it can be observed
that the quantum model exhibits a faster convergence.

4.2 Time Series Classification Using PTB Dataset


In this paper, we use the PTB Diagnostic dataset that consists of Electrocar-
diogram (ECG) records. The PTB diagnostic database obtained from [30], con-
tains 14552 samples belonging to two classes: 4046 normal and 10506 myocardial
infarction (abnormal) ECG beats. Hereafter, “A” and “N” denote normal and
abnormal classes respectively. The sampling frequency of this database is equal
to 125 Hz. Additionally, the ECG signals are zero-padded to the fixed size 187.
Representative samples of normal and abnormal ECG beats are shown in Fig. 6.
In our experiments, we used 4000 samples of each class and a random 80:20
train-test split.
The QCNN architecture includes the 1D quantum convolutional layer
described in Sect. 3 followed by ReLU activation and max pooling operation
with a kernel size of 2. Then, 2 classical convolutional layers with 64 and 128
output channels, respectively are applied. Both convolutional layers have a kernel
size of 3, a stride of 1, and padding. Additionally, the ReLU activation function
is applied to both convolutional layers and each one is followed by a max pooling
layer. The last part of the architecture consists of a fully connected layer with
512 neurons with ReLU activation function followed by a fully connected layer
for classification.
The model is compared with MLP and 1D CNN. All models were trained
using the Adam optimizer with Cross-Entropy Loss, 50 epochs, and an initial
learning rate of 1e − 3. During training, we reduce the learning rate by using
the StepLR scheduler with step size and learning rate decay equal to 20 and 0.1,
respectively.
From Fig. 5d we can observe that the 1D QCNN and 1D CNN are comparable
in terms of convergence speed whereas the MLP converges slower. As we can
32 M. A. Rivera-Ruiz et al.

see in Table 2 1D QCNN outperforms classical models in terms of accuracy,


overcoming the 1D CNN and MLP by 0.063% and 1.875% respectively.
The confusion matrices shown in Fig. 7 give us an overview of the correctly
and incorrectly classified samples during the testing phase. We can observe that
the majority of predictions correspond to diagonal elements, which is a good
indicator since a perfect classifier would imply off-diagonal elements equal to
zero.
From Tables 2 and 3 we can observe that the 1D QCNN outperforms the
other models in terms of accuracy as well as average precision, recall and F1-
score. Regarding specific classes, the 1D QCNN has the highest precision for
class “A”, the highest recall for class “N” and the highest F1-score for both
classes when compared to the other models. Thus, the 1D QCNN is superior
to the classical models 1D CNN and MLP, except that the precision metric for
class “N” and the recall metric for class “A” are slightly lower when compared
to the 1D CNN.

Fig. 6. Sample plots of heartbeats of two classes for the PTB dataset.

Fig. 7. Normalized Confusion Matrices of the 1D QCNN, 1D CNN and MLP.


1D Quantum Convolutional Neural Network 33

5 Conclusions
In this paper, we present a 1D quantum convolution that uses a quantum circuit
to extract features from input data. In order to evaluate its ability as a feature
detector we propose a Quantum Convolutional Neural Network for time series
forecasting and classification.
In this work, we conducted a series of experiments with the benchmark
datasets Mackey Glass and Lorenz attractor that correspond to univariate and
multivariate time series, respectively. Additionally, two real-world univariate
time series, USD-EURO exchange rates, and PTB database were utilized. The
former dataset was used for time series forecasting and the latter for time series
classification. In all scenarios, the proposed 1D QCNN shows a competitive per-
formance when compared to its classical competitors, the 1D CNN and the
MLP. Therefore, the proposed 1D quantum convolution is capable of effectively
extracting local features from the input vector.
In an upcoming study, a comprehensive evaluation of the proposed 1D
QCNN architecture will be conducted, encompassing comparisons with alter-
native encoding methods and exploration of different variational layers. Further-
more, a deeper analysis of the theoretical justification behind the variational
layers depicted in Figs. 3a and 3b will be undertaken.

References
1. Abbas, A., Sutter, D., Zoufal, C., Lucchi, A., Figalli, A., Woerner, S.: The power
of quantum neural networks. Nat. Comput. Sci. 1(6), 403–409 (2021)
2. Alejandra, R.R.M., Andres, M.V., Mauricio, L.R.J.: Time series forecasting with
quantum machine learning architectures. In: Pichardo Lagunas, O., Martı́nez-
Miranda, J., Martı́nez Seis, B. (eds.) Advances in Computational Intelligence,
MICAI 2022, vol. 13612, pp. 66–82. Springer, Cham (2022). https://doi.org/10.
1007/978-3-031-19493-1 6
3. Bergholm, V., Izaac, J., Schuld, M., Gogolin, C.: PennyLane: automatic differen-
tiation of hybrid quantum-classical computations (2022)
4. Cerezo, M., et al.: Variational quantum algorithms. Nat. Rev. Phys. 3(9), 625–644
(2021)
5. Feynman, R.P.: Simulating physics with computers. In: Feynman and Computa-
tion, pp. 133–153. CRC Press (2018)
6. Havlı́ček, V., et al.: Supervised learning with quantum-enhanced feature spaces.
Nature 567(7747), 209–212 (2019)
7. Henderson, M., Shakya, S., Pradhan, S., Cook, T.: Quanvolutional neural networks:
powering image recognition with quantum circuits. Quantum Mach. Intell. 2(1), 2
(2020)
8. Hong, Z., Wang, J., Qu, X., Zhu, X., Liu, J., Xiao, J.: Quantum convolutional neu-
ral network on protein distance prediction. In: 2021 International Joint Conference
on Neural Networks (IJCNN), pp. 1–8. IEEE (2021)
9. Houssein, E.H., Abohashima, Z., Elhoseny, M., Mohamed, W.M.: Hybrid quantum-
classical convolutional neural network model for COVID-19 prediction using chest
X-ray images. J. Comput. Des. Eng. 9(2), 343–363 (2022). https://doi.org/10.
1093/jcde/qwac003
34 M. A. Rivera-Ruiz et al.

10. Hur, T., Kim, L., Park, D.K.: Quantum convolutional neural network for classical
data classification. Quantum Mach. Intell. 4(1), 3 (2022). https://doi.org/10.1007/
s42484-021-00061-x
11. Li, W., Deng, D.L.: Recent advances for quantum classifiers. Sci. China Phys.
Mech. Astron. 65(2), 220301 (2021). https://doi.org/10.1007/s11433-021-1793-6
12. Liu, J., Lim, K.H., Wood, K.L., Huang, W., Guo, C., Huang, H.L.: Hybrid
quantum-classical convolutional neural networks. Sci. China Phys. Mech. Astron.
64(9), 290311 (2021)
13. Lloyd, S., Mohseni, M., Rebentrost, P.: Quantum algorithms for supervised and
unsupervised machine learning (2013)
14. Lu, S., Braunstein, S.: Quantum decision tree classifier. Quantum Inf. Process. 13,
757–770 (2014). https://doi.org/10.1007/s11128-013-0687-5
15. Mari, A., Bromley, T.R., Izaac, J., Schuld, M., Killoran, N.: Transfer learning in
hybrid classical-quantum neural networks. Quantum 4, 340 (2020). https://doi.
org/10.22331/q-2020-10-09-340
16. Mitarai, K., Negoro, M., Kitagawa, M., Fujii, K.: Quantum circuit learning. Phys.
Rev. A 98, 032309 (2018). https://doi.org/10.1103/PhysRevA.98.032309, https://
link.aps.org/doi/10.1103/PhysRevA.98.032309
17. Nielsen, M.A., Chuang, I.L.: Quantum Computation and Quantum Information.
Cambridge University Press, Cambridge (2000)
18. Park, G., Huh, J., Park, D.K.: Variational quantum one-class classifier. Mach.
Learn. Sci. Technol. 4(1), 015006 (2023). https://doi.org/10.1088/2632-2153/
acafd5
19. Preskill, J.: Quantum computing 40 years later. Nat. Rev. Phys. 4(1) (2023).
https://doi.org/10.1038/s42254-021-00410-6
20. Ramezani, S.B., Sommers, A., Manchukonda, H.K., Rahimi, S., Amirlatifi, A.:
Machine learning algorithms in quantum computing: a survey. In: 2020 Interna-
tional Joint Conference on Neural Networks (IJCNN), pp. 1–8 (2020). https://doi.
org/10.1109/IJCNN48605.2020.9207714
21. Rebentrost, P., Mohseni, M., Lloyd, S.: Quantum support vector machine for big
data classification. Phys. Rev. Lett. 113(13), 130503 (2014). https://doi.org/10.
1103/physrevlett.113.130503
22. Sameer, M., Gupta, B.: A novel hybrid classical-quantum network to detect epilep-
tic seizures. medRxiv, pp. 2022-05 (2022)
23. Schuld, M., Bergholm, V., Gogolin, C., Izaac, J., Killoran, N.: Evaluating analytic
gradients on quantum hardware. Phys. Rev. A 99(3), 032331 (2019). https://doi.
org/10.1103/physreva.99.032331
24. Schuld, M., Bocharov, A., Svore, K.M., Wiebe, N.: Circuit-centric quantum clas-
sifiers. Phys. Rev. A 101, 032308 (2020). https://doi.org/10.1103/PhysRevA.101.
032308, https://link.aps.org/doi/10.1103/PhysRevA.101.032308
25. Schuld, M., Petruccione, F.: Supervised Learning with Quantum Computers.
Springer, Cham (2018). https://doi.org/10.1007/978-3-319-96424-9
26. Schuld, M., Sinayskiy, I., Petruccione, F.: An introduction to quantum
machine learning. Contemp. Phys. 56(2), 172–185 (2014). https://doi.org/10.1080/
00107514.2014.964942
27. Schuld, M., Sinayskiy, I., Petruccione, F.: Simulating a perceptron on a quan-
tum computer. Phys. Lett. A 379(7), 660–663 (2015). https://doi.org/10.1016/j.
physleta.2014.11.061
28. Schuld, M., Sweke, R., Meyer, J.J.: Effect of data encoding on the expressive power
of variational quantum-machine-learning models. Phys. Rev. A 103(3), 032430
(2021). https://doi.org/10.1103/physreva.103.032430
1D Quantum Convolutional Neural Network 35

29. Shahwar, T., et al.: Automated detection of Alzheimer’s via hybrid classical
quantum neural networks. Electronics 11, 721 (2022). https://doi.org/10.3390/
electronics11050721
30. Fazeli, S.: ECG heartbeat categorization dataset (2018). https://www.kaggle.com/
datasets/shayanfazeli/heartbeat. Accessed 28 Feb 2023
31. Antweiler, W.: Pacific exchange rate service (2023). http://fx.sauder.ubc.ca/data.
html. Accessed 20 Jan 2023
32. Yang, Y.F., Sun, M.: Semiconductor defect detection by hybrid classical-quantum
deep learning. In: 2022 IEEE/CVF Conference on Computer Vision and Pattern
Recognition (CVPR). IEEE, June 2022. https://doi.org/10.1109/cvpr52688.2022.
00236

View publication stats

You might also like