module Measurable::Minkowski
Public Instance Methods
minkowski(u, v) → Numeric
click to toggle source
Calculate the sum of the absolute value of the differences between each coordinate of u
and v
.
Arguments:
-
u
-> An array of Numeric objects. -
v
-> An array of Numeric objects.
Returns:
-
The
Minkowski
(or L1) distance betweenu
andv
.
Raises:
-
ArgumentError
-> The sizes ofu
andv
don't match.
# File lib/measurable/minkowski.rb, line 17 def minkowski(u, v) # TODO: Change this to a more specific, custom-made exception. raise ArgumentError if u.size != v.size u.zip(v).reduce(0) do |acc, elem| acc += (elem[0] - elem[1]).abs end end