{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, FlexibleContexts #-}
module Data.Random.Distribution.Weibull where

import Data.Random.Distribution
import Data.Random.Distribution.Uniform

data Weibull a = Weibull { Weibull a -> a
weibullLambda :: !a, Weibull a -> a
weibullK :: !a }
    deriving (Weibull a -> Weibull a -> Bool
(Weibull a -> Weibull a -> Bool)
-> (Weibull a -> Weibull a -> Bool) -> Eq (Weibull a)
forall a. Eq a => Weibull a -> Weibull a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Weibull a -> Weibull a -> Bool
$c/= :: forall a. Eq a => Weibull a -> Weibull a -> Bool
== :: Weibull a -> Weibull a -> Bool
$c== :: forall a. Eq a => Weibull a -> Weibull a -> Bool
Eq, Int -> Weibull a -> ShowS
[Weibull a] -> ShowS
Weibull a -> String
(Int -> Weibull a -> ShowS)
-> (Weibull a -> String)
-> ([Weibull a] -> ShowS)
-> Show (Weibull a)
forall a. Show a => Int -> Weibull a -> ShowS
forall a. Show a => [Weibull a] -> ShowS
forall a. Show a => Weibull a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Weibull a] -> ShowS
$cshowList :: forall a. Show a => [Weibull a] -> ShowS
show :: Weibull a -> String
$cshow :: forall a. Show a => Weibull a -> String
showsPrec :: Int -> Weibull a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Weibull a -> ShowS
Show)

instance (Floating a, Distribution StdUniform a) => Distribution Weibull a where
    rvarT :: Weibull a -> RVarT n a
rvarT (Weibull a
lambda a
k) = do
        a
u <- StdUniform a -> RVarT n a
forall (d :: * -> *) t (n :: * -> *).
Distribution d t =>
d t -> RVarT n t
rvarT StdUniform a
forall t. StdUniform t
StdUniform
        a -> RVarT n a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
lambda a -> a -> a
forall a. Num a => a -> a -> a
* (a -> a
forall a. Num a => a -> a
negate (a -> a
forall a. Floating a => a -> a
log a
u)) a -> a -> a
forall a. Floating a => a -> a -> a
** a -> a
forall a. Fractional a => a -> a
recip a
k)

instance (Real a, Distribution Weibull a) => CDF Weibull a where
    cdf :: Weibull a -> a -> Double
cdf (Weibull a
lambda a
k) a
x = Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double -> Double
forall a. Floating a => a -> a
exp (Double -> Double
forall a. Num a => a -> a
negate ((a -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac a
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ a -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac a
lambda) Double -> Double -> Double
forall a. Floating a => a -> a -> a
** a -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac a
k))