{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module ELynx.Tree.Distribution.BirthDeathNearlyCritical
( BirthDeathNearlyCriticalDistribution (..),
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 BirthDeathNearlyCriticalDistribution = BDNCD
{
BirthDeathNearlyCriticalDistribution -> Time
bdncdTOr :: Time,
BirthDeathNearlyCriticalDistribution -> Time
bdncdLa :: Rate,
BirthDeathNearlyCriticalDistribution -> Time
bdncdMu :: Rate
}
deriving (BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution -> Bool
(BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution -> Bool)
-> (BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution -> Bool)
-> Eq BirthDeathNearlyCriticalDistribution
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution -> Bool
$c/= :: BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution -> Bool
== :: BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution -> Bool
$c== :: BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution -> Bool
Eq, Typeable, Typeable BirthDeathNearlyCriticalDistribution
DataType
Constr
Typeable BirthDeathNearlyCriticalDistribution
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BirthDeathNearlyCriticalDistribution
-> c BirthDeathNearlyCriticalDistribution)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r)
-> Constr
-> c BirthDeathNearlyCriticalDistribution)
-> (BirthDeathNearlyCriticalDistribution -> Constr)
-> (BirthDeathNearlyCriticalDistribution -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c BirthDeathNearlyCriticalDistribution))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BirthDeathNearlyCriticalDistribution))
-> ((forall b. Data b => b -> b)
-> BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution)
-> (forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathNearlyCriticalDistribution
-> r)
-> (forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathNearlyCriticalDistribution
-> r)
-> (forall u.
(forall d. Data d => d -> u)
-> BirthDeathNearlyCriticalDistribution -> [u])
-> (forall u.
Int
-> (forall d. Data d => d -> u)
-> BirthDeathNearlyCriticalDistribution
-> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution)
-> Data BirthDeathNearlyCriticalDistribution
BirthDeathNearlyCriticalDistribution -> DataType
BirthDeathNearlyCriticalDistribution -> Constr
(forall b. Data b => b -> b)
-> BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BirthDeathNearlyCriticalDistribution
-> c BirthDeathNearlyCriticalDistribution
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r)
-> Constr
-> c BirthDeathNearlyCriticalDistribution
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)
-> BirthDeathNearlyCriticalDistribution
-> u
forall u.
(forall d. Data d => d -> u)
-> BirthDeathNearlyCriticalDistribution -> [u]
forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathNearlyCriticalDistribution
-> r
forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathNearlyCriticalDistribution
-> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r)
-> Constr
-> c BirthDeathNearlyCriticalDistribution
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BirthDeathNearlyCriticalDistribution
-> c BirthDeathNearlyCriticalDistribution
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c BirthDeathNearlyCriticalDistribution)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BirthDeathNearlyCriticalDistribution)
$cBDNCD :: Constr
$tBirthDeathNearlyCriticalDistribution :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution
gmapMp :: (forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution
gmapM :: (forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BirthDeathNearlyCriticalDistribution
-> m BirthDeathNearlyCriticalDistribution
gmapQi :: Int
-> (forall d. Data d => d -> u)
-> BirthDeathNearlyCriticalDistribution
-> u
$cgmapQi :: forall u.
Int
-> (forall d. Data d => d -> u)
-> BirthDeathNearlyCriticalDistribution
-> u
gmapQ :: (forall d. Data d => d -> u)
-> BirthDeathNearlyCriticalDistribution -> [u]
$cgmapQ :: forall u.
(forall d. Data d => d -> u)
-> BirthDeathNearlyCriticalDistribution -> [u]
gmapQr :: (r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathNearlyCriticalDistribution
-> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathNearlyCriticalDistribution
-> r
gmapQl :: (r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathNearlyCriticalDistribution
-> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> BirthDeathNearlyCriticalDistribution
-> r
gmapT :: (forall b. Data b => b -> b)
-> BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution
$cgmapT :: (forall b. Data b => b -> b)
-> BirthDeathNearlyCriticalDistribution
-> BirthDeathNearlyCriticalDistribution
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BirthDeathNearlyCriticalDistribution)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c BirthDeathNearlyCriticalDistribution)
dataCast1 :: (forall d. Data d => c (t d))
-> Maybe (c BirthDeathNearlyCriticalDistribution)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c BirthDeathNearlyCriticalDistribution)
dataTypeOf :: BirthDeathNearlyCriticalDistribution -> DataType
$cdataTypeOf :: BirthDeathNearlyCriticalDistribution -> DataType
toConstr :: BirthDeathNearlyCriticalDistribution -> Constr
$ctoConstr :: BirthDeathNearlyCriticalDistribution -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r)
-> Constr
-> c BirthDeathNearlyCriticalDistribution
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r)
-> Constr
-> c BirthDeathNearlyCriticalDistribution
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BirthDeathNearlyCriticalDistribution
-> c BirthDeathNearlyCriticalDistribution
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BirthDeathNearlyCriticalDistribution
-> c BirthDeathNearlyCriticalDistribution
$cp1Data :: Typeable BirthDeathNearlyCriticalDistribution
Data, (forall x.
BirthDeathNearlyCriticalDistribution
-> Rep BirthDeathNearlyCriticalDistribution x)
-> (forall x.
Rep BirthDeathNearlyCriticalDistribution x
-> BirthDeathNearlyCriticalDistribution)
-> Generic BirthDeathNearlyCriticalDistribution
forall x.
Rep BirthDeathNearlyCriticalDistribution x
-> BirthDeathNearlyCriticalDistribution
forall x.
BirthDeathNearlyCriticalDistribution
-> Rep BirthDeathNearlyCriticalDistribution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BirthDeathNearlyCriticalDistribution x
-> BirthDeathNearlyCriticalDistribution
$cfrom :: forall x.
BirthDeathNearlyCriticalDistribution
-> Rep BirthDeathNearlyCriticalDistribution x
Generic)
instance D.Distribution BirthDeathNearlyCriticalDistribution where
cumulative :: BirthDeathNearlyCriticalDistribution -> Time -> Time
cumulative = BirthDeathNearlyCriticalDistribution -> Time -> Time
cumulative
cumulative :: BirthDeathNearlyCriticalDistribution -> Time -> Double
cumulative :: BirthDeathNearlyCriticalDistribution -> Time -> Time
cumulative (BDNCD Time
t Time
l Time
m) Time
s
| Time
s Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
<= Time
0 = Time
0
| Time
s Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
> Time
t = Time
1
| Bool
otherwise = Time
o0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
o1
where
o0 :: Time
o0 = Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l) Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/ Time
t Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/ (Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l)
o1 :: Time
o1 = (- Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
t) Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
m Time -> Time -> Time
forall a. Num a => a -> a -> a
- Time
l) Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/ (Time
2.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l) Time -> Time -> Time
forall a. Floating a => a -> a -> a
** Time
2)
instance D.ContDistr BirthDeathNearlyCriticalDistribution where
density :: BirthDeathNearlyCriticalDistribution -> Time -> Time
density = BirthDeathNearlyCriticalDistribution -> Time -> Time
density
quantile :: BirthDeathNearlyCriticalDistribution -> Time -> Time
quantile = BirthDeathNearlyCriticalDistribution -> Time -> Time
quantile
density :: BirthDeathNearlyCriticalDistribution -> Time -> Double
density :: BirthDeathNearlyCriticalDistribution -> Time -> Time
density (BDNCD Time
t Time
l Time
m) Time
s
| Time
s Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
< Time
0 = Time
0
| Time
s Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
> Time
t = Time
0
| Bool
otherwise = Time
o0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
o1
where
o0 :: Time
o0 = (Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l) Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/ (Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l) Time -> Time -> Time
forall a. Floating a => a -> a -> a
** Time
2)
o1 :: Time
o1 = (-Time
2.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
- Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l) Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
m Time -> Time -> Time
forall a. Num a => a -> a -> a
- Time
l) Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/ (Time
2.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
s Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l) Time -> Time -> Time
forall a. Floating a => a -> a -> a
** Time
3)
quantile :: BirthDeathNearlyCriticalDistribution -> Double -> Time
quantile :: BirthDeathNearlyCriticalDistribution -> Time -> Time
quantile (BDNCD Time
t Time
l Time
m) Time
p
| Time
p Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
>= Time
0 Bool -> Bool -> Bool
&& Time
p Time -> Time -> Bool
forall a. Ord a => a -> a -> Bool
<= Time
1 =
Time
res
| Bool
otherwise =
[Char] -> Time
forall a. HasCallStack => [Char] -> a
error ([Char] -> Time) -> [Char] -> Time
forall a b. (a -> b) -> a -> b
$
[Char]
"PointProcess.quantile: p must be in [0,1] range. Got: "
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Time -> [Char]
forall a. Show a => a -> [Char]
show Time
p
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"."
where
den :: Time
den = Time
l Time -> Time -> Time
forall a. Num a => a -> a -> a
* (-Time
3.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
2.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* (-Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
p) Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l) Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
m
t1 :: Time
t1 = (Time
2.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
l Time -> Time -> Time
forall a. Num a => a -> a -> a
- Time
4.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
p Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
m)) Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/ Time
den
t2Nom :: Time
t2Nom =
Time
4.0
Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t
Time -> Time -> Time
forall a. Num a => a -> a -> a
* ( Time
l
Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
4.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
8.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
p Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l))
Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
2.0
Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
2.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l Time -> Time -> Time
forall a. Num a => a -> a -> a
- Time
4.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
p Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
1.0 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
l))
Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
m
Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time
t
Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
m
Time -> Time -> Time
forall a. Num a => a -> a -> a
* Time
m
)
t2 :: Time
t2 = Time
t2Nom Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/ (Time
den Time -> Time -> Time
forall a. Floating a => a -> a -> a
** Time
2)
res :: Time
res = Time
0.5 Time -> Time -> Time
forall a. Num a => a -> a -> a
* (Time
t1 Time -> Time -> Time
forall a. Num a => a -> a -> a
+ Time -> Time
forall a. Floating a => a -> a
sqrt Time
t2)
instance D.ContGen BirthDeathNearlyCriticalDistribution where
genContVar :: BirthDeathNearlyCriticalDistribution -> Gen (PrimState m) -> m Time
genContVar = BirthDeathNearlyCriticalDistribution -> Gen (PrimState m) -> m Time
forall d (m :: * -> *).
(ContDistr d, PrimMonad m) =>
d -> Gen (PrimState m) -> m Time
D.genContinuous