module Measurable::Tanimoto

Public Instance Methods

tanimoto(u, v) → Float click to toggle source

Tanimoto distance is a coefficient explicitly chosen such as to allow for two dissimilar specimens to be similar to a third one. This breaks the triangle inequality, thus this isn't a metric.

More information and references on this are needed. It's left here mostly as a piece of curiosity.

See: # en.wikipedia.org/wiki/Jaccard_index#Tanimoto.27s_Definitions_of_Similarity_and_Distance

Arguments:

  • u -> An array of Numeric objects.

  • v -> An array of Numeric objects.

Returns:

  • A measure of the similarity between u and v.

Raises:

  • ArgumentError -> The sizes of u and v don't match.

# File lib/measurable/tanimoto.rb, line 25
def tanimoto(u, v)
  # TODO: Change this to a more specific, custom-made exception.
  raise ArgumentError if u.size != v.size

  -Math.log2(jaccard_index(u, v))
end