We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2bca7e5 commit 891b752Copy full SHA for 891b752
1 file changed
Minkowski_distance/Lua/Yonaba/minkowski_distance.lua
@@ -0,0 +1,18 @@
1
+-- Minkowski Distance distance implementation
2
+-- See: http://en.wikipedia.org/wiki/Minkowski_distance
3
+
4
+-- Returns the Minkowski distance between two vectors
5
+-- p : a first vector
6
+-- q : a second vector
7
+-- n : the distance order
8
+-- returns : the distance between p and q
9
+local function minkowski_distance(p, q, n)
10
+ assert(#p == #q, 'vectors must have the same length')
11
+ local s = 0
12
+ for i in ipairs(p) do
13
+ s = s + math.abs(p[i] - q[i]) ^ n
14
+ end
15
+ return s ^ (1 / n)
16
+end
17
18
+return minkowski_distance
0 commit comments