Skip to main content
Scientific Reports logoLink to Scientific Reports
. 2021 Jul 30;11:15559. doi: 10.1038/s41598-021-95156-7

Quantum algorithm for MMNG-based DBSCAN

Xuming Xie 1,#, Longzhen Duan 1,#, Taorong Qiu 1,✉, Junru Li 2
PMCID: PMC8324839  PMID: 34330983

Abstract

DBSCAN is a famous density-based clustering algorithm that can discover clusters with arbitrary shapes without the minimal requirements of domain knowledge to determine the input parameters. However, DBSCAN is not suitable for databases with different local-density clusters and is also a very time-consuming clustering algorithm. In this paper, we present a quantum mutual MinPts-nearest neighbor graph (MMNG)-based DBSCAN algorithm. The proposed algorithm performs better on databases with different local-density clusters. Furthermore, the proposed algorithm has a dramatic increase in speed compared to its classic counterpart.

Subject terms: Computer science, Information theory and computation

Introduction

Clustering, an important branch of unsupervised machine learning, is the process of partitioning a dataset into subsets of points called clusters, such that similar points are grouped in the same cluster and dissimilar points are put in different clusters. This procedure is widely used in many scientific fields, including bioinformatics1–4, image processing5–8, and social networks9,10.

DBSCAN11, a density-based clustering algorithm, is one of the most famous clustering algorithms. The distinguishing advantage of the DBSCAN algorithm is that it can be used to discover arbitrarily shaped clusters. Furthermore, it does not need the minimal requirements of domain knowledge to determine the input parameters, and can also exclude outliers from the clusters. However, DBSCAN has two dire drawbacks. First, DBSCAN has a low efficiency on databases with different local-density clusters; second, the algorithm is very time-consuming.

Quantum computing has attracted tremendous attention due to its parallel capability. In 1982, Feynman pointed out that quantum computers might achieve significant increase in speed over classical computers on certain specific problems12. Shor’s algorithm13 and Grover’s algorithm14 are two of the most popular quantum algorithms. Shor’s algorithm has an exponential increase in speed, and Grover’s algorithm has a quadratic increase in speed over their classical counterparts. With the rise of quantum computing, many researchers have also designed various quantum machine learning algorithms and quantum data mining algorithms, such as quantum linear regression15–17, quantum support vector machine18,19, quantum k-nearest neighbors classification20, quantum deep learning21, and quantum association rules mining22. Recently, tremendous advances have been made in constructing quantum computers. Krantz et al.23,24 introduced the central concepts and challenges of superconducting quantum circuits. Huang et al.25 provided experimental efforts toward large-scale superconducting quantum computers. Bruzewicz et al.26 concluded the basics of trapped-ion quantum computing and explored the outlook for trapped-ion quantum computing.

Inspired by quantum computing, we propose a quantum mutual MinPts-nearest neighbor graph (MMNG)-based DBSCAN algorithm. First, we design a quantum mutual MinPts-nearest neighbor graph algorithm that is devoted to dividing a database into subsets. After that, we quantize the original DBSCAN algorithm to cluster each subset.

Preliminaries

In this section, we provide the necessary background knowledge for this paper. First, we briefly introduce the basic definitions of the classical DBSCAN algorithm. Then, we review the fundamental concepts of Grover’s algorithm.

DBSCAN

The DBSCAN algorithm offers a new notion of “cluster” and “noise” in a database D of N points of some k-dimensional space S. The whole set of definitions is given as follows.

Definition 1

(Eps-neighborhood of a point) The Eps-neighborhood of a point p, denoted by NEps(p), is defined by NEps(p)={q∈D|Dist(p,q)≤Eps}.

The Eps-neighborhood, the fundamental definition of the algorithm, can be used to distinguish core points and noncore points. Eps is the distance threshold. Core points are the points inside of any cluster, and noncore points are the points on the border of any cluster or the points belonging to none of the clusters. Let p be a point in a database D, where |NEps(p)| denotes the number of points within the Eps-neighborhood of p. Let MinPts be the threshold of the number of points; if |NEps(p)|≥MinPts, then p is a core point; otherwise, p is a noncore point.

