Quantum HNSW graph KNN method based on pellets

Through the quantum HNSW graph KNN method based on particle spheres, the problem of high time complexity in the classic KNN method under large data volume is solved, efficient KNN classification is realized, and it has become the algorithm with the lowest time complexity at present.

CN119513715AActive Publication Date: 2025-02-25SICHUAN KAIXIANGYUAN SOFTWARE TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411653421.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-02-25
Estimated Expiration
2044-11-19

AI Technical Summary

Technical Problem

When facing large data volumes, the algorithm time complexity is high, affecting the classification efficiency.

Method used

The KNN method based on particle spheres is adopted to generate particle sphere data sets and construct multi-layer quantum HNSW maps, optimize the distance calculation steps, and combine the advantages of classical computers and quantum computers to improve the classification performance of KNN algorithms.

Benefits of technology

It effectively reduces the amount of data involved in KNN classification calculation, optimizes the distance calculation steps, improves the classification performance of the KNN algorithm, reduces the computational complexity, and becomes the algorithm with the lowest time complexity in KNN algorithms at present.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119513715A_ABST
    Figure CN119513715A_ABST
Patent Text Reader

Abstract

The invention relates to a particle-ball-based quantum HNSW graph KNN method, and belongs to the field of quantum calculation and machine learning. According to the method, firstly, a data set D is converted into a granular ball data set M through classical calculation, and the amount of data participating in calculation is effectively reduced; afterwards, by means of quantum computing parallelism, a QRAM algorithm and angle coding, the pellet data set is coded into a quantum state, Swap-test and iteration are used for comparing quantum circuits to calculate similarity, and a multilayer quantum HNSW graph is constructed; and finally, K nearest neighbors of the test data points are determined through quantum search and a priority queue, and the test data points are classified according to classification results of the neighbors. According to the method, the advantages of a classic computer and a quantum computer are combined, the calculation data volume and the time complexity are reduced, meanwhile, high classification precision is kept, and a new thought and method are provided for the quantum machine learning field.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of quantum computing and machine learning, and relates to a quantum hierarchical navigation small world (HNSW) graph K-nearest neighbors (KNN) method based on a particle sphere. Background Art

[0002] In the field of machine learning, classical computers face huge challenges in terms of computing power and algorithms. Breakthroughs in quantum mechanics and quantum computing have led to the rapid development of quantum computers. Quantum computers use the superposition, parallelism and quantum entanglement of quantum states to demonstrate advantages far beyond classical computers in computing specific problems. Using a granular ball to replace the sample points in the data set, the granular ball simplifies the attributes of the data while showing the overall characteristics of the data set. This is a robust and scalable granular computing learning method. In addition, the classifier and KNN in machine learning can improve efficiency without causing a significant decrease in accuracy after combining with the granular ball. At the same time, although the classical KNN method can realize the classification of inserted data points, when facing large amounts of data, there is still a problem of high algorithm time complexity that affects classification efficiency. Therefore, the quantum HNSW graph KNN method based on granular balls has certain advantages over the classical KNN method in terms of the amount of data involved in the calculation and the algorithm time complexity, but because the relevant data needs to be stored during the composition process, it will consume more storage space and quantum bits. Summary of the invention

[0003] In view of this, the purpose of the present invention is to provide a quantum HNSW graph KNN method based on particle spheres to solve the technical problems of large amount of data involved in calculation and high algorithm time complexity in classical KNN.

[0004] In order to achieve the above object, the present invention provides the following technical solutions:

[0005] A quantum HNSW graph KNN method based on a particle sphere comprises the following steps:

[0006] S1: Generate a sphere dataset M through a point dataset D;

[0007] S2: Quantum HNSW graph construction work, determine the insertion layer and neighbor nodes of the insertion point, calculate the similarity between the inserted data point and the neighbor nodes of the current layer of the graph and its one-hop data points, and find the minimum value;

[0008] S3: According to the minimum value found in S2, a graph connection relationship between the insertion point and the minimum value point is established, and the minimum value point is used as the neighbor node of the lower layer to continue the insertion work of the next layer;

[0009] S4: Repeat steps S2 and S3 until the particle-sphere data set M is traversed and the construction of the multi-layer quantum HNSW graph is completed;

