packages feed

nlp-scores 0.6.0 → 0.6.2

raw patch · 3 files changed

+13/−14 lines, 3 filesdep +strict

Dependencies added: strict

Files

NLP/Scores.hs view
@@ -55,7 +55,7 @@ import qualified Data.Set as Set import qualified Data.Map as Map import Prelude hiding (sum)-+import Data.Strict.Tuple (Pair((:!:))) import NLP.Scores.Internals  @@ -104,11 +104,11 @@ mi :: (Ord a, Ord b) => Counts a b -> Double mi (Counts cxy cx cy) =   let n = Map.foldl' (+) 0 cxy-      cell (P x y) nxy = +      cell (x :!: y) nxy =          let nx = cx Map.! x             ny = cy Map.! y         in  nxy / n * logBase 2 (nxy * n / nx / ny)-  in sum [ cell (P x y) nxy | (P x y, nxy) <- Map.toList cxy ]+  in sum [ cell (x :!: y) nxy | (x :!: y, nxy) <- Map.toList cxy ]  -- | Variation of information: VI(X,Y) = H(X) + H(Y) - 2 MI(X,Y) vi :: (Ord a, Ord b) => Counts a b -> Double@@ -150,7 +150,7 @@ -- | The mean of a sequence of numbers. mean :: (F.Foldable t, Fractional n, Real a) => t a -> n mean xs = -    let (P tot len) = F.foldl' (\(P s l) x -> (P (s+x) (l+1))) (P 0 0) xs+    let (tot :!: len) = F.foldl' (\(s :!: l) x -> ((s+x) :!: (l+1))) (0 :!: 0) xs     in realToFrac tot/len {-# SPECIALIZE mean :: [Double] -> Double #-} @@ -189,15 +189,15 @@  -- | Creates count table 'Counts' 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) = +counts xs = F.foldl' f empty . zipWithTF (:!:) xs . F.toList+    where f cs@(Counts cxy cx cy) p@(x :!: y) =              cs { joint       = Map.insertWith' (+) p 1 cxy                , marginalFst = Map.insertWith' (+) x 1 cx                , marginalSnd = Map.insertWith' (+) y 1 cy }  -- | Joint count countJoint :: (Ord a, Ord b) => a -> b -> Counts a b -> Count          -countJoint x y = Map.findWithDefault 0 (P x y) . joint+countJoint x y = Map.findWithDefault 0 (x :!: y) . joint -- | Count of first element countFst :: Ord k => k -> Counts k b -> Count countFst x = Map.findWithDefault 0 x . marginalFst
NLP/Scores/Internals.hs view
@@ -1,25 +1,24 @@ module NLP.Scores.Internals     ( Counts(..)     , Count-    , P(..)     , empty     , unionPlus     ) where import qualified Data.Map as Map import Data.Monoid+import Data.Strict.Tuple  -- | A count type Count = Double -- | Count table data Counts a b =    Counts -  { joint :: !(Map.Map (P a b) Count) -- ^ Counts of both components+  { joint :: !(Map.Map (Pair a b) Count) -- ^ Counts of both components   , marginalFst :: !(Map.Map a Count) -- ^ Counts of the first component   , marginalSnd :: !(Map.Map b Count) -- ^ Counts of the second component   } -data P a b = P !a !b deriving (Eq, Ord)-+   -- | The empty count table empty :: (Ord a, Ord b) => Counts a b empty = Counts Map.empty Map.empty Map.empty
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.6.0+Version:             0.6.2  -- A short (one-line) description of the package. Synopsis:            Scoring functions commonly used for evaluation in NLP and IR@@ -29,7 +29,7 @@  -- An email address to which users can send suggestions, bug reports, -- and patches.-Maintainer:          gchrupala@lsv.uni-saarland.de+Maintainer:          grzegorz.chrupala@gmail.com  -- A copyright notice. -- Copyright:           @@ -51,7 +51,7 @@   Exposed-modules:     NLP.Scores, NLP.Scores.Internals      -- Packages needed in order to build this package.-  Build-depends:  base >= 3 && < 5 ,  containers >= 0.4.2+  Build-depends:  base >= 3 && < 5 ,  containers >= 0.4.2 , strict >= 0.3   -- Modules not exported by this package.   -- Other-modules: