1 DQuantum Convolutional Neural Networkfor Time Series Forecastingand Classification
1 DQuantum Convolutional Neural Networkfor Time Series Forecastingand Classification
net/publication/375518556
CITATIONS READS
0 145
5 authors, including:
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.
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.
2 Preliminaries
In this section, we discuss the necessary background on the basic concepts of
quantum computing.
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]:
Using Dirac’s Bra-Ket notation the state of the qubit |Ψ can be written as:
With:
Cq1 ,q2 ,...,qn 2 = 1, Cq1 ,q2 ,...,qn ∈ C. (4)
(q1 ,q2 ,...,qn )∈{0,1}
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.
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
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.
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
3 1D Quantum Convolution
– 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.
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).
[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.
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.
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.
ẋ = σ(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.
Table 2. Comparison results among the proposed 1D QCNN, 1D CNN, and MLP for
the PTB Diagnostic dataset.
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.
Fig. 6. Sample plots of heartbeats of two classes for the PTB dataset.
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