[0010] S5: Quantum HNSW graph search work, input test data point J from the top layer, and calculate the minimum distance between J and the neighboring nodes of the current layer and their one-hop data points;

[0011] S6: insert the minimum value of this layer into a priority queue of size K, and let the nearest node be the neighbor node of the next layer, and continue the search work of the next layer;

[0012] S7: Repeat steps S5 and S6 until the quantum HNSW graph structure is traversed and the search is completed;

[0013] S8: Determine the major categories among the K neighbors of the inserted data point J according to the priority queue determined in S7, and classify the data point J according to the major categories.

[0014] Further, the S1 generates a particle-sphere dataset M through a point dataset D. This method is completed using classical calculations and specifically includes the following steps:

[0015] S11: Take the entire data set D as the initial sphere, randomly select a point in the sphere as the center, and select another heterogeneous point with the farthest distance as the other center;

[0016] S12: Determine whether the purity of each ball meets the threshold T, and continue to split the balls that do not meet the purity. The classification rule is: calculate the distance between the remaining data points and the two center points, and divide the data points into the balls corresponding to the center points with the closest distance;

[0017] S13: In the newly generated sphere, the original center is taken as the center, and another heterogeneous point with the farthest distance is selected as another center. On this basis, step S12 is repeated until the purity of all spheres meets the threshold T, and the sphere data set M is obtained. The amount of data in the sphere data set is recorded as n.

[0018] Furthermore, the S2, quantum HNSW graph construction work, determines the number of insertion layers and neighbor nodes of the insertion point, calculates the similarity between the inserted data point and the neighbor nodes of the current layer of the graph and its one-hop data points, and finds the minimum value; the method is completed using quantum computing, and specifically includes the following steps:

[0019] S21: Determine the total number of layers of the multi-layer spherical quantum HNSW graph and the number of layers to be inserted at each insertion point. The total number of layers is related to the number n of spherical data sets M. The specific number of layers is logn layers. The number of layers inserted at each point is generated by a random function to generate the maximum value l max , the random function is where r∈(0,1) is a random number generated from a uniform distribution, and finally l max =min(L,logn), which means the insertion point will be from l max Build graph connections layer by layer down to the bottom layer;

[0020] S22: Use the QRAM algorithm and angle encoding to encode the particle-sphere data set into a quantum state. For the particle-sphere data set M, its data set size is 2 k , the data dimension is a, and the data range of each dimension is in, According to the maximum value of each dimension of data, the address bit is designed, and a new register group 1 is added to store the address of the data set. The specific number of bits is k. Different dimensions share the address bit. According to the data dimension a, 2a QRAM and angle encoding are performed. A new register group 2 is added to store QRAM encoded data, and a new register group 3 is added to store angle encoded data. For the preparation of each data of the particle ball data set M, the quantum bit required for the QRAM data bus is set to t according to the numerical range of each dimension. a , use QRAM to store data on the data bus and control the data on the data bus in parallel with the address bit, and then map the data on the data bus to the angle on the Bloch sphere through angle encoding. The specific steps of angle encoding are: use a quantum bit to store the angle, the data is stored in binary form on the data bus, the data bit is the control bit, and the value is taken from the high bit to the low bit of the data. x starts from 0 and increases by 1 in sequence. If the corresponding bit of the value is 1, use the CRY gate to control the rotation When one preparation is completed, the data bus is restored to |0> for the next preparation;

[0021] S23: Define the corresponding data point set S in each layer of the graph i (i∈[0,logn]) and the adjacency matrix J i (i∈[0,logn]), determine the point set S to be calculated based on the data point set and adjacency matrix of each layer combined with the neighbor nodes determined in the previous layer ci (i∈[0,logn]), inserting points and point set S through address bit index in QRAM ci The data bits of S22 are encoded with the angle in S22, and the angle data is stored in the corresponding angle bit in register group 3. Register group 4 is added as the control bit to insert the point and point set S ci The angle qubits corresponding to all points in register group 3 act on the Swap-test quantum circuit respectively, and the similarity results are stored in the corresponding qubits in register group 4;

[0022] S24: Use the iterative comparison quantum circuit to obtain the minimum value of the probability of measuring 1 in the obtained similarity, which represents the two closest quantum states. Add register group 5 as the data quantum bit involved in the comparison, and add register group 6 as the auxiliary bit required for the comparison. The similarity calculated in S23 is minimized through the comparison circuit.

