Commits

Grzegorz Chrupała committed b120cce

errorRate

Comments (0)

Files changed (2)

nlp-scores/NLP/Scores.hs

 module NLP.Scores 
     ( 
     -- * Scores for classification and ranking
-      accuracy
+      errorRate
+    , accuracy
     , recipRank
     , avgPrecision
     -- * Scores for clustering
 
 import NLP.Scores.Internals
 
+
+-- | Error rate: the proportion of elements in the first sequence NOT
+-- equal to elements at corresponding positions in second
+-- sequence. Sequences should be of equal lengths.
+errorRate :: (Eq a, Fractional c, T.Traversable t, F.Foldable s) =>  t a -> s a -> c
+errorRate xs ys = 1 - accuracy xs ys
+{-# SPECIALIZE errorRate :: [Double] -> [Double] -> Double #-}
+
 -- | Accuracy: the proportion of elements in the first sequence equal
 -- to elements at corresponding positions in second
 -- sequence. Sequences should be of equal lengths.
 vi cs@(Counts _ cx cy) = entropy (elems cx) + entropy (elems cy) - 2 * mi cs
   where elems = Map.elems
 
--- | Kullback-Leibler divergence: KL(X,Y) = SUM_i P(X=i) log_2(P(X=i)/P(Y=i)). 
+-- | Kullback-Leibler divergence: KL(X,Y) = SUM_i P(X=i) log_2(P(X=i)\/P(Y=i)). 
 -- The distributions can be unnormalized.
         
 kullbackLeibler :: (Eq a, Floating a, F.Foldable f, T.Traversable t) => t a -> f a -> a
         mult w p = w * p
         {-# INLINE mult #-}  
 
--- | Jensen-Shannon divergence: JS(X,Y) = 1/2 KL(X,(X+Y)/2) + 1/2 KL(Y,(X+Y)/2).
+-- | Jensen-Shannon divergence: JS(X,Y) = 1\/2 KL(X,(X+Y)\/2) + 1\/2 KL(Y,(X+Y)\/2).
 -- The distributions can be unnormalized.
 jensenShannon :: (Eq a, Floating a, T.Traversable t, T.Traversable u) => t a -> u a -> a
 jensenShannon xs ys = 0.5 * kullbackLeibler xs zs + 0.5 * kullbackLeibler ys zs
     in realToFrac tot/len
 {-# SPECIALIZE mean :: [Double] -> Double #-}
 
--- | The binomial coefficient: C^n_k = PROD^k_i=1 (n-k-i)/i
+-- | The binomial coefficient: C^n_k = PROD^k_i=1 (n-k-i)\/i
 choice :: (Enum b, Fractional b) => b -> b -> b
 choice n k = foldl' (*) 1 [n-k+1 .. n] / foldl' (*) 1 [1 .. k]
 {-# SPECIALIZE choice :: Double -> Double -> Double #-}

nlp-scores/nlp-scores.cabal

 -- The package version. See the Haskell package versioning policy
 -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
 -- standards guiding when and how versions should be incremented.
-Version:             0.5.4
+Version:             0.5.6
 
 -- A short (one-line) description of the package.
 Synopsis:            Scoring functions commonly used for evaluation in NLP and IR