Module: Measurable::Tanimoto
- Included in:
- Measurable
- Defined in:
- lib/measurable/tanimoto.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
:nodoc:.
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#tanimoto(u, v) ⇒ Object
call-seq: tanimoto(u, v) -> Float.
Class Method Details
.extended(base) ⇒ Object
:nodoc:
33 34 35 36 37 38 39 40 |
# File 'lib/measurable/tanimoto.rb', line 33 def self.extended(base) # :nodoc: # Tanimoto similarity is the same as Jaccard similarity. base.instance_eval do extend Measurable::Jaccard alias :tanimoto_similarity :jaccard end super end |
.included(base) ⇒ Object
:nodoc:
42 43 44 45 46 47 48 |
# File 'lib/measurable/tanimoto.rb', line 42 def self.included(base) # :nodoc: base.class_eval do include Measurable::Jaccard alias :tanimoto_similarity :jaccard end super end |
Instance Method Details
#tanimoto(u, v) ⇒ Object
call-seq:
tanimoto(u, v) -> Float
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
andv
.
-
-
Raises :
-
ArgumentError
-> The sizes ofu
andv
don’t match.
-
26 27 28 29 30 31 |
# File 'lib/measurable/tanimoto.rb', line 26 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 |