[0023] Further, S3 establishes a graph connection relationship between the insertion point and the minimum value point according to the minimum value found by S2, and uses the minimum value point as a neighbor node of the lower layer to continue the insertion work of the next layer. This method is completed using quantum computing and specifically includes the following steps:

[0024] S31: It is stipulated that when constructing a graph, the number of neighbors of a point is less than or equal to m. The node to be connected with the insertion point in this layer is determined according to the minimum similarity value obtained in S24, and the corresponding element in the adjacency matrix is ​​set to 1 to represent the connection relationship between the two points. The graph connection relationship established between each data point and the outside world shall not exceed m.

[0025] S32: Using the node in the current layer that has a connection relationship with the insertion point as a neighbor node when building a connection relationship in the next layer;

[0026] Further, in S4, steps S2 and S3 are repeated until the particle-sphere data set M is traversed, and the construction of the multi-layer particle-sphere quantum HNSW graph is completed. This method is completed using quantum computing, and specifically includes the following steps:

[0027] S41: Insertion point from l max At the beginning, each layer downward executes steps S31 and S32 to build the graph connection relationship until the insertion point reaches the bottom layer, and the insertion of the point is completed;

[0028] S42: Let each point in the particle sphere data set M perform the insertion work according to S41, and build a new graph connection relationship during the insertion process, that is, update the data point set S of each layer. i (i∈[0,logn]) and the adjacency matrix J i (i∈[0,logn]) until all points in the sphere data set M are inserted;

[0029] Further, the S5, quantum HNSW graph search work, inputs the test data point J from the top layer, and calculates the minimum value of the distance between J and the one-hop data point of the neighbor node of the current layer. The method is completed using quantum computing, and specifically includes the following steps:

[0030] S51: Starting from the top layer of the quantum HNSW graph, the test data point J is encoded through QRAM and angle using the same method as S22, S23, and S24, and the similarity between the test data point and the neighboring nodes of the current layer and its one-hop nodes is calculated. The data point closest to the test data point J in this layer is obtained through iterative quantum comparison circuits;

[0031] Further, S6 inserts the minimum value obtained in the layer into a priority queue of size K, and uses the nearest node of the current layer as the neighbor node of the next layer to continue the search work of the next layer, which specifically includes the following steps:

[0032] S61: Get the data point closest to the test data point in the current layer in S51, and insert the point into a priority queue Q of size K. The priority queue takes the value with the largest distance as the high priority, that is, when popping out an element from the queue, the value with the largest distance will be popped out first;

[0033] S62: taking the data point closest to the test data point in the current layer in S51 as the neighbor node of the test data point in the next layer, and allowing the test data point to enter the next layer to continue the search;

[0034] Further, the step S7 repeats the steps S5 and S6 until the multi-layer graph structure is traversed and the search is completed, which specifically includes the following steps:

[0035] S71: Let the inserted data point search downwards from the highest layer, repeating steps S51, S61 and S62, and inserting the minimum similarity value of each layer into the priority queue (the same point can be inserted repeatedly but the priority queue does not store repeated values);

[0036] S72: Determine whether the priority queue is full. If the priority queue is full before the search is completed, compare the newly inserted similarity with the maximum similarity of the priority queue. If the newly inserted similarity is large, the priority queue is not changed. Otherwise, the maximum similarity is popped out and a new similarity value is inserted.

[0037] Further, the S8, according to the priority queue obtained in S7, determines the major categories of the K neighbors of the inserted data point J, and classifies the data point J according to the major categories, specifically including the following steps:

[0038] S81: Calculate the proportion of data types in the priority queue Q, obtain the main types in Q, and classify the test data point J as the main type in Q.

[0039] The beneficial effects of the present invention are:

[0040] First, the present invention effectively reduces the amount of data involved in KNN classification calculation through the granular spherical characteristics.

[0041] Second, the present invention utilizes quantum parallelism to optimize the distance calculation steps and reduce the calculation time.

[0042] Third, the present invention combines the respective advantages of classical computers and quantum computers to improve the classification performance of the KNN algorithm and lay the foundation for future quantum machine learning.

[0043] Fourth, the present invention designs an efficient quantum HNSW graph KNN classification algorithm based on particle spheres, which is the algorithm with the lowest time complexity among the current KNN algorithms.

