A training method of a quantum support vector machine and a related device

By selecting a subset of samples for training and updating the parameters of the quantum support vector machine using the loss function value and measurement results, the problem of long training time for QSVM is solved, achieving a faster training process and better model adaptability.

CN122491536APending Publication Date: 2026-07-31ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
Filing Date
2025-01-25
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

The current quantum support vector machine (QSVM) training process requires loading all training data to calculate the kernel matrix in each iteration, resulting in large computational load, long time consumption, and difficulty in efficient training.

Method used

Select a subset of samples for training, calculate the gradient using the loss function value and update the variational parameters of the quantum circuit constructed by the kernel function of the quantum support vector machine using the measurement results, and determine the latest vector parameters based on the gradient and measurement results, thereby reducing the amount of data processing in each iteration.

Benefits of technology

It shortens the training time, improves the convergence speed of quantum support vector machines, reduces training time, and enhances the adaptability and generalization ability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122491536A_ABST
    Figure CN122491536A_ABST
Patent Text Reader

Abstract

This application discloses a training method and related apparatus for a quantum support vector machine (SVM), belonging to the field of quantum computing technology. The method includes: selecting a first sample and at least one second sample from a training sample set, wherein the second sample is a sample in the training sample set other than the first sample, and the sum of the number of the first sample and the second sample selected in the current iteration is less than the number of samples in the training sample set; updating the variational parameters of the quantum circuit constructed for the kernel function of the quantum support vector machine based on the gradient calculated by the loss function value obtained in the current iteration, wherein the loss function value is determined using the latest vector parameters of the quantum support vector machine and measurement results, and the measurement results are obtained by updating the variational parameters of the quantum circuit based on the first sample and the second sample; determining the latest vector parameters of the quantum support vector machine based on the obtained gradient and measurement results, and completing the training of the quantum support vector machine. Applying the embodiments of this application can reduce the training time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of quantum computing technology, and in particular to a training method and related apparatus for a quantum support vector machine. Background Technology

[0002] The Quantum Support Vector Machine (QSVM) is an important model in the field of quantum machine learning. It is an extension of the classical Support Vector Machine (SVM) in a quantum computing environment. The main goal of QSVM is also to construct a classification hyperplane to separate data points of different classes.

[0003] Currently, QSVM training is transformed into solving a dual problem. The objective function of the dual problem includes Lagrange multipliers. Upon completion of training, support vectors are determined based on samples where the Lagrange multipliers are greater than 0. The solution process requires loading all training data to calculate the kernel matrix. An optimization algorithm (such as SMO) is then used to update the Lagrange multipliers based on the kernel matrix and the objective function. The variational parameters of the kernel function are then updated based on the updated Lagrange multipliers to achieve the training objective. However, because each iteration requires loading all training data to calculate the kernel matrix, which involves significant computation, the training time is relatively long. Summary of the Invention

[0004] The purpose of this application is to provide a training method and related apparatus for quantum support vector machines, aiming to reduce training time.

[0005] One embodiment of this application provides a training method for a quantum support vector machine, the method comprising:

[0006] From the training sample set, select a first sample and at least one second sample, wherein the second sample is a sample in the training sample set other than the first sample, and the sum of the number of the first sample and the second sample selected in the current iteration is less than the number of samples in the training sample set;

[0007] The gradient calculated based on the loss function value obtained in the current iteration is used to update the variational parameters of the quantum circuit constructed for the kernel function of the quantum support vector machine. The loss function value is determined using the latest vector parameters of the quantum support vector machine and the measurement results, which are obtained by updating the variational parameters of the quantum circuit based on the first sample and a second sample.

[0008] Based on the obtained gradients and measurement results, the latest vector parameters of the quantum support vector machine are determined, and the training of the quantum support vector machine is completed.

[0009] Optionally, determining the latest vector parameters of the quantum support vector machine based on the obtained gradient and measurement results includes:

[0010] The update method of the vector parameters of the quantum support vector machine is determined by the first relation and the second relation. The first relation is the relationship between the currently calculated gradient and 0, and the second relation is the relationship between the target value and the first preset value. The target value is determined by the difference between the predicted value and the true value determined by all the measurement results obtained at present.

[0011] Using the determined update method, the latest vector parameters of the quantum support vector machine are determined.

[0012] Optionally, the target value is obtained by calculating the difference between the predicted value and the true value based on the adjusted weights and the measurement results with non-zero gradients. The adjusted weights are determined by the relationship between the target result and the first preset value. The target result is obtained by calculating the absolute value of the difference between the predicted value and the true value based on the latest vector parameters and the corresponding measurement results.

[0013] Optionally, the update method includes a first update method and a second update method;

