{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module ELynx.Distribution.BirthDeathCritical
( BirthDeathCriticalDistribution(..)
, cumulative
, density
, quantile
) where
import Data.Data (Data, Typeable)
import GHC.Generics (Generic)
import qualified Statistics.Distribution as D
import ELynx.Distribution.Types
data BirthDeathCriticalDistribution = BDCD
{ bdcdTOr :: Time
, bdcdLa :: Rate
} deriving (Eq, Typeable, Data, Generic)
instance D.Distribution BirthDeathCriticalDistribution where
cumulative = cumulative
cumulative :: BirthDeathCriticalDistribution -> Time -> Double
cumulative (BDCD t l) x
| x <= 0 = 0
| x > t = 1
| otherwise = x / (1.0 + l * x) * (1.0 + l * t) / t
instance D.ContDistr BirthDeathCriticalDistribution where
density = density
quantile = quantile
density :: BirthDeathCriticalDistribution -> Time -> Double
density (BDCD t l) x
| x < 0 = 0
| x > t = 0
| otherwise = (1.0 + l * t) / (t * (1.0 + l * x)**2)
quantile :: BirthDeathCriticalDistribution -> Double -> Time
quantile (BDCD t l) p
| p >= 0 && p <= 1 = res
| otherwise =
error $ "PointProcess.quantile: p must be in [0,1] range. Got: " ++ show p ++ "."
where res = p * t / (1 + l*t - l*p*t)
instance D.ContGen BirthDeathCriticalDistribution where
genContVar = D.genContinuous