Image classification optimization method based on quantum VSQC-WOA
By designing strongly entangled local shadow circuits and sliding mechanisms to extract shadow features, combined with neural networks and whale optimization algorithms, the problem of poor adaptability of quantum circuits in image classification tasks is solved, and efficient feature extraction and classification accuracy is achieved.
Patent Information
- Application Number
- CN202510434560.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-08
- Publication Date
- 2025-07-22
AI Technical Summary
Existing quantum circuit designs have poor adaptability in image classification tasks and are difficult to adapt to diverse data sets and task requirements, resulting in high development costs and limited hardware deployment compatibility.
The image classification optimization method based on quantum VSQC-WOA is adopted, and shadow features are extracted by designing strongly entangled local shadow circuits and sliding mechanisms, and classified them in combination with neural networks. The model parameters are optimized using variational shadow quantum circuits and whale optimization algorithms.
It realizes the flexible adaptability and efficient feature extraction of quantum circuits in image classification tasks, improves classification accuracy and generalization capabilities of models, and reduces adjustment and optimization costs.
Smart Images

Figure CN120355992A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image classification, and particularly relates to an image classification optimization method based on quantum VSQC-WOA. Background Art
[0002] With the rapid development of technology, quantum machine learning and quantum neural networks have gradually become research hotspots in the field of artificial intelligence. Quantum machine learning combines the principles of quantum mechanics and classical machine learning, providing new solutions for tasks such as image classification. Quantum neural networks, in particular, combine the efficiency of quantum computing and the learning ability of neural networks, aiming to improve the speed and efficiency of data processing through the unique properties of quantum mechanics.
[0003] In the field of image classification, quantum machine learning algorithms can process large image datasets more effectively than classical algorithms, thus achieving faster and more accurate classification. The superposition and entanglement properties of qubits enable QNNs to process a large amount of data simultaneously, explore multiple solutions, improve accuracy, and bring more powerful model performance. Although quantum neural networks have made significant progress in fields such as image classification, they still have some deficiencies that limit their widespread promotion in practical applications.
[0004] Existing quantum circuit designs are often optimized for specific tasks or datasets, lacking generality. This results in the need to redesign quantum circuits when faced with diverse image classification tasks, increasing development costs and time. In addition, the complexity of quantum circuits also limits their deployment and compatibility on different hardware platforms. The datasets in image classification tasks usually have diverse characteristics. However, existing quantum neural networks show certain limitations when dealing with these diverse data. The structure and parameters of quantum neural networks are often optimized for specific datasets and are difficult to adapt to the differences of different datasets. This leads to the need for a large amount of adjustment and optimization of quantum neural networks in practical applications to adapt to different datasets and task requirements. Summary of the Invention
[0005] The present invention aims to provide an image classification optimization method based on quantum VSQC-WOA to solve the technical problem of poor adaptability of existing quantum circuits.
[0006] To achieve the above object, the present invention adopts the following technical solution: an image classification optimization method based on quantum VSQC-WOA, wherein the image classification model includes a variational shadow quantum circuit for extracting quantum shadow features and a neural network for mapping the shadow features to classification labels;
[0007] In a variational shadow quantum circuit, a strongly entangled local shadow circuit designed to extract shadow features is adopted, and a sliding mechanism is used to perform sliding extraction with the local shadow circuit to obtain multiple shadow features;
[0008] The sliding mechanism includes:
[0009] S1. For a system containing n qubits, the local shadow circuit first acts on the subspace of the first n qubits of the quantum state, and the size of n is set according to requirements; on this subspace, the local shadow circuit performs quantum operations and measures the expectation value of the Pauli operator to obtain the first shadow feature; qsc n qsc The size of n is set according to requirements; on this subspace, the local shadow circuit performs quantum operations and measures the expectation value of the Pauli operator to obtain the first shadow feature;
[0010] S2. The local shadow circuit then slides on the quantum state to the next subspace. Specifically, it performs the same local shadow circuit operation on the subspace from qubit 2 to qubit (2 + n - 1) to obtain the second shadow feature; nd to (2 + n qsc - 1) th to obtain the second shadow feature;
[0011] S3. The local shadow circuit continues to slide on different subspaces of the quantum state, covering a subspace of n qubits each time until it covers all possible subspaces of the entire quantum state; after each slide, the local shadow circuit measures the expectation value of the Pauli operator to generate a new shadow feature; finally, through the sliding mechanism, the shadow circuit can generate (n - n + 1) shadow features; qsc until it covers all possible subspaces of the entire quantum state; after each slide, the local shadow circuit measures the expectation value of the Pauli operator to generate a new shadow feature; finally, through the sliding mechanism, the shadow circuit can generate (n - n qsc + 1) shadow features;
[0012] The structure of the strongly entangled local shadow circuit includes a first module circuit and a second module circuit. The first module circuit is used to apply a parameterized single - qubit rotation gate to each qubit to introduce a parameterized local rotation operation to adjust the amplitude and phase of the quantum state; the second module circuit is used to perform a series of controlled - NOT gate operations through multi - layer recursive depth after the single - qubit rotation gate operation to achieve entanglement between qubits.
[0013] The principle and advantages of this solution are as follows: The present invention uses a variational shadow quantum circuit to extract the quantum shadow features of an image. The variational shadow quantum circuit is a circuit that can parametrically adjust the quantum state. By optimizing the parameters, features useful for the image classification task can be extracted. In the variational shadow quantum circuit, a strongly entangled local shadow circuit is designed, which realizes fine control of the quantum state through parameterized single - qubit rotation gates and adjustment of the entanglement relationship between qubits.
[0014] The sliding mechanism allows the local shadow circuit to slide over different subspaces of the quantum state. Each slide covers a certain number of qubits and performs the same quantum operation. Through the sliding mechanism, multiple shadow features can be systematically extracted, and these features together constitute a comprehensive representation of the image in the quantum space. The extracted shadow features are input into a neural network, which is responsible for mapping these quantum features to classification labels, thus completing the image classification task.
[0015] By designing a strongly entangled quantum state evolution circuit, an efficient feature extraction function is achieved. The strongly entangled local shadow circuit can capture the complex correlation information in the quantum state and provide rich feature representations for the classification task. The sliding property of the quantum circuit further expands its adaptability. The sliding mechanism enables the quantum circuit to flexibly handle different data distributions and image sizes without significant adjustment of the circuit structure. This convolutional operation through the sliding of qubit positions can be flexibly adjusted to adapt to different image features and classification requirements. This flexibility makes the quantum circuit more advantageous in the image classification task. Combining local shadow feature extraction and the sliding mechanism, the model can efficiently represent global features. By systematically extracting multiple shadow features, the model can capture the comprehensive information of the image in the quantum space and provide an accurate basis for the classification task.
[0016] The present invention can solve the technical problem of poor adaptability of existing quantum circuits. In practical applications, the parameters and structure of the quantum circuit can be flexibly adjusted to adapt to different image classification tasks and data sets. Through the strongly entangled local shadow circuit and the sliding mechanism, the present invention can efficiently extract the quantum features of the image and provide rich information for the classification task.
[0017] Preferably, as an improvement, the first module circuit includes a single qubit rotation gate group of Rx-Ry-Rx, so that the initial state of each qubit sequentially passes through the R x (θ) rotation gate, the R y (θ) rotation gate and the R x (θ) rotation gate for rotation operations; the second module circuit includes a ring-connected CNOT controlled-NOT gate with an R z (θ) rotation gate and an R y (θ) rotation gate, so that after the operation of the first module circuit, it sequentially passes through the ring-connected CNOT controlled-NOT gate with an R z (θ) rotation gate and the R y (θ) rotation gate.
[0018] The beneficial effects of this improvement are as follows: Through the single-qubit rotation gate group of Rx-Ry-Rx, each qubit undergoes a refined rotation operation, which helps introduce parameterized local rotations and adjust the amplitude and phase of the quantum state. This refined manipulation enables the circuit to more efficiently extract the characteristic information in the quantum state. The combined use of the ring-connected CNOT controlled-NOT gate and the rotation gate with rotation gates enhances the entanglement relationship between qubits. This strong entanglement helps the circuit capture the complex correlation information in the quantum state, thereby improving the accuracy of feature extraction.
[0019] The parameterization of the rotation gate and the controlled-NOT gate means that the parameters can be adjusted to adapt to different image classification tasks and datasets. This flexibility makes the circuit more advantageous in dealing with different scenarios. The design of the ring-connected CNOT controlled-NOT gate makes the circuit easy to expand. By increasing the number of qubits and adjusting the connection method, more complex quantum circuits can be constructed to adapt to more complex image classification tasks. The RZ rotation gate in the circuit and the final RY gate are used in combination to further adjust the phase of the quantum state and enhance the expressive power of the circuit. This enhanced expressive power enables the circuit to extract highly non-linear and entangled features, providing an efficient feature representation for the quantum classifier.
[0020] Preferably, as an improvement, the second module circuit is repeated multiple times to form a multi-layer structure.
[0021] The beneficial effects of this improvement are as follows: By repeating the second module circuit multiple times to form a multi-layer structure, the complexity of the quantum circuit can be significantly increased. This multi-layer structure allows the circuit to capture and process the information in the quantum state at a deeper level, thereby significantly improving the expressiveness of the circuit, being able to more accurately extract and characterize image features, and providing a richer and more efficient feature representation for the quantum classifier. Different image classification tasks may require different levels of feature extraction and processing, and the multi-layer structure can meet these requirements by adjusting the number of layers and the parameters of each layer of the circuit. This flexibility enables the circuit to better adapt to various complex image classification scenarios.
[0022] Preferably, as an improvement, the optimization method further includes calculating the gradient of the quantum circuit parameters using the parameter shift method and updating the parameters of the quantum circuit using an optimization algorithm according to the gradient. The specific steps are as follows:
[0023] Save the original parameter values of the quantum circuit, and then apply a positive shift +δ and a negative shift -δ to each parameter in the quantum circuit to generate corresponding quantum states; calculate the expectation values for the quantum states after the positive and negative shifts to obtain O θ+δ 、O θ-δ, and estimate the gradient of the parameter by using the difference between the two. After calculating the gradient, restore the circuit parameter to the initial state; use the calculated gradient to update the parameter of the quantum circuit by the gradient descent method.
[0024] The beneficial effect of this improvement is that the parameter shift method calculates the gradient by directly applying forward and backward shifts on the quantum circuit. This method is more accurate than the traditional finite difference method. The finite difference method relies on numerical approximation and may introduce additional errors, while the parameter shift method can estimate the gradient value more precisely. Since the parameter shift method can provide more accurate gradient information, it can accelerate the convergence process of the optimization algorithm. In optimization algorithms such as gradient descent, accurate gradients can guide the parameters to be updated to the optimal value faster, thus improving the optimization efficiency.
[0025] The design of the parameter shift method takes into account the limitations of existing quantum hardware. It does not require additional quantum resources or complex quantum operations, so it is easier to implement on existing quantum computers. This makes the improved method have better practicability and feasibility. By using the gradient information calculated by the parameter shift method to adjust the parameters of the quantum circuit, the performance of the quantum classifier can be significantly improved. More accurate parameter updates can enable the quantum circuit to better capture and process image features, thus improving the accuracy and efficiency of classification. Compared with the traditional gradient calculation method, the parameter shift method usually has lower computational complexity. It avoids complex numerical calculations and a large number of quantum state simulations, thus saving computational resources and improving computational efficiency.
[0026] Preferably, as an improvement, the optimization method further includes designing a loss function of the neural network, calculating the gradients of the weights and biases of the neural network based on the loss function by using the backpropagation algorithm, and then optimizing the weights and biases of the neural network by using the stochastic gradient descent method based on the gradients.
[0027] The beneficial effect of this improvement is that by designing an appropriate loss function and calculating the gradients of the neural network weights and biases by using the backpropagation algorithm, the training process of the neural network can be efficiently guided. The backpropagation algorithm can quickly calculate the gradient of each parameter, providing an accurate direction for subsequent optimization. The stochastic gradient descent method (SGD) can update the parameters by using only a part of the data in each iteration, thus accelerating the training speed and reducing the consumption of computational resources. By optimizing the weights and biases of the neural network by using SGD based on the gradients, the neural network can converge to the optimal solution faster, improving the performance and accuracy of the model.
[0028] Preferably, as an improvement, when the image classification model is a binary classification, the loss function used is the mean squared error loss function, and its expression is as follows:
[0029]
[0030] Among them, the data set y (m) ∈ {0, 1} indicates that each data point is encoded as a density matrix and is attached with the corresponding binary label y (m) ; the predicted label is defined as σ(z) represents the sigmoid activation function, w is the weight of the neural network, and b is the bias of the neural network.
[0031] The beneficial effect of this improvement is that the improved binary classification model adopts the mean squared error loss function. This loss function can accurately measure the difference between the predicted label and the true label, which helps the model to more accurately capture the differences between classes during training. By using the sigmoid activation function, the output of the neural network is mapped to the interval (0, 1), making the output more in line with the requirements of the binary classification task and improving the classification accuracy of the model. The design of the improved loss function helps the model to better balance the influence of different data points on the overall loss during training, thereby improving the generalization ability of the model and enabling it to perform better when facing new data.
[0032] Preferably, as an improvement, when the image classification model is a multi-label classification, the loss function is designed based on the cross-entropy formula:
[0033]
[0034] Among them, the data set y (m) is a one-hot vector, which is used to represent the class to which the m th th data sample belongs; the output of this quantum circuit is a K-dimensional vector which is defined as follows:
[0035] activation function.
[0037] The beneficial effect of this improvement is that for the multi-label classification task, the improved model adopts the loss function design based on the cross-entropy formula. This loss function can better handle the dependency relationships between labels and improve the performance of the model in the multi-label classification task. By introducing the softmax activation function, the output of the neural network is converted into a probability distribution, enabling the model to output the confidence levels of multiple labels, thereby more reasonably evaluating the accuracy of the model prediction.
[0038] The improved model uses a K-dimensional vector to represent the category of data samples, and through one-hot vector encoding, the label representation of each sample becomes clearer and more explicit, which helps the model better learn the mapping relationship between labels and features during the training process. By adjusting the parameters W and bias b, the weights and biases of the loss function can be flexibly controlled, thereby optimizing the model performance and making it more flexible and accurate when dealing with multi-label data.
[0039] Preferably, as an improvement, the optimization method further includes using the Whale Optimization Algorithm (WOA) to globally optimize the weights and biases of the neural network; the optimization stage of the Whale Optimization Algorithm includes a first stage and a second stage. The first stage implements surrounding the prey and spiral updating of positions, and the second stage is randomly searching for the prey.
[0040] The beneficial effect of this improvement is that the Whale Optimization Algorithm (WOA) can more widely search for the optimal solution in the search space through the balance of global exploration and local exploitation. In the first stage, the whales randomly move to other positions in the population, expanding the search range, which helps to jump out of the local optimal solution and improve the global optimization ability. In the exploitation stage, when the control parameters meet certain conditions, the whales update their positions through a spiral path or linear contraction around the current optimal solution, simulating the hunting behavior. This refined search method helps to find the global optimal solution faster and improves the optimization efficiency and accuracy of the model.
[0041] The WOA algorithm realizes flexible switching between global exploration and local exploitation by dynamically adjusting the control parameters. This mechanism helps the algorithm avoid prematurely falling into the local optimal solution during the search process, enabling it to more comprehensively explore the solution space and find better solutions. By globally optimizing the weights and biases of the neural network using the Whale Optimization Algorithm, the neural network can better fit the data and improve the model's expressive ability. At the same time, the optimized weights and biases also help to improve the classification accuracy of the model, enabling the model to perform better when dealing with complex tasks.
[0042] Preferably, as an improvement, the shadow feature o i is calculated as follows:
[0043]
[0044] The shadow circuit U(θ) and the physical observable value always act on the same local qubits; the shadow circuit U(θ) is further decomposed into a series of parameterized unitary operators:
[0045]
[0046] where, U l (θ l)=exp(-iθ l P l / 2), V l represents a fixed operator, P l Indicates three types of revolving doors: X, Y, and Z.
[0047] The beneficial effect of this improvement is that the shadow circuit and the physical observable value always act on the same local quantum bit. This design fully considers the physical characteristics of current quantum hardware, making the actual operation more in line with the hardware conditions and improving the feasibility of implementation. By decomposing the shadow circuit into a series of parameterized unitary operators, the gradient can be calculated more conveniently, which is crucial for optimizing circuit parameters. This decomposition method makes parameter adjustment more efficient and accurate, which helps to improve the efficiency of quantum computing.
[0048] The improved method allows for a more accurate evaluation of the expected value of a local quantum state by calculating and summing it item by item. This helps to gain a deeper understanding of the characteristics of quantum states and provides strong support for the application of quantum computing. By calculating and decomposing shadow features, this design significantly improves the expressiveness of the circuit, enabling it to handle more complex and diverse quantum states. This enhances the flexibility and capabilities of quantum computing, making it possible to explore a wider range of quantum phenomena and applications.
[0049] Preferably, as an improvement, the optimization method further comprises preprocessing the input initial image data to obtain a data vector, and performing quantum state mapping on the data vector;
[0050] Convert the two-dimensional image into a one-dimensional vector X, and arrange the pixel values of each image in order into a one-dimensional array X = [x1, x2, ..., x d ]; and add zeros to the end of the flattened vector so that all image vectors have the same fixed length; the flattened image vector is normalized to obtain a data vector, and normalization is achieved by calculating its L2 norm and dividing each element of the vector by this norm, so that the length of the image vector is adjusted to 1; the normalization calculation formula is as follows:
[0051]
[0052] Among them, X norm is the normalized data vector, X is the original one-dimensional vector, ‖X‖2 is the L2 norm of vector X; the calculation formula of L2 norm is as follows:
[0053] Among them, x i is the i-th element of vector X;
[0054] Use amplitude encoding to convert the data vector X normThe amplitude mapped to the quantum state; the quantum state encoded by its amplitude can be expressed as:
[0055] |ψ> = ∑ i x norm,i |i>;
[0056] Map each element x norm of the data vector X norm,i to the amplitude of the quantum state.
[0057] The beneficial effect of this improvement is that by preprocessing the input initial image data, including converting the two-dimensional image into a one-dimensional vector and normalizing it, the redundancy of the data is effectively reduced, and the compression and optimization of the data are achieved. This not only improves the efficiency of data processing but also reduces the occupancy of storage space. Description of the Drawings
[0058] Figure 1 For n = 4, the structural diagram of the variational shadow quantum circuit with n qsc = 2.
[0059] Figure 2 The structural diagram of the strongly entangled local shadow circuit.
[0060] Figure 3 The shadow circuit structural diagrams of Circuit - 1 to 4.
[0061] Figure 4 The comparison chart of the classification accuracies of 5 shadow circuits on 10 groups of binary classification tasks.
[0062] Figure 5 The comparison chart of the classification accuracies of VSQC and other models on 10 groups of binary classification tasks. Detailed Implementation Modes
[0063] The following is a further detailed description through specific implementation modes:
[0064] Example 1
[0065] An image classification optimization method based on quantum VSQC - WOA, where VSQC refers to the variational shadow quantum circuit and WOA refers to the whale optimization algorithm.
[0066] This optimization method is for the training optimization of an image classification model that extracts quantum shadow features of data using the characteristics of the shadow circuit and performs subsequent processing and classification through a neural network.
[0067] The image classification model includes a quantum feature extractor for extracting quantum shadow features and a classical post-processor for mapping the shadow features to classification labels. In this embodiment, the classical post-processor employs a shallow neural network with a fully connected neural network (FCNN); the quantum feature extractor is implemented based on a multi-layer variational quantum circuit.
[0068] An image classification optimization method based on quantum VSQC-WOA includes:
[0069] S1. Preprocess the input initial image data to obtain a data vector, and perform a quantum state mapping on the data vector;
[0070] S11. Convert the two-dimensional image into a one-dimensional vector X, and arrange the pixel values of each image in sequence into a one-dimensional array X = [x1, x2, …, x d ; and add zeros at the end of the flattened vector to make it reach the required fixed length to ensure that all image vectors have the same length.
[0071] S12. Normalize the flattened image vector to obtain a data vector, and achieve normalization by calculating its L2 norm and dividing each element of the vector by this norm, so that the length of the image vector is adjusted to 1, avoiding the influence of data dimension differences on model training; the normalization calculation formula is as follows:
[0072]
[0073] where, X norm is the normalized data vector, X is the original one-dimensional vector, ‖X‖2 is the L2 norm of the vector X; the calculation formula of the L2 norm is as follows:
[0074] where, x i is the i-th element of the vector X.
[0075] S13. Use amplitude encoding to map the data vector X norm to the amplitude of the quantum state; the quantum state of its amplitude encoding can be expressed as:
[0076] |ψ> = ∑ i x norm,i |i>;
[0077] Map each element x norm of the data vector X norm,i to the amplitude of the quantum state, thereby providing input data for subsequent quantum computing tasks.
[0078] S2. In the variational shadow quantum circuit (VSQC), design a strongly entangled local shadow circuit for extracting shadow features, and adopt a sliding mechanism to perform sliding extraction using the local shadow circuit to obtain multiple shadow features.
[0079] The implementation steps of the sliding mechanism include:
[0080] S21. For a system containing n qubits, the local shadow circuit first acts on the subspace of the first n qsc qubits of the quantum state, and the size of n qsc is set according to requirements; on this subspace, the local shadow circuit performs quantum operations and measures the expectation value of the Pauli operator to obtain the first shadow feature.
[0081] S22. The local shadow circuit then slides on the quantum state to the next subspace. Specifically, it performs the same local shadow circuit operation on the subspace from 2 nd to (2 + n qsc -1) th qubits to obtain the second shadow feature.
[0082] S23. The local shadow circuit continues to slide on different subspaces of the quantum state, each time covering a subspace of n qsc qubits until it covers all possible subspaces of the entire quantum state; after each slide, the local shadow circuit measures the expectation value of the Pauli operator to generate a new shadow feature; finally, through the sliding mechanism, the shadow circuit can generate (n - n qsc +1) shadow features. Although a single shadow circuit is used by default, more complex classification tasks can be accommodated by increasing the number of shadow circuits (n s ), corresponding to generating n s (n - n qsc +1) shadow features.
[0083] As shown in the appendix Figure 1 , the figure shows the structural diagram of the variational shadow quantum circuit with n = 4 and n qsc = 2. U(θ) is the local shadow circuit; in the quantum device, the shadow circuit acts on the subspace of the input state ρ in , performs measurements and extracts shadow features. In the entire system, the shadow circuit slides to cover different subspaces of the Hilbert space, and can collect the expectation values of the input state Pauli - , that is, the generated "shadow features". In the Hilbert space composed of n qubits, the parameters and designs of all sliding shadow circuits U(θ) are the same, thus ensuring the consistency and reproducibility of the results.
[0084] The sliding mechanism can efficiently extract global features by gradually scanning different subspaces of the quantum state. This mechanism can not only capture local features but also cover the entire quantum state through sliding to achieve the representation of global features. This enables the model to process complex high-dimensional data and provide rich feature representations for classification tasks.
[0085] As shown in the appendix Figure 2 The strongly entangled local factor circuit U(θ) includes a first module circuit and a second module circuit. The first module circuit is used to apply parameterized single-qubit rotation gates to each qubit, and these rotation gates are used to introduce parameterized local rotation operations to adjust the amplitude and phase of the quantum state; the second module circuit is used to perform a series of controlled-NOT gate operations through multi-layer recursion after the single-qubit rotation gate operation to achieve entanglement between qubits.
[0086] Specifically, the first module circuit includes a single-qubit rotation gate group of Rx-Ry-Rx, so that the initial state of each qubit sequentially passes through the R x (θ) rotation gate, the R y (θ) rotation gate, and the R x (θ) rotation gate for rotation operations. The matrices of the R x (θ) rotation gate and the R y (θ) rotation gate are as follows:
[0087]
[0088] The second module circuit includes a ring-connected CNOT controlled-NOT gate with an R z (θ) rotation gate and an R y (θ) rotation gate, so that after the operation of the first module circuit, it sequentially passes through the ring-connected CNOT controlled-NOT gate with an R z (θ) rotation gate and an R y (θ) rotation gate. The matrices of the R z (θ) rotation gate and the CNOT controlled-NOT gate are as follows:
[0089]
[0090] Among them, in order to enhance the expressive power of the quantum circuit, the second module circuit within the dashed box is repeated D times to form a multi-layer structure, thereby significantly improving the expressiveness and adaptability of the circuit. The strongly entangled local shadow circuit can efficiently extract quantum features and achieve strong entanglement of the quantum state through parameterized quantum gate operations and multi-bit entanglement operations. This design can not only capture the complex structural information of the data but also provide rich quantum feature representations for subsequent classification tasks, significantly improving the classification performance of the model.
[0091] S3. Calculate the gradient of the quantum circuit parameters using the parameter shift method, and update the parameters of the quantum circuit using an optimization algorithm according to the gradient.
[0092] S31. Save the original parameter values of the quantum circuit. Then, for each parameter θ in the quantum circuit, apply a positive shift +δ and a negative shift -δ to generate corresponding quantum states, where δ is a small positive number.
[0093] S32. Calculate the expectation values for the quantum states after the positive and negative shifts to obtain O θ+δ 、O θ-δ , and estimate the gradient of the parameter using the difference between the two. After calculating the gradient, restore the circuit parameters to the initial state. The gradient calculation formula is:
[0094]
[0095] S33. Use the calculated gradient to update the parameters of the quantum circuit through the gradient descent method:
[0096]
[0097] where η is the learning rate, which is used to control the step size of parameter update.
[0098] S4. Design the loss function of the fully connected neural network, calculate the gradients of the weights and biases of the fully connected neural network based on the loss function, and then perform local optimization on the weights and biases using the stochastic gradient descent method based on the gradients.
[0099] (1) In the variational shadow quantum circuit framework for binary classification, the loss function used is the mean squared error loss function, and its expression is as follows:
[0100]
[0101] where the dataset y (m) ∈{0,1} represents that each data point is encoded as a density matrix and is attached with the corresponding binary label y (m) ; the predicted label is defined as σ(z) represents the sigmoid activation function, w is the weight of the fully connected neural network, and b is the bias of the fully connected neural network; the shadow feature o i is calculated as follows:
[0102]
[0103] The shadow circuit U(θ) and the physical observable Always act on the same local qubits to ensure that the extracted quantum features are consistent with the local properties of the target state. The shadow circuit U(θ) is further decomposed into a series of parameterized unitary operators:
[0104]
[0105] where U l (θ l ) = exp(-iθ l P l / 2), V l represents a fixed operator, such as a CNOT gate, etc.; P l represents the X, Y, Z rotation gates.
[0106] The unitary evolution matrix of the strongly entangled local shadow circuit in this embodiment can be expressed as:
[0107]
[0108] This decomposition method not only conforms to the physical limitations of current quantum hardware but also facilitates gradient optimization, thereby efficiently adjusting the circuit parameters and accurately evaluating the expected value of the local quantum state. This design ensures the flexibility of feature extraction while enhancing the circuit's ability to express complex quantum states.
[0109] Based on the purpose of minimizing the loss function, calculate the gradients of the weights, biases, and quantum circuit parameters. The gradients of the weights, biases, and quantum circuit parameters here are the partial derivatives of the loss function with respect to these parameters, representing the rate of change of the loss function in the parameter space. Then, use the gradient descent optimization algorithm to update the parameters according to the calculated partial derivatives; the formulas for the gradients of the binary classification loss function with respect to the weights, biases, and quantum circuit parameters are as follows:
[0110]
[0111] (2) In the variational shadow quantum circuit framework for multi-label classification, the loss function is designed based on the cross-entropy formula:
[0112]
[0113] where the data set y (m) is a one-hot vector, used to represent the category to which the m th th data sample belongs. For example, in the case where the total number of categories K = 3, if the sample belongs to category 0, then if the sample belongs to category 1, then for category 2, This representation clearly defines the class membership of each sample, providing a basis for the calculation of the loss function.
[0114] Here, the output of the variational shadow quantum circuit (VSQC) is a K-dimensional vector which is defined as follows:
[0115]
[0116] where, represents the softmax activation function, and the shadow feature o i is calculated as follows:
[0117]
[0118] For the purpose of minimizing the loss function, the gradients of the weights, biases, and quantum circuit parameters are calculated. The gradients of the weights, biases, and quantum circuit parameters here are the partial derivatives of the loss function with respect to these parameters, representing the rate of change of the loss function in the parameter space. Then, the optimization algorithm of gradient descent is used to update the parameters according to the calculated partial derivatives; the formulas for the gradients of the multi-label classification loss function with respect to the weights, biases, and quantum circuit parameters are as follows:
[0119]
[0120] The values of these partial derivatives will serve as key elements in the optimization process to quantify the sensitivity of the current parameters to the loss function. Specifically, using the backpropagation algorithm, the gradient of the loss function can be efficiently propagated from the output layer back to the input layer, calculating and accumulating the gradients of each weight and bias b layer by layer. The parameters are updated in each iteration to gradually minimize the objective loss function. Through such a process, classical devices can efficiently optimize the neural network parameters and work in coordination with the parameter optimization of the quantum circuit, thereby continuously improving the overall model performance.
[0121] S5. The whale optimization algorithm (WOA) is used to globally optimize the weights and biases of the fully connected neural network;
[0122] The current weight and bias values of the fully connected neural network are used as the initial population input to the whale optimization algorithm. These populations are randomly generated and represent a set of possibilities for the neural network parameters. The optimization stage of the whale optimization algorithm includes a first stage and a second stage. The first stage implements surrounding the prey and spiral updating the position, and the second stage is to randomly search for the prey. The data models for each stage are as follows:
[0123] Surrounding the prey;
[0124] In the WOA algorithm, after the humpback whale locates the position of the prey, it conducts a surrounding search around the prey. Since the position of the optimal solution in the search space is unknown, the algorithm assumes that the current best candidate solution is close to the target prey or the optimal solution. Therefore, other search agents (i.e., whales) will attempt to adjust their positions and move towards the current best solution in order to find a better solution. This behavior is modeled by specific equations, simulating the process of whales surrounding the prey.
[0125]
[0126] Where represents the early best position of the whale at iteration □. is the current position of the whale, is the distance vector between the whale and the prey, and || represents the absolute value. C and A are coefficient vectors, and their calculation formulas are as follows:
[0127]
[0128] Among them, is the linear attenuation factor, and are random numbers that follow a uniform distribution in [0, 1]. The value of can be within the interval (-a, a), where the value of a decreases from 2 to 0 through iteration.
[0129] Update the position in a spiral pattern;
[0130] By calculating the distance between the whale's position (X, Y) and the prey's position (X * , Y * ), their interval can be determined. Next, a spiral equation is generated between these positions to simulate the spiral movement trajectory of the humpback whale around the prey. As follows:
[0131]
[0132] Among them, b is a constant value used to identify the logarithmic spiral shape, and l is a random number within the range of [-1, 1]. This behavior is represented in WOA as changing the position of the whale during the optimization process. There is a 50% chance of choosing between the shrinking surrounding mechanism and the spiral model, and their component designs are as follows (where p is a random number in (0, 1)):
[0133]
[0134] Searching for prey:
[0135] During the process of searching for prey, whales discover prey through random search based on each other's positions, and this method relies on the variance of vectors. To avoid the search falling into a local optimal solution, the WOA algorithm forces the search agent to move away from the current whale by using vectors with random values greater than or less than 1. Throughout the exploration phase, the global search ability is enhanced by readjusting the positions of the search agents instead of relying solely on the best search agent. This strategy helps the WOA algorithm avoid local optima and enhances the efficiency of global search. The mathematical model is expressed as follows:
[0136]
[0137] where is a randomly selected position vector (random whale) from the current population.
[0138] In summary, the overall process of this optimization method includes: first, the input data set is encoded into a quantum state through a quantum circuit. The quantum shadow circuit generates multiple shadow features and transmits them to a fully connected neural network (FCNN). In the classification task, the binary classification network is responsible for binary classification, outputting classes {0, 1}, and the multi-classification network outputs multiple classes {0, 1, 2, …}. The parameters in the FCN are optimized by the whale optimization algorithm (WOA), and the optimization is completed by minimizing the loss function (mean square error MSE or cross-entropy loss CrossEntropyLoss) in combination with the parameter shift method and stochastic gradient descent (SGD). The structure of the quantum circuit adopts a strongly entangled design, and an efficient quantum state evolution is generated through a series of rotation gates and controlled gates.
[0139] Example 2
[0140] Based on the technical solution of Example 1, to more powerfully prove that the performance of the image classification model improved by this optimization method has been significantly enhanced, a comparative experiment on the MNIST data set was conducted on the image classification model based on this optimization method. The construction and measurement of the involved quantum circuits were all carried out using Paddle - quantum, and the training and testing of the model were completed under the Pytorch deep learning framework. The system hardware environment is a 12th Gen Intel(R) core(TM) i5 - 12600KF processor and an NVIDIA GeForce RTX 3060Ti. The software environment is Python 3.8.18, Pytorch 2.2.0+cu121, and Paddle - quantum 2.4.0.
[0141] The MNIST dataset contains 60,000 training samples and 10,000 test samples. Each sample is a grayscale image of 28x28 pixels. The value of each pixel represents the brightness of that pixel, ranging from 0 to 255. Each image is labeled with a number ranging from 0 to 9, which is a multi-classification problem with a total of 10 different classes.
[0142] In the study of the embodiments, during the process of data loading and preprocessing, the training data and test data are respectively extracted from the training set and test set of the MNIST dataset. 1000 training samples and 200 test samples are selected for each class. After the data is loaded, the training samples and test samples are randomly shuffled to ensure that the data for each training and test is consistent and repeatable.
[0143] In this experiment, through multiple experiments and debugging, the hyperparameters of the model are carefully set with the aim of optimizing its training efficiency and generalization ability while ensuring the model performance. During the process of hyperparameter tuning, special attention is paid to how to effectively avoid the phenomenon of barren plateaus as well as gradient vanishing and gradient explosion problems. By reasonably designing the learning rate, initial parameter distribution, and optimizer configuration, the stability and expressiveness of the model are further improved.
[0144] Then the hyperparameter settings include: the number of qubits N is 10, the width n of the shadow circuit qsc is 2, the depth D of the shadow circuit, that is, the number of repetitions of the second module is 3, the number of training epochs Epochs is 20, the learning rate LR is 0.09, the training batch BATCH is 20, the size of the training set N train is 1000, the size of the test set N test is 200.
[0145] Experiment 1: Prove the superior performance of the VSQC model
[0146] 10 groups of binary classification tasks are randomly selected from 45 groups of binary classification tasks in the MNIST dataset to compare the classification effects of this local shadow circuit with 4 other locally shadow circuits with different designs on the 10 groups of binary classification tasks.
[0147] These 4 locally shadow circuits with different designs are all constructed through unique design concepts to explore the influence of different quantum circuit structures on the classification performance. These 4 locally shadow circuits are Circuit-1, Circuit-2, Circuit-3, and Circuit-4 in sequence, and the strong entanglement local shadow circuit of this scheme is used as Circuit-5.
[0148] The shadow circuit structure diagrams of Circuit-1 to 4 are as shown in the appendix Figure 3As shown, the first part of Circuit-1 uses the Rx-Ry-Rx combination to represent the general rotation on each single-qubit subspace. The subsequent repeated block consists of CNOT gates and single-qubit Ry rotations. The first parts of Circuit-2 and Circuit-3 both use the Rx-Ry combination to represent the general rotation on each single-qubit subspace. The subsequent repeated block also consists of CNOT gates and single-qubit Ry rotations. The first part of Circuit-4 uses the H-Rx-Ry-Rx combination to represent the general rotation on each single-qubit subspace. The subsequent repeated block consists of a CNOT entanglement layer with RZ gates and single-qubit Ry rotations. The block circuit within the dashed box is repeated D times to expand the expressiveness of the quantum circuit.
[0149] As attached Figure 4 shown, by comparing the classification accuracies, the results show that Circuit-5 performs the best in all tasks, significantly outperforming the other 4 shadow circuit structures. The excellent performance of Circuit-5 reflects its advantages in feature extraction and information representation.
[0150] Based on this result, we further adopted Circuit-5 as the core component to construct the shadow circuit structure of the variational shadow quantum circuit (VSQC). The VSQC model fully utilizes the capabilities of Circuit-5 in quantum state operation and feature capture, combining the flexibility and scalability of parameterized quantum circuits. Comprehensive comparative experiments were conducted between the VSQC model based on Circuit-5 and other existing classical and quantum hybrid models.
[0151] As attached Figure 5 shown, the experimental results indicate that the VSQC model exhibits significant advantages in classification performance, not only having a higher accuracy rate but also demonstrating good generalization ability and stability. This series of experimental results fully verify the important role of the shadow circuit we designed in improving the performance of quantum neural networks, and also demonstrate the potential application prospects of quantum computing in image classification tasks.
[0152] Experiment 2: Prove the superior performance of the VSQC model optimized by WOA
[0153] Taking the three-class classification task as an experimental example, four groups of three-class classification tasks were selected from the MNIST dataset, namely {0, 1, 2}, {1, 5, 7}, {3, 4, 6}, and {6, 7, 8}, to comprehensively evaluate the classification ability of the model. In the experiment, all models used the same hyperparameter settings to ensure the fairness and comparability of the results.
[0154] First, comparative experiments were conducted on the VSQC-WOA model using a variety of different optimization algorithms, including the Particle Swarm Optimization (PSO), Genetic Algorithm Optimization (GAO), Artificial Immune Algorithm (AIO), and the baseline VSQC model without incorporating WOA. By comparing and analyzing the impact of different optimization strategies on the performance of the VSQC model, the role of WOA in enhancing the model's performance was explored. The evaluation metrics included classification accuracy, precision, recall, F1 score, and loss value. A comprehensive analysis of these metrics could fully reflect the performance of the VSQC-WOA model in the three-class classification task.
[0155] From the experimental results, the VSQC model optimized by WOA performed best in all tasks. In terms of the four metrics of accuracy, precision, recall, and F1 score, the results of the WOA-optimized model exceeded 97% in all cases, and reached the top level of 99% in some tasks (such as {3,4,6} and {6,7,8}). In contrast, PSO and GAO were next, while the performance of AIO and the baseline model (VSQC) was significantly weaker, especially in {1,5,9}, where the metrics of the baseline model were the lowest, only reaching around 92%-94%. In terms of the trend of the loss value, the model optimized by WOA demonstrated rapid convergence ability and stability. After approximately 10 rounds of training, the loss value stabilized at the lowest level close to 0.05. The loss values of PSO and GAO decreased more slowly and had slight fluctuations in the later stage; the loss values of AIO and the baseline model VSQC fluctuated greatly and were particularly difficult to converge in {6,7,8}. These data indicate that WOA optimization significantly improved the performance and robustness of the VSQC model, making it the optimal algorithmic solution with the best optimization effect in multi-class classification tasks.
[0156] In this experiment, we further comprehensively compared the VSQC-WOA model with other classical models, including the traditional Support Vector Machine (SVM), Convolutional Neural Network (CNN), Quantum Neural Network (VQC), Random Forest (RF) model, and the baseline model (VSQC), to evaluate the overall performance advantages of the VSQC-WOA model.
[0157] From the experimental results, the VSQC-WOA model outperforms other models in all four groups of tasks, especially showing significant advantages in {1,5,9} and {6,7,8}. Specifically, the accuracy of the VSQC-WOA model remains above 98% in all tasks, while the accuracy of other models fluctuates greatly. The accuracy of VQC, CNN, and SVM is between 92% - 96%, and the performance of the RF model is relatively weak, reaching only 85% - 90% in some tasks. In terms of the precision and recall metrics, the VSQC-WOA model also performs excellently, both above 97%. Especially in tasks {3,4,6} and {6,7,8}, the precision and recall respectively reach above 99%, significantly leading other models. The trend of the F1 score is consistent with other metrics, and the performance of the VSQC-WOA model always remains at the highest level, fully verifying its effectiveness and superiority in multi-classification tasks. These results indicate that the VSQC-WOA model not only has obvious competitiveness in classification performance but also is superior to traditional classical models and other quantum models in terms of generalization ability and stability.
[0158] In summary, the detailed comparison under four groups of three-classification tasks demonstrated through various comparative experiments further verifies the effectiveness of WOA optimization in improving the performance of quantum models, provides strong support for the application of the VSQC-WOA model in multi-classification problems, and also indicates that the model has broad application potential.
[0159] The above are only embodiments of the present invention, and specific technical solutions and / or common knowledge such as characteristics well known in the art are not described in detail herein. It should be noted that for those skilled in the art, without departing from the technical solution of the present invention, several modifications and improvements can still be made, which should also be regarded as the protection scope of the present invention, and these will not affect the implementation effect of the present invention and the practicality of the patent. The protection scope required by this application should be subject to the content of its claims, and the specific implementation manners described in the specification can be used to interpret the content of the claims.
Claims
1. An image classification optimization method based on quantum VSQC-WOA, characterized in that The image classification model includes a variational shadow quantum circuit for extracting quantum shadow features and a neural network for mapping the shadow features to classification labels; In the variational shadow quantum circuit, a strongly entangled local shadow circuit for extracting shadow features is designed, and a sliding mechanism is adopted to perform sliding extraction using the local shadow circuit to obtain multiple shadow features; The sliding mechanism includes: S1. For a system containing n qubits, the local shadow circuit first acts on the subspace of the first n qubits of the quantum state, and the size of n is set according to requirements; on this subspace, the local shadow circuit performs quantum operations and measures the expectation value of the Pauli operator to obtain the first shadow feature; qsc The size of n qsc is set according to requirements; on this subspace, the local shadow circuit performs quantum operations and measures the expectation value of the Pauli operator to obtain the first shadow feature; S2. The local shadow circuit then slides on the quantum state to the next subspace, specifically, from 2 nd to (2 + n qsc - 1) th Implement the same local shadow circuit operation on the subspace of qubits to obtain the second shadow feature; S3. The local shadow circuit continues to slide on different subspaces of the quantum state, with each slide covering a subspace of n qsc qubits until all possible subspaces of the entire quantum state are covered; after each slide, the local shadow circuit measures the expected value of the Pauli operator to generate a new shadow feature; finally, through the sliding mechanism, the shadow circuit can generate (n - n qsc +1) shadow features; The structure of the strongly entangled local shadow circuit includes a first module circuit and a second module circuit. The first module circuit is used to apply a parameterized single-qubit rotation gate to each qubit to introduce a parameterized local rotation operation to adjust the amplitude and phase of the quantum state. The second module circuit is used to perform a series of controlled-NOT gate operations through multi-layer recursion after the single-qubit rotation gate operation to achieve entanglement between qubits.
2. The image classification optimization method based on quantum VSQC-WOA according to claim 1, wherein: The first module circuit includes a single-qubit rotation gate set of Rx-Ry-Rx, which makes the initial state of each qubit pass through the R x (θ) rotation gate, the R y (θ) rotation gate, and the R x (θ) rotation gate for rotation operations in sequence; the second module circuit includes a ring-connected CNOT controlled-NOT gate with an R z (θ) rotation gate and an R y (θ) rotation gate, such that after the operations of the first module circuit, it passes through the ring-connected CNOT controlled-NOT gate with an R z (θ) rotation gate and the R y (θ) rotation gate in sequence.
3. The image classification optimization method based on quantum VSQC-WOA according to claim 2, wherein: The second module circuit is repeated multiple times to form a multi-layer structure.
4. The image classification optimization method based on quantum VSQC-WOA according to claim 3, characterized in that, The optimization method further includes calculating the gradient of the quantum circuit parameters using the parameter shift method and updating the parameters of the quantum circuit using an optimization algorithm based on the gradient. The specific steps include: Save the original parameter values of the quantum circuit. Then, for each parameter in the quantum circuit, apply a positive shift +δ and a negative shift -δ to generate the corresponding quantum states. Calculate the expectation values for the quantum states after the positive and negative shifts to obtain O θ+δ and O θ-δ . Estimate the gradient of the parameter using the difference between the two. After calculating the gradient, restore the circuit parameters to their initial state. Update the parameters of the quantum circuit using the calculated gradient through the gradient descent method.
5. The image classification optimization method based on quantum VSQC-WOA according to claim 4, wherein: The optimization method further includes designing a loss function for the neural network, calculating the gradients of the weights and biases of the neural network based on the loss function using the backpropagation algorithm, and then optimizing the weights and biases of the neural network using the stochastic gradient descent method based on the gradients.
6. The image classification optimization method based on quantum VSQC-WOA according to claim 5, wherein: When the image classification model is a binary classification, the loss function used is the mean squared error loss function, and its expression is as follows: Among them, the dataset y (m) ∈ {0, 1} indicates that each data point is encoded as a density matrix and is accompanied by the corresponding binary label y (m) ; the predicted label is defined as σ(z) represents the sigmoid activation function, w is the weight of the neural network, and b is the bias of the neural network.
7. The image classification optimization method based on quantum VSQC-WOA according to claim 5, characterized in that: When the image classification model is a multi-label classification, the loss function is designed based on the cross-entropy formula: Among them, the data set y (m) is a one-hot vector used to represent the class th to which the m-th data sample belongs; the output of the quantum circuit is a K-dimensional vector which is defined as follows: Activation function.
8. The image classification optimization method based on quantum VSQC-WOA according to claim 7, characterized in that: The optimization method further includes globally optimizing the weights and biases of the neural network using the whale optimization algorithm. The optimization stage of the whale optimization algorithm includes a first stage and a second stage. The first stage implements surrounding the prey and spiral updating of positions, and the second stage is randomly searching for the prey.
9. The image classification optimization method based on quantum VSQC-WOA according to claim 6, wherein The shadow feature o i has the following calculation formula: Shadow circuit U(θ) and physical observables always act on the same local qubits; further decompose the shadow circuit U(θ) into a series of parameterized unitary operators: Among them, U l (θ l ) = exp(-iθ l P l / 2), V l represents a fixed operator, and P l represents three kinds of rotation gates of X, Y, and Z.
10. The image classification optimization method based on quantum VSQC-WOA according to claim 9, wherein, The optimization method further includes preprocessing the input initial image data to obtain a data vector and performing a quantum state mapping on the data vector; Convert the two-dimensional image into a one-dimensional vector X. By means of a flattening operation, arrange the pixel values of each image in sequence into a one-dimensional array X = [x1, x2, …, x d ; and append zeros to the end of the flattened vector to make all image vectors reach the same fixed length; perform normalization on the flattened image vector to obtain the data vector, which is achieved by calculating its L2 norm and dividing each element of the vector by this norm, so that the length of the image vector is adjusted to 1; the normalization calculation formula is as follows: where X norm is the normalized data vector, X is the original one-dimensional vector, and ‖X‖2 is the L2 norm of vector X; the calculation formula of the L2 norm is as follows: where x i is the i-th element of vector X; Use amplitude encoding to map the data vector X norm to the amplitude of a quantum state; the quantum state encoded by its amplitude can be expressed as: |ψ> = ∑ i x norm,i |i>; Map each element \(x\) of the data vector \(X\) norm to the amplitude of a quantum state. norm,i