[0014] The method for determining the update of vector parameters of the quantum support vector machine through the first and second relations includes:

[0015] If the gradient obtained using the first relation is not all zero, and the target value obtained using the second relation is greater than the first preset value, the update method for the vector parameters of the quantum support vector machine is determined to be the first update method; otherwise, the update method is determined to be the second update method.

[0016] Optionally, the first update method is to update the quantum support vector machine vector parameters to the sum of the latest vector parameters and the second preset value;

[0017] The second update method is to keep the vector parameters of the quantum support vector machine unchanged.

[0018] Optionally, training of a quantum support vector machine is complete if any of the following conditions are met:

[0019] The gradients obtained in the current iteration are all 0;

[0020] The target value obtained in the current iteration is less than or equal to the first preset value;

[0021] The current iteration count has reached the preset maximum iteration count.

[0022] Optionally, updating the variational parameters of the quantum circuit constructed from the kernel function of the quantum support vector machine based on the gradient calculated from the loss function value obtained in the current iteration includes:

[0023] The gradient is calculated by averaging all loss function values ​​obtained in the current iteration.

[0024] The variational parameters of the quantum circuit constructed from the kernel function of the quantum support vector machine are updated by calculating the gradient.

[0025] Optionally, updating the variational parameters of the quantum circuit constructed from the kernel function of the quantum support vector machine based on the gradient calculated from the loss function value obtained in the current iteration includes:

[0026] Based on the first sample and a selected second sample, the loss function value is obtained by constructing a quantum circuit using the kernel function of the quantum support vector machine;

[0027] The gradient is calculated using the loss function value, and the variational parameters of the quantum circuit are updated using the gradient.

[0028] Select a second sample from the second samples that have not been selected in the current iteration, and return to the step of obtaining the loss function value by constructing a quantum circuit based on the first sample and the selected second sample through the kernel function of the quantum support vector machine, until all second samples in the current iteration have been selected.

[0029] Another embodiment of this application provides a training device for a quantum support vector machine, the device comprising:

[0030] The selection module is used to select a first sample and at least one second sample from the training sample set, wherein the second sample is a sample in the training sample set other than the first sample, and the sum of the number of the first sample and the second sample selected in the current iteration is less than the number of samples in the training sample set.

[0031] The first update module is used to update the variational parameters of the quantum circuit constructed by the kernel function of the quantum support vector machine based on the gradient calculated by the loss function value obtained in the current iteration. The loss function value is determined using the latest vector parameters of the quantum support vector machine and the measurement results. The measurement results are obtained by updating the variational parameters of the quantum circuit based on the first sample and a second sample.

[0032] The second update module is used to determine the latest vector parameters of the quantum support vector machine based on the obtained gradient and measurement results, and to complete the training of the quantum support vector machine.

[0033] Another embodiment of this application provides a computer device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the training method of the quantum support vector machine in any of the above embodiments.

[0034] Another embodiment of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a computer, causes the computer to perform the training method of the quantum support vector machine in any of the above embodiments.

[0035] Compared with existing technologies, this application only needs to load a portion of the sample data during iteration, resulting in a smaller amount of data to process. Consequently, the computational load for operations such as calculating loss function values ​​and gradients is relatively small, enabling each iteration to be completed faster and thus shortening the overall training time. The latest vector parameters are then determined using the gradients and measurement results. This update mechanism allows the quantum support vector machine to adapt to data changes more quickly, which helps to improve the convergence speed of the quantum support vector machine and thus reduce training time. Attached Figure Description

[0036] Figure 1 This is an example system block diagram of a training method for a quantum support vector machine provided in an embodiment of this application;

[0037] Figure 2 A flowchart illustrating a training method for a quantum support vector machine provided in this application embodiment;

[0038] Figure 3 A schematic diagram of a quantum circuit constructed for a kernel function is provided as an embodiment of this application;

[0039] Figure 4 A structural diagram of a training device for a quantum support vector machine provided in an embodiment of this application;

[0040] Figure 5 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation

[0041] 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 of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0042] Classical computers use transistors to encode information in binary data, such as bits, where each bit can represent a value of 1 or 0. These 1s and 0s act as switches to drive the functions of a classical computer. If there are n bits of data, there are 2^n possible classical states, and one state is represented at a time.

