
26 Jul
2011
26 Jul
'11
6:35 p.m.
On Tue, 26 Jul 2011, Alexander Solla wrote:
Given two (IntMap Double)s a and b, I would compute the projection of a along b as
cosineSimilarity :: IntMap Double -> IntMap Double -> Double cosineSimilarity a b = (dot a b) / ((norm a) * (norm b)) where dot = sum . elems . intersectionWith (*) norm = (**0.5) . sum . fmap (**2) . elems
Never write (**2) and (**0.5)! Use (^2) and sqrt! http://www.haskell.org/haskellwiki/Power_function