Sha256: ef748314768145525b80f121fd91359497a9e01a7c7d717b59cbb5c45f7fcbce
Contents?: true
Size: 735 Bytes
Versions: 17
Compression:
Stored size: 735 Bytes
Contents
module DbClustering module DistanceMetrics class AverageDifference include Math def initialize(min_dimensions: 1) @min_dimensions = min_dimensions end def distance(vector1, vector2) vector1_array = vector1.array_for_comparison(vector2) vector2_array = vector2.array_for_comparison(vector1) if vector1_array.count != vector2_array.count raise "Vectors with different sizes cannot be compared" end if vector1_array.count < @min_dimensions return Float::INFINITY end sum = vector1_array.map.with_index{ |x, i| (x - vector2_array[i]).abs }.reduce(&:+) sum / vector1_array.count.to_f end end end end
Version data entries
17 entries across 17 versions & 1 rubygems