Internal:QDist

From crtc.cs.odu.edu
Jump to navigation Jump to search

Quantum Euclidean Distance (QDist)

Code

The code can be cloned from the following repo:

wahab.hpc.odu.edu:/RC/group/RC_NIKOS/CodeRepository/quantum.git

It is found in the common directory of the repo.

Introduction

This page focuses on the application of concurrent distance calculations for two main applications via the employment of a universal quantum computer:

  1. Edge weight generation
  2. Similarity metric evaluation

Edge Weights

The first step in creating a graph G(E,V) is initializing the nodes N and edges V. If the graph is weighted, then part of the graph initialization is assigning weights to each edge e ∈ E. One of the most well-known examples of this need is in the Traveling Salesman Problem (TSP) [1]. In addition to any problem that addresses the concept of a network described by a graph G(E,V), it can also be practically applied to any application of mapping software. This is of direct benefit to companies seeking to maximize efficiency in logistics by effectively solving the shortest path problem [2]. If the nodes represent features which can be represented in Euclidean space, the Euclidean distance E(a, b) is an intuitive metric which can be used to determine the cost of traveling between points a and b:

E(a, b) = √((a - b) • (a - b))

Similarity Metrics

Many unsupervised machine learning problems, such as k-means [3] or DBSCAN [4], require the evaluation of how similar two samples to each other. One method of representing this quantitatively is cosine similarity, which uses the dot product to produce a value proportional to the cosine of the angle θ between the two samples, if their feature values are represented as vectors:

a • b = ||a|| ||b|| cos(θ)

However, this may not suitable for the intention of some problems. Two vectors of varying magnitudes, but the same unit vector representation, will produce the same angle when compared to another vector. Consider the following example:

v1 = [1 2]

v2 = [2 1]

v3 = [20 10]

(v1 • v2) / ||v1|| ||v2|| = 0.80

(v1 • v3) / ||v1|| ||v3|| = 0.80

This may be efficient for some applications, but a more precise definition of "closeness" might be desired in others. In this case, the Euclidean distance is more aptly suited, as defined in the previous section.

Quantum Limitations

Universal Quantum Computers (UQCs) are, unsurprisingly, constrained by the laws of quantum mechanics and their operations on quantum states. Quantum states are only implicitly capable of representing the dot product between states. As such, without further manipulation, only the metric of cosine similarity is attainable [6] - not Euclidean distance. Even after manipulation by quantum gates, the Euclidean distance between two vectors can only be accurately computed using UQCs [7] if the two vectors a and b being compared have the same norm. This can be seen using the same three vectors from the previous section.

v1 = [1 2]

v2 = [2 1]

v3 = [20 10]

v1' = v1 / ||v1|| = [0.447 0.894]

v2' = v2 / ||v2|| = [0.894 0.447]

v3' = v3 / ||v3|| = [0.894 0.447]

E(v1', v2') = 0.632

E(v1', v3') = 0.632

To retrieve the value of E(v1, v2):

E(v1, v2) = ||v1|| * E(v1', v2') = ||v2|| * E(v1', v2') = 1.414

Attempting the same rescaling to obtain E(v1, v3) is not possible:

||v1|| * E(v1', v3') = 1.414

||v2|| * E(v1', v3') = 14.142

E(v1', v3') = 20.616

Thus, in a graphical sense, only points which exist on the same n-sphere may be compared directly using a quantum computer. In general, datasets do not exist under these specific conditions, and common preprocessing of datasets does not result in these conditions either.

Purpose

The report provides further discussion on similarity metrics computing using UQCs [6,7] and then provides complete algorithms for the calculation of Euclidean distance, with and without same-normed vectors. The code for generating the necessary circuits is also provided, along with examples using publicly available datasets.

Methods

Same-normed Vectors

Given two sets of real-valued vectors V1 = {v11, ... , v1m} and V2 = {v21, ... , v2n}, vij ∈ ℜp, it is desired to find every distance E(v1j, v2k). A quantum circuit φ0 with 4 quantum registers is initialized such that:

φ1 = |0>1|0>2|0>3|0>4


