packages feed

hstatistics 0.2.0.2 → 0.2.0.3

raw patch · 3 files changed

+27/−11 lines, 3 filesdep ~hmatrix-gsl-stats

Dependency ranges changed: hmatrix-gsl-stats

Files

CHANGES view
@@ -18,3 +18,10 @@ 0.1.0.5: 		added multifit to Numeric.GSL.Fitting.Linear 		attempt to fix problem on hackage with configure (removed printCurrentDirectory)++0.2.0.1:+		moved GSL.* to hmatrix-gsl-stats+		added Numeric.Statistics.Shannon++0.2.0.3:+		added mutual_information to Numeric.Statistics.Shannon
hstatistics.cabal view
@@ -1,5 +1,5 @@ Name:               hstatistics-Version:            0.2.0.2+Version:            0.2.0.3 License:            GPL License-file:       LICENSE Copyright:          (c) A.V.H. McPhail 2010@@ -22,7 +22,7 @@ library      Build-Depends:      base >= 3 && < 5,-                        hmatrix >= 0.9.3, hmatrix-gsl-stats >= 0.1.0.1+                        hmatrix >= 0.9.3, hmatrix-gsl-stats >= 0.1.0.2      Extensions:          
lib/Numeric/Statistics/Shannon.hs view
@@ -14,28 +14,37 @@ -----------------------------------------------------------------------------  module Numeric.Statistics.Shannon (-                         entropy-                         ) where+                                   entropy+                                   , mutual_information+                                  ) where   import Data.Packed.Vector -import Numeric.GSL.Histogram hiding(sum)+import qualified Numeric.GSL.Histogram as H+import qualified Numeric.GSL.Histogram2D as H2  import Numeric.LinearAlgebra.Algorithms import Numeric.LinearAlgebra.Interface()  import Prelude hiding (sum) -sum x = dot x (constant  1 (dim x))--prob p y = let Just y' = find p y -           in getBin p y'+sum x = dot x (constant 1.0 (dim x))  -- | the entropy \sum p_i l\ln{p_i} of a sequence-entropy :: Histogram             -- the underlying distribution+entropy :: H.Histogram             -- the underlying distribution         -> Vector Double         -- the sequence (expected to fall within bounds of Histogram)         -> Double                -- the entropy-entropy p x = let ps = mapVector (prob p) x+entropy p x = let ps = H.prob p x               in sum (ps * log ps)  +-- | the mutuaal information \sum_x \sum_y \ln{\frac{p(x,y)}{p(x)p(y)}}+mutual_information :: H2.Histogram2D -- the underlying distribution+                   -> H.Histogram   -- the first dimension distribution+                   -> H.Histogram   -- the second dimension distribution+                   -> (Vector Double, Vector Double) -- the sequence (expected to fall within bounds of Histogram)+                   -> Double      -- the mutual information+mutual_information p px py z@(x,y) = let ps = H2.prob p z+                                         xs = H.prob px x+                                         ys = H.prob py y+                               in sum $ log (ps/(xs*ys))