Recognizing the pattern of binary Hermitian matrices by quantum kNN and SVM methods

Recognizing the pattern of binary Hermitian matrices by quantum kNN and SVM methods The article contains a description of two quantum circuits for pattern recognition. The first approach is realized with use of k nearest neighbors algorithm and the second with support vector machine. The task is to distinguish between Hermitian and non-Hermitian matrices. The quantum circuits are constructed to accumulate elements of a learning set. After this process, circuits are able to produce a quantum state which contains the information if a tested element fits to the trained pattern. To improve the efficiency of presented solutions, the matrices were uniquely labeled with feature vectors. The role of the feature vectors is to highlight some features of the objects which are crucial in the process of classification. The circuits were implemented in Python programming language and some numeric experiments were conducted to examine the capacity of presented solutions in pattern recognition. Keywords Quantum circuits · Pattern recognition · Supervised machine learning · Hamming distance 1 Introduction ficial neural networks: the data describing the patterns are enclosed in learning and testing sets, and the circuit obtains A conception of solving problems with use of k Near- the learning set and is able to recognize if a tested element est Neighbor (kNN) algorithm was created in fifties of the fits to the pattern emerging from the learning set. An aim of previous century [2] and it is still very popular and devel- this article is to verify a thesis if quantum circuits based on ops constantly. In addition, the concept of Support Vector kNN and SVM methods are able to recognize Hermitian and Machine (SVM) for problems of classification is a known non-Hermitian matrices. solution, which actual version was presented in 1995 [1]. As This work is an extended version of conference ACIIDS researchers working on some aspects of quantum computing, 2017 paper: [15]—in that article, we simulated a quantum cir- we were inspired by kNN and SVM methods to apply the idea cuit based on kNN algorithm which role was to classify the of pattern recognition in quantum circuits [4,6,14,16]. Hermitian and non-Hermitian matrices. This article is orga- We refer to [9,12,13], where it was shown that it is possi- nized as follows: in Sect. 2, we present some basic definitions ble to build a quantum circuit which works as a classifier. The helpful in understanding the main idea of this work. Sec- basic idea was prepared to be utilized in the field of image tion 3 is dedicated to the detailed description of the quantum processing [8,17,18]. The kNN and SVM were constructed circuit for kNN method and Sect. 4 contains the construc- with visible inspiration flowing out of methods used in arti- tion of quantum solution for SVM. In Sect. 5, the results of computational experiments were analysed. A summary and conclusions are presented in Sect. 6. B Joanna Wisnie ´ wska jwisniewska@wat.edu.pl Marek Sawerwain M.Sawerwain@issi.uz.zgora.pl 2 Quantum computing—basic definitions Institute of Information Systems, Faculty of Cybernetics, Military University of Technology, Kaliskiego 2, 00-908 Warsaw, Poland To explain the analysed matter, we need to introduce a few definitions corresponding to quantum information process- Institute of Control and Computation Engineering, University of Zielona Góra, Licealna 9, 65-417 Zielona Góra, Poland ing [5]. First, notion concerns a quantum bit—so-called qubit 123 Vietnam Journal of Computer Science which is a normalized vector in a two-dimensional Hilbert |x=|x ⊗|x  ⊗ ··· ⊗ |x ⊗|x . (6) 0 1 n−2 n−1 space H . The impact of Hadamard gate on state |x  is Two orthogonal qubits constitute a computational basis. Of course, we can imagine the infinite number of such paired H |x= H (|x ⊗|x  ⊗ ··· ⊗ |x ⊗|x ) 0 1 n−2 n−1 qubits. One of the most known basis is so-called standard basis. This basis is created by qubits: = H |x ⊗ H |x  ⊗ ··· ⊗ H |x ⊗ H |x 0 1 n−2 n−1 n−1 n−1 = H |x = √ |0+ (−1) |1 . 1 0 i =0 i =0 |0= , |1= . (1) 2 0 1 (7) where the form |· is a Dirac notation. The difference between As we can see the Hadamard gate makes all absolute values classical bit and qubit is that qubit may be a "mixture" of of state’s amplitudes even (equal to ), so it causes the orthogonal vectors. This phenomenon is called superposi- phenomenon of superposition in a quantum register. tion. Hence, the state of quantum bit |ψ  we can present as It is important to remember that quantum gates, in contrast to classical ones, always have the same number of inputs and 2 2 |ψ= α |0+ α |1, where |α | +|α | = 1. (2) 0 1 0 1 outputs. It is so because they were designed as reversible The coefficients α and α are complex numbers and they 0 1 operators the matrix form of quantum gate is unitary and are termed amplitudes. A character of quantum state is non- Hermitian. deterministic. The probability that the state |ψ  equals |0 is Another basic gate is an exclusive-or (XO R) gate, called |α | and, adequately, the probability that the state |ψ  is |1 also a controlled negation (CN OT ) gate. This gate has two is expressed by value |α | . Of course, it is also possible that 1 entries and, naturally, two outputs. The operation XO R one of the amplitudes equals to 0 and the other to 1 (in this is realized on the second qubit (the first qubit remains case state |ψ  is one of basic states). unchanged): If we need more than one quantum bit to perform any calculations, we can use a quantum register which is a system XO R|00=|00, XO R|01=|01, of qubits, joined by a tensor product (denoted by symbol ⊗) XO R|10=|11, XO R|11=|10. (8) in a mathematical sense. For example, the state |φ of 3-qubit register containing qubits |0, |1 and |1 is The matrix form of this gate is ⎡ ⎤ 1 0 0 |φ=|0⊗|1⊗|1= ⊗ ⊗ . (3) 0 1 1 ⎢ ⎥ ⎢ ⎥ XO R = . (9) ⎣ ⎦ Usually, we omit the symbols ⊗, so the above state may be also denoted as |φ=|011. In case of any n-qubit state |ϕ, its form can be expressed as a superposition of basic states: 3The k nearest neighbors algorithm |ϕ= α |00 ... 000+ α |00 ... 001 0 1 In this work, we would like to use a quantum circuit to check if +α |00 ... 010+ ... + α n |11 ... 111 (4) 2 (2 −1) some matrices are Hermitian or not. The approach presented in this section is based on the k Nearest Neighbors (kNN) where the normalization condition must be fulfilled: algorithm for pattern classification [9]. As an example, we chose the matrices which are binary and unitary, sized 4 × 4 2 −1 as in Fig. 1. In this case, all analysed matrices are column (or |α | = 1,α ∈ C. (5) i i row, interchangeably) permutations of identity matrix I . i =0 4×4 Let us remind that a matrix U is Hermitian when it is equal To perform the calculations on quantum states, we use to its conjugate transpose: quantum gates. Quantum gates have to preserve a quan- tum state—that means the performed operation preserves the U = U . (10) state’s normalization condition—so they have to be unitary operators to ensure this feature. Because the analysed set of matrices does not contain any The gate which is very useful in many algorithms is a matrices with complex elements, it would be some simpli- Hadamard gate H.Let |x  be a n-qubit state as in example fication to say that a Hermitian matrix is just equal to its Eq. (3), but with labeled qubits: transpose what can be observed in Fig. 1. 123 Vietnam Journal of Computer Science In carried out computational experiment matrices 4 × 4 were taken into account, so the number of quantum circuit’s (Fig. 2) inputs/outputs is 33. In general, if the matrices are sized k × k, the number of inputs/outputs is 2k + 1. The first k inputs serve to enter the succeeding elements of testing set. The next k inputs serve to constitute a learning set. There is also one ancilla input on which the Hadamard operation is performed. First, we would like to describe a block labeled Op. Learn.Set. Its role in the circuit is to accumulate the ele- ments of learning set. The learning set contains binary series describing Hermitian matrices. We can roughly call these series permutative—the number of ones is similar (e.g., for unitary matrices is always equal to 4), but they occupy other positions in series. It means that the block Op.Learn.Set is a subsystem built of gates XO R and H, because the XO R gates ensure the permutations and H gates allow to accumu- late some different series in qubits of quantum register. The block Op.Test.Set is also constructed of XO R and H gates, but it differs from the subsystem Op.Learn. Set. This block contains only one element of testing set, representing Hermitian or non-Hermitian matrix, in each computational experiment. It means that, in case of unitary Fig. 1 Set of all binary and unitary matrices sized 4 × 4, divided into matrices 4 × 4, we have to perform 24 experiments, always Hermitian and non-Hermitian matrices. The bigger dots stand for 1 and with different block Op.Test.Set. the smaller dots for 0 Summarizing this part of the circuit, we have the initial quantum state entering the system: ⊗2k +1 |ψ =|0 . (12) Then, the first k qubits will be affected by the block Op.Test.Set and successive k qubits by the block Op.Learn.Set to produce the superposition of elements from a learning set: p p √ |l ,..., l , (13) Fig. 2 Quantum circuit classifying Hermitian and non-Hermitian p=1 matrices where L denotes the number of elements in learning set and l represents the successive qubits. The quantum circuit to perform a Hermitian matrices’ The first k qubits describe an element from a testing recognition is shown in Fig. 2. Although in this work, we set. It means that after the operations caused by blocks only test a circuit for matrices sized 4 × 4, the presented Op.Learn.Set, Op.Test.Set and Hadamard gate on circuit is universal in terms of matrix dimensions. ancilla qubit the system’s state is To describe the matrices, we use 16-element binary series which are built of matrix elements row by row: ⎛ ⎞ p p ⎝ ⎠ |ψ =|t ,..., t 2⊗ √ |l ,..., l 1 1 2 k 1 ⎡ ⎤ p=1 ⎢ ⎥ ⎢ ⎥ ⊗ √ (|0+|1) (14) → 1000|0010|0001|0100 → 1000001000010100. ⎣ ⎦ (11) where t stands for the qubits of element from the testing set. 123 Vietnam Journal of Computer Science The next block serves to calculate the Hamming distance is close to the pattern described in the learning set (is Her- between one test series and elements of learning set. The mitian), and if the result is |1, the matrix should not be Hamming distance is a measure expressing the difference Hermitian. between two series. It tells how many elements, occupy- It should be emphasized that the quantum implementa- ing the same positions, differ from each other. The block tion of kNN method has a lower computational complexity Ham.Dist.Calculation uses the XO R operations on in comparison with kNN method running on a classical every couple of qubits (t , l ) and saves their results as d in computer. The first difference is connected with the phase the part of register which previously contained elements of a of learning—in the classical approach, the complexity is learning set: affected by the number and length of series included in the learning set, while in quantum system, only the length p p 2 k of learning series influences its complexity. The second XO R(t , l ) = (t , d ), i = 1,..., k . (15) i i i i advantage of quantum approach in the field of complexity is an ability to compare a tested element with all ele- After this operation, the system’s state is ments from learning set simultaneously (a phenomenon of quantum parallelism takes place during the calculation of L p p |ψ =|t ,..., t 2⊗ |d ,..., d 2 1 k 2 p=1 1 L Hamming distances). Finally, the complexity of quantum √ kNN is: O(k + Hc), where Hc stands for the complexity ⊗ (|0+|1). of Hamiltonian (17) simulation. The simulation of Hamil- (16) tonian [3] may realized with no greater complexity than log(1/) O(tdH  + ), where t is a interval of time, d is max log log(1/) If the differences are already computed, then they must a sparse of Hamiltonian, H  is a value of Hamiltonian’s max be summed to obtain the Hamming distance. The block maximal element, and  stands for accuracy. Quantum Summing stands for the operation U : ⊗k 10 10 −i H 2 4 Support vector machine 2k U = e , H = I ⊗ ⊗ , (17) 2 2 k ×k 00 0 −1 Support Vector Machine (SVM) is a method used in a field where i represents the imaginary unit. This results with the of supervised learning. Let us assume that we have a learning state |ψ : set containing vectors from two different classes: C and C . 1 2 The SVM’s goal is to find a hyperplane g(x): |ψ = √ p=1 2L T g(x) = w x + w (20) i d(t ,l ) p p 2k e |t ,..., t 2⊗|d ,..., d ⊗|0+ k 2 p separating vectors from C and C : −i d(t ,l ) 1 2 p p 2k + e |t ,..., t 2⊗|d ,..., d ⊗|1 . k 2 (18) g(x) ≥ 1, ∀ ∈ C x 1 g(x) ≤−1, ∀ ∈ C (21) x 2 The last step is designed to reverse the Hadamard operation on the last qubit (of course with use of reversible H gate). In addition, the hyperplane must be calculated in a way That will allow to measure the last qubit in the standard basis maximizing the margin z, which is a distance between a and obtain |0 or |1 with sufficiently high probability. The hyperplane and objects from C and C : 1 2 final state of the whole system is |g(x)| 1 1 L z = = (22) |ψ = √ w w p=1 p p p cos d(t , l ) |t ,..., t 2⊗|d ,..., d ⊗|0+ k 2 2 k That means an aim is to minimize w. This task may be 2k p p p formulated as finding a solution of Lagrange function L(˘) + sin d(t , l ) |t ,..., t 2⊗|d ,..., d ⊗|1 . k 2 2 1 2k using Karush–Kuhn–Tucker conditions: (19) M M Now, the measurement needs to be done only on the last L(λ) = g (x)λ − λ K λ (23) i i i i , j j ancilla qubit. If the result is |0 that means the tested matrix i =1 i , j =1 123 Vietnam Journal of Computer Science where 2 2 C = w + λ . (27) 0 i i =1 The training data Oracle causes that all eigenvectors |ˆ u of Fig. 3 Scheme of quantum circuit implementing the SVM method matrix F: |ˆ u= √ w |0|0+ λ |x ||i |x  (28) 0 i i i under constraints: u ˆ i =1 where λ = 0 and g (x)λ ≥ 0, (24) i i i i =1 2 2 2 N = w + λ |x | . (29) u ˆ i 0 i i =1 where M is a number of training examples, vector λ stands for the Lagrange multipliers and K is a kernel matrix K = i , j The last block is to calculate the probability telling if an x · x . Then, the machine should be able to classify the j arbitrary vector |t from the training set may be classified to unknown vectors according to (21). C or C : 1 2 The computational complexity of SVM is polynomial and depends on the dimensions of classified vectors and the num- |t= √ |0|0+ |t||i |t (30) ber of elements in the training set. Of course, using the i =1 quantum version of this method, the complexity may be reduced to logarithmic. The speedup is achieved utilizing with a quantum circuit to calculate in parallel the inner products of the vectors. Then, the SVM training is converted to an N = M |t| + 1. (31) approximate least-squares problem which may be solved by the quantum matrix inversion algorithm with O(κ log X ), The final state of the system is where κ stands for a condition number of a X-equation sys- tem [7,9–11]. |ψ= √ |ˆ u|0+|t|1 (32) The process of quantum calculations may be shown as in Fig. 3 according to [18]. The presented circuit has (N + 2) inputs/outputs, where N is a number of elements in classified and the measurement on the last qubit has to be performed. If vectors. Solving (23) leads to a least-square approximation of the obtained value is |1, it means that the vector |t belongs calculating matrix F , because the SVM parameters M +1×M +1 to the class C , and if the value of the last qubit is |0, then are determined by the vector belongs to C . T T −1 T T (w , λ ) = F (0, g(x) ) , (25) 5 Results of the experiments so the first block performs the matrix F inversion to calcu- We conducted a computational experiments to examine if a late the hyperplane g(x), but it also accumulates the values quantum system is able to recognize the pattern of Hermitian of training set, because for matrix F, it is possible to calcu- and non-Hermitian matrices sized 4 × 4. The calculations late its eigenvectors |u  and corresponding eigenvalues α for kNN were based on Eq. (19) and the calculations for j j ( j = 1, ..., (M + 1)). On the first N qubits of the compu- SVM on (28) and (30). The results presented in this section tational register phase estimation generates the state storing were delivered by a script written in Python programming training data. After the operation performed by the block language. MatrixInversion, we will obtain the state: The first experiments were conducted on sets of unitary matrices described as 16-element binary series as in (11). The results of these computations are presented in Table 1 (the numbers were rounded to four decimal places). For kNN |w , λ= √ w |0+ λ |i  (26) 0 0 i C method, the learning set contains the Hermitian matrices. i =1 123 Vietnam Journal of Computer Science Table 1 Results of pattern recognition for quantum versions of kNN Table 2 Results of pattern recognition for quantum versions of kNN and SVM methods and SVM methods Hermitian matrices in TS non-Hermitian matrices in TS Hermitian matrices in TS non-Hermitian matrices in TS kNN SVM kNN SVM kNN SVM kNN SVM P P P P P P P P P P P P |0 |1 |0 |1 |0 |1 |0 |1 0.6207 0.3792 0.5000 0.6472 0.3527 0.4999 0.8898 0.1101 0.5634 0.7562 0.2437 0.5452 0.6972 0.3027 0.5427 0.6826 0.3173 0.4430 0.9223 0.0776 0.5634 0.7562 0.2437 0.5452 0.6207 0.3792 0.5569 0.6826 0.3173 0.4430 0.9223 0.0776 0.5872 0.8319 0.1680 0.5059 0.6972 0.3027 0.5569 0.6472 0.3527 0.5000 0.9223 0.0776 0.5820 0.8373 0.1626 0.4482 0.6207 0.3792 0.5569 0.6472 0.3527 0.4999 0.9223 0.0776 0.6097 0.6913 0.3086 0.5452 0.6972 0.3027 0.5568 0.6826 0.3173 0.4430 0.9440 0.0559 0.5634 0.7237 0.2762 0.5358 0.6972 0.3027 0.5569 0.6472 0.3527 0.4858 0.9007 0.0992 0.5634 0.6696 0.3303 0.5144 0.6972 0.3027 0.5427 0.6826 0.3173 0.4430 0.9332 0.0667 0.5634 0.6696 0.3303 0.5340 0.6972 0.3027 0.5568 0.6826 0.3173 0.4430 0.8790 0.1209 0.5905 0.7056 0.2943 0.4897 0.7621 0.2378 0.5000 0.6472 0.3527 0.4858 0.8790 0.1209 0.6047 0.7056 0.2943 0.5404 0.6472 0.3527 0.5000 0.7056 0.2943 0.4675 0.6826 0.3173 0.4430 0.7014 0.2943 0.5405 0.6826 0.3173 0.4430 0.6696 0.3303 0.5405 0.6826 0.3173 0.5000 0.7056 0.2943 0.5405 The learning set contains only Hermitian matrices. Abbreviation TS The learning set contains only Hermitian matrices. Abbreviation TS stands for the test set. The matrices 4 × 4 were written as 16-element stands for the test set. The matrices 4 × 4 were encoded as 16-element series feature vectors As we can see the Hermitian matrices were recognized with a quite high probability. The problem is that also the non- Hermitian matrices were recognized as patterns similar to patterns in learning set—the kNN method uses the Hamming distance to distinguish between series and all used series con- tain 4 elements equal to one and 12 elements equal to zero, so probably, the series were treated as similar by the utilized method. For the SVM method, we assume that Hermitian matrices belong to the class C and non-Hermitian to C . The algo- 1 2 rithm for SVM was implemented to point the class with value P:if P > 0.5 the matrix belongs to C and if P < 0.5–C . 1 2 Fig. 4 Discrimination line for values of probability for the kNN method In comparison with the SVM method allowed to obtain better when matrices are encoded with feature vectors results. However, there are 2 Hermitian and 3 non-Hermitian matrices with P = 0.5000, so the method was not able to classify these matrices unambiguously. written in a series. Let us assign the matrices to labels: at the To improve the pattern recognition, we propose to label beginning, the set of series presenting matrices is sorted in the the matrices and run the calculations using labels. The same way as labels; we extract all 1024 Hermitian matrices labels should be constructed as feature vectors in a way from the set of series and we assign them to the first 1024 increasing the Hamming distances between Hermitian and labels; other non-Hermitian matrices we assign to remaining non-Hermitian matrices. labels. This approach allows to decrease the number of ones The labels are 16-bit binary series to provide a unique label in labels corresponding to Hermitian matrices and to increase for every binary matrix sized 4 × 4. The labels are ordered: the number of ones in labels corresponding to non-Hermitian the first label contains 16 zeros, next 16 labels contain 1 matrices. Table 2 contains the results of learning using labels. figure one and 15 zeros, subsequent series contain 2 ones, 3 We can see that the kNN method still tends to classify ones, and so on until we obtain a series of 16 ones. In every all matrices as Hermitian, but it is possible to calculate a group of labels with the same number of ones, the series discrimination line (see Fig. 4) between values of P for |0 are sorted ascending in the meaning of the binary number Hermitian and non-Hermitian matrices, because the lowest 123 Vietnam Journal of Computer Science Table 3 Results of pattern recognition for quantum versions of kNN and SVM methods Hermitian matrices in TS non-Hermitian matrices in TS kNN SVM kNN SVM P P P P P P |0 |1 |0 |1 0.8859 0.1140 0.5596 0.7468 0.2531 0.5425 0.9183 0.0816 0.5596 0.7865 0.2134 0.5425 0.9118 0.0881 0.5596 0.8011 0.1988 0.4696 0.9118 0.0881 0.5596 0.7856 0.2143 0.5359 0.9002 0.0997 0.5823 0.7459 0.2540 0.4942 0.9079 0.0920 0.5596 0.7451 0.2548 0.5425 Fig. 5 Discrimination line for values of probability for the SVM method 0.8898 0.1101 0.5596 0.7488 0.2511 0.5380 when matrices are encoded with feature vectors 0.9040 0.0959 0.5596 0.7488 0.2511 0.4749 0.9028 0.0971 0.5810 0.7331 0.2668 0.5380 value of probability for Hermitian matrices is 0.8790 and the 0.8963 0.1036 0.5596 0.7331 0.2668 0.4993 highest value of P for non-Hermitian matrices is 0.8313. |0 0.9704 0.0295 0.8530 0.7046 0.2953 0.5376 The same situation we can observe for the SVM method with 0.9446 0.0553 0.5832 0.7016 0.2983 0.5380 a discrimination line (see Fig. 5) between values 0.5634 and 0.9446 0.0553 0.5832 0.7040 0.2959 0.5373 0.5452. 0.9473 0.0526 0.5832 0.7046 0.2953 0.4857 The last experiment was conducted with use of labels, but 0.9366 0.0633 0.5832 0.7961 0.2038 0.5425 the learning and test sets were more numerous (28 Hermitian 0.9313 0.0686 0.5832 0.7509 0.2490 0.5425 and 40 non-Hermitian matrices were used). The sets were 0.9313 0.0686 0.5832 0.7153 0.2846 0.5380 enhanced with labels corresponding to non-unitary matrices. 0.9313 0.0686 0.5981 0.7205 0.2794 0.5380 The results are presented in Table 3. 0.9145 0.0854 0.5596 0.7385 0.2614 0.5380 Increasing the number of elements in the learning set 0.9079 0.0920 0.5596 0.7385 0.2614 0.5380 caused some improvement for kNN method—the lowest 0.9079 0.0920 0.5596 0.6575 0.3424 0.5347 value of P = 0.8859 for Hermitian matrices and the |0 0.9079 0.0920 0.5654 0.6823 0.3176 0.5347 highest value of P = 0.8011 for non-Hermitian matri- |0 0.9079 0.0920 0.5831 0.6362 0.3637 0.5347 ces. However, this strategy did not improve the results for 0.8975 0.1024 0.5596 0.6376 0.3623 0.5347 SVM method. 0.8975 0.1024 0.5983 0.5235 0.4764 0.5322 Of course, it should be emphasized that the presented 0.9079 0.0920 0.5596 0.5502 0.4497 0.5322 approach with use of quantum versions of kNN and SVM 0.9079 0.0920 0.5964 0.5578 0.4421 0.5322 has a probabilistic character. That implies the fact that the 0.8975 0.1024 0.5853 0.5230 0.4769 0.5322 calculations have to be repeated to obtain the most accurate 0.5710 0.4289 0.5322 approximation of distribution shown in tables above. The 0.5641 0.4358 0.5322 probabilities of measuring |0 or |1 on the last qubit are dif- ferent, so it allows to indicate the distance of analysed case 0.5443 0.4556 0.5322 from the learning set. In general, the computations illustrated 0.4556 0.5443 0.5301 by the quantum circuits should be performed O( P(1− P) ) 0.4145 0.5854 0.5301 times to obtain probability P distribution with accuracy ε. 0.4423 0.5576 0.5284 0.4352 0.5647 0.5284 0.4765 0.5234 0.5284 6 Summary 0.4502 0.5497 0.5284 0.2317 0.7682 0.5246 The computational experiments showed that the quantum cir- 0.1990 0.8009 0.5246 cuits are able to distinguish between the pattern of Hermitian 0.1115 0.8884 0.5228 and non-Hermitian matrices. Abbreviation TS stands for the test set. The binary matrices (unitary In case of kNN, the way of encoding patterns is very and non-unitary) were encoded as feature vectors important. The kNN method uses Hamming distance to dis- tinguish between the matrices so using feature vectors to 123 Vietnam Journal of Computer Science describe the recognized objects should comply the charac- 2. Fix, E., Hodges, J.L.: Discriminatory Analysis, Nonparametric Dis- crimination: Consistency Properties. Technical Report 4, USAF ter of Hamming distance measure. The distances between School of Aviation Medicine, Randolph Field, Texas (1951) objects from the same class should be as small as possible. On 3. Low, G.H., Chuang, I.L.: Optimal Hamiltonian Simulation the other side, distances between objects belonging to other by Quantum Signal Processing. arXiv:1606.02685v2 [quant-ph] classes should be increased. In our experiments, we used the (2016) 4. Mateus, P., Omar, Y.: Quantum Pattern Matching. system of labels to describe the matrices. Hermitian matrices arXiv:quant-ph/0508237v1 (2005) were described by vectors with the minimal needed number 5. Nielsen, M.A., Chuang, I.L.: Quantum computation and quantum of ones and non-Hermitian matrices with maximal number of information. Cambridge University Press, New York (2000) ones. In case of feature vectors for unitary Hermitian matri- 6. Pinkse, P.W.H., Goorden, S.A., Horstmann, M., Škoric, ´ B., Mosk, A.P.: Quantum pattern recognition. 2013 Conference on and ces, the number of ones is equal to 2 and for non-Hermitian International Quantum Electronics Conference Lasers and Electro- matrices: 4 and 5. The pattern recognition was more efficient Optics Europe (CLEO EUROPE/IQEC), Munich, pp. 1–1 (2013) when the learning set was extended by non-unitary matrices. 7. Rebentrost, P., Mohseni, M., Lloyd, S.: Quantum support vector The conclusion is obvious: not only the number of ones is an machine for big data classification. Phys. Rev. Lett. 113, 130503 (2014) important factor for Hamming distance, but also the position 8. Schaller, G., Schtzhold, R.: Quantum algorithm for optical- of figures in series and non-unitary matrices brought some template recognition with noise filtering. Phys. Rev. A 74, 012303 diversity in this aspect (there may be Hermitian matrices with (2006) 0 to 4 figures equal to one and non-Hermitian with 4–16 fig- 9. Schuld, M., Sinayskiy, I., Petruccione, F.: Quantum computing for pattern classication. In: 13th Pacic Rim International Conference ures equal to one). The similar results were presented in [9]. on Articial Intelligence (PRICAI) and Also Appear in the Springer The SVM method was surprisingly efficient even for a Lecture Notes in Computer Science 8862 (2014) small learning set and series generated directly from matrices 10. Schuld, M., Sinayskiy, I., Petruccione, F.: An introduction to quan- as in (11). Utilizing the feature vectors allowed to introduce tum machine learning. Contemp. Phys. 52, 172–185 (2014). https:// doi.org/10.1080/00107514.2014.964942 a clear discrimination line between the values of P pointing 11. Senekane, M., Taele, B.M.: Prediction of solar irradiation using objects from the classes C and C . 1 2 quantum support vector machine learning algorithm. Smart Grid It should also be emphasized that the character of quantum Renew. Energy 7, 293–301 (2016). https://doi.org/10.4236/sgre. computations is probabilistic and conducting more experi- 2016.712022 12. Trugenberger, C.A.: Quantum pattern recognition. Quantum Inf. ments would let to describe the obtained values with higher Process. 1(6), 471–493 (2002) accuracy. 13. Trugenberger, C.A.: Phase transitions in quantum pattern recogni- The further work on the idea of using quantum circuit tion. Phys. Rev. Lett. 89, 277903 (2002) as a classifier should develop in direction of deeper analy- 14. Wiebe, N., Kapoor, A., Svore, K.M.: Quantum algorithms for nearest-neighbor methods for supervised and unsupervised learn- sis of Hamiltonian H used in (19)—especially to formulate ing. Quantum Inf. Comput. 15(3–4), 316–356 (2015) the matrix U given there. The other issue is to simulate 15. Winiewska, J., Sawerwain, M.: Recognizing the pattern of binary the behaviour of quantum circuit and check if the averaged hermitian matrices by a quantum circuit. Intelligent Information results will overlap with calculated values of probability from and Database Systems. 9th Asian Conference, ACIIDS 2017, Pro- ceedings, Part I, pp. 466–475 (2017) Tables 1, 2, 3. Finally, looking for the system of describing 16. Yoo, S., Bang, J., Lee, C., Lee, J.: A quantum speedup in machine matrices by feature vectors to increase pattern recognition learning: finding an N-bit Boolean function for a classification. would be also very interesting. New J. Phys. 16(10), 103014 (2014) 17. Ruan, Y., Chen, H., Tan, J., Li, X.: Quantum computation for large- scale image classication. Quantum Inf. Process. 15(10), 4049–4069 Open Access This article is distributed under the terms of the Creative (2016) Commons Attribution 4.0 International License (http://creativecomm 18. Zhaokai, L., Xiaomei, L., Nanyang, X., Jiangfeng, D.: Experimen- ons.org/licenses/by/4.0/), which permits unrestricted use, distribution, tal realization of quantum articial intelligence. arXiv: 1410.1054v1 and reproduction in any medium, provided you give appropriate credit [quant-ph] (2014) to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made. Publisher’s Note Springer Nature remains neutral with regard to juris- dictional claims in published maps and institutional affiliations. References 1. Cortes, C., Vapnik, V.: Support-vector networks. Mach. Learn. 20(3), 273–297 (1995) http://www.deepdyve.com/assets/images/DeepDyve-Logo-lg.png Vietnam Journal of Computer Science Springer Journals