Definition 2

(directly density-reachable) A point p is directly density-reachable from a point q if

  1. p∈NEps(q) and

  2. |NEps(p)|≥MinPts

Directly density-reachable is not always symmetric. When p and q are both core points, the direct density reachability is symmetric; when one is a core point and the other is a border point, the direct density reachability is asymmetric.

Definition 3

(density-reachable) A point p is density-reachable from a point q if there is a chain of points p1,p2,…,pN∈D, p1=q, pN=p such that pi+1 is directly density-reachable from pi.

Definition 4

(density-connected) A point p is density-connected to a point q if there is a point o such that p and q are density-reachable from o.

Definition 5

(cluster) Let D be a database of points. A cluster C is a nonempty subset of D satisfying the following conditions:

  1. ∀p,q: if p∈C and q is density-reachable from p then q∈C.

  2. ∀p,q∈C: p is density-connected to q.

In the database D, not all the points belong to clusters. The points that do not belong to any cluster are defined as “noise” in the DBSCAN algorithm.

Definition 6

(noise) Let C1,…,Ck be the clusters of the database D, i=1,…,k. Then, we define the noise as the set of points in the database D not belonging to any cluster Ci, i.e., noise = {p∈D|∀i:p∉Ci}.

Grover’s algorithm

Let us assume that we wish to search M(1≤M≤N) solutions from an unstructured search space of N elements. Rather than examining N elements one by one, Grover’s algorithm checks the elements in parallel by assigning indexes to all of the elements and storing the indexes in a quantum register. With a series of unitary operations augmenting the success probability gradually, Grover’s algorithm can obtain the indexes of the target elements with a high probability.

The proposed algorithm

In this section, we design a quantum mutual MinPts-nearest neighbor graph algorithm and a quantum DBSCAN algorithm and present a quantum MMNG-based DBSCAN algorithm.

Quantum MMNG algorithm

Let D be a database, p and q be some objects in D, and MinPts be a positive integer. The relative concept will be introduced as follow.

Definition 7

(Mutual MinPts-nearest neighbor (MMN)): If p is in the MinPts-nearest neighborhood of q and q is in the MinPts-nearest neighborhood of p, then we call p a mutual MinPts-nearest neighbor of q; similarly, q is a mutual MinPts-nearest neighbor of p.

Definition 8

(Mutual MinPts-nearest neighbor graph (MMNG)): The mutual MinPts-nearest neighbor graph can be constructed by connecting each point to its mutual MinPts-nearest neighbors.

Note that MMNG is an algorithm with high complexity. To speed up the MMNG, we intend to quantize the MMNG algorithm. Dürr et al.27 developed a quant_find_smallest_values algorithm for finding the c closest neighbors of a point with high probability within Ocn time. Based on the quant_find_smallest_values, we propose a quantized MMNG algorithm, as shown in algorithm 1.graphic file with name 41598_2021_95156_Figa_HTML.jpg

In this paper, algorithm 1 is used to obtain the subsets of database D. After obtaining the subsets, we apply the quantum DBSCAN algorithm on each subset to obtain the eventual clusters and the noise set.

Quantum DBSCAN algorithm

We consider a database DN={p1,…,pN}, which is composed of n points, and each point pi has k attributes. For each point pi in DN={p1,…,pN}, it is necessary to calculate Dist(pi,pj) n-1 times to determine the Eps-neighborhood of pi. Determining the Eps-neighborhood is fairly time-consuming. To solve this problem, we intend to screen the points in the Eps-neighborhood of pi with quantum search.

In our model, a quantum distance black box is proposed. The proposed black box can accept two types of inputs, as illustrated in Fig. 1. i is a one-state input and the index of point pi; j is a superposition of inputs and includes the indexes of all the points. Evidently, this is feasible because one q-bit can be a pure state or a superposition of states. Furthermore, one query to this black box means asking for distances between the point pi and all the points pj s (when i=j, Dist(pi,pj)=0). After obtaining the distances, the black box compares them with the Eps distance. Then, a selection function f(i,j) assigns a value of 1 when Dist(pi,pj) is smaller than or equal to the Eps distance and a value of 0 otherwise. The selection function is shown in Eq. (1).

