1. Bryan O'Sullivan
  2. statistics

Commits

Aleksey Khudyakov  committed 57f2911

Add logarithm of probablity density

Both density and logDensity could be expressed terms of each other
so default implementations are added.

Currently none of the distributions have good implementations of
logDensity since they use default implementation.

Affects #41

  • Participants
  • Parent commits 4481953
  • Branches default

Comments (0)

Files changed (1)

File Statistics/Distribution.hs

View file
  • Ignore whitespace
     probability :: d -> Int -> Double
 
 
--- | Continuous probability distributuion
+-- | Continuous probability distributuion.
+--
+--   Minimal complete definition is 'quantile' and either 'density' or
+--   'logDensity'.
 class Distribution d => ContDistr d where
     -- | Probability density function. Probability that random
     -- variable /X/ lies in the infinitesimal interval
     -- [/x/,/x+/δ/x/) equal to /density(x)/⋅δ/x/
     density :: d -> Double -> Double
+    density d = exp . logDensity d
+    {-# INLINE density #-}
 
     -- | Inverse of the cumulative distribution function. The value
     -- /x/ for which P(/X/≤/x/) = /p/. If probability is outside
     -- of [0,1] range function should call 'error'
     quantile :: d -> Double -> Double
 
+    -- | Natural logarithm of density.
+    logDensity :: d -> Double -> Double
+    logDensity d = log . density d
+    {-# INLINE logDensity #-}
 
 
 -- | Type class for distributions with mean. 'maybeMean' should return