[0044] Fifth, the present invention designs and provides a new KNN algorithm idea that combines classical and quantum computing.

[0045] Sixth, the present invention utilizes the particle-sphere quantum HNSW graph structure to simultaneously implement rough search and fine search, thereby reducing the overall calculation steps and reducing the calculation complexity.

[0046] Other advantages, objectives and features of the present invention will be described in the following description to some extent, and to some extent, will be obvious to those skilled in the art based on the following examination and study, or can be taught from the practice of the present invention. The objectives and other advantages of the present invention can be realized and obtained through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention will be described in detail below in conjunction with the accompanying drawings, wherein:

[0048] Figure 1 is an overall flow chart of the method in an embodiment of the present invention;

[0049] Figure 2 This is a data diagram after the granular spherical attribute simplification of the data in the present invention;

[0050] Figure 3 A specific circuit diagram prepared for data of one dimension in the present invention;

[0051] Figure 4 A specific circuit diagram for the angles of all data designed for the present invention;

[0052] Figure 5 A specific circuit diagram for obtaining the similarity between two quantum states in an embodiment of the present invention;

[0053] Figure 6 A specific circuit diagram for comparing the size relationship of numbers in the present invention;

[0054] Figure 7 A single-layer schematic diagram of a graph connection relationship constructed at a certain layer for the insertion point of the present invention;

[0055] Figure 8 It is an overall schematic diagram of the connection relationship of the graph constructed from the topmost layer to the bottommost layer of the insertion point of the present invention;

[0056] Fig. 9 A schematic diagram of the structure of the priority queue defined in the present invention;

[0057] Fig.10 It is a schematic diagram of the priority queue after the insertion point is searched through the graph in the implementation example of the present invention. DETAILED DESCRIPTION

[0058] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments only illustrate the basic concept of the present invention in a schematic manner, and the following embodiments and features in the embodiments can be combined with each other without conflict.

[0059] Among them, the drawings are only used for illustrative explanations, and they only represent schematic diagrams rather than actual pictures, and should not be understood as limitations on the present invention. In order to better illustrate the embodiments of the present invention, some parts of the drawings may be omitted, enlarged or reduced, and do not represent the size of actual products. For those skilled in the art, it is understandable that some well-known structures and their descriptions in the drawings may be omitted.

[0060] The same or similar numbers in the drawings of the embodiments of the present invention correspond to the same or similar parts; in the description of the present invention, it should be understood that if the terms "upper", "lower", "left", "right", "front", "rear", etc. indicate the orientation or position relationship, they are based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation. Therefore, the terms describing the position relationship in the drawings are only used for illustrative purposes and cannot be understood as limiting the present invention. For ordinary technicians in this field, the specific meanings of the above terms can be understood according to specific circumstances.

[0061] See also Figures 1 to 10 , which is a quantum HNSW graph KNN method based on particle spheres.

[0062] like Figure 1 As shown, this embodiment provides a quantum HNSW graph KNN method based on a particle sphere, comprising the following steps:

[0063] S1: Get the complete dataset D and generate the spherical dataset M through the dataset D;

[0064] Specifically, the generation process includes:

[0065] S11: The entire data set D is used as the initial sphere. In this embodiment, the data set D has 45 data points, including 18 red data points and 27 black data points. A point is randomly selected from the sphere as the center, and another heterogeneous point with the farthest distance is selected as another center.

[0066] S12: Determine whether the purity of the spheres meets the threshold value of 0.6, and continue to split the spheres that do not meet the purity. The classification rule is: calculate the distance between the remaining data points and the two center points, and divide the data points into the spheres corresponding to the center points closest to them;

[0067] S13: Take the original center of the newly generated sphere as the center, and select another outlier point with the farthest distance as another center. On this basis, continue to perform step S12 until the purity of all spheres meets the threshold value of 0.6, and obtain the sphere data set M. The amount of data in the sphere data set is recorded as n. In this implementation example, the amount of data n in the sphere data set M is 12, including 4 red balls and 8 black balls. The original data set is simplified by the spheres as follows Figure 2 shown.

[0068] S2: Calculate the similarity between the inserted data point and the one-hop data point of the neighboring node in the current layer graph and find the minimum value;