f(i,j)=0,ifDist(pi,pj)>Eps1,ifDist(pi,pj)≤Eps 1

Figure 1.

Figure 1

The oracle to compute the distance between pi and all the possible pjs. r is an ancillary register.

Meanwhile, a flipping operation is carried out in the black box. As depicted in Eq. (2), if f(i,j)=1, the ancillary register r is flipped; if f(i,j)=0, the ancillary register |r⟩ remained unaltered. The symbol ⊕ denotes module 2, also known as an exclusive-or.

ijr→ijr⊕f(i,j) 2

Based on the aforementioned black box, we designed algorithm 2 (quant_find_Eps-neighborhood as described below) as a subroutine of the quantum-based DBSCAN algorithm. Given a specific point pi, algorithm 2 is able to fix its Eps-neighborhood.graphic file with name 41598_2021_95156_Figb_HTML.jpg

Once the Eps-neighborhoods are fixable quantum-mechanically, core points and noncore points become discernable according to the basic notions of the classic DBSCAN. If a point is a noncore point, we keep looking for a core point because there is no need to create a new cluster for a noncore point; however, if a point is a core point, we set up a new cluster and expand it. With the expanding methodology offered in the original DBSCAN algorithm, the quantum-based DBSCAN algorithm quant_DBSCAN(DN, Eps, MinPts) is presented hereafter, as shown in algorithm 3.graphic file with name 41598_2021_95156_Figc_HTML.jpg

Quantum algorithm for MMNG-based DBSCAN

The proposed algorithm divides the database into subsets first and then applies the quantum DBSCAN algorithm to each subset. Note that different subsets have a different Eps in our algorithm. For a specific subset, we select the average MinPts distance as the Eps of the subset.graphic file with name 41598_2021_95156_Figd_HTML.jpg

The algorithm analysis

In this section, we briefly analyze the complexity of our algorithm first and then present the success probability of our algorithm.

The complexity

Dürr et al.27 proved that the complexity of quant_find_smallest_values is Ocn. It is easy to see that the complexity of algorithm 1 is O(NMinPts∗n).

For algorithm 2, there are |NEps(p)|+1 targets for each point. According to the original version of Grover’s algorithm, algorithm 2 needs to interrogate the oracle approximately N|NEps(p)|+1 times. It can easily be perceived that the smaller |NEps(p)| is, the more queries are needed. In the worst case scenario, when |NEps(p)|=0, the queries of the oracle are approximately N times. In other words, the complexity of algorithm 2 is O(N).

For algorithm 3, we need to calculate the Eps-neighborhood of every point. This means that algorithm 3 needs to call algorithm 2 N times. Thus, we can ensure that the complexity of algorithm 3 is smaller than O(NN), even though the |NEps(p)|s are different for different points.

In other words, the complexity of our proposed algorithm is approximately O(NMinPts∗n).

The success probability

Dürr et al.27 proved that quant_find_smallest_values is able to obtain c nearest neighbors with a high probability. It is easy to infer that algorithm 1 can obtain subsets with a high probability.

It is noteworthy that |NEps(p)| s are different from point to point, which means that there are different numbers of targets when algorithm 2 is dealing with different points. As a result, the success probabilities are different when calculating different Eps-neighborhoods. By referencing the former work, the success probability of algorithm 2 can be calculated via Eq. (3) after T iterations.

P=sin2((2T+1)arcsin|NEps(p)|+1N) 3

We already know that T≈N|NEps(p)|+1. Usually, MinPts is far less than N, and |NEps(p)| are numbers close to MinPts. As a result, it can be inferred that the success probability of algorithm 3 is high.

Our proposed method is a combination of algorithm 1 and algorithm 3, thus success probability of the proposed method is high.

Performance evaluation

To show the effectiveness of the proposed algorithm, performance evaluation based on two databases is conducted. To compare our algorithm with the classic DBSCAN method and the NaNG method, we use the two synthetic sample databases depicted in Fig. 2.

Figure 2.

Figure 2

Sample databases.

