With the Euclidean distance we measure the distance between two vector points. The Euclidean distance between of (6,4,3) and (9,2,1) will be \(d=\sqrt{(6-9)^2+(4-2)^2+(3-1)^2}=\sqrt{17}=4.123\). Often in cryptography and machine learning, we represent these as polynomial values. For example, we might have three data sets of \(A=[5,4,1,11,10]\), \(B=[3,3,2,10,8]\) and \(C=[5,6,1,12,9]\), and then can compute the Euclidean distance between them using polynomial operations:
Euclidean DistanceTheoryWith the Euclidean distance we measure the distance between two vector points. The Euclidean distance between of (6,4,3) and (9,2,1) will be \(d=\sqrt{(6-9)^2+(4-2)^2+(3-1)^2}=\sqrt{17}=4.123\). Often in cryptography and machine learning, we represent these as polynomial values. For example, we might have three data sets of \(A=[5,4,1,11,10]\), \(B=[3,3,2,10,8]\) and \(C=[5,6,1,12,9]\), and then can compute the Euclidean distance between them using polynomial operations. These can then be represented as polynomial values of: \(a=5x^4+4x^3+x^2+11x+10\) \(b=3x^4+3x^3+2x^2+10x+8\) \(c=5x^4+6x^3+x^2+12x+9\) In Python we can use Numpy to convert these: A=[5,4,1,11,10] B=[3,3,2,10,8] C=[5,6,1,12,9] a=np.poly1d(A) b=np.poly1d(B) c=np.poly1d(C) and then to compute the Euclidean distance with: distab = np.linalg.norm(a - b) distac = np.linalg.norm(a - c) distbc = np.linalg.norm(b - c) CodingHere is an outline of the code: import numpy as np import sys A=[5,4,1,11,10] B=[3,3,2,10,8] C=[5,6,1,12,9] if (len(sys.argv)>1): A=eval("["+sys.argv[1]+"]") if (len(sys.argv)>2): B=eval("["+sys.argv[2]+"]") if (len(sys.argv)>3): C=eval("["+sys.argv[3]+"]") a=np.poly1d(A) b=np.poly1d(B) c=np.poly1d(C) print ("A:\n",np.poly1d(a)) print ("B:\n",np.poly1d(b)) print ("C:\n",np.poly1d(c)) distab = np.linalg.norm(a - b) distac = np.linalg.norm(a - c) distbc = np.linalg.norm(b - c) print(f"Euclidean distance (a-b): {distab}") print(f"Euclidean distance (a-c): {distac}") print(f"Euclidean distance (a-c): {distbc}") A sample run is: A: 4 3 2 5 x + 4 x + 1 x + 11 x + 10 B: 4 3 2 3 x + 3 x + 2 x + 10 x + 8 C: 4 3 2 5 x + 6 x + 1 x + 12 x + 9 Euclidean distance (a-b): 3.3166247903554 Euclidean distance (a-c): 2.449489742783178 Euclidean distance (a-c): 4.358898943540674 We can check the distance from A to B, with: \(d=\sqrt{(5-3)^2 + (4-3)^2 + (1-2)^2 + (11-10)^2+(10-8)^2} = \sqrt{11} = 3.3166247903554\) Coding |