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

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

    data Weibull a = Weibull { forall a. Weibull a -> a
    weibullLambda :: !a, forall 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
    $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
    /= :: 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
    $cshowsPrec :: forall a. Show a => Int -> Weibull a -> ShowS
    showsPrec :: Int -> Weibull a -> ShowS
    $cshow :: forall a. Show a => Weibull a -> String
    show :: Weibull a -> String
    $cshowList :: forall a. Show a => [Weibull a] -> ShowS
    showList :: [Weibull a] -> ShowS
    Show)

    instance (Floating a, Distribution StdUniform a) => Distribution Weibull a where
        rvarT :: forall (n :: * -> *). Weibull a -> RVarT n a
    rvarT (Weibull a
    lambda a
    k) = do
            u <- StdUniform a -> RVarT n a
    forall (n :: * -> *). 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
            return (lambda * (negate (log u)) ** recip 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))