A series of Hadamard gates is then applied to registers 1, 2, and 4:

Using an appropriate controlled-amplitude encoding circuit, the state φ3 is created:

Finally, applying a Hadamard gate to the first register results in φ4:

Applying a projection of |1><1| onto the first register and taking the inner product results in the squared Euclidean distance of the normalized vectors E(v1j', v2k')2. To convert to the actual squared Euclidean distance E(v1j, v2k)2, use the norm ζ of all the vectors:

E(v1j, v2k)2 = ζ2 * E(v1j', v2k')2

Vectors with Different Norms

As described in the introduction, there is no way to reconcile the distance between vectors with different norms. However, if it is desired to evaluate the distance of all vectors in two sets simultaneously, as in the previous section, the vectors must be manipulated to create same-normed vectors. This is possible by artificially increasing the dimensionality of the vector space to a size 2q > p, in which q is the number of qubits and p is the actual dimension of the vector space. By choosing a norm ζ as the largest norm of any of the vectors in either set V1 and V2. Then, a new vector element d can be set in any of the artificial elements of the new vectors vjk' to create vectors with the new with the same norm ζ. This effectively projects these points to the surface of the 2q-sphere.

d = √(ζ2 - Σ(vjk))

Once this vector manipulation is complete, the same quantum circuit from the previous section can be used to find the squared difference between elements of all vectors. The actual elements of these differences can then be added together and multiplied by the squared norm, ζ2 to obtain the squared Euclidean distance E(v1j, v2k)2. The artificial elements of vjk' are discarded. The unfortunate consequence of the artificial elements is that no quantum inner circuit can be applied, since it is impossible to separate the index states, as the SWAP operation is applied to a qubit, not a state.

Datasets

Randomly Generated Spherical Coordinates

To test the application of the algorithm to points with the same norm, the first dataset to be used will be two randomly generated sets of points constrained to the surface of the same sphere.

Molecular Structures

The National Center for Biotechnology Information's (NCBI) Pubchem database will be used as a practical use case for this algorithm. One of the most important aspects of modeling molecules is knowing the forces between atoms. These forces are inherently inter-related with the steady-state distances between atoms within the molecule or other, bonded molecules. Thus, the quantum Euclidean distance process will be used to determine these inter-atomic distances.

The Pubchem database has a number of molecular structures available to download as three-dimensional coordinates. In this report, both Ibuprofen [8] and Aspirin [9] will be used.

Molecular model of ibuprofen [8]
Molecular model of aspirin [9]

Results

Conclusions

References

[1] Jünger, M., Reinelt, G., & Rinaldi, G. (1995). Chapter 4 The traveling salesman problem.

[2] Schrijver, A. (2012). On the History of the Shortest Path Problem.

[3] Yadav, J., & Sharma, M. (2013). A Review of K-mean Algorithm.

[4] Khan, K., Rehman, S.U., Aziz, K., Fong, S.J., Sarasvady, S., & Vishwa, A. (2014). DBSCAN: Past, present and future. The Fifth International Conference on the Applications of Digital Information and Web Technologies (ICADIWT 2014), 232-238.

[5] Gunawan, D., Sembiring, C., & Budiman, M.A. (2018). The Implementation of Cosine Similarity to Calculate Text Relevance between Two Documents. Journal of Physics: Conference Series, 978.

[6] Afham, Basheer, A., & Goyal, S.K. (2020). Quantum k-nearest neighbor machine learning algorithm. arXiv: Quantum Physics.

[7] Yu, K., Guo, G., Li, J., & Lin, S. (2020). Quantum Algorithms for Similarity Measurement Based on Euclidean Distance. International Journal of Theoretical Physics, 59, 3134 - 3144.

[8] National Center for Biotechnology Information (2023). PubChem Compound Summary for CID 2244, Aspirin. Retrieved November 9, 2023 from https://pubchem.ncbi.nlm.nih.gov/compound/Aspirin.

[9] National Center for Biotechnology Information (2023). PubChem Compound Summary for CID 3672, Ibuprofen. Retrieved November 9, 2023 from https://pubchem.ncbi.nlm.nih.gov/compound/Ibuprofen.