The experimental results on database 1 are shown in Fig. 3. A total of 399 objects are included in database 1. In the figure, the black squares represent the points that are detected as outliers. The experimental result of DBSCAN on database 1 is undesirable, and the accuracy is approximately 74.6%. The experimental result of NaNG is better than that of DBSCAN, with an accuracy of 90.73%. Our proposed method has the best performance on database 1, with an accuracy of approximately 95.74%.

Figure 3.

Figure 3

Clustering results of database 1.

The experimental results on database 2 are shown in Fig. 4. As shown in Fig. 4a, database 2 includes 320 objects and 8 clusters. As shown in Fig. 4b, the result of DBSCAN is tolerable with an accuracy of 92.5%. From the result shown in Fig. 4c, we can see that NaNG mistakenly combines two clusters into one. The accuracy of NaNG is 87.5%. As shown in Fig. 4d, the performance of the proposed method is the same as DBSCAN with an accuracy of 92.5%.

Figure 4.

Figure 4

Clustering results of database 2.

Conclusion

Inspired by the mutual neighbor method and quantum computing, in this work, we present a quantum MMNG-based DBSCAN. Compared to the original DBSCAN, the proposed method performs better on databases with different local-density clusters. Furthermore, the proposed method is dramatically faster than its classical counterpart.

Author contributions

X.X. and L.D. wrote the main manuscript text. T.Q. and J.L. analysed the performance of the algorithm. All authors reviewed the manuscript.

Funding

Funding was provided by National Natural Science Foundation of China(62066027).

Competing interests

The authors declare no competing interests.

Footnotes

Publisher's note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

These authors contributed equally: Xuming Xie and Longzhen Duan.

