{-# LANGUAGE
MultiParamTypeClasses,
FlexibleInstances, FlexibleContexts,
UndecidableInstances
#-}
{-# OPTIONS_GHC -fno-warn-simplifiable-class-constraints #-}
module Data.Random.Distribution.Exponential where
import Data.Random.RVar
import Data.Random.Distribution
import Data.Random.Distribution.Uniform
newtype Exponential a = Exp a
floatingExponential :: (Floating a, Distribution StdUniform a) => a -> RVarT m a
floatingExponential :: forall a (m :: * -> *).
(Floating a, Distribution StdUniform a) =>
a -> RVarT m a
floatingExponential a
lambdaRecip = do
a
x <- forall a (m :: * -> *). Distribution StdUniform a => RVarT m a
stdUniformT
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. Num a => a -> a
negate (forall a. Floating a => a -> a
log a
x) forall a. Num a => a -> a -> a
* a
lambdaRecip)
floatingExponentialCDF :: Real a => a -> a -> Double
floatingExponentialCDF :: forall a. Real a => a -> a -> Double
floatingExponentialCDF a
lambdaRecip a
x = Double
1 forall a. Num a => a -> a -> a
- forall a. Floating a => a -> a
exp (forall a. Num a => a -> a
negate (forall a b. (Real a, Fractional b) => a -> b
realToFrac a
x) forall a. Fractional a => a -> a -> a
/ forall a b. (Real a, Fractional b) => a -> b
realToFrac a
lambdaRecip)
exponential :: Distribution Exponential a => a -> RVar a
exponential :: forall a. Distribution Exponential a => a -> RVar a
exponential = forall (d :: * -> *) t. Distribution d t => d t -> RVar t
rvar forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Exponential a
Exp
exponentialT :: Distribution Exponential a => a -> RVarT m a
exponentialT :: forall a (m :: * -> *).
Distribution Exponential a =>
a -> RVarT m a
exponentialT = forall (d :: * -> *) t (n :: * -> *).
Distribution d t =>
d t -> RVarT n t
rvarT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Exponential a
Exp
instance (Floating a, Distribution StdUniform a) => Distribution Exponential a where
rvarT :: forall (n :: * -> *). Exponential a -> RVarT n a
rvarT (Exp a
lambdaRecip) = forall a (m :: * -> *).
(Floating a, Distribution StdUniform a) =>
a -> RVarT m a
floatingExponential a
lambdaRecip
instance (Real a, Distribution Exponential a) => CDF Exponential a where
cdf :: Exponential a -> a -> Double
cdf (Exp a
lambdaRecip) = forall a. Real a => a -> a -> Double
floatingExponentialCDF a
lambdaRecip