Recognizing the pattern of binary Hermitian matrices by quantum kNN and SVM methods

Free
8 pages
Loading next page...
 
/lp/springer_journal/recognizing-the-pattern-of-binary-hermitian-matrices-by-quantum-knn-O7VL8al444
Publisher
Springer Berlin Heidelberg
Copyright
Copyright © 2018 by The Author(s)
Subject
Computer Science; Information Systems and Communication Service; Artificial Intelligence (incl. Robotics); Computer Applications; e-Commerce/e-business; Computer Systems Organization and Communication Networks; Computational Intelligence
ISSN
2196-8888
eISSN
2196-8896
D.O.I.
10.1007/s40595-018-0115-y
Publisher site
See Article on Publisher Site

Abstract

The article contains a description of two quantum circuits for pattern recognition. The first approach is realized with use of k nearest neighbors algorithm and the second with support vector machine. The task is to distinguish between Hermitian and non-Hermitian matrices. The quantum circuits are constructed to accumulate elements of a learning set. After this process, circuits are able to produce a quantum state which contains the information if a tested element fits to the trained pattern. To improve the efficiency of presented solutions, the matrices were uniquely labeled with feature vectors. The role of the feature vectors is to highlight some features of the objects which are crucial in the process of classification. The circuits were implemented in Python programming language and some numeric experiments were conducted to examine the capacity of presented solutions in pattern recognition. Keywords Quantum circuits · Pattern recognition · Supervised machine learning · Hamming distance 1 Introduction ficial neural networks: the data describing the patterns are enclosed in learning and testing sets, and the circuit obtains A conception of solving problems with use of k Near- the learning set and is able to recognize if a tested element est Neighbor (kNN) algorithm was created in fifties of the fits to the pattern emerging from the learning set. An aim of previous century [2] and it is still very popular and devel- this article is to verify a thesis if quantum circuits based on ops constantly. In addition, the concept of Support Vector kNN and SVM methods are able to recognize Hermitian and Machine (SVM) for problems of classification is a known non-Hermitian matrices. solution, which actual version was presented in 1995 [1]. As This work is an extended version of conference ACIIDS researchers working on some aspects of quantum computing, 2017 paper: [15]—in that article, we simulated a quantum cir- we were inspired by kNN and SVM methods to apply the idea cuit based on kNN algorithm which role was to classify the of pattern recognition in quantum circuits [4,6,14,16]. Hermitian and non-Hermitian matrices. This article is orga- We refer to [9,12,13], where it was shown that it is possi- nized as follows: in Sect. 2, we present some basic definitions ble to build a quantum circuit which works as a classifier. The helpful in understanding the main idea of this work. Sec- basic idea was prepared to be utilized in the field of image tion 3 is dedicated to the detailed description of the quantum processing [8,17,18]. The kNN and SVM were constructed circuit for kNN method and Sect. 4 contains the construc- with visible inspiration flowing out of methods used in arti- tion of quantum solution for SVM. In Sect. 5, the results of computational experiments were analysed. A summary and conclusions are presented in Sect. 6. B Joanna Wisnie ´ wska jwisniewska@wat.edu.pl Marek Sawerwain M.Sawerwain@issi.uz.zgora.pl 2 Quantum computing—basic definitions Institute of Information Systems, Faculty of Cybernetics, Military University of Technology, Kaliskiego 2, 00-908 Warsaw, Poland To explain the analysed matter, we need to introduce a few definitions corresponding to quantum information process- Institute of Control and Computation Engineering, University of Zielona Góra, Licealna 9, 65-417 Zielona Góra, Poland ing [5]. First, notion concerns a quantum bit—so-called qubit 123 Vietnam Journal of Computer Science which is a normalized vector in a two-dimensional Hilbert |x=|x ⊗|x  ⊗ ··· ⊗ |x ⊗|x . (6) 0 1 n−2 n−1 space H . The impact of Hadamard gate on state |x  is Two orthogonal qubits constitute a computational basis. Of course, we can imagine the infinite number of such paired H |x= H (|x ⊗|x  ⊗ ··· ⊗ |x ⊗|x ) 0 1 n−2 n−1 qubits. One of the most known basis is so-called standard basis. This basis is created by qubits: = H |x ⊗ H |x  ⊗ ··· ⊗ H |x ⊗ H |x 0 1 n−2 n−1 n−1 n−1 = H |x = √ |0+ (−1) |1 . 1 0 i =0 i =0 |0= , |1= . (1) 2 0 1 (7) where the form |· is a Dirac notation. The difference between As we can see the Hadamard gate makes all absolute values classical bit and qubit is that qubit may be a "mixture" of of state’s amplitudes even (equal to ), so it causes the orthogonal vectors. This phenomenon is called superposi- phenomenon of superposition in a quantum register. tion. Hence, the state of quantum bit |ψ  we can present as It is important to remember that quantum gates, in contrast to classical ones, always have the same number of inputs and 2 2 |ψ= α |0+ α |1, where |α | +|α | = 1. (2) 0 1 0 1 outputs. It is so because they were designed as reversible The coefficients α and α are complex numbers and they 0 1 operators the matrix form of quantum gate is unitary and are termed amplitudes. A character of quantum state is non- Hermitian. deterministic. The probability that the state |ψ  equals |0 is Another basic gate is an exclusive-or (XO R) gate, called |α | and, adequately, the probability that the state |ψ  is |1 also a controlled negation (CN OT ) gate. This gate has two is expressed by value |α | . Of course, it is also possible that 1 entries and, naturally, two outputs. The operation XO R one of the amplitudes equals to 0 and the other to 1 (in this is realized on the second qubit (the first qubit remains case state |ψ  is one of basic states). unchanged): If we need more than one quantum bit to perform any calculations, we can use a quantum register which is a system XO R|00=|00, XO R|01=|01, of qubits, joined by a tensor product (denoted by symbol ⊗) XO R|10=|11, XO R|11=|10. (8) in a mathematical sense. For example, the state |φ of 3-qubit register containing qubits |0, |1 and |1 is The matrix form of this gate is ⎡ ⎤ 1 0 0 |φ=|0⊗|1⊗|1= ⊗ ⊗ . (3) 0 1 1 ⎢ ⎥ ⎢ ⎥ XO R = . (9) ⎣ ⎦ Usually, we omit the symbols ⊗, so the above state may be also denoted as |φ=|011. In case of any n-qubit state |ϕ, its form can be expressed as a superposition of basic states: 3The k nearest neighbors algorithm |ϕ= α |00 ... 000+ α |00 ... 001 0 1 In this work, we would like to use a quantum circuit to check if +α |00 ... 010+ ... + α n |11 ... 111 (4) 2 (2 −1) some matrices are Hermitian or not. The approach presented in this section is based on the k Nearest Neighbors (kNN) where the normalization condition must be fulfilled: algorithm for pattern classification [9]. As an example, we chose the matrices which are binary and unitary, sized 4 × 4 2 −1 as in Fig. 1. In this case, all analysed matrices are column (or |α | = 1,α ∈ C. (5) i i row, interchangeably) permutations of identity matrix I . i =0 4×4 Let us remind that a matrix U is Hermitian when it is equal To perform the calculations on quantum states, we use to its conjugate transpose: quantum gates. Quantum gates have to preserve a quan- tum state—that means the performed operation preserves the U = U . (10) state’s normalization condition—so they have to be unitary operators to ensure this feature. Because the analysed set of matrices does not contain any The gate which is very useful in many algorithms is a matrices with complex elements, it would be some simpli- Hadamard gate H.Let |x  be a n-qubit state as in example fication to say that a Hermitian matrix is just equal to its Eq. (3), but with labeled qubits: transpose what can be observed in Fig. 1. 123 Vietnam Journal of Computer Science In carried out computational experiment matrices 4 × 4 were taken into account, so the number of quantum circuit’s (Fig. 2) inputs/outputs is 33. In general, if the matrices are sized k × k, the number of inputs/outputs is 2k + 1. The first k inputs serve to enter the succeeding elements of testing set. The next k inputs serve to constitute a learning set. There is also one ancilla input on which the Hadamard operation is performed. First, we would like to describe a block labeled Op. Learn.Set. Its role in the circuit is to accumulate the ele- ments of learning set. The learning set contains binary series describing Hermitian matrices. We can roughly call these series permutative—the number of ones is similar (e.g., for unitary matrices is always equal to 4), but they occupy other positions in series. It means that the block Op.Learn.Set is a subsystem built of gates XO R and H, because the XO R gates ensure the permutations and H gates allow to accumu- late some different series in qubits of quantum register. The block Op.Test.Set is also constructed of XO R and H gates, but it differs from the subsystem Op.Learn. Set. This block contains only one element of testing set, representing Hermitian or non-Hermitian matrix, in each computational experiment. It means that, in case of unitary Fig. 1 Set of all binary and unitary matrices sized 4 × 4, divided into matrices 4 × 4, we have to perform 24 experiments, always Hermitian and non-Hermitian matrices. The bigger dots stand for 1 and with different block Op.Test.Set. the smaller dots for 0 Summarizing this part of the circuit, we have the initial quantum state entering the system: ⊗2k +1 |ψ =|0 . (12) Then, the first k qubits will be affected by the block Op.Test.Set and successive k qubits by the block Op.Learn.Set to produce the superposition of elements from a learning set: p p √ |l ,..., l , (13) Fig. 2 Quantum circuit classifying Hermitian and non-Hermitian p=1 matrices where L denotes the number of elements in learning set and l represents the successive qubits. The quantum circuit to perform a Hermitian matrices’ The first k qubits describe an element from a testing recognition is shown in Fig. 2. Although in this work, we set. It means that after the operations caused by blocks only test a circuit for matrices sized 4 × 4, the presented Op.Learn.Set, Op.Test.Set and Hadamard gate on circuit is universal in terms of matrix dimensions. ancilla qubit the system’s state is To describe the matrices, we use 16-element binary series which are built of matrix elements row by row: ⎛ ⎞ p p ⎝ ⎠ |ψ =|t ,..., t 2⊗ √ |l ,..., l 1 1 2 k 1 ⎡ ⎤ p=1 ⎢ ⎥ ⎢ ⎥ ⊗ √ (|0+|1) (14) → 1000|0010|0001|0100 → 1000001000010100. ⎣ ⎦ (11) where t stands for the qubits of element from the testing set. 123 Vietnam Journal of Computer Science The next block serves to calculate the Hamming distance is close to the pattern described in the learning set (is Her- between one test series and elements of learning set. The mitian), and if the result is |1, the matrix should not be Hamming distance is a measure expressing the difference Hermitian. between two series. It tells how many elements, occupy- It should be emphasized that the quantum implementa- ing the same positions, differ from each other. The block tion of kNN method has a lower computational complexity Ham.Dist.Calculation uses the XO R operations on in comparison with kNN method running on a classical every couple of qubits (t , l ) and saves their results as d in computer. The first difference is connected with the phase the part of register which previously contained elements of a of learning—in the classical approach, the complexity is learning set: affected by the number and length of series included in the learning set, while in quantum system, only the length p p 2 k of learning series influences its complexity. The second XO R(t , l ) = (t , d ), i = 1,..., k . (15) i i i i advantage of quantum approach in the field of complexity is an ability to compare a tested element with all ele- After this operation, the system’s state is ments from learning set simultaneously (a phenomenon of quantum parallelism takes place during the calculation of L p p |ψ =|t ,..., t 2⊗ |d ,..., d 2 1 k 2 p=1 1 L Hamming distances). Finally, the complexity of quantum √ kNN is: O(k + Hc), where Hc stands for the complexity ⊗ (|0+|1). of Hamiltonian (17) simulation. The simulation of Hamil- (16) tonian [3] may realized with no greater complexity than log(1/) O(tdH  + ), where t is a interval of time, d is max log log(1/) If the differences are already computed, then they must a sparse of Hamiltonian, H  is a value of Hamiltonian’s max be summed to obtain the Hamming distance. The block maximal element, and  stands for accuracy. Quantum Summing stands for the operation U : ⊗k 10 10 −i H 2 4 Support vector machine 2k U = e , H = I ⊗ ⊗ , (17) 2 2 k ×k 00 0 −1 Support Vector Machine (SVM) is a method used in a field where i represents the imaginary unit. This results with the of supervised learning. Let us assume that we have a learning state |ψ : set containing vectors from two different classes: C and C . 1 2 The SVM’s goal is to find a hyperplane g(x): |ψ = √ p=1 2L T g(x) = w x + w (20) i d(t ,l ) p p 2k e |t ,..., t 2⊗|d ,..., d ⊗|0+ k 2 p separating vectors from C and C : −i d(t ,l ) 1 2 p p 2k + e |t ,..., t 2⊗|d ,..., d ⊗|1 . k 2 (18) g(x) ≥ 1, ∀ ∈ C x 1 g(x) ≤−1, ∀ ∈ C (21) x 2 The last step is designed to reverse the Hadamard operation on the last qubit (of course with use of reversible H gate). In addition, the hyperplane must be calculated in a way That will allow to measure the last qubit in the standard basis maximizing the margin z, which is a distance between a and obtain |0 or |1 with sufficiently high probability. The hyperplane and objects from C and C : 1 2 final state of the whole system is |g(x)| 1 1 L z = = (22) |ψ = √ w w p=1 p p p cos d(t , l ) |t ,..., t 2⊗|d ,..., d ⊗|0+ k 2 2 k That means an aim is to minimize w. This task may be 2k p p p formulated as finding a solution of Lagrange function L(˘) + sin d(t , l ) |t ,..., t 2⊗|d ,..., d ⊗|1 . k 2 2 1 2k using Karush–Kuhn–Tucker conditions: (19) M M Now, the measurement needs to be done only on the last L(λ) = g (x)λ − λ K λ (23) i i i i , j j ancilla qubit. If the result is |0 that means the tested matrix i =1 i , j =1 123 Vietnam Journal of Computer Science where 2 2 C = w + λ . (27) 0 i i =1 The training data Oracle causes that all eigenvectors |ˆ u of Fig. 3 Scheme of quantum circuit implementing the SVM method matrix F: |ˆ u= √ w |0|0+ λ |x ||i |x  (28) 0 i i i under constraints: u ˆ i =1 where λ = 0 and g (x)λ ≥ 0, (24) i i i i =1 2 2 2 N = w + λ |x | . (29) u ˆ i 0 i i =1 where M is a number of training examples, vector λ stands for the Lagrange multipliers and K is a kernel matrix K = i , j The last block is to calculate the probability telling if an x · x . Then, the machine should be able to classify the j arbitrary vector |t from the training set may be classified to unknown vectors according to (21). C or C : 1 2 The computational complexity of SVM is polynomial and depends on the dimensions of classified vectors and the num- |t= √ |0|0+ |t||i |t (30) ber of elements in the training set. Of course, using the i =1 quantum version of this method, the complexity may be reduced to logarithmic. The speedup is achieved utilizing with a quantum circuit to calculate in parallel the inner products of the vectors. Then, the SVM training is converted to an N = M |t| + 1. (31) approximate least-squares problem which may be solved by the quantum matrix inversion algorithm with O(κ log X ), The final state of the system is where κ stands for a condition number of a X-equation sys- tem [7,9–11]. |ψ= √ |ˆ u|0+|t|1 (32) The process of quantum calculations may be shown as in Fig. 3 according to [18]. The presented circuit has (N + 2) inputs/outputs, where N is a number of elements in classified and the measurement on the last qubit has to be performed. If vectors. Solving (23) leads to a least-square approximation of the obtained value is |1, it means that the vector |t belongs calculating matrix F , because the SVM parameters M +1×M +1 to the class C , and if the value of the last qubit is |0, then are determined by the vector belongs to C . T T −1 T T (w , λ ) = F (0, g(x) ) , (25) 5 Results of the experiments so the first block performs the matrix F inversion to calcu- We conducted a computational experiments to examine if a late the hyperplane g(x), but it also accumulates the values quantum system is able to recognize the pattern of Hermitian of training set, because for matrix F, it is possible to calcu- and non-Hermitian matrices sized 4 × 4. The calculations late its eigenvectors |u  and corresponding eigenvalues α for kNN were based on Eq. (19) and the calculations for j j ( j = 1, ..., (M + 1)). On the first N qubits of the compu- SVM on (28) and (30). The results presented in this section tational register phase estimation generates the state storing were delivered by a script written in Python programming training data. After the operation performed by the block language. MatrixInversion, we will obtain the state: The first experiments were conducted on sets of unitary matrices described as 16-element binary series as in (11). The results of these computations are presented in Table 1 (the numbers were rounded to four decimal places). For kNN |w , λ= √ w |0+ λ |i  (26) 0 0 i C method, the learning set contains the Hermitian matrices. i =1 123 Vietnam Journal of Computer Science Table 1 Results of pattern recognition for quantum versions of kNN Table 2 Results of pattern recognition for quantum versions of kNN and SVM methods and SVM methods Hermitian matrices in TS non-Hermitian matrices in TS Hermitian matrices in TS non-Hermitian matrices in TS kNN SVM kNN SVM kNN SVM kNN SVM P P P P P P P P P P P P |0 |1 |0 |1 |0 |1 |0 |1 0.6207 0.3792 0.5000 0.6472 0.3527 0.4999 0.8898 0.1101 0.5634 0.7562 0.2437 0.5452 0.6972 0.3027 0.5427 0.6826 0.3173 0.4430 0.9223 0.0776 0.5634 0.7562 0.2437 0.5452 0.6207 0.3792 0.5569 0.6826 0.3173 0.4430 0.9223 0.0776 0.5872 0.8319 0.1680 0.5059 0.6972 0.3027 0.5569 0.6472 0.3527 0.5000 0.9223 0.0776 0.5820 0.8373 0.1626 0.4482 0.6207 0.3792 0.5569 0.6472 0.3527 0.4999 0.9223 0.0776 0.6097 0.6913 0.3086 0.5452 0.6972 0.3027 0.5568 0.6826 0.3173 0.4430 0.9440 0.0559 0.5634 0.7237 0.2762 0.5358 0.6972 0.3027 0.5569 0.6472 0.3527 0.4858 0.9007 0.0992 0.5634 0.6696 0.3303 0.5144 0.6972 0.3027 0.5427 0.6826 0.3173 0.4430 0.9332 0.0667 0.5634 0.6696 0.3303 0.5340 0.6972 0.3027 0.5568 0.6826 0.3173 0.4430 0.8790 0.1209 0.5905 0.7056 0.2943 0.4897 0.7621 0.2378 0.5000 0.6472 0.3527 0.4858 0.8790 0.1209 0.6047 0.7056 0.2943 0.5404 0.6472 0.3527 0.5000 0.7056 0.2943 0.4675 0.6826 0.3173 0.4430 0.7014 0.2943 0.5405 0.6826 0.3173 0.4430 0.6696 0.3303 0.5405 0.6826 0.3173 0.5000 0.7056 0.2943 0.5405 The learning set contains only Hermitian matrices. Abbreviation TS The learning set contains only Hermitian matrices. Abbreviation TS stands for the test set. The matrices 4 × 4 were written as 16-element stands for the test set. The matrices 4 × 4 were encoded as 16-element series feature vectors As we can see the Hermitian matrices were recognized with a quite high probability. The problem is that also the non- Hermitian matrices were recognized as patterns similar to patterns in learning set—the kNN method uses the Hamming distance to distinguish between series and all used series con- tain 4 elements equal to one and 12 elements equal to zero, so probably, the series were treated as similar by the utilized method. For the SVM method, we assume that Hermitian matrices belong to the class C and non-Hermitian to C . The algo- 1 2 rithm for SVM was implemented to point the class with value P:if P > 0.5 the matrix belongs to C and if P < 0.5–C . 1 2 Fig. 4 Discrimination line for values of probability for the kNN method In comparison with the SVM method allowed to obtain better when matrices are encoded with feature vectors results. However, there are 2 Hermitian and 3 non-Hermitian matrices with P = 0.5000, so the method was not able to classify these matrices unambiguously. written in a series. Let us assign the matrices to labels: at the To improve the pattern recognition, we propose to label beginning, the set of series presenting matrices is sorted in the the matrices and run the calculations using labels. The same way as labels; we extract all 1024 Hermitian matrices labels should be constructed as feature vectors in a way from the set of series and we assign them to the first 1024 increasing the Hamming distances between Hermitian and labels; other non-Hermitian matrices we assign to remaining non-Hermitian matrices. labels. This approach allows to decrease the number of ones The labels are 16-bit binary series to provide a unique label in labels corresponding to Hermitian matrices and to increase for every binary matrix sized 4 × 4. The labels are ordered: the number of ones in labels corresponding to non-Hermitian the first label contains 16 zeros, next 16 labels contain 1 matrices. Table 2 contains the results of learning using labels. figure one and 15 zeros, subsequent series contain 2 ones, 3 We can see that the kNN method still tends to classify ones, and so on until we obtain a series of 16 ones. In every all matrices as Hermitian, but it is possible to calculate a group of labels with the same number of ones, the series discrimination line (see Fig. 4) between values of P for |0 are sorted ascending in the meaning of the binary number Hermitian and non-Hermitian matrices, because the lowest 123 Vietnam Journal of Computer Science Table 3 Results of pattern recognition for quantum versions of kNN and SVM methods Hermitian matrices in TS non-Hermitian matrices in TS kNN SVM kNN SVM P P P P P P |0 |1 |0 |1 0.8859 0.1140 0.5596 0.7468 0.2531 0.5425 0.9183 0.0816 0.5596 0.7865 0.2134 0.5425 0.9118 0.0881 0.5596 0.8011 0.1988 0.4696 0.9118 0.0881 0.5596 0.7856 0.2143 0.5359 0.9002 0.0997 0.5823 0.7459 0.2540 0.4942 0.9079 0.0920 0.5596 0.7451 0.2548 0.5425 Fig. 5 Discrimination line for values of probability for the SVM method 0.8898 0.1101 0.5596 0.7488 0.2511 0.5380 when matrices are encoded with feature vectors 0.9040 0.0959 0.5596 0.7488 0.2511 0.4749 0.9028 0.0971 0.5810 0.7331 0.2668 0.5380 value of probability for Hermitian matrices is 0.8790 and the 0.8963 0.1036 0.5596 0.7331 0.2668 0.4993 highest value of P for non-Hermitian matrices is 0.8313. |0 0.9704 0.0295 0.8530 0.7046 0.2953 0.5376 The same situation we can observe for the SVM method with 0.9446 0.0553 0.5832 0.7016 0.2983 0.5380 a discrimination line (see Fig. 5) between values 0.5634 and 0.9446 0.0553 0.5832 0.7040 0.2959 0.5373 0.5452. 0.9473 0.0526 0.5832 0.7046 0.2953 0.4857 The last experiment was conducted with use of labels, but 0.9366 0.0633 0.5832 0.7961 0.2038 0.5425 the learning and test sets were more numerous (28 Hermitian 0.9313 0.0686 0.5832 0.7509 0.2490 0.5425 and 40 non-Hermitian matrices were used). The sets were 0.9313 0.0686 0.5832 0.7153 0.2846 0.5380 enhanced with labels corresponding to non-unitary matrices. 0.9313 0.0686 0.5981 0.7205 0.2794 0.5380 The results are presented in Table 3. 0.9145 0.0854 0.5596 0.7385 0.2614 0.5380 Increasing the number of elements in the learning set 0.9079 0.0920 0.5596 0.7385 0.2614 0.5380 caused some improvement for kNN method—the lowest 0.9079 0.0920 0.5596 0.6575 0.3424 0.5347 value of P = 0.8859 for Hermitian matrices and the |0 0.9079 0.0920 0.5654 0.6823 0.3176 0.5347 highest value of P = 0.8011 for non-Hermitian matri- |0 0.9079 0.0920 0.5831 0.6362 0.3637 0.5347 ces. However, this strategy did not improve the results for 0.8975 0.1024 0.5596 0.6376 0.3623 0.5347 SVM method. 0.8975 0.1024 0.5983 0.5235 0.4764 0.5322 Of course, it should be emphasized that the presented 0.9079 0.0920 0.5596 0.5502 0.4497 0.5322 approach with use of quantum versions of kNN and SVM 0.9079 0.0920 0.5964 0.5578 0.4421 0.5322 has a probabilistic character. That implies the fact that the 0.8975 0.1024 0.5853 0.5230 0.4769 0.5322 calculations have to be repeated to obtain the most accurate 0.5710 0.4289 0.5322 approximation of distribution shown in tables above. The 0.5641 0.4358 0.5322 probabilities of measuring |0 or |1 on the last qubit are dif- ferent, so it allows to indicate the distance of analysed case 0.5443 0.4556 0.5322 from the learning set. In general, the computations illustrated 0.4556 0.5443 0.5301 by the quantum circuits should be performed O( P(1− P) ) 0.4145 0.5854 0.5301 times to obtain probability P distribution with accuracy ε. 0.4423 0.5576 0.5284 0.4352 0.5647 0.5284 0.4765 0.5234 0.5284 6 Summary 0.4502 0.5497 0.5284 0.2317 0.7682 0.5246 The computational experiments showed that the quantum cir- 0.1990 0.8009 0.5246 cuits are able to distinguish between the pattern of Hermitian 0.1115 0.8884 0.5228 and non-Hermitian matrices. Abbreviation TS stands for the test set. The binary matrices (unitary In case of kNN, the way of encoding patterns is very and non-unitary) were encoded as feature vectors important. The kNN method uses Hamming distance to dis- tinguish between the matrices so using feature vectors to 123 Vietnam Journal of Computer Science describe the recognized objects should comply the charac- 2. Fix, E., Hodges, J.L.: Discriminatory Analysis, Nonparametric Dis- crimination: Consistency Properties. Technical Report 4, USAF ter of Hamming distance measure. The distances between School of Aviation Medicine, Randolph Field, Texas (1951) objects from the same class should be as small as possible. On 3. Low, G.H., Chuang, I.L.: Optimal Hamiltonian Simulation the other side, distances between objects belonging to other by Quantum Signal Processing. arXiv:1606.02685v2 [quant-ph] classes should be increased. In our experiments, we used the (2016) 4. Mateus, P., Omar, Y.: Quantum Pattern Matching. system of labels to describe the matrices. Hermitian matrices arXiv:quant-ph/0508237v1 (2005) were described by vectors with the minimal needed number 5. Nielsen, M.A., Chuang, I.L.: Quantum computation and quantum of ones and non-Hermitian matrices with maximal number of information. Cambridge University Press, New York (2000) ones. In case of feature vectors for unitary Hermitian matri- 6. Pinkse, P.W.H., Goorden, S.A., Horstmann, M., Škoric, ´ B., Mosk, A.P.: Quantum pattern recognition. 2013 Conference on and ces, the number of ones is equal to 2 and for non-Hermitian International Quantum Electronics Conference Lasers and Electro- matrices: 4 and 5. The pattern recognition was more efficient Optics Europe (CLEO EUROPE/IQEC), Munich, pp. 1–1 (2013) when the learning set was extended by non-unitary matrices. 7. Rebentrost, P., Mohseni, M., Lloyd, S.: Quantum support vector The conclusion is obvious: not only the number of ones is an machine for big data classification. Phys. Rev. Lett. 113, 130503 (2014) important factor for Hamming distance, but also the position 8. Schaller, G., Schtzhold, R.: Quantum algorithm for optical- of figures in series and non-unitary matrices brought some template recognition with noise filtering. Phys. Rev. A 74, 012303 diversity in this aspect (there may be Hermitian matrices with (2006) 0 to 4 figures equal to one and non-Hermitian with 4–16 fig- 9. Schuld, M., Sinayskiy, I., Petruccione, F.: Quantum computing for pattern classication. In: 13th Pacic Rim International Conference ures equal to one). The similar results were presented in [9]. on Articial Intelligence (PRICAI) and Also Appear in the Springer The SVM method was surprisingly efficient even for a Lecture Notes in Computer Science 8862 (2014) small learning set and series generated directly from matrices 10. Schuld, M., Sinayskiy, I., Petruccione, F.: An introduction to quan- as in (11). Utilizing the feature vectors allowed to introduce tum machine learning. Contemp. Phys. 52, 172–185 (2014). https:// doi.org/10.1080/00107514.2014.964942 a clear discrimination line between the values of P pointing 11. Senekane, M., Taele, B.M.: Prediction of solar irradiation using objects from the classes C and C . 1 2 quantum support vector machine learning algorithm. Smart Grid It should also be emphasized that the character of quantum Renew. Energy 7, 293–301 (2016). https://doi.org/10.4236/sgre. computations is probabilistic and conducting more experi- 2016.712022 12. Trugenberger, C.A.: Quantum pattern recognition. Quantum Inf. ments would let to describe the obtained values with higher Process. 1(6), 471–493 (2002) accuracy. 13. Trugenberger, C.A.: Phase transitions in quantum pattern recogni- The further work on the idea of using quantum circuit tion. Phys. Rev. Lett. 89, 277903 (2002) as a classifier should develop in direction of deeper analy- 14. Wiebe, N., Kapoor, A., Svore, K.M.: Quantum algorithms for nearest-neighbor methods for supervised and unsupervised learn- sis of Hamiltonian H used in (19)—especially to formulate ing. Quantum Inf. Comput. 15(3–4), 316–356 (2015) the matrix U given there. The other issue is to simulate 15. Winiewska, J., Sawerwain, M.: Recognizing the pattern of binary the behaviour of quantum circuit and check if the averaged hermitian matrices by a quantum circuit. Intelligent Information results will overlap with calculated values of probability from and Database Systems. 9th Asian Conference, ACIIDS 2017, Pro- ceedings, Part I, pp. 466–475 (2017) Tables 1, 2, 3. Finally, looking for the system of describing 16. Yoo, S., Bang, J., Lee, C., Lee, J.: A quantum speedup in machine matrices by feature vectors to increase pattern recognition learning: finding an N-bit Boolean function for a classification. would be also very interesting. New J. Phys. 16(10), 103014 (2014) 17. Ruan, Y., Chen, H., Tan, J., Li, X.: Quantum computation for large- scale image classication. Quantum Inf. Process. 15(10), 4049–4069 Open Access This article is distributed under the terms of the Creative (2016) Commons Attribution 4.0 International License (http://creativecomm 18. Zhaokai, L., Xiaomei, L., Nanyang, X., Jiangfeng, D.: Experimen- ons.org/licenses/by/4.0/), which permits unrestricted use, distribution, tal realization of quantum articial intelligence. arXiv: 1410.1054v1 and reproduction in any medium, provided you give appropriate credit [quant-ph] (2014) to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made. Publisher’s Note Springer Nature remains neutral with regard to juris- dictional claims in published maps and institutional affiliations. References 1. Cortes, C., Vapnik, V.: Support-vector networks. Mach. Learn. 20(3), 273–297 (1995)

Journal

Vietnam Journal of Computer ScienceSpringer Journals

Published: May 30, 2018

References

You’re reading a free preview. Subscribe to read the entire article.


DeepDyve is your
personal research library

It’s your single place to instantly
discover and read the research
that matters to you.

Enjoy affordable access to
over 18 million articles from more than
15,000 peer-reviewed journals.

All for just $49/month

Explore the DeepDyve Library

Search

Query the DeepDyve database, plus search all of PubMed and Google Scholar seamlessly

Organize

Save any article or search result from DeepDyve, PubMed, and Google Scholar... all in one place.

Access

Get unlimited, online access to over 18 million full-text articles from more than 15,000 scientific journals.

Your journals are on DeepDyve

Read from thousands of the leading scholarly journals from SpringerNature, Elsevier, Wiley-Blackwell, Oxford University Press and more.

All the latest content is available, no embargo periods.

See the journals in your area

DeepDyve

Freelancer

DeepDyve

Pro

Price

FREE

$49/month
$360/year

Save searches from
Google Scholar,
PubMed

Create lists to
organize your research

Export lists, citations

Read DeepDyve articles

Abstract access only

Unlimited access to over
18 million full-text articles

Print

20 pages / month

PDF Discount

20% off