References

  • 1.Li W, Godzik A. Cd-hit: A fast program for clustering and comparing large sets of protein or nucleotide sequences. Bioinformatics. 2006;22:1658–1659. doi: 10.1093/bioinformatics/btl158. [DOI] [PubMed] [Google Scholar]
  • 2.King AD, Przlj N, Jurisica I. Protein complex prediction via cost-based clustering. Bioinformatics. 2004;20:3013–3020. doi: 10.1093/bioinformatics/bth351. [DOI] [PubMed] [Google Scholar]
  • 3.Huang D, Sherman BT, Lempicki RA. Systematic and integrative analysis of large gene lists using david bioinformatics resources. Nat. Protoc. 2009;4:44–57. doi: 10.1038/nprot.2008.211. [DOI] [PubMed] [Google Scholar]
  • 4.Rossant C, Kadir SN, Goodman DFM. Spike sorting for large, dense electrode arrays. Nat. Neurosci. 2016;19:634–641. doi: 10.1038/nn.4268. [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 5.Moosmann F, Nowak E, Jurie F. Randomized clustering forests for image classification. IEEE Trans. Pattern Anal. Mach. Intell. 2008;30:1632–1646. doi: 10.1109/TPAMI.2007.70822. [DOI] [PubMed] [Google Scholar]
  • 6.Ducournau A, Bretto A, Rital S, Laget B, et al. A reductive approach to hypergraph clustering: An application to image segmentation. Pattern Recognit. 2012;45:2788–2803. doi: 10.1016/j.patcog.2012.01.005. [DOI] [Google Scholar]
  • 7.Chaira T. A novel intuitionistic fuzzy c means clustering algorithm and its application to medical images. Appl. Soft Comput. 2011;11:1711–1717. doi: 10.1016/j.asoc.2010.05.005. [DOI] [Google Scholar]
  • 8.Zheng M, Bu J, Chen C, et al. Graph regularized sparse coding for image representation. IEEE Trans. Image Process. 2011;20:1327–1336. doi: 10.1109/TIP.2010.2090535. [DOI] [PubMed] [Google Scholar]
  • 9.Chakrabarti S. Data mining for hypertext: A tutorial survey. ACM SIGKDD Explor. Newsl. 2000;1:1–11. doi: 10.1145/846183.846187. [DOI] [Google Scholar]
  • 10.Chang M, Chen L, Hung L, et al. Exact algorithms for problems related to the densest k-set problem. Inf. Process. Lett. 2014;114:510–513. doi: 10.1016/j.ipl.2014.04.009. [DOI] [Google Scholar]
  • 11.Martin, E., Hans-Peter, K., Jorg, S., et al. A density-based algorithm for discovering clusters in large spatial databases with noise. In Proceedings of the 2nd International Conference on Knowledge Discovering in Databases and Data Mining, 122–128 (1996).
  • 12.Feynman RP. Simulating physics with computers. Int. J. Theor. Phys. 1982;21:467–488. doi: 10.1007/BF02650179. [DOI] [Google Scholar]
  • 13.Shor PW. Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM J. Comput. 1997;26:1484–1509. doi: 10.1137/S0097539795293172. [DOI] [Google Scholar]
  • 14.Grover, L. K. A fast quantum mechanical algorithm for database search. In Proceedings of the 28th Annual ACM Symposium on the Theory of Computing, 212–219 (1996).
  • 15.Wiebe N, Braun D, Lloyd S. Quantum algorithm for data fitting. Phys. Rev. Lett. 2012;109:050505. doi: 10.1103/PhysRevLett.109.050505. [DOI] [PubMed] [Google Scholar]
  • 16.Schuld M, Sinayskiy I, Petruccione F. Prediction by linear regression on a quantum computer. Phys. Rev. A. 2016;94:022342. doi: 10.1103/PhysRevA.94.022342. [DOI] [Google Scholar]
  • 17.Wang G. Quantum algorithm for linear regression. Phys. Rev. A. 2017;96:012335. doi: 10.1103/PhysRevA.96.012335. [DOI] [Google Scholar]
  • 18.Rebentrost P, Mohseni M, Lloyd S. Quantum support vector machine for big data classification. Phys. Rev. Lett. 2014;113:130503. doi: 10.1103/PhysRevLett.113.130503. [DOI] [PubMed] [Google Scholar]
  • 19.Li Z, Liu X, Xu N. Experimental realization of a quantum support vector machine. Phys. Rev. Lett. 2015;114:140504. doi: 10.1103/PhysRevLett.114.140504. [DOI] [PubMed] [Google Scholar]
  • 20.Ruan Y, Xue X, Liu H, Tan J, Li X. Quantum algorithm for k-nearest neighbors classification based on the metric of hamming distance. Int. J. Theor. Phys. 2017;56:3496–3507. doi: 10.1007/s10773-017-3514-4. [DOI] [Google Scholar]
  • 21.Cheng S, Chen J, Wang L. Quantum entanglement: from quantum states of matter to deep learning. Physics. 2017;46:416–423. [Google Scholar]
  • 22.Yu CH, Gao F, Wang QL, Wen QY. Quantum algorithm for association rules mining. Phys. Rev. A. 2016;94:042311. doi: 10.1103/PhysRevA.94.042311. [DOI] [Google Scholar]
  • 23.Krantz P, Kjaergaard M, Yan F, et al. A quantum engineer’s guide to superconducting qubits. Appl. Phys. Rev. 2019;6:021318. doi: 10.1063/1.5089550. [DOI] [Google Scholar]
  • 24.Kjaergaard M, Schwartz ME, Braumuller J, et al. Superconducting qubits: current state of play. Annu. Rev. Condens. Matter Phys. 2019;11:369–395. doi: 10.1146/annurev-conmatphys-031119-050605. [DOI] [Google Scholar]
  • 25.Huang HL, et al. Superconducting quantum computing: a review. Sci. China Inf. Sci. 2020;63:1–32. [Google Scholar]
  • 26.Bruzewicz CD, Chiaverini J, McConnell R, et al. Trapped-ion quantum computing: Progress and challenges. Appl. Phys. Rev. 2019;6:021314. doi: 10.1063/1.5088164. [DOI] [Google Scholar]
  • 27.Dürr, C., Heiligman, M., Høyer, P., & Mhalla, M. Quantum query complexity of some graph problems. In Proceedings of the 31st International Conference on Automata, Languages and Programming, 481–493 (2004)

Articles from Scientific Reports are provided here courtesy of Nature Publishing Group

RESOURCES