[0043] Quantum computers use quantum processors that operate on data represented by qubits, also known as quantum bits. A qubit can represent the classical binary states "0" or "1", or a superposition of "0" and "1". Because it can represent a superposition of "0" and "1", a qubit can represent both "0" and "1" states simultaneously. For example, if there are n bits of data, n quantum states can be represented simultaneously. Furthermore, qubits in a superposition can be correlated with each other, a phenomenon known as entanglement. The state of one qubit (whether it's 1, 0, or both) can depend on the state of another qubit, and more information can be encoded within two entangled qubits. Based on the principles of superposition and entanglement, qubits enable quantum computers to perform functions that might be relatively complex and time-consuming for classical computers.

[0044] Please refer to Figure 1 This illustrates an example system block diagram of a training method for quantum support vector machines provided in one embodiment of this application. System 100 may be a hybrid computing system comprising a combination of one or more quantum computers, quantum systems, and / or classical computers. Figure 1 In the example shown, system 100 may include a quantum system 110 and a classical computer 120. In one implementation, the quantum system 110 and the classical computer 120 may be configured to communicate via one or more wired and / or wireless connections (e.g., wireless networks). The quantum system 110 may include a quantum chipset consisting of one or more quantum chips, comprising various hardware components for processing data encoded in qubits. The quantum chipset may be a quantum computing core surrounded by infrastructure to protect the quantum chips from electromagnetic noise sources, mechanical vibration sources, heat sources, and other noise sources that can degrade the performance of the quantum chips. The classical computer 120 may be electronically integrated with the quantum system 110 via any suitable wired and / or wireless electronic connection.

[0045] exist Figure 1 In the example shown, quantum system 110 can be any suitable set of components capable of performing quantum operations on a physical system. Quantum operations, for example, can be quantum logic gate operations that manipulate the quantum states of qubits to evolve and / or become entangled. Figure 1In the illustrated example embodiment, the quantum system 110 may include a measurement and control unit 111, an interface 112, and a quantum chip 113. In some embodiments, all or part of each of the measurement and control unit 111, interface 112, and quantum chip 113 may be located in a cryogenic environment to facilitate the performance of quantum operations. The quantum chip 113 may be any hardware capable of processing information using quantum states. This hardware may include multiple qubits and means for coupling or entanglement of the qubits to process information using quantum states. Qubits may include, but are not limited to, charge qubits, flux qubits, phase qubits, spin qubits, and ion qubits. The quantum chip may include a set of quantum logic gates configured to perform quantum logic operations on the qubits stored in a quantum register. The quantum gates may include one or more single-qubit gates, two-qubit gates, and / or other multi-qubit gates.

[0046] The measurement and control unit 111 can be any combination of digital computing devices capable of performing quantum computing (e.g., executing quantum circuits) in conjunction with interface 112. This digital computing device may include a digital processor and memory for storing and executing quantum instructions using interface 112. The digital computing device may also include a communication protocol device for receiving instructions and sending the results of the performed quantum computing to a classical computer. Additionally, the digital computing device may include a communication interface having interface 112. In one embodiment, the measurement and control unit 111 may be configured to receive classical instructions (e.g., from classical computer 120) and convert these classical instructions into measurement and control instructions for interface 112. The measurement and control instructions provided by the measurement and control unit 111 to interface 112 may be, for example, digital signals indicating which quantum gates in a quantum gate array need to be applied to the qubits to perform a specific function. Interface 112 may be configured to convert these digital signals into analog signals (e.g., analog pulses of microwave pulses), which can be used to apply quantum gates to the qubits to manipulate the interactions between the qubits.

[0047] Interface 112 may be a classical-quantum interface, comprising a combination of devices capable of receiving instructions from the integrated measurement and control unit 111 and converting those instructions into a means for implementing quantum operations. In one embodiment, interface 112 may convert instructions from the integrated measurement and control unit 111 into drive signals capable of driving or manipulating qubits, and / or applying quantum gates to qubits. Additionally, interface 112 may be configured to convert signals received from the quantum chip 113 into digital signals capable of being processed and transmitted by the integrated measurement and control unit 111. Devices included in interface 112 may include, but are not limited to, digital-to-analog converters, analog-to-digital converters, waveform generators, attenuators, amplifiers, optical fibers, lasers, and filters. Interface 112 may further include circuitry configured to measure multiple qubits after the application of quantum gates, wherein the measurements may produce results represented in classical bits. Each measurement performed by interface 112 may be read out to a device connected to the quantum system 110, such as a classical computer 120. The multiple measurement results provided by interface 112 may represent probabilistic results.

[0048] The classical computer 120 can include hardware components such as a processor and storage devices (e.g., including memory devices and classical registers) for processing data encoded in classical bits. In one embodiment, the classical computer 120 can be configured to provide the quantum system 110 with various control signals, instructions, and data encoded in classical bits. Further, quantum states measured by the quantum system 110 can be read out by the classical computer 120, and the classical computer 120 can store the measured quantum states as classical bits in classical registers. In one embodiment, the classical computer 120 can be any suitable combination of computer-executable hardware and / or computer-executable software capable of executing the preparation module 121 to perform quantum computation using data stored in the data storage module 122 as part of the construction and computation. The data storage module 122 can be a repository for data to be analyzed using quantum computing algorithms and the results of that analysis. The preparation module 121 can be a program or module capable of preparing classical data from the data storage module 122 as part of a quantum circuit implementation. Preparation module 121 can be instantiated as part of a larger algorithm, such as an application programming interface (API) function call, or by resolving hybrid classical-quantum computing into aspects of quantum and classical computing. For example, preparation module 121 can generate instructions for creating quantum circuits using quantum gates. In an embodiment, such instructions can be stored by the measurement and control unit 111 and can be instantiated by components of interface 112 to execute, enabling quantum operations of quantum gates to be performed on quantum chip 113.

[0049] The classic computer 120 may be a laptop computer, desktop computer, vehicle-integrated computer, smart mobile device, tablet device, and / or any other suitable classic computing device. Additionally or alternatively, the classic computer 120 may also operate as part of a cloud computing service model, such as Software as a Service (SaaS), Platform as a Service (PaaS), or Infrastructure as a Service (IaaS). The classic computer 120 may also reside in a cloud computing deployment model, such as a private cloud, community cloud, public cloud, or hybrid cloud.

[0050] See Figure 2 , Figure 2 This application provides a method for training a quantum support vector machine, the method comprising the following steps:

[0051] S201: From the training sample set, select a first sample and at least one second sample, wherein the second sample is a sample in the training sample set other than the first sample, and the sum of the number of the first sample and the second sample selected in the current iteration is less than the number of samples in the training sample set.

[0052] Both the first and second samples can be randomly selected. However, the selection of the second sample has a constraint: in one iteration, it must be a sample from the training sample set excluding the first sample. Furthermore, in the current iteration, the combined number of the first and second samples selected must be less than the total number of samples in the training sample set. This step aims to use a subset of samples for training, rather than all samples, reducing memory consumption and facilitating parallelization, thus reducing computational load and allowing for gradual optimization of the quantum support vector machine. Because each iteration uses only a portion of the sample set, the quantum support vector machine does not overly rely on a few specific samples, but rather gradually encounters different sample combinations throughout the training process, which helps improve the generalization ability of the quantum support vector machine and avoids overfitting. Compared to training a quantum support vector machine using a dual-form support vector regression algorithm, the method described in this application does not require loading all data at once, has online learning capabilities, and can handle large-scale datasets.

[0053] During training, the number of second samples selected in each iteration can be different, and the specific number can change as training progresses. Specifically, a parameter can be set for the number of second samples, and this parameter can be updated based on the training results.

[0054] S202: Based on the gradient calculated from the loss function value obtained in the current iteration, update the variational parameters of the quantum circuit constructed for the kernel function of the quantum support vector machine, wherein the loss function value is determined using the latest vector parameters of the quantum support vector machine and the measurement results, and the measurement results are obtained by updating the variational parameters of the quantum circuit based on the first sample and a second sample.

[0055] Support Vector Machines (SVMs) can be used for both classification and regression tasks. The kernel function is the core tool for handling nonlinear problems in SVMs. It extends SVMs from handling only linearly separable data to handling a wide range of nonlinearly separable data. By mapping the original data to a high-dimensional feature space, it makes the data in that high-dimensional feature space linearly or approximately linearly separable. Simultaneously, through clever inner product calculations, it avoids the high computational cost of high-dimensional mapping, laying the foundation for the powerful performance and wide application of SVMs. By flexibly selecting and adjusting the kernel function, SVMs can exhibit superior performance in various classification and regression tasks.

[0056] Kernel functions calculate the inner product of samples in the feature space, thus obtaining the similarity of samples in the original space and enabling the linearization of nonlinear data. A kernel function can be expressed as, for example, K(x, x′) = |<φ(x)|φ(x′)>|, or K(x, x′) = |<φ(x)|φ(x′)>| 2 Here, K(x, x′) is the value of the kernel function, representing a similarity measure between two data points x and x′. φ(x) and φ(x′) represent the eigenvectors obtained after mapping data points x and x′ to a feature space (usually high-dimensional). <·|·> is the inner product operation, used to calculate the inner product of two eigenvectors. |<φ(x)|φ(x′)>| calculates the modulus (the inner product is a complex number) of the inner product between two eigenvectors in the feature space, representing the similarity between data points x and x′ in the feature space. If this value is close to 1, it indicates that data points x and x′ are very similar in the feature space; if it is close to 0, it indicates that data points x and x′ are less similar. The purpose of the kernel function is to calculate the similarity between two data points in the feature space through the inner product, without needing to explicitly calculate the eigenvectors in the feature space. That is, it allows calculations in high-dimensional or infinite-dimensional feature spaces without explicitly knowing the values ​​of the eigenvectors φ(x) and φ(x′). If the kernel function outputs a positive definite kernel matrix, and this kernel function is constructed using a quantum circuit, then the construction of the quantum circuit allows the calculation of the kernel function to be achieved through the inner product of quantum states, thereby guaranteeing the positive definiteness of the kernel function. For example, a reference quantum circuit for constructing the kernel function could be as follows: Figure 3 As shown, ψ represents the quantum state of the input data. It is a dagger notation, which is commonly used in mathematics to represent the conjugate transpose operation, also known as Hermitian conjugate.

[0057] In Quantum Support Vector Machines (QSVM), the loss function is used to measure the model's performance. During training, the value of the loss function at the current iteration is calculated. Based on this loss function value, its gradient can be calculated, reflecting the rate of change of the loss function under the current parameters. In this embodiment, the loss function needs to be calculated using the latest vector parameters. The measurement results are obtained by encoding the first and second samples into quantum states, processing them through a quantum circuit containing variational parameters, and finally obtaining the measurement results. These measurement results will be used to calculate the value of the loss function because they reflect the performance of the quantum circuit under the current variational parameter settings, thus affecting the performance of the quantum support vector machine. After obtaining the measurement results, the value of the loss function can be calculated. When calculating the gradient based on the loss function, either the parameter shifting method or the stochastic gradient descent method can be used to obtain the gradient.

[0058] In this embodiment of the application, the loss function can be the objective function, given a training sample set {x}. i ,y i},in The optimization objective is to learn a function mapping f(x) i ), capable of predicting target y i Since they are similar, f(·) is the kernel function, and the objective function to be solved can be:

