Module: Measurable::Maxmin
- Included in:
- Measurable
- Defined in:
- lib/measurable/maxmin.rb
Instance Method Summary collapse
-
#maxmin(u, v) ⇒ Object
call-seq: maxmin(u, v) -> Float.
Instance Method Details
#maxmin(u, v) ⇒ Object
call-seq:
maxmin(u, v) -> Float
The “Max-min distance” is used to measure similarity between two vectors.
When used in k-means clustering, this similarity measure can give better results in some datasets, as pointed out in the paper “K-means clustering using Max-min distance measure” — Visalakshi, N. K.; Suguna, J.
See: ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=05156398
-
Arguments :
-
u
-> An array of Numeric objects. -
v
-> An array of Numeric objects.
-
-
Returns :
-
Similarity between
u
andv
.
-
-
Raises :
-
ArgumentError
-> The sizes ofu
andv
don’t match.
-
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/measurable/maxmin.rb', line 23 def maxmin(u, v) # TODO: Change this to a more specific, custom-made exception. raise ArgumentError if u.size != v.size sum_min, sum_max = u.zip(v).reduce([0.0, 0.0]) do |acc, attributes| acc[0] += attributes.min acc[1] += attributes.max acc end sum_min / sum_max end |