{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module ELynx.Tree.Distribution.BirthDeathCritical
( BirthDeathCriticalDistribution (..),
cumulative,
density,
quantile,
)
where
import Data.Data
( Data,
Typeable,
)
import ELynx.Tree.Distribution.Types
import GHC.Generics (Generic)
import qualified Statistics.Distribution as D
data BirthDeathCriticalDistribution = BDCD
{
BirthDeathCriticalDistribution -> Double
bdcdTOr :: Time,
BirthDeathCriticalDistribution -> Double
bdcdLa :: Rate
}
deriving (BirthDeathCriticalDistribution
-> BirthDeathCriticalDistribution -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BirthDeathCriticalDistribution
-> BirthDeathCriticalDistribution -> Bool
$c/= :: BirthDeathCriticalDistribution
-> BirthDeathCriticalDistribution -> Bool
== :: BirthDeathCriticalDistribution
-> BirthDeathCriticalDistribution -> Bool
$c== :: BirthDeathCriticalDistribution
-> BirthDeathCriticalDistribution -> Bool
Eq, Typeable, Typeable BirthDeathCriticalDistribution
BirthDeathCriticalDistribution -> DataType
BirthDeathCriticalDistribution -> Constr
(forall b. Data b => b -> b)
-> BirthDeathCriticalDistribution -> BirthDeathCriticalDistribution
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int
-> (forall d. Data d => d -> u)
-> BirthDeathCriticalDistribution
-> u
forall u.
(forall d. Data d => d -> u)
-> BirthDeathCriticalDistribution -> [u]
forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathCriticalDistribution
-> r
forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathCriticalDistribution
-> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BirthDeathCriticalDistribution
-> m BirthDeathCriticalDistribution
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathCriticalDistribution
-> m BirthDeathCriticalDistribution
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r)
-> Constr
-> c BirthDeathCriticalDistribution
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BirthDeathCriticalDistribution
-> c BirthDeathCriticalDistribution
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c BirthDeathCriticalDistribution)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BirthDeathCriticalDistribution)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathCriticalDistribution
-> m BirthDeathCriticalDistribution
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathCriticalDistribution
-> m BirthDeathCriticalDistribution
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathCriticalDistribution
-> m BirthDeathCriticalDistribution
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathCriticalDistribution
-> m BirthDeathCriticalDistribution
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BirthDeathCriticalDistribution
-> m BirthDeathCriticalDistribution
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BirthDeathCriticalDistribution
-> m BirthDeathCriticalDistribution
gmapQi :: forall u.
Int
-> (forall d. Data d => d -> u)
-> BirthDeathCriticalDistribution
-> u
$cgmapQi :: forall u.
Int
-> (forall d. Data d => d -> u)
-> BirthDeathCriticalDistribution
-> u
gmapQ :: forall u.
(forall d. Data d => d -> u)
-> BirthDeathCriticalDistribution -> [u]
$cgmapQ :: forall u.
(forall d. Data d => d -> u)
-> BirthDeathCriticalDistribution -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathCriticalDistribution
-> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathCriticalDistribution
-> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathCriticalDistribution
-> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathCriticalDistribution
-> r
gmapT :: (forall b. Data b => b -> b)
-> BirthDeathCriticalDistribution -> BirthDeathCriticalDistribution
$cgmapT :: (forall b. Data b => b -> b)
-> BirthDeathCriticalDistribution -> BirthDeathCriticalDistribution
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BirthDeathCriticalDistribution)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BirthDeathCriticalDistribution)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c BirthDeathCriticalDistribution)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c BirthDeathCriticalDistribution)
dataTypeOf :: BirthDeathCriticalDistribution -> DataType
$cdataTypeOf :: BirthDeathCriticalDistribution -> DataType
toConstr :: BirthDeathCriticalDistribution -> Constr
$ctoConstr :: BirthDeathCriticalDistribution -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r)
-> Constr
-> c BirthDeathCriticalDistribution
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r)
-> Constr
-> c BirthDeathCriticalDistribution
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BirthDeathCriticalDistribution
-> c BirthDeathCriticalDistribution
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BirthDeathCriticalDistribution
-> c BirthDeathCriticalDistribution
Data, forall x.
Rep BirthDeathCriticalDistribution x
-> BirthDeathCriticalDistribution
forall x.
BirthDeathCriticalDistribution
-> Rep BirthDeathCriticalDistribution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BirthDeathCriticalDistribution x
-> BirthDeathCriticalDistribution
$cfrom :: forall x.
BirthDeathCriticalDistribution
-> Rep BirthDeathCriticalDistribution x
Generic)
instance D.Distribution BirthDeathCriticalDistribution where
cumulative :: BirthDeathCriticalDistribution -> Double -> Double
cumulative = BirthDeathCriticalDistribution -> Double -> Double
cumulative
cumulative :: BirthDeathCriticalDistribution -> Time -> Double
cumulative :: BirthDeathCriticalDistribution -> Double -> Double
cumulative (BDCD Double
t Double
l) Double
x
| Double
x forall a. Ord a => a -> a -> Bool
<= Double
0 = Double
0
| Double
x forall a. Ord a => a -> a -> Bool
> Double
t = Double
1
| Bool
otherwise = Double
x forall a. Fractional a => a -> a -> a
/ (Double
1.0 forall a. Num a => a -> a -> a
+ Double
l forall a. Num a => a -> a -> a
* Double
x) forall a. Num a => a -> a -> a
* (Double
1.0 forall a. Num a => a -> a -> a
+ Double
l forall a. Num a => a -> a -> a
* Double
t) forall a. Fractional a => a -> a -> a
/ Double
t
instance D.ContDistr BirthDeathCriticalDistribution where
density :: BirthDeathCriticalDistribution -> Double -> Double
density = BirthDeathCriticalDistribution -> Double -> Double
density
quantile :: BirthDeathCriticalDistribution -> Double -> Double
quantile = BirthDeathCriticalDistribution -> Double -> Double
quantile
density :: BirthDeathCriticalDistribution -> Time -> Double
density :: BirthDeathCriticalDistribution -> Double -> Double
density (BDCD Double
t Double
l) Double
x
| Double
x forall a. Ord a => a -> a -> Bool
< Double
0 = Double
0
| Double
x forall a. Ord a => a -> a -> Bool
> Double
t = Double
0
| Bool
otherwise = (Double
1.0 forall a. Num a => a -> a -> a
+ Double
l forall a. Num a => a -> a -> a
* Double
t) forall a. Fractional a => a -> a -> a
/ (Double
t forall a. Num a => a -> a -> a
* (Double
1.0 forall a. Num a => a -> a -> a
+ Double
l forall a. Num a => a -> a -> a
* Double
x) forall a. Floating a => a -> a -> a
** Double
2)
quantile :: BirthDeathCriticalDistribution -> Double -> Time
quantile :: BirthDeathCriticalDistribution -> Double -> Double
quantile (BDCD Double
t Double
l) Double
p
| Double
p forall a. Ord a => a -> a -> Bool
>= Double
0 Bool -> Bool -> Bool
&& Double
p forall a. Ord a => a -> a -> Bool
<= Double
1 =
Double
res
| Bool
otherwise =
forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
[Char]
"PointProcess.quantile: p must be in [0,1] range. Got: "
forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Double
p
forall a. [a] -> [a] -> [a]
++ [Char]
"."
where
res :: Double
res = Double
p forall a. Num a => a -> a -> a
* Double
t forall a. Fractional a => a -> a -> a
/ (Double
1 forall a. Num a => a -> a -> a
+ Double
l forall a. Num a => a -> a -> a
* Double
t forall a. Num a => a -> a -> a
- Double
l forall a. Num a => a -> a -> a
* Double
p forall a. Num a => a -> a -> a
* Double
t)
instance D.ContGen BirthDeathCriticalDistribution where
genContVar :: forall g (m :: * -> *).
StatefulGen g m =>
BirthDeathCriticalDistribution -> g -> m Double
genContVar = forall d g (m :: * -> *).
(ContDistr d, StatefulGen g m) =>
d -> g -> m Double
D.genContinuous