[0059]

[0060] Where C is the regularization parameter, K θ (·,·) is the kernel function, ε is the soft margin threshold, also known as the first preset value, that is, the prediction error within the range of ε is considered a correct prediction, w is the vector parameter, and b is the bias parameter.

[0061] The variational parameters can be updated by averaging the loss function values ​​obtained in the current iteration to calculate the gradient. This gradient is then used to update the variational parameters of the quantum circuit constructed from the kernel function of the quantum support vector machine. This update occurs after each iteration. For example, with four second samples, four loss function values ​​are obtained. The average of these four loss function values ​​is calculated, and the gradient is used to update the variational parameters. Using the average value when calculating the gradient may provide stronger robustness to noise, especially when there is significant noise between samples, resulting in a more stable gradient estimate and reducing the computational cost of gradient calculation.

[0062] The variational parameter update can be based on the first sample and a selected second sample, using a quantum circuit constructed with a kernel function for a quantum support vector machine to obtain the loss function value; using the loss function value, the gradient is calculated, and the variational parameters of the quantum circuit are updated using the gradient; a second sample is selected from the unselected second samples in the current iteration, and the process of obtaining the loss function value based on the first sample and a selected second sample using a quantum circuit constructed with a kernel function for a quantum support vector machine is repeated until all second samples in the current iteration are selected. This variational parameter update involves updating the variational parameters once for each loss function value. For example, if there are four second samples and one loss function value is obtained, the gradient corresponding to that loss function value is used to update the variational parameters. Then, the updated variational parameters are used to obtain the loss function value for another second sample, and the variational parameters are updated again until all four second samples have been updated. Multiple updates to the variational parameters in a single iteration may lead to faster convergence, especially when the sample data has a certain order or local features, allowing for better utilization of sample information. For optimizing the variational parameter θ in quantum circuits, a fixed learning rate can be used for updating.