[0069] Specifically, the calculation process includes:

[0070] S21: First, determine the total number of layers of the multi-layer granular-sphere map and the number of layers to be inserted at each insertion point, and define the relationship between the total number of layers and the granular-sphere data set n as follows: In this example, n is 12, so the specific number of layers is 4. The number of layers inserted at each point is generated by a random function to generate the maximum value l max , the random function is where r∈(0,1) is a random number generated from a uniform distribution, and finally l max =min(L,4), which means the insertion point will be from l max Build graph connections layer by layer down to the bottom layer;

[0071] S22: Encode the particle ball data set into a quantum state using the QRAM algorithm and angle encoding. In this embodiment, the particle ball data set M is 12 labeled data, the dimension of the data set is 2, the value range of the data set is [0,15], one type of label is red, and the other type of label is black:

[0072]

[0073] Design the address bit, add register group 1 to store the address of the data set, the specific number of bits is 4, different dimensions share the address bit, according to the data dimension 2, add register group 2 to store the QRAM encoded data bits, for the particle ball data set M, each data preparation, according to the value range of each dimension to determine the QRAM data bus required quantum bits is 4 bits, so the QRAM quantum circuit used in this example is as follows Figure 3 As shown in the figure, the address register |add1add0> has passed through the H gate, and |m3m2m1m0> stores 4 values ​​respectively. Then, a new register group 3 is added to store the angle coding data. The angle coding is used to map the data on the data bus to the angle on the Bloch sphere, as shown in the figure. Figure 4 As shown in the figure, the specific steps of angle encoding are: use a quantum bit to store the angle, the data is stored in binary form on the data bus, the data bit is the control bit, and the value is taken from the high bit to the low bit of the data. x starts from 0 and increases by 1 in sequence. If the corresponding bit of the value is 1, the CRY gate is used to control the rotation. When one preparation is completed, the data bus is restored to |0> for the next preparation;

[0074] S23: Define the corresponding data point set S in each layer of the graph i (i∈[0,logn]) and the adjacency matrix J i (i∈[0,logn]), determine the point set S to be calculated based on the data point set and adjacency matrix of each layer combined with the neighbor nodes determined in the previous layer ci (i∈[0,logn]), use Swap-test to get the similarity between the insertion point and the neighboring nodes of this layer and their one-hop data points, such as Figure 5 As shown, first add a register |b>, then use the H gate on the register |b>, then use the register |b> as a control bit to perform a SWAP operation on the angle register, and finally use the H gate on the register |b> to save the similarity between the data and the cluster center in the register |b>;

[0075] S24: Use the iterative comparison quantum circuit to obtain the minimum value of the probability of measuring 1 in the obtained similarity. The specific quantum circuit is as follows Figure 6 As shown in the figure, it is defined that the neighbors of a point are less than or equal to m when constructing the graph, where |data_a0data_a1> and data_b0data_b1> are used as data qubits for comparison, and |h0h1> is used as the auxiliary bit required for comparison. ci The similarity calculated with the insertion point is compared pairwise to obtain the minimum value.

[0076] S3: According to the minimum value found in S2, a graph connection relationship between the insertion point and the minimum value point is established, and the minimum value point is used as the neighbor node of the lower layer to continue the insertion work of the next layer;

[0077] Specifically, the insertion process includes:

[0078] S31: determining the corresponding node to be connected to the insertion point at the layer according to the minimum similarity value obtained in S24, and setting the corresponding element in the adjacency matrix to 1 to represent the connection relationship between the two points;

[0079] S32: Use the nodes in the current layer that are connected to the insertion point as neighbor nodes when building a connection relationship in the next layer. Figure 7 As shown in the figure, the blue point is used as the new insertion point of this layer. The data point closest to it is determined by calculating the distance between the neighbor node and its one-hop node. The black line represents the original connection, while the yellow line represents the newly created connection of the insertion point in this layer. The newly created connection point will be used as the insertion point to insert the neighbor node of the next layer.

[0080] S4: Repeat steps S2 and S3 until the particle-sphere data set M is traversed and the construction of the multi-layer particle-sphere quantum HNSW graph is completed;

[0081] Specifically, the construction process includes:

