(defn tanimoto-coefficient
"
http://en.wikipedia.org/wiki/Jaccard_index
The cosine similarity metric may be extended such that it yields the Jaccard coefficient in the case of binary attributes. This is the Tanimoto coefficient. "
[a b]
(let [counts
(apply merge-with +
(map
(fn [[x y]]
{:dot (* x y)
:a (pow x 2)
:b (pow y 2)})
(map vector a b)))]
(/ (:dot counts)
(-
(+ (:a counts)
(:a counts))
(:dot counts)))))
Comments top
No comments for tanimoto-coefficient. Log in to add a comment.