[0063] S203: Based on the obtained gradient and measurement results, determine the latest vector parameters of the quantum support vector machine and complete the training of the quantum support vector machine.

[0064] In this embodiment, the vector parameters can be support vectors of a quantum support vector machine (SVM). Support vector machines can be used not only for classification problems but also for regression problems; the model used for regression tasks is called a support vector regression model (SVM-Regression). In SVR, the goal is to find a function such that most training data points lie within a "pipe" of a specific width around that function. In SVR, support vectors are the data points located on the boundary of this "pipe" or outside the band. These points play a crucial role in determining the shape of the regression function. Similar to classification SVMs, SVR determines the regression function by minimizing an objective function that includes a penalty term. Support vectors are the data points that contribute to the objective function; their positions and corresponding objective values ​​determine the position and shape of the regression hyperplane (in high-dimensional space). For example, consider a simple linear SVR model where the regression function can be represented as y = ω·x + b (where ω is the vector parameter and b is the bias parameter). Support vectors determine the position of this linear function by influencing the solution process for ω and b. Specifically, the solution process involves minimizing an objective function that minimizes the distance from data points to the regression function while preserving the simplicity of the regression function (through regularization terms). The positions and objective values ​​of the support vectors directly participate in this minimization process. Support vectors carry the most important information in the dataset. During prediction, the prediction result for a new data point is calculated based on the regression function determined by the support vectors. For example, for a nonlinear SVR model, after mapping the data to a high-dimensional space using a kernel function, the support vectors define a complex regression surface in that high-dimensional space. When predicting a new input, the predicted value is calculated based on this high-dimensional regression surface defined by the support vectors and their positions in the high-dimensional space. Correctly identifying and utilizing support vectors can improve prediction accuracy. Using the embodiments of this application, it is possible to simultaneously learn a suitable kernel function and support vectors in Hilbert space.

