{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -fno-warn-simplifiable-class-constraints #-}

module Data.Random.Distribution.Pareto where

import Data.Random

pareto :: Distribution Pareto a => a -> a -> RVar a
pareto :: forall a. Distribution Pareto a => a -> a -> RVar a
pareto a
xM a
a = forall (d :: * -> *) t. Distribution d t => d t -> RVar t
rvar (forall a. a -> a -> Pareto a
Pareto a
xM a
a)

paretoT :: Distribution Pareto a => a -> a -> RVarT m a
paretoT :: forall a (m :: * -> *).
Distribution Pareto a =>
a -> a -> RVarT m a
paretoT a
xM a
a = forall (d :: * -> *) t (n :: * -> *).
Distribution d t =>
d t -> RVarT n t
rvarT (forall a. a -> a -> Pareto a
Pareto a
xM a
a)

data Pareto a = Pareto !a !a

instance (Floating a, Distribution StdUniform a) => Distribution Pareto a where
    rvarT :: forall (n :: * -> *). Pareto a -> RVarT n a
rvarT (Pareto a
xM a
a) = do
        a
u <- forall a (m :: * -> *). Distribution StdUniform a => RVarT m a
stdUniformT
        forall (m :: * -> *) a. Monad m => a -> m a
return (a
xM forall a. Fractional a => a -> a -> a
/ (a
1 forall a. Num a => a -> a -> a
- a
u) forall a. Floating a => a -> a -> a
** forall a. Fractional a => a -> a
recip a
a)

instance (Real a, Distribution Pareto a) => CDF Pareto a where
    cdf :: Pareto a -> a -> Double
cdf (Pareto a
xM a
a) a
x
         | a
x forall a. Ord a => a -> a -> Bool
>= a
xM      = Double
1 forall a. Num a => a -> a -> a
- (forall a b. (Real a, Fractional b) => a -> b
realToFrac a
xM forall a. Fractional a => a -> a -> a
/ forall a b. (Real a, Fractional b) => a -> b
realToFrac a
x) forall a. Floating a => a -> a -> a
** forall a b. (Real a, Fractional b) => a -> b
realToFrac a
a
         | Bool
otherwise    = Double
0