[0082] S41: Insertion point from l max At the beginning, each layer downward executes steps S31 and S32 to build the graph connection relationship until the insertion point reaches the bottom layer, completing the insertion of the point.

[0083] S42: Let each point in the particle sphere data set M perform its own insertion work according to S41, and build a new graph connection relationship during the insertion process, that is, update the data point set S of each layer i (i∈[0,logn]) and the adjacency matrix J i (i∈[0,logn]), until all points in the spherical data set are inserted. The construction process of the multi-layer quantum HNSW graph in this implementation example is as follows: Figure 8 As shown;

[0084] S5: Quantum HNSW graph search work, input test data point J from the top layer, and calculate the minimum value of the distance between J and the one-hop data point of the neighbor node in the current layer;

[0085] Specifically, the single-layer search process includes:

[0086] S51: Use the same method as S22, S23 and S24 to encode the test data point J through QRAM and angle, calculate the similarity between the test data point and the neighboring node of the current layer and its one-hop node, and find the data point closest to the test data point J in this layer through iterative quantum comparison circuit;

[0087] S6: insert the minimum value obtained in this layer into the priority queue of size K, and let the nearest node be the neighbor node of the next layer to continue the search work of the next layer;

[0088] Specifically, the iterative search process includes:

[0089] S61: Get the data point closest to the test data point in the current layer obtained in S51, and insert the point into a priority queue Q of size K, where the value with the largest distance is given high priority, that is, when popping out elements from the queue, the value with the largest distance will be popped out first. In this implementation example, the structure of the priority queue is as follows: Fig. 9 As shown;

[0090] S62: taking the data point closest to the test data point in the current layer determined in S51 as a neighbor node of the test data point in the next layer, and allowing the test data point to enter the next layer to continue searching;

[0091] S7: Repeat steps S5 and S6 until the multi-layer graph structure is traversed;

[0092] Specifically, the traversal process includes:

[0093] S71: Let the inserted data point start from the highest layer and search downward layer by layer, by repeating steps S51, S61 and S62, and insert the similarity of each layer into the priority queue (the same point can be inserted repeatedly but the priority queue does not store repeated values). In this implementation example, the search process is also as follows Figure 8 As shown, it is hereby explained that in the construction process, the blue points are the construction points of the inserted graph structure, and in the search process of this step, the blue points are the test points for testing the classification performance of the particle-sphere quantum HNSW graph structure;

[0094] S72: Determine whether the priority queue is full. If the priority queue is full before the search is completed, compare the newly inserted similarity with the maximum similarity of the priority queue. If the newly inserted similarity is large, the priority queue is not changed. Otherwise, the maximum similarity is popped out and a new similarity value is inserted. In this implementation example, the test point searches from the top to the bottom priority queue. Fig.10 As shown;

[0095] S8: Determine the major categories among the K neighbors of the inserted data point J according to the priority queue obtained in S7, and classify the data point J according to the major categories;

[0096] Specifically, the design process includes:

[0097] S81: The final priority queue in this implementation example is as follows Fig.10 As shown, when the K value is 4, the proportion of data types in the priority queue Q is calculated, and the main type in Q is red. Therefore, after searching the multi-layer particle-sphere quantum HNSW graph, the type of the test point J is set to red to complete the final classification.

[0098] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solution, which should be included in the scope of the claims of the present invention.

Claims

1. A quantum HNSW graph KNN method based on granular spheres, characterized by: The method comprises the following steps: S1: Generate a sphere dataset M through a point dataset D; S2: Quantum HNSW graph construction work, determine the insertion layer and neighbor nodes of the insertion point, calculate the similarity between the inserted data point and the neighbor nodes of the current layer of the graph and its one-hop data points, and find the minimum value; S3: According to the minimum value found in S2, a graph connection relationship between the insertion point and the minimum value point is established, and the minimum value point is used as the neighbor node of the lower layer to continue the insertion work of the next layer; S4: Repeat steps S2 and S3 until the particle-sphere data set M is traversed and the construction of the multi-layer quantum HNSW graph is completed; S5: Quantum HNSW graph search work, input test data point J from the top layer, and calculate the minimum distance between J and the neighboring nodes of the current layer and their one-hop data points; S6: insert the minimum value of this layer into a priority queue of size K, and let the nearest node be the neighbor node of the next layer, and continue the search work of the next layer; S7: Repeat steps S5 and S6 until the quantum HNSW graph structure is traversed and the search is completed; S8: Determine the major categories among the K neighbors of the inserted data point J according to the priority queue determined in S7, and classify the data point J according to the major categories.