[0065] This application only needs to load a portion of the sample data during iteration, resulting in a smaller amount of data to process. Consequently, the computational load for operations such as calculating the loss function value and gradient is relatively small, enabling each iteration to be completed faster and thus shortening the overall training time. The latest vector parameters are then determined using the gradient and measurement results. This update mechanism allows the quantum support vector machine to adapt to changes in data more quickly, which helps to improve the convergence speed of the quantum support vector machine and thus reduce training time.

[0066] The gradient and measurement results determine how the vector parameters are updated. The updated parameters are obtained by following the determined update method. Based on the obtained gradient and measurement results, the latest vector parameters of the quantum support vector machine are determined, including:

[0067] The update method of the vector parameters of the quantum support vector machine is determined by the first relation and the second relation. The first relation is the relationship between the currently calculated gradient and 0, and the second relation is the relationship between the target value and the first preset value. The target value is determined by the difference between the predicted value and the true value determined by all the measurement results obtained at present.

[0068] Using the determined update method, the latest vector parameters of the quantum support vector machine are determined.

[0069] The first and second relations determine how the vector parameters are updated. The first relation is the magnitude relationship between the gradient and 0, and the first preset value can be a soft-margin threshold. Specifically, the update methods include a first update method and a second update method. If the gradient obtained using the first relation is not all zero, and the target value obtained using the second relation is greater than the first preset value, the update method for the quantum support vector machine's vector parameters is determined to be the first update method; otherwise, the update method is determined to be the second update method.

[0070] In this embodiment of the application, the target value is obtained by calculating the difference between the predicted value and the true value based on the adjustment weight and the measurement result with a gradient that is not zero. The adjustment weight is determined by the relationship between the target result and the first preset value. The target result is obtained by calculating the absolute value of the difference between the predicted value and the true value based on the latest vector parameters and the corresponding measurement result.

[0071] The formula for calculating the target value can be expressed as:

[0072]

[0073] Where λ is a parameter used to adjust the learning rate, t is the number of measurements with a non-zero gradient in the current iteration, and δ... i To adjust the weights, specifically, an indicator function is used to indicate |w T K θ (·,x i )+by i In the case of |-ε, return 1 if the result is greater than 0, otherwise return 0. θ (·,x i ) represents the i-th column of the kernel matrix.

[0074] In some embodiments of this application, the first update method is: updating the quantum support vector machine vector parameters to the sum of the latest vector parameters and a second preset value;

[0075] The second update method is to keep the vector parameters of the quantum support vector machine unchanged.

[0076] For a quantum support vector machine used for regression tasks, the update of the vector parameter w in one iteration can be expressed as:

[0077]

[0078] Where, η t It is a learning rate that decays with the number of iterations t, and η t = 1 / (λt). g t Let δ be the gradient of the vector parameter w in the current iteration t. t It is an indicator function used to indicate |w T K θ (·,x i )+by i In the case of |-ε, if the result is greater than 0, return 1; otherwise, return 0. t represents the t-th iteration. This represents the kernel matrix obtained in the current iteration.

[0079] In most cases, all sample data is required to calculate the kernel matrix. Using only partial training data, the kernel function cannot be directly obtained, thus making it impossible to determine the vector parameters w. t Optimization is needed. Therefore, when using partial sample data, the update method can be determined based on the first and second relations. For the first update method, a second preset value is added to the vector parameters obtained in the previous iteration. The second preset value can be 1. This update method is determined as follows:

[0080] First, consider w in one iteration. t The update steps are changed by multiplying both sides by t, and then replacing η. t We have:

[0081]

[0082] We can consider multiple different iteration numbers t to obtain

[0083]

