packages feed

nlp-scores 0.5.4 → 0.6.0

raw patch · 2 files changed

+14/−5 lines, 2 files

Files

NLP/Scores.hs view
@@ -19,7 +19,8 @@ module NLP.Scores      (      -- * Scores for classification and ranking-      accuracy+      errorRate+    , accuracy     , recipRank     , avgPrecision     -- * Scores for clustering@@ -57,6 +58,14 @@  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.@@ -106,7 +115,7 @@ 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@@ -118,7 +127,7 @@         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@@ -145,7 +154,7 @@     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.cabal view
@@ -7,7 +7,7 @@ -- 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.6.0  -- A short (one-line) description of the package. Synopsis:            Scoring functions commonly used for evaluation in NLP and IR