{-# 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 :: a -> a -> RVar a pareto a xM a a = Pareto a -> RVar a forall (d :: * -> *) t. Distribution d t => d t -> RVar t rvar (a -> a -> Pareto a forall a. a -> a -> Pareto a Pareto a xM a a) paretoT :: Distribution Pareto a => a -> a -> RVarT m a paretoT :: a -> a -> RVarT m a paretoT a xM a a = Pareto a -> RVarT m a forall (d :: * -> *) t (n :: * -> *). Distribution d t => d t -> RVarT n t rvarT (a -> a -> Pareto a 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 :: Pareto a -> RVarT n a rvarT (Pareto a xM a a) = do a u <- RVarT n a forall a (m :: * -> *). Distribution StdUniform a => RVarT m a stdUniformT a -> RVarT n a forall (m :: * -> *) a. Monad m => a -> m a return (a xM a -> a -> a forall a. Fractional a => a -> a -> a / (a 1 a -> a -> a forall a. Num a => a -> a -> a - a u) a -> a -> a forall a. Floating a => a -> 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 a -> a -> Bool forall a. Ord a => a -> a -> Bool >= a xM = Double 1 Double -> Double -> Double forall a. Num a => a -> a -> a - (a -> Double forall a b. (Real a, Fractional b) => a -> b realToFrac a xM Double -> Double -> Double forall a. Fractional a => a -> a -> a / a -> Double forall a b. (Real a, Fractional b) => a -> b realToFrac a x) Double -> Double -> Double forall a. Floating a => a -> a -> a ** a -> Double forall a b. (Real a, Fractional b) => a -> b realToFrac a a | Bool otherwise = Double 0