Commits

Grzegorz Chrupała committed 313628c

Generalized signatures in NLP.Scores.

Comments (0)

Files changed (1)

nlp-scores/NLP/Scores.hs

 -- | Accuracy: the proportion of elements in the first sequence equal
 -- to elements at corresponding positions in second
 -- sequence. Sequences should be of equal lengths.
-accuracy :: (Eq a, Fractional c, T.Traversable t) =>  t a -> t a -> c
+accuracy :: (Eq a, Fractional c, T.Traversable t, F.Foldable s) =>  t a -> s a -> c
 accuracy xs = mean . fmap fromEnum . zipWithTF (==) xs . F.toList
 {-# SPECIALIZE accuracy :: [Double] -> [Double] -> Double #-}
 
 histogram = F.foldl' (\ z k -> Map.insertWith' (+) k 1 z) Map.empty
 
 -- | Creates count table 'Counts'
-counts :: (Ord a, Ord b, F.Foldable t) => t a -> t b -> Counts a b
-counts xs = foldl' f empty . zipWith P (F.toList xs) . F.toList
+counts :: (Ord a, Ord b, T.Traversable t, F.Foldable s) => t a -> s b -> Counts a b
+counts xs = F.foldl' f empty . zipWithTF P xs . F.toList
     where f cs@(Counts cxy cx cy) p@(P x y) = 
             cs { joint       = Map.insertWith' (+) p 1 cxy
                , marginalFst = Map.insertWith' (+) x 1 cx