[0084]

[0085]

[0086] Summing the results of multiple different iterations t above, and then dividing both sides by t, we get:

[0087]

[0088] The summation symbol counts the number of times the gradient is not zero up to the tth iteration, but... Since we cannot obtain it directly, we can substitute the above summation into the objective function, which gives us:

[0089]

[0090] As can be seen from the above formula, direct calculation of w can be avoided. t+1 Instead of counting the number of times the gradient is not zero up to the tth iteration, we only need to count the number of times the gradient is not zero to replace the vector parameters.

[0091] In some embodiments of this application, training of the quantum support vector machine is completed if any of the following conditions are met:

[0092] The gradients obtained in the current iteration are all 0;

[0093] The target value obtained in the current iteration is less than or equal to the first preset value;

[0094] The current iteration count has reached the preset maximum iteration count.

[0095] There are three criteria for marking the completion of quantum support vector machine (SVM) training; satisfying any one of them indicates training is complete. When all gradients are zero, it means the loss function has reached an extreme point with the current parameters. For training a quantum SVM, the goal is usually to reach a local minimum. At this point, further parameter updates will not cause the loss function to decrease further, so training can be considered to have reached a stable state and is complete. The first preset value is a pre-defined threshold. When the calculated loss function value is less than or equal to this threshold, the current quantum SVM is considered to have achieved good performance and meets the set requirements, so further training is unnecessary. To avoid the training process getting stuck in long periods of non-convergence or infinite loops, a maximum number of iterations is set. Even if the above two conditions are not met, training will terminate when the number of iterations reaches this upper limit. This is a safety measure to prevent the algorithm from getting bogged down in long periods of ineffective computation, especially when facing complex datasets or models where the algorithm may fail to converge. By setting a maximum number of iterations, the algorithm can be guaranteed to produce a result within limited time and resources. These training completion conditions constrain the training process of quantum support vector machines from different perspectives, ensuring that the training process can be completed within a reasonable time and performance range, and can be flexibly adjusted according to different needs and actual situations to achieve the optimal training effect.

[0096] See Figure 4 , Figure 4 A training device for a quantum support vector machine provided in this application embodiment may include:

[0097] Selection module 401 is used to select a first sample and at least one second sample from the training sample set, wherein the second sample is a sample in the training sample set other than the first sample, and the sum of the number of the first sample and the second sample selected in the current iteration is less than the number of samples in the training sample set.

[0098] The first update module 402 is used to update the variational parameters of the quantum circuit constructed by the kernel function of the quantum support vector machine based on the gradient calculated by the loss function value obtained in the current iteration. The loss function value is determined using the latest vector parameters of the quantum support vector machine and the measurement results. The measurement results are obtained by updating the variational parameters of the quantum circuit based on the first sample and a second sample.

[0099] The second update module 403 is used to determine the latest vector parameters of the quantum support vector machine based on the obtained gradient and measurement results, and to complete the training of the quantum support vector machine.

[0100] The specific functions and effects of the above-mentioned quantum support vector machine training device can be explained by referring to other embodiments of this application, and will not be repeated here. Each sub-circuit in the quantum support vector machine training device can be implemented entirely or partially through software, hardware, or a combination thereof. Each sub-circuit can be embedded in or independent of the processor in a computer device in hardware form, or it can be stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each of the above sub-circuits.

[0101] Please see Figure 5 This application also provides a computer device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the quantum support vector machine training method in any of the above embodiments. Please refer to [link to relevant documentation]. Figure 5 The computer device can be a classical computer or a quantum computer.

[0102] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a computer, causes the computer to perform the training method of the quantum support vector machine in any of the above embodiments.

[0103] This application also provides a computer program product containing instructions that, when executed by a computer, cause the computer to perform the training method of the quantum support vector machine in any of the above embodiments.

[0104] It is understood that in the various embodiments of this application, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not limit the implementation process of the embodiments of this application in any way.

[0105] It is understood that the various implementation methods described in this application can be implemented individually or in combination, and the implementation methods in this application are not limited in this respect.

[0106] Unless otherwise stated, all technical and scientific terms used in the embodiments of this application have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The term "and / or" as used in this application includes any and all combinations of one or more of the associated listed items. The singular forms "a," "the," and "the" as used in the embodiments of this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.

[0107] It is understood that the processor in the embodiments of this application can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method embodiments can be completed by the integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software sub-circuits in the decoding processor. The software sub-circuits can be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above method.

[0108] It is understood that the memory in the embodiments of this application may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Specifically, non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may be random access memory (RAM). It should be noted that the memory in the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0109] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0110] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the aforementioned method implementations, and will not be repeated here.

[0111] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0112] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.

[0113] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0114] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0115] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for training a quantum support vector machine, characterized in that, The method includes: From the training sample set, select a first sample and at least one second sample, wherein the second sample is a sample in the training sample set other than the first sample, and the sum of the number of the first sample and the second sample selected in the current iteration is less than the number of samples in the training sample set; The gradient calculated based on the loss function value obtained in the current iteration is used to update the variational parameters of the quantum circuit constructed for the kernel function of the quantum support vector machine. The loss function value is determined using the latest vector parameters of the quantum support vector machine and the measurement results, which are obtained by updating the variational parameters of the quantum circuit based on the first sample and a second sample. Based on the obtained gradients and measurement results, the latest vector parameters of the quantum support vector machine are determined, and the training of the quantum support vector machine is completed.

2. The method of claim 1, wherein, The process of determining the latest vector parameters of the quantum support vector machine based on the obtained gradient and measurement results includes: The update method of the vector parameters of the quantum support vector machine is determined by the first relation and the second relation. The first relation is the relationship between the currently calculated gradient and 0, and the second relation is the relationship between the target value and the first preset value. The target value is determined by the difference between the predicted value and the true value determined by all the measurement results obtained at present. Using the determined update method, the latest vector parameters of the quantum support vector machine are determined.

3. The method of claim 2, wherein, The target value is obtained by calculating the difference between the predicted value and the true value based on the adjusted weights and the measurement results with non-zero gradients. The adjusted weights are determined by the relationship between the target result and a first preset value. The target result is obtained by calculating the absolute value of the difference between the predicted value and the true value based on the latest vector parameters and the corresponding measurement results.

4. The method of claim 2, wherein, The update methods include a first update method and a second update method; The method for determining the update of vector parameters of the quantum support vector machine through the first and second relations includes: If the gradient obtained using the first relation is not all zero, and the target value obtained using the second relation is greater than the first preset value, the update method for the vector parameters of the quantum support vector machine is determined to be the first update method; otherwise, the update method is determined to be the second update method.

5. The method of claim 4, wherein, The first update method is to update the quantum support vector machine vector parameters to the sum of the latest vector parameters and the second preset value; The second update method is to keep the vector parameters of the quantum support vector machine unchanged.

6. The method of claim 1, wherein, The training of a quantum support vector machine is complete if any of the following conditions are met: The gradients obtained in the current iteration are all 0; The target value obtained in the current iteration is less than or equal to the first preset value; The current iteration count has reached the preset maximum iteration count.

7. The method according to any one of claims 1 to 6, wherein The gradient calculated based on the loss function value obtained in the current iteration is used to update the variational parameters of the quantum circuit constructed from the kernel function of the quantum support vector machine, including: The gradient is calculated by averaging all loss function values ​​obtained in the current iteration. The variational parameters of the quantum circuit constructed from the kernel function of the quantum support vector machine are updated by calculating the gradient.

8. The method according to any one of claims 1 to 6, wherein The gradient calculated based on the loss function value obtained from the current iteration is used to update the variational parameters of the quantum circuit constructed using the kernel function of the quantum support vector machine, including: Based on the first sample and a selected second sample, the loss function value is obtained by constructing a quantum circuit using the kernel function of the quantum support vector machine; The gradient is calculated using the loss function value, and the variational parameters of the quantum circuit are updated using the gradient. Select a second sample from the second samples that have not been selected in the current iteration, and return to the step of obtaining the loss function value by constructing a quantum circuit based on the first sample and the selected second sample through the kernel function of the quantum support vector machine, until all second samples in the current iteration have been selected. 9.A training device of a quantum support vector machine, characterized by, The device includes: The selection module is used to select a first sample and at least one second sample from the training sample set, wherein the second sample is a sample in the training sample set other than the first sample, and the sum of the number of the first sample and the second sample selected in the current iteration is less than the number of samples in the training sample set. The first update module is used to update the variational parameters of the quantum circuit constructed by the kernel function of the quantum support vector machine based on the gradient calculated by the loss function value obtained in the current iteration. The loss function value is determined using the latest vector parameters of the quantum support vector machine and the measurement results. The measurement results are obtained by updating the variational parameters of the quantum circuit based on the first sample and a second sample. The second update module is used to determine the latest vector parameters of the quantum support vector machine based on the obtained gradient and measurement results, and to complete the training of the quantum support vector machine.

10. A computer device comprising a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the training method of the quantum support vector machine according to any one of claims 1-8.

11. A computer-readable storage medium having a computer program stored thereon, which, when executed by a computer, causes the computer to perform the training method of the quantum support vector machine according to any one of claims 1-8.