Handwritten digit recognition methods, products, media, and equipment based on quantum neural networks
By constructing a quantum neural network based on quantum optimization algorithms and utilizing multi-qubit controlled Ry gates and swapping testing techniques, the problem of low efficiency and accuracy of existing quantum neural networks in handwritten digit recognition was solved, achieving a more efficient recognition effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHANGCHUN UNIV OF SCI & TECH
- Filing Date
- 2024-07-31
- Publication Date
- 2026-08-04
AI Technical Summary
Existing quantum neural network models fail to fully utilize the properties of quantum superposition and parallel computing, resulting in low efficiency and accuracy in handwritten digit recognition.
A quantum neural network is constructed using a quantum optimization algorithm. The network structure is determined by minimizing the cross-entropy loss function. Image data is converted into quantum image information using a multi-qubit controlled Ry gate. Quantum layers and activation layers are constructed by combining exchange testing technology to achieve nonlinear mapping, and finally, the handwritten digit recognition result is output.
It improves the efficiency and accuracy of handwritten digit recognition, makes full use of quantum superposition properties and parallel computing characteristics, reduces storage resources, and increases computing and training speed.
Smart Images

Figure CN119131812B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of quantum computing technology, and in particular to a method, product, medium, and device for handwritten digit recognition based on quantum neural networks. Background Technology
[0002] Currently, the recognition of human handwriting remains a hot research topic. Handwriting recognition technology has been widely applied in tax form processing, mail sorting, and computerized document review. Among these applications, the recognition of handwritten digits is prevalent in scenarios such as bank check information, envelope postal code information, and customs. These applications typically require handwritten digit recognition algorithms to have high recognition speed, accuracy, reliability, and stability. Although there are only ten categories of handwritten digits and their strokes are simple, recognizing them remains a significant challenge. Existing technologies employ quantum neural networks to achieve handwritten digit recognition.
[0003] Quantum neural networks are a popular interdisciplinary field arising from the intersection of traditional computer science and quantum information science. Combining the fundamental principles of artificial neural networks with the quantum computing paradigm can solve bottlenecks hindering the development of both fields, and it has shown broad application prospects in areas such as function approximation and big data processing. Artificial neural networks are parallel distributed information processors composed of neurons, capable of learning patterns and relationships from massive amounts of data to solve various complex tasks. With the development of quantum computing, quantum neural networks offer new possibilities for solving problems that classical computers have failed to address. However, despite the widespread attention given to quantum neural networks, practical applications related to their fundamental quantum neuron computing mechanisms are scarce.
[0004] By combining the unique properties of neural networks with quantum computing, and utilizing quantum characteristics such as quantum entanglement, interference, and superposition, some scholars have proposed systematic methods for implementing quantum neural networks. These networks can handle binary strings of arbitrary length. However, limited by the scale of input qubits in confined quantum simulators, quantum neural networks still fall short in reflecting the computational mechanisms of basic neurons. Compared to classical versions, quantum neural networks offer exponentially increased memory capacity, faster learning capabilities, and higher stability and reliability. Although various quantum neural network models have been developed and significant progress has been made in quantum communication, quantum encryption algorithms, quantum image processing, and quantum artificial intelligence, existing quantum neural network models largely employ a quantum-classical hybrid framework. Their normal operation often relies on traditional algorithms or computational models, and the traditional computational components within the network often contribute more to the final output of the entire quantum neural network.
[0005] Most quantum neural network models can also be called quantum-inspired neural networks, but they cannot run on quantum computers. Instead, they are classical neural networks inspired by quantum principles with the addition of some quantum algorithms or quantum computing units. Furthermore, most existing quantum neural network models utilize a method of independently encoding pixels with single qubits to quantize image data; that is, the number of pixels in the image is the same as the number of qubits input to the quantum neural network. Therefore, they fail to fully utilize the property of quantum superposition, resulting in stringent requirements on the storage capacity of quantum registers and severely weakening the speedup advantages of quantum parallel computing for quantum algorithms.
[0006] In summary, existing quantum neural network models cannot fully utilize the advantages of quantum superposition and parallel algorithms, resulting in problems such as high storage resources and low computational efficiency. Consequently, when using quantum neural network models to recognize handwritten digits, there are issues with low recognition efficiency and accuracy. Summary of the Invention
[0007] The purpose of this application is to provide a handwritten digit recognition method, product, medium, and device based on quantum neural networks, which can fully utilize the quantum superposition characteristics and parallel computing features of quantum neural networks, thereby effectively improving the efficiency and accuracy of handwritten digit recognition.
[0008] To achieve the above objectives, this application provides the following solution:
[0009] In a first aspect, this application provides a handwritten digit recognition method based on a quantum neural network, including:
[0010] Acquire image data of handwritten digits;
[0011] Image data is input into a quantum neural network, which outputs handwritten digit recognition results. The quantum neural network is determined using a quantum optimization algorithm with the goal of minimizing the cross-entropy loss function. The quantum neural network includes an input layer, a quantum layer, an activation layer, and an output layer connected in sequence. The input layer is equipped with a multi-qubit controlled Ry gate. The input layer is used to convert image data into a quantum image, obtaining an image information qubit sequence.
[0012] The quantum layer is used for:
[0013] The weighted qubit sequence is obtained based on the image information qubit sequence;
[0014] Output information data is obtained based on the image information qubit sequence and the weight qubit sequence;
[0015] The activation layer is used to perform nonlinear mapping on the output information data and then input it to the output layer; the output layer is used to output the handwritten digit recognition result.
[0016] Secondly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the handwritten digit recognition method based on a quantum neural network.
[0017] Thirdly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the handwritten digit recognition method based on a quantum neural network.
[0018] Fourthly, this application provides a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the handwritten digit recognition method based on a quantum neural network.
[0019] According to the specific embodiments provided in this application, the following technical effects are disclosed:
[0020] This application provides a method, product, medium, and device for handwritten digit recognition based on a quantum neural network. First, a quantum neural network is determined using a quantum optimization algorithm with the goal of minimizing the cross-entropy loss function. This quantum neural network can fully utilize the quantum superposition property to reduce storage resources and can also leverage the characteristics of quantum parallel computing to improve the computation and training speed of the quantum neural network. Subsequently, image data of the handwritten digits is acquired and input into the quantum neural network to obtain the handwritten digit recognition result, thereby effectively improving the efficiency and accuracy of handwritten digit recognition. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 An application environment diagram of the handwritten digit recognition method based on quantum neural networks provided in this application;
[0023] Figure 2 A flowchart illustrating the handwritten digit recognition method based on quantum neural networks provided in this application;
[0024] Figure 3 A schematic diagram illustrating the process of constructing a quantum neural network provided in this application;
[0025] Figure 4 A schematic diagram of the handwritten digit training set samples provided in this application;
[0026] Figure 5 A circuit diagram of the image information qubit sequence provided in this application;
[0027] Figure 6 A circuit diagram of the weighted qubit sequence provided in this application;
[0028] Figure 7 A circuit diagram of the switching test technology provided in this application;
[0029] Figure 8 An auxiliary structural diagram of the output state of a quantum layer neuron provided in this application;
[0030] Figure 9 The circuit diagram of the activation layer provided in this application;
[0031] Figure 10 A schematic diagram of the global circuit of the quantum neural network provided in this application;
[0032] Figure 11 The simulation experiment provided for this application is compared with the experimental results of the classical neural network.
[0033] Figure 12 The classification results of the simulation experiment provided in this application are shown in the figure. Detailed Implementation
[0034] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0035] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0036] The handwritten digit recognition method based on quantum neural networks provided in this application can be applied to, for example... Figure 1In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be set up independently, integrated into server 104, or placed in the cloud or on another server. Terminal 102 can send the image data to be processed to server 104. After receiving the image data, server 104 inputs it into a pre-constructed quantum neural network. Server 104 can then provide feedback on the handwritten digit recognition results obtained from the image data to terminal 102. Furthermore, in some embodiments, the handwritten digit recognition method based on the quantum neural network can also be implemented independently by server 104 or terminal 102. For example, terminal 102 can directly input the image data to be processed into the quantum neural network, or server 104 can obtain the image data to be processed from the data storage system and input it into the quantum neural network.
[0037] The terminal 102 can be, but is not limited to, various desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, and smart in-vehicle devices. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted devices. The server 104 can be implemented using a standalone server or a server cluster composed of multiple servers, or it can be a cloud server.
[0038] In one exemplary embodiment, such as Figure 2 As shown, a handwritten digit recognition method based on a quantum neural network is provided. This method is executed by a computer device, specifically by a terminal or server alone, or by both a terminal and a server. In this embodiment, the method is applied to... Figure 1 Taking server 104 as an example, the explanation includes the following steps 1 and 2. Wherein:
[0039] Step 1: Obtain image data of handwritten digits.
[0040] Step 2: Input the image data into the quantum neural network and output the handwritten digit recognition result.
[0041] The quantum neural network of this application is determined by a quantum optimization algorithm with the aim of minimizing the cross-entropy loss function; the quantum neural network includes an input layer, a quantum layer, an activation layer and an output layer connected in sequence; the input layer is provided with a multi-qubit controlled Ry gate; the input layer is used to convert image data into a quantum image to obtain an image information qubit sequence.
[0042] The quantum layer is used to: obtain a weighted quantum bit sequence based on the image information quantum bit sequence; and obtain output information data based on the image information quantum bit sequence and the weighted quantum bit sequence. The activation layer is used to perform a nonlinear mapping on the output information data and then input it to the output layer; the output layer is used to output the handwritten digit recognition result.
[0043] This application's handwritten digit recognition method based on quantum neural networks focuses on using a commutation test to map the inner product of the constructed image information qubit sequence and the weight qubit sequence to the result qubit, thereby constructing the neurons of the initial quantum neural network. Subsequently, it performs image binary classification on 0 / 1 labeled data from the MNIST dataset. By repeatedly optimizing the weight parameters in the initial quantum neural network, a final quantum neural network is constructed and used to classify handwritten digit image data, obtaining the optimal classification result for handwritten digits. Figure 3 As shown, the details are as follows:
[0044] First, obtain the initial training set of handwritten digits and preprocess it to obtain the handwritten digit training set.
[0045] Specifically, a dataset with 0 / 1 labels was randomly selected from the MNIST dataset and divided into an initial training set and a test set, each containing 2000 images. The images in the randomly selected dataset were grayscale images, each 28×28 pixels. The image sizes were then adjusted to 2×2, 4×4, 8×8, and 16×16 pixels, and generally represented as N×N, such as... Figure 4 As shown. The process extracts information from each pixel in each image. Since the image data are all grayscale images, each pixel has only one set of image information. Then, the equation θ = π / 2 - arctan(inputs), where inputs is the input pixel value, is used to convert the i-th input pixel value into its corresponding angle value θ. i Let i = (1,2,…,N×N), and control its range within [0,π / 2] to obtain the handwritten digit training set.
[0046] The quantum neural network is then constructed, specifically including the following steps: (1) constructing the initial quantum state in the initial quantum neural network; (2) initializing the weight qubit state of the initial quantum layer in the initial quantum neural network; (3) constructing the neurons in the initial quantum neural network based on steps (1) and (2) using the exchange test technique; (4) constructing the activation layer part of the initial quantum neural network; (5) training the initial quantum neural network; (6) updating the weight parameters of the initial quantum neural network; and (7) constructing the quantum neural network.
[0047] (1) Constructing the initial quantum state in the initial quantum neural network
[0048] The classical images (image data from the handwritten digit training set) are converted into quantum images and used as input to the initial quantum neural network, which includes several qubits with an initial state of |0>. The input layer of the initial quantum neural network consists of two types of qubits: one type stores the sequence of positional information of the corresponding pixels in the image, and the other type stores the grayscale information of the pixels in the image.
[0049] 1. Determine the number of reusable control qubits as C based on the image size of the image data in the handwritten digit training set, and add a Hadamard gate to put it in a superposition state.
[0050] 2. The number of image information qubit sequences is determined to be M based on the initial number of neurons M in the quantum layer.
[0051] 3. Based on the qubits mentioned above, add a multi-qubit controlled Ry gate to construct the input layer of the initial quantum neural network. Each image information qubit sequence requires C control qubits and one qubit to store the image information qubit sequence. This combination is repeated M times.
[0052] 4. The number of multi-qubit controlled Ry gates required to add to an image information qubit sequence depends on the image size and the number of pixels in the handwritten digit training set. C .
[0053] 5. For the multi-qubit controlled Ry gate required for the image information qubit sequence, set the input parameter value to the angle value θ. i The corresponding control bit sequence is determined by the binary sequence converted from the position information corresponding to the angle value, as shown below.
[0054] Specifically, the specific steps for constructing the initial quantum neural network input layer in step (1) are as follows:
[0055] The first step involves converting a classical image into a quantum image through controlled rotation of a multi-qubit Ry gate. A sequence of image information qubits is then constructed as the input to the initial quantum neural network. The number of image information qubits in the input layer is directly related to the number of neurons in the initial quantum layer. Constructing the initial quantum layer of M neurons requires 3M+C qubits with an initial state of |0>. At this point, the quantum system state is... in, The direct product symbol in quantum computing represents the initial state of the quantum system, which has 3M+C qubits with an initial state of |0>.
[0056] The second step is to determine the number of control qubits C based on the current image size N×N, where n = N×N = 2. CWhere n represents the total number of pixels in an image (n in the following text refers to the total number of pixels), in a quantum circuit, the first C qubits are used as control bits. For these C qubits, a Hadamard gate is first added to put them into a superposition state. At this point, Hadamard gate operations have been added to C qubits, and no operations have been added to the 3M qubits. Therefore, the unitary operation corresponding to the Hadamard gate is: Where C represents the number of control qubits, M represents the number of neurons, H represents the Hadamard gate operation, and I represents the unit gate operation.
[0057] The third step is to construct an image information qubit sequence. Since an image has n pixels, n multi-qubit controlled Ry gates need to be added. This involves converting all pixels in an image into angle values, and then sorting the corresponding angle values from left to right and top to bottom. If the pixel in the image located at (x, y) corresponds to an angle value of θ after transformation, where θ is the parameter value of the quantum gate, then x and y are converted to lengths of... The binary sequence, when concatenated, becomes the control sequence for a multi-qubit controlled Ry gate, i.e., xy = b. C-1 b C-2 …b1b0, where b C-1 ,b C-2 b1, b0 are binary bits, each taking the value 0 or 1. C-1 ,…,b C / 2 b represents the bits of the binary representation of x. C / 2-1 b0 represents the bits of the binary representation of y, and the qubit sequence of a pixel in the image is |X|. i >=|Ry(θ i )b C-1 b C-2 …b1b0>, a sequence of image information qubits is represented as |X>=|x1>+...+|x n >=|Ry(θ1)00...0>+...+|Ry(θ n )11...1>,Ry(·) denotes the quantum rotation gate operation.
[0058] In the circuit, with a multi-qubit controlled Ry gate as the center and a corresponding control sequence of 1 (solid circle), a direct summation is performed on the left side of the equation Ry(θ). Conversely, a direct summation is performed on the right side of the equation, iterating sequentially. The corresponding unitary operation for the angle value θ1 after the first pixel transformation is... The corresponding unitary operation for the angle value θ2 after the second pixel transformation is: And so on, the angle value θ corresponding to the nth pixel after transformationn The corresponding unit operation is
[0059] The fourth step is to construct M image information qubit sequences. One image information qubit sequence requires C+1 qubits, and M image information qubit sequences require C+M qubits. The variation in constructing M image information qubit sequences lies in the change of the unit qubit position in each sequence. All qubits are divided into two parts: the part from the multi-qubit controlled Ry gate to the farthest control bit qubit, and the remaining unit qubit part. For the first image information qubit sequence, the multi-qubit controlled Ry gate and the nearest control bit qubit are considered as a whole, with 0 unit qubits in between, and the remaining part has 3M-1 unit qubits. The corresponding unitary operation for the first pixel value θ1 of the first image information qubit sequence is... The second image information qubit sequence has one unit qubit in the middle and 3M-2 unit qubits in the remaining part. The corresponding unitary operation for the first pixel value θ1 of the second image information qubit sequence is: Similarly, in the Mth image information qubit sequence, there are M-1 unit qubits in between, and 2M unit qubits remaining. The corresponding unitary operation for the angle value θ1 corresponding to the first pixel of the Mth image information qubit sequence after transformation is: Therefore, for the k-th image information qubit sequence pixel, the corresponding angle value θ after conversion j The corresponding unit operation is:
[0060]
[0061] Where, k = (1,2,...,M), j = (1,2,...,n), Let C be the unitary operation corresponding to the j-th multi-qubit controlled Ry gate of the j-th pixel in the k-th image information qubit sequence, where C is the number of control qubits and M is the number of neurons. The k-th image information qubit sequence can be represented as follows:
[0062] (2) Initialize the weight qubit states of the initial quantum layer in the initial quantum neural network
[0063] 1. The image information qubit sequence and the weight qubit sequence are in one-to-one correspondence.
[0064] 2. The number of weight qubit sequences for initializing the initial quantum layer is determined to be M based on the number M neurons in the quantum layer.
[0065] 3. Based on the qubits mentioned above, add multi-qubit controlled Ry gates to construct the weighted qubit sequence of the initial quantum layer. Each weighted qubit sequence requires C control qubits and one qubit to store the weighted qubit information sequence. This combination is repeated M times.
[0066] 4. The number of multi-qubit controlled Ry gates required to construct a weighted qubit sequence is the same as the number required to construct an image information qubit sequence.
[0067] 5. For the multi-qubit controlled Ry gate required for the weighted qubit sequence, set the required parameter values to be within the range of The random angle, its control bit sequence is consistent with the control bit sequence in the corresponding image information qubit sequence.
[0068] Specifically, the strategy for constructing the weight qubit states of the initial quantum layer in the initial quantum neural network in step (2) is as follows:
[0069] The construction method for the weight qubit sequence in the initial quantum layer neurons is the same as the construction principle for the image information qubit sequence, the difference being the choice of parameters. Initially, the weights are... random angle α i , i = (1,2,...,n). The image information qubit sequence corresponds one-to-one with the weight qubit sequence. This is to ensure that the pixels in the image are fully combined with their corresponding weight information. Similarly, the M neurons in the initial quantum layer require M weight qubit sequences. A weight qubit sequence is represented as:
[0070] |W>=|w1>+...+|w n >=|Ry(α1)00...0>+...+|Ry(α n )11...1> (2)
[0071] Where |Ry(α1)00...0> represents the state of the first weighted qubit after adding the first weighted parameter α1 to the multi-qubit controlled Ry gate, |w1>, |Ry(α n )11...1> is to add the nth weight parameter α n After the multi-qubit controlled Ry gate, the state |w of the first weighted qubit is now... n The superposition of n states constitutes the first weighted qubit sequence |W>.
[0072] Constructing an M-weighted qubit sequence: one image information qubit sequence requires C+1 qubits, and an M-image information qubit sequence requires C+M qubits. Similarly, divide all qubits into two parts: the part from the multi-qubit controlled Ry gate to the farthest control bit qubit, and the remaining unit qubit part. For the first weighted qubit sequence, consider the number of unit qubits between the multi-qubit controlled Ry gate and the nearest control bit qubit, which is M. The remaining unit qubit part has 2M-1 units. For the first parameter value of the first weighted qubit sequence... The corresponding unit operation is:
[0073]
[0074] The second weighted qubit sequence has M+1 unit qubits spaced apart, and the remaining part has 2M-2 unit qubits. For the first parameter value of the second weighted qubit sequence... The corresponding unit operation is:
[0075]
[0076] Similarly, the Mth weighted qubit sequence has 2M-1 unit qubits between each other, and M unit qubits remaining. For the first parameter value α1 of the Mth weighted qubit sequence... M The corresponding unit operation is:
[0077]
[0078] Therefore, for the kth image information qubit sequence, the parameter values of the kth weight qubit sequence are... The corresponding unit operation is:
[0079]
[0080] in, Let be the unitary operation corresponding to the controlled Ry gate of the j-th multi-qubit in the k-th weighted qubit sequence. The k-th weighted qubit sequence can be represented as:
[0081]
[0082] (3) Based on steps (1) and (2), construct neurons in the initial quantum neural network using the exchange test technique.
[0083] 1. Using the exchange test technique, perform an inner product between the image information qubit and the weight qubit, store the inner product result, and use it as the output of the initial quantum layer neurons in the initial quantum neural network.
[0084] 2. The quantum circuit of the switching test technology consists of three qubits and two types of quantum gates, namely the Hadamard gate and the controlled switching (CSWAP) gate.
[0085] 3. The three qubits of the exchange test technology are the image information qubit sequence, the weight qubit sequence, and the |0> qubit in the initial quantum state.
[0086] 4. In the exchange test quantum circuit section, the first Hadamard gate is used to put the qubit with the initial state |0> into a superposition state. Then, a controlled exchange gate is used to map the inner product of the image information qubit sequence and the weight qubit sequence onto the qubit. Finally, the second Hadamard gate is used to fully entangle the image information and the weight parameters, which is used as the output of the initial quantum layer of this layer.
[0087] Specifically, the strategy for constructing neurons in the initial quantum layer using the exchange test technique in step (4) refers to: using the exchange test technique to fully inner-product the image information qubit sequence and the weight information qubit sequence and mapping the result onto the third qubit to achieve the neuron's output. The specific strategy is as follows:
[0088] a) Constructing a quantum layer neuron requires a sequence of image information qubits |X k >, a weighted information qubit sequence |W k >, and the qubit |S| that stores the mapping result of the two with an initial state of |0>. k >,k=(1,2,...,M).
[0089] b) The principle of exchange testing technology is through |X k >and|W k Information on two bit sequences | <X k |W k >| 2 To quantify their similarity, we derive |S k The state of >, |S k The probability of >=|0> is |S k The probability of >=|1> is
[0090] c) Swapping Test Technique: The quantum circuit consists of two types of quantum gates. First, a Hadamard gate operation is added to the |0> qubit to put it in a superposition state; second, a controlled swapping gate is added to the three qubits, with the qubit |S>... k >Create control bits; finally, in the quantum bit |S k Add the Hadamard door operation again.
[0091] d) In the quantum circuit for constructing a complete neuron using the commutative testing technique, there are two unitary operations. The unitary operation for adding a Hadamard gate to the k-th neuron is:
[0092]
[0093] The data required for the k-th neuron includes the k-th image information qubit sequence and its corresponding k-th weight qubit sequence. Given M image information qubit sequences |X... k >With a sequence of M weighted qubits|W k In a one-to-one correspondence, for a unitary operation involving the addition of a controlled swapping gate, all qubits between the control bit and the furthest swapping bit are considered as a whole. There are 2M-2 unit qubits centered on the swapping bit closest to the control bit. The unitary operation corresponding to a distance M from the control bit is...
[0094] In the first neuron, regarding the unitary operation of the controlled commutative gate, there are C qubits above and M-1 qubits below, corresponding to the unitary operation as follows:
[0095]
[0096] In the second neuron, regarding the unitary operation of the controlled commutation gate, there are C+1 qubits above and M-2 qubits below, corresponding to the unitary operation as follows:
[0097]
[0098] Similarly, in the Mth neuron, regarding the unitary operation of the controlled commutation gate, there are C+M-1 unit qubits above and 2M-2 unit qubits below, corresponding to the unitary operation as follows:
[0099]
[0100] Therefore, the controlled swapping gate unitary operation in the k-th neuron is:
[0101]
[0102] SWAP is the swapping quantum gate operation in a controlled swapping gate. In the quantum layer portion of the entire quantum circuit, the unitary operation for preparing the k-th neuron is:
[0103]
[0104] The quantum state of the k-th neuron is:
[0105]
[0106] for The probability when |1> is At this time, the neuron's output state is for:
[0107]
[0108] by For example, the other three sets of cosθsinα, sinθcosα, and sinθsinα follow the same pattern, with the following premise:
[0109]
[0110] Where θα is the abbreviation of cosθcosα, which can be summarized as follows:
[0111]
[0112] Where l represents the round number, t represents the t-th relation expression in the iterative relation, and k varies with l, depending on the corresponding change in l. The frequency of occurrence of internal parameters also changes accordingly. Verification revealed the following pattern: The final output quantum state is related to the number of control qubits C. When there are l control qubits, This refers to the output state of the neuron.
[0113] (4) Constructing the initial quantum neural network activation layer
[0114] 1. The active layer quantum circuit mainly consists of swapping gates, Hadamard gates, controlled phase-shifting gates, and multi-qubit XOR gates.
[0115] 2. The main idea of constructing a quantum layer activation circuit is to use a controlled phase shift gate to flip the quantum state output by the initial quantum layer neuron at a specified angle and map it onto a new quantum bit. Then, based on the relationship between the two quantum bits, the circuit is mapped onto a third quantum bit through an XOR gate to complete the nonlinear mapping of the activation layer, which serves as the output of the activation layer.
[0116] Specifically, the method for constructing the initial quantum neural network activation layer in step (4) is as follows:
[0117] Constructing a quantum activation layer mainly involves four quantum gates and three qubits |S k >、|δ1>、|δ2>, firstly, the qubits |S containing the quantum state information of the initial quantum layer neurons' output quantum states are exchanged through a swapping gate. k The information of the qubit |δ1> with an initial state of |0> is used to put |δ1> into a superposition state through a Hadamard gate operation, and then |S> is put into a superposition state through a controlled phase shift gate. kPhase adjustment is performed on the quantum state in >, and finally |S is operated on. k >, |δ1> is the control bit, and |δ2> is the target bit. Add a multi-qubit XOR gate to achieve the effect of nonlinear mapping of the quantum state of the activation layer. |δ2> is the output of the quantum activation layer.
[0118] (5) Training the initial quantum neural network
[0119] A quantum optimization algorithm is used to train an initial quantum neural network and optimize the trainable quantum parameters in the initial quantum neural network.
[0120] Specifically, first, the weight parameters of the quantum gates in the initial quantum neural network and the initial states of the qubits need to be initialized. Second, the qubits encoded as input data are transformed through a series of quantum gate operations to simulate the nonlinear activation function in the initial quantum neural network, thereby realizing complex transformations of the quantum state. Finally, the transformed quantum state is measured to obtain a classical output. By training this initial quantum neural network, it learns to extract features from the input data and perform effective predictions or classifications.
[0121] (6) Initial quantum neural network weight parameter update
[0122] After updating the weight parameters in the initial quantum neural network using the cross-entropy loss function, proceed to step (1). Specifically, the key to updating the weight parameters of the initial quantum neural network in step (6) is as follows: The first element is the loss function used to measure the difference between the current output of the initial quantum neural network and the true label. The cross-entropy loss function is a commonly used loss function in classification tasks, which can measure the difference between the probability distribution predicted by the initial quantum neural network and the true distribution. The second element is the backpropagation algorithm for calculating the gradient of the loss function with respect to the parameters of the initial quantum neural network. The third element is the optimization algorithm for updating the parameters of the initial quantum neural network using the calculated gradient. The Adam optimization algorithm dynamically adjusts the learning rate during training by maintaining an adaptive learning rate for each parameter, enabling the initial quantum neural network to converge faster and improve performance. The above updates aim to minimize the loss function, thereby improving the prediction performance of the initial quantum neural network.
[0123] (7) Constructing a quantum neural network
[0124] After constructing an initial quantum neural network consisting of an input layer, an initial quantum layer, an activation layer, and an output layer connected in sequence, the handwritten digit training set is input into the input layer to obtain an image information qubit sequence. The image information qubit sequence is then input into the initial quantum layer, and the weight parameters in the initial quantum layer are updated using a quantum optimization algorithm with the goal of minimizing the cross-entropy loss function, resulting in a quantum layer. The activation layer is used to perform nonlinear mapping based on the output information data of the quantum layer and then input it into the output layer. The output layer is used to output the handwritten digit recognition result. The quantum neural network is obtained by connecting the input layer, quantum layer, activation layer, and output layer in sequence.
[0125] Furthermore, the construction of a quantum neural network also includes testing its training effectiveness and outputting classification results. Specifically, test and validation sets are obtained from the MNIST dataset. These sets are unused data that can be used to simulate the performance of the quantum neural network on unknown data. Therefore, during training, the validation set is used periodically to evaluate the performance of the quantum neural network and ensure that it does not overfit. The test set is then used to finally evaluate the performance of the quantum neural network. For classification tasks, the output of the quantum neural network is typically a probability distribution representing the probability that the input data belongs to each category. Based on these probabilities, the most likely category of the input data is determined, and the corresponding classification result is output to ensure high accuracy of the quantum neural network's classification results.
[0126] After constructing the quantum neural network, the image data to be processed can be input into the quantum neural network to achieve the recognition of handwritten digits. Specifically, as a specific embodiment, this application verifies the effectiveness of the handwritten digit recognition method based on the quantum neural network through a simulation experiment, as follows:
[0127] S1, extract the 0 / 1 labeled data from the MNIST dataset and resize it.
[0128] S2, Construct the initial quantum state in the initial quantum neural network.
[0129] A classical image is converted into a quantum image and used as the input to a quantum neural network. Several qubits with an initial state of |0> are used. The input layer consists of two types of qubits: one type stores the sequence of positional information of corresponding pixels in the image, and the other type stores the image pixel information. The adjusted image size determines the number of reusable control qubits to be C. A Hadamard gate is added to put it in a superposition state. Based on the number of neurons in the quantum layer, M image information qubit sequences are required. Multi-qubit controlled Ry gates are added to construct the input layer of the quantum neural network. Each time an image information qubit sequence |X is constructed... k>This requires C control qubits and one qubit storing image information information sequence, and this combination is repeated M times.
[0130] Reference Figure 5 The number of controlled Ry gates required to add qubits to an image information qubit sequence depends on the number of pixels in the adjusted input image. C For the multi-qubit controlled Ry gate required for the image information qubit sequence, the input parameter value is set to the angle value, and the corresponding control bit sequence is determined by the binary sequence converted from the position information corresponding to the angle value.
[0131] S3, initialize the relevant weight qubit states of the initial quantum layer in the initial quantum neural network.
[0132] Similarly, the weight qubit sequence |W| of M quantum layers needs to be initialized based on the number of neurons in the quantum layer. k >, and the image information qubit sequence corresponds one-to-one with the weight qubit sequence; add a multi-qubit controlled Ry gate to construct the weight qubit sequence of the quantum layer. Each weight qubit sequence requires C control qubits and one qubit to store the weight qubit information sequence. This combination is repeated M times.
[0133] Reference Figure 6 The number of qubit-controlled Ry gates required to construct a weighted qubit sequence is the same as that required to construct an image information qubit sequence. For the multi-qubit-controlled Ry gates required for the weighted qubit sequence, the required parameter value is set to a random angle in the range of [0, π / 2], and its control bit sequence is consistent with the control bit sequence in the corresponding image information qubit sequence.
[0134] S4 utilizes the exchange test technique to construct neurons in the initial quantum layer.
[0135] Reference Figure 7 The quantum circuit for the swapping test technique consists of three qubits and two types of quantum gates: the Hadamard gate and the controlled swapping gate. The first Hadamard gate is used to make the initial state of the qubit |S> equal to |0>. k The image information qubit sequence is in a superposition state, followed by a controlled swapping gate, causing the sequence to be in a superposition state |X. k >and the weighted qubit sequence|W k The inner product result is mapped onto this qubit, and the image information and weight parameters are fully entangled through a second Hadamard gate as the output of this quantum layer.
[0136] The core of the swapping test technology is to make the image information qubit sequence |X k >With the weighted qubit sequence|Wk > Perform a full inner product, store the result as the output of the quantum layer neuron |S k >. For the output |S of the quantum layer neuron k The derivation of the formula for |1> is referenced. Figure 8 .
[0137] S5, Constructing the initial quantum neural network activation layer.
[0138] Reference Figure 9 The activation layer quantum circuit mainly involves four quantum gates and three qubits |S k >、|δ1>、|δ2>, firstly, the qubits containing the quantum state information of the output quantum layer neurons are exchanged through the exchange gate, |S>. k The information of the qubit |δ1> with an initial state of |0> is used to put |δ1> into a superposition state through a Hadamard gate operation, and then |S> is put into a superposition state through a controlled phase shift gate. k Phase adjustment is performed on the quantum state in >, and finally |S is operated on. k >, |δ1> is the control bit, and |δ2> is the target bit. Add a multi-qubit XOR gate to achieve the effect of nonlinear mapping of the quantum state of the activation layer. |δ2> is the output of the quantum activation layer.
[0139] S6, Training the initial quantum neural network.
[0140] An initial quantum neural network consists of an input layer, a quantum layer, an activation layer, and an output layer. Figure 10 The global construction graph of the quantum neural network is used to train the network.
[0141] S7, parameter update: After updating the weight parameters in the initial quantum neural network using the cross-entropy loss function, continue executing S2.
[0142] S8 tests the training effect of the quantum neural network and outputs the classification results.
[0143] This application constructs a fully parameterized quantum neural network based on amplitude encoding, using quantum information processing as the fundamental theoretical framework and combining it with exchange testing. This network is specifically designed for quantum image classification. It fully leverages the characteristics of quantum parallel computing to place the quantum neural network framework within a unified quantum system, effectively separating classical information and related technologies for processing classical information from existing quantum-classical hybrid neural networks. The quantum neural network in this application encompasses the basic structure and implementation method of feedforward neural networks and can effectively utilize quantum superposition states to encode and process image information. By using the sequence of qubits in superposition states for encoding image information as input to the quantum neural network, the quantum neural network constructed based on the principle of quantum superposition significantly reduces the storage size of training and testing datasets. The exchange testing maps the inner product of the input qubit sequence (both in quantum superposition states) and the weight qubit sequence to the probability amplitude of the result qubit, thus completing the mapping from neuron input to output. This fully utilizes the characteristics of quantum parallel computing to optimize the computation process of network data, achieving a computational complexity of O(1) for the inner product of grayscale values and weights, thereby greatly improving the learning efficiency of the quantum neural network.
[0144] Figure 11 The results show a comparison of classification performance between classical neural networks and quantum neural networks with the same network structure after 100 training rounds, under dataset sizes of 2×2 and 4×4. It can be seen that, with limited available datasets, the classical neural network does not exhibit good learnability, with classification accuracy consistently remaining at 53.93%, while the quantum neural network model still achieves a high level of accuracy even with limited data. Figure 12 A comparison of quantum neural networks with datasets of 2×2, 4×4, and 8×8 sizes shows that as the available dataset information increases, the quantum neural network can complete the learning and optimization process more quickly and efficiently, achieving an accuracy of up to 98%. The proposed nonlinear mapping method, which can be implemented in a quantum computer, effectively reduces the loss value of the quantum neural network model. Therefore, this application addresses the correlation between image data by utilizing properties such as quantum superposition and entanglement to reduce the storage overhead of quantum neural network training data, decrease the parameter size, and obtain better classification results.
[0145] For the measurement portion required in the quantum neural network of this application, the measurement is set to a single bit containing the output information of the entire quantum neural network, thereby greatly reducing interference to the quantum state of the neural network. Simulation results in the experimental section have demonstrated that even with a small number of neurons, this quantum neural network still exhibits efficient learning capabilities. The quantum neural network proposed in this application guarantees the closed nature and stability of the quantum system during the feedforward propagation of quantum information within the neural network, thereby greatly improving the execution efficiency and quantum operability of the quantum algorithm, and effectively enhancing the efficiency and accuracy of handwritten digit recognition.
[0146] In some embodiments, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the aforementioned handwritten digit recognition method based on a quantum neural network.
[0147] In some embodiments, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the aforementioned handwritten digit recognition method based on a quantum neural network.
[0148] In some embodiments, this application also provides a computer device, including a processor, a memory, an input / output interface (I / O), a communication interface, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the aforementioned handwritten digit recognition method based on quantum neural networks.
[0149] The processor, memory, and input / output interface are connected via a system bus, and the communication interface is also connected to the system bus via the input / output interface. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores pending transactions. The input / output interface allows the processor to exchange information with external devices. The communication interface allows communication with external terminals via a network connection. When the computer program is executed by the processor, it implements the quantum neural network-based handwritten digit recognition method.
[0150] It should be noted that the object information (including but not limited to object device information, object personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the object or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0151] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0152] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0153] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A handwritten digit recognition method based on quantum neural networks, characterized in that, include: Acquire image data of handwritten digits; Image data is input into a quantum neural network, which outputs handwritten digit recognition results. The quantum neural network was determined using a quantum optimization algorithm with the aim of minimizing the cross-entropy loss function; The method for determining the quantum neural network specifically includes: obtaining an initial training set of handwritten digits and preprocessing it to obtain a handwritten digit training set, specifically including: obtaining image data of handwritten digits with 0 / 1 labels from the MNIST dataset as the initial training set; adjusting the image size of the image data in the initial training set to 2×2, 4×4, 8×8 and 16×16 respectively; and simultaneously extracting the information of each pixel in the image data and converting the pixel value of each pixel into an angle value to obtain the handwritten digit training set. Construct an initial quantum neural network; the initial quantum neural network includes an input layer, an initial quantum layer, an activation layer, and an output layer connected in sequence; The handwritten digit training set is input into the input layer to obtain an image information qubit sequence. Specifically, this includes: inputting the handwritten digit training set into the input layer; determining the number of control qubits and the number of multi-qubit controlled Ry gates based on the image size and number of pixels in the image data within the training set; adding Hadamard gates to put the control qubits into a superposition state; and converting the image data into a quantum image through a mapping operation using multi-qubit controlled Ry gates. The quantum image includes several initial states... Quantum bits; based on control bit qubits, multi-qubit controlled Ry gates, and several initial states. The qubits are used to obtain the image information qubit sequence; The image information qubit sequence is input into the initial quantum layer. The weight parameters in the initial quantum layer are updated using a quantum optimization algorithm with the goal of minimizing the cross-entropy loss function to obtain the quantum layer. The activation layer is used to perform nonlinear mapping on the output information data of the quantum layer and then input it into the output layer. The output layer is used to output the handwritten digit recognition result. The input layer, quantum layer, activation layer and output layer are connected in sequence to obtain the quantum neural network. The quantum neural network includes an input layer, a quantum layer, an activation layer, and an output layer connected in sequence; the input layer is equipped with a multi-qubit controlled Ry gate; the input layer is used to convert image data into a quantum image to obtain an image information qubit sequence; The quantum layer is used for: The weighted qubit sequence is obtained based on the image information qubit sequence; Output information data is obtained based on the image information qubit sequence and the weight qubit sequence; The activation layer is used to perform nonlinear mapping on the output information data and then input it to the output layer; the output layer is used to output the handwritten digit recognition result.
2. The handwritten digit recognition method based on quantum neural networks according to claim 1, characterized in that, The weighted qubit sequence corresponds one-to-one with the image information qubit sequence.
3. The handwritten digit recognition method based on quantum neural networks according to claim 2, characterized in that, The process of obtaining output information data based on the image information qubit sequence and the weight qubit sequence specifically includes: Based on the image information qubit sequence and the weight qubit sequence, the output information data is obtained using a swap test technique.
4. The handwritten digit recognition method based on quantum neural networks according to claim 1, characterized in that, The activation layer includes a swap gate, a Hadamard gate, a controlled phase shift gate, and a multi-qubit XOR gate.
5. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the handwritten digit recognition method based on a quantum neural network as described in any one of claims 1-4.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the handwritten digit recognition method based on a quantum neural network as described in any one of claims 1-4.
7. A computer device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the handwritten digit recognition method based on a quantum neural network as described in any one of claims 1-4.