Anonymous avatar Anonymous committed 098714f

MaybeEntropy instance for GammaDistribution

Comments (0)

Files changed (1)

Statistics/Distribution/Gamma.hs

 import Data.Data (Data, Typeable)
 import GHC.Generics (Generic)
 import Numeric.MathFunctions.Constants (m_pos_inf, m_NaN)
-import Numeric.SpecFunctions           (incompleteGamma, invIncompleteGamma)
+import Numeric.SpecFunctions (
+  incompleteGamma, invIncompleteGamma, logGamma, digamma)
 import Statistics.Distribution.Poisson.Internal  as Poisson
 import qualified Statistics.Distribution         as D
 import qualified System.Random.MWC.Distributions as MWC
     maybeStdDev   = Just . D.stdDev
     maybeVariance = Just . D.variance
 
+instance D.MaybeEntropy GammaDistribution where
+  maybeEntropy (GD a l)
+    | a > 0 && l > 0 = 
+      Just $
+      a 
+      + log l 
+      + logGamma a 
+      + (1-a) * digamma a
+    | otherwise = Nothing
+
 instance D.ContGen GammaDistribution where
     genContVar (GD a l) = MWC.gamma a l
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.