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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to