module Statistics.Distribution.Exponential
(
ExponentialDistribution
, fromLambda
, fromSample
) where
import Data.Typeable (Typeable)
import qualified Statistics.Distribution as D
import qualified Statistics.Sample as S
import Statistics.Types (Sample)
newtype ExponentialDistribution = ED {
edLambda :: Double
} deriving (Eq, Read, Show, Typeable)
instance D.Distribution ExponentialDistribution where
probability (ED l) x = l * exp (l * x)
cumulative (ED l) x = 1 exp (l * x)
inverse (ED l) p = log (1 p) / l
instance D.Variance ExponentialDistribution where
variance (ED l) = l * l
instance D.Mean ExponentialDistribution where
mean = edLambda
fromLambda :: Double
-> ExponentialDistribution
fromLambda = ED
fromSample :: Sample -> ExponentialDistribution
fromSample = ED . S.mean