2. The particle-sphere-based quantum HNSW graph KNN method according to claim 1, characterized in that: In S1, the particle-sphere dataset M is generated by the point dataset D using classical calculation, which specifically includes the following steps: S11: Take the entire data set D as the initial sphere, randomly select a point in the sphere as the center, and select another heterogeneous point with the farthest distance as the other center; S12: Determine whether the purity of each ball meets the threshold T, and continue to split the balls that do not meet the purity. The classification rule is: calculate the distance between the remaining data points and the two center points, and divide the data points into the balls corresponding to the center points with the closest distance; S13: In the newly generated sphere, the original center is taken as the center, and another heterogeneous point with the farthest distance is selected as another center. On this basis, step S12 is repeated until the purity of all spheres meets the threshold T, and the sphere data set M is obtained. The amount of data in the sphere data set is recorded as n.

3. The particle-sphere-based quantum HNSW graph KNN method according to claim 2, characterized in that: In S2, the quantum HNSW graph is constructed to determine the number of layers and neighbor nodes of the insertion point, calculate the similarity between the inserted data point and the neighbor nodes of the current layer of the graph and its one-hop data points, and find the minimum value; This is done using quantum computing, which includes the following steps: S21: Determine the total number of layers of the multi-layer spherical quantum HNSW graph and the number of layers to be inserted at each insertion point. The total number of layers is related to the number n of spherical data sets M. The specific number of layers is logn layers. The number of layers inserted at each point is generated by a random function to generate the maximum value l max , the random function is where r∈(0,1) is a random number generated from a uniform distribution, and finally l max =min(L,logn), which means the insertion point will be from l max Build graph connections layer by layer down to the bottom layer; S22: Use the QRAM algorithm and angle encoding to encode the particle-sphere data set into a quantum state. For the particle-sphere data set M, its data set size is 2 k , the data dimension is a, and the data range of each dimension is in, According to the maximum value of each dimension of data, the address bit is designed, and a new register group 1 is added to store the address of the data set. The specific number of bits is k. Different dimensions share the address bit. According to the data dimension a, 2a QRAM and angle encoding are performed. A new register group 2 is added to store QRAM encoded data, and a new register group 3 is added to store angle encoded data. For the preparation of each data of the particle ball data set M, the quantum bit required for the QRAM data bus is set to t according to the numerical range of each dimension. a , use QRAM to store data on the data bus and control the data on the data bus in parallel with the address bit, and then map the data on the data bus to the angle on the Bloch sphere through angle encoding. The specific steps of angle encoding are: use a quantum bit to store the angle, the data is stored in binary form on the data bus, the data bit is the control bit, and the value is taken from the high bit to the low bit of the data. x starts from 0 and increases by 1 in sequence. If the corresponding bit of the value is 1, use the CRY gate to control the rotation When one preparation is completed, the data bus is restored to |0> for the next preparation; S23: Define the corresponding data point set S in each layer of the graph i , i∈[0,logn] and the adjacency matrix J i , i∈[0,logn], according to the data point set and adjacency matrix of each layer combined with the neighbor nodes determined in the previous layer, the point set S to be involved in the calculation is determined ci (i∈[0,logn]), inserting points and point set S through address bit index in QRAM ci The data bits of S22 are encoded with the angle in S22, and the angle data is stored in the corresponding angle bit in register group 3. Register group 4 is added as the control bit to insert the point and point set S ci The angle qubits corresponding to all points in register group 3 act on the Swap-test quantum circuit respectively, and the similarity results are stored in the corresponding qubits in register group 4; S24: Use the iterative comparison quantum circuit to obtain the minimum value of the probability of measuring 1 in the obtained similarity, which represents the two closest quantum states. Add register group 5 as the data quantum bit involved in the comparison, and add register group 6 as the auxiliary bit required for the comparison. The similarity calculated in S23 is minimized through the comparison circuit.

4. The particle-sphere-based quantum HNSW graph KNN method according to claim 3, characterized in that: In S3, according to the minimum value found in S2, a graph connection relationship between the insertion point and the minimum value point is established, and the minimum value point is used as a neighbor node of the lower layer to continue the insertion work of the next layer, which is completed using quantum computing, and specifically includes the following steps: S31: It is stipulated that when constructing a graph, the number of neighbors of a point is less than or equal to m. The node to be connected with the insertion point in this layer is determined according to the minimum similarity value obtained in S24, and the corresponding element in the adjacency matrix is ​​set to 1 to represent the connection relationship between the two points. The number of graph connection relationships established between each data point and the outside world shall not exceed m. S32: Use the nodes in the current layer that are connected to the insertion point as neighbor nodes when building a connection relationship in the next layer.

5. The particle-sphere-based quantum HNSW graph KNN method according to claim 4, characterized in that: In S4, steps S2 and S3 are repeated until the particle-sphere data set M is traversed, and the construction of the multi-layer particle-sphere quantum HNSW graph is completed using quantum computing, which specifically includes the following steps: S41: Insertion point from l max At the beginning, each layer downward executes steps S31 and S32 to build the graph connection relationship until the insertion point reaches the bottom layer, and the insertion of the point is completed; S42: Let each point in the particle sphere data set M perform the insertion work according to S41, and build a new graph connection relationship during the insertion process, that is, update the data point set S of each layer. i , i∈[0,logn] and the adjacency matrix J i ,i∈[0,logn], until all points in the sphere data set M are inserted.

6. The particle-sphere-based quantum HNSW graph KNN method according to claim 5, characterized in that: In S5, the quantum HNSW graph search work inputs the test data point J from the top layer and calculates the minimum value of the distance between J and the one-hop data point of the neighbor node of the current layer, which is completed using quantum computing, and specifically includes the following steps: S51: Starting from the top layer of the quantum HNSW graph, the test data point J is encoded through QRAM and angle using the same method as S22, S23, and S24, and the similarity between the test data point and the neighboring nodes of the current layer and its one-hop nodes is calculated. The data point closest to the test data point J in this layer is obtained through iterative quantum comparison circuits.

7. The particle-sphere-based quantum HNSW graph KNN method according to claim 6, characterized in that: In S6, the minimum value obtained in the current layer is inserted into a priority queue of size K, and the nearest node of the current layer is used as the neighbor node of the next layer to continue the search work of the next layer, which specifically includes the following steps: S61: Get the data point closest to the test data point in the current layer in S51, and insert the point into a priority queue Q of size K. The priority queue takes the value with the largest distance as the high priority, that is, when popping out an element from the queue, the value with the largest distance will be popped out first; S62: The data point in the current layer closest to the test data point in S51 is used as the neighbor node of the test data point in the next layer, so that the test data point enters the next layer to continue the search.

8. The particle-sphere-based quantum HNSW graph KNN method according to claim 7, characterized in that: In S7, steps S5 and S6 are repeated until the multi-layer graph structure is traversed and the search is completed, which specifically includes the following steps: S71: Let the inserted data point start from the highest layer and search downward layer by layer, repeating steps S51, S61 and S62, inserting the minimum similarity value of each layer into the priority queue, wherein the same point can be inserted repeatedly but the priority queue does not store repeated values; S72: Determine whether the priority queue is full. If the priority queue is full before the search is completed, compare the newly inserted similarity with the maximum similarity of the priority queue. If the newly inserted similarity is large, the priority queue is not changed. Otherwise, the maximum similarity is popped out and a new similarity value is inserted.

9. The particle-sphere-based quantum HNSW graph KNN method according to claim 8, characterized in that: In S8, the major categories of the K neighbors of the inserted data point J are determined according to the priority queue obtained in S7, and the data point J is classified according to the major categories, which specifically includes the following steps: S81: Calculate the proportion of data types in the priority queue Q, obtain the types in Q, and classify the test data point J into the types in Q.

Citation Information

Patent Citations

  • CBIR method based on improved PQ algorithm

    CN111177435A

  • Quantum particle ball generation method

    CN116933881A

  • DBSCAN point cloud clustering method for multi-granularity neighbors based on granular balls

    CN118015318A

  • Approximate nearest neighbor search for single instruction, multiple thread (SIMT) or single instruction, multiple data (SIMD) type processors

    US20210157606A1

  • Methods and systems for dimensionality reduction

    WO2024097099A1