{-# LANGUAGE
MultiParamTypeClasses, FunctionalDependencies,
FlexibleContexts, FlexibleInstances,
UndecidableInstances, EmptyDataDecls,
TemplateHaskell,
BangPatterns
#-}
module Data.Random.Distribution.Uniform
( Uniform(..)
, uniform
, uniformT
, StdUniform(..)
, stdUniform
, stdUniformT
, stdUniformPos
, stdUniformPosT
, integralUniform
, realFloatUniform
, floatUniform
, doubleUniform
, fixedUniform
, enumUniform
, boundedStdUniform
, boundedEnumStdUniform
, realFloatStdUniform
, fixedStdUniform
, floatStdUniform
, doubleStdUniform
, boundedStdUniformCDF
, realStdUniformCDF
, realUniformCDF
, enumUniformCDF
) where
import Data.Random.Internal.Fixed
import Data.Random.Distribution
import Data.Random.RVar
import Data.Fixed
import Data.Word
import Data.Int
import Control.Monad.Loops
import qualified System.Random.Stateful as Random
{-# INLINE integralUniform #-}
integralUniform :: Random.UniformRange a => a -> a -> RVarT m a
integralUniform :: a -> a -> RVarT m a
integralUniform !a
x !a
y = (a, a) -> RGen -> RVarT m a
forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
Random.uniformRM (a
x, a
y) RGen
RGen
integralUniformCDF :: (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF :: a -> a -> a -> b
integralUniformCDF a
a a
b a
x
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
a = a -> a -> a -> b
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF a
b a
a a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
a = b
0
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
b = b
1
| Bool
otherwise = (a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
x b -> b -> b
forall a. Num a => a -> a -> a
- a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
a) b -> b -> b
forall a. Fractional a => a -> a -> a
/ (a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
b b -> b -> b
forall a. Num a => a -> a -> a
- a -> b
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
a)
boundedStdUniform :: (Distribution Uniform a, Bounded a) => RVar a
boundedStdUniform :: RVar a
boundedStdUniform = a -> a -> RVar a
forall a. Distribution Uniform a => a -> a -> RVar a
uniform a
forall a. Bounded a => a
minBound a
forall a. Bounded a => a
maxBound
boundedStdUniformCDF :: (CDF Uniform a, Bounded a) => a -> Double
boundedStdUniformCDF :: a -> Double
boundedStdUniformCDF = Uniform a -> a -> Double
forall (d :: * -> *) t. CDF d t => d t -> t -> Double
cdf (a -> a -> Uniform a
forall t. t -> t -> Uniform t
Uniform a
forall a. Bounded a => a
minBound a
forall a. Bounded a => a
maxBound)
boundedEnumStdUniform :: (Enum a, Bounded a) => RVarT m a
boundedEnumStdUniform :: RVarT m a
boundedEnumStdUniform = a -> a -> RVarT m a
forall a (m :: * -> *). Enum a => a -> a -> RVarT m a
enumUniform a
forall a. Bounded a => a
minBound a
forall a. Bounded a => a
maxBound
boundedEnumStdUniformCDF :: (Enum a, Bounded a, Ord a) => a -> Double
boundedEnumStdUniformCDF :: a -> Double
boundedEnumStdUniformCDF = a -> a -> a -> Double
forall a. (Enum a, Ord a) => a -> a -> a -> Double
enumUniformCDF a
forall a. Bounded a => a
minBound a
forall a. Bounded a => a
maxBound
floatStdUniform :: RVarT m Float
floatStdUniform :: RVarT m Float
floatStdUniform = do
Float
x <- (Float, Float) -> RVarT m Float
forall a (m :: * -> *). UniformRange a => (a, a) -> RVarT m a
uniformRangeRVarT (Float
0, Float
1)
if Float
x Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
== Float
1 then RVarT m Float
forall (m :: * -> *). RVarT m Float
floatStdUniform else Float -> RVarT m Float
forall (f :: * -> *) a. Applicative f => a -> f a
pure Float
x
{-# INLINE doubleStdUniform #-}
doubleStdUniform :: RVarT m Double
doubleStdUniform :: RVarT m Double
doubleStdUniform = do
Double
x <- (Double, Double) -> RVarT m Double
forall a (m :: * -> *). UniformRange a => (a, a) -> RVarT m a
uniformRangeRVarT (Double
0, Double
1)
if Double
x Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
1 then RVarT m Double
forall (m :: * -> *). RVarT m Double
doubleStdUniform else Double -> RVarT m Double
forall (f :: * -> *) a. Applicative f => a -> f a
pure Double
x
realFloatStdUniform :: RealFloat a => RVarT m a
realFloatStdUniform :: RVarT m a
realFloatStdUniform = do
let (Integer
b, Int
e) = a -> (Integer, Int)
forall a. RealFloat a => a -> (Integer, Int)
decodeFloat a
one
Integer
x <- Integer -> Integer -> RVarT m Integer
forall a (m :: * -> *).
Distribution Uniform a =>
a -> a -> RVarT m a
uniformT Integer
0 (Integer
bInteger -> Integer -> Integer
forall a. Num a => a -> a -> a
-Integer
1)
if Integer
x Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
0
then a -> RVarT m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a
0 a -> a -> a
forall a. a -> a -> a
`asTypeOf` a
one)
else a -> RVarT m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> Int -> a
forall a. RealFloat a => Integer -> Int -> a
encodeFloat Integer
x Int
e)
where one :: a
one = a
1
fixedStdUniform :: HasResolution r => RVarT m (Fixed r)
fixedStdUniform :: RVarT m (Fixed r)
fixedStdUniform = RVarT m (Fixed r)
forall (m :: * -> *). RVarT m (Fixed r)
x
where
res :: Integer
res = RVarT m (Fixed r) -> Integer
forall r (f :: * -> *) (g :: * -> *).
HasResolution r =>
f (g r) -> Integer
resolutionOf2 RVarT m (Fixed r)
x
x :: RVarT m (Fixed r)
x = do
Integer
u <- Integer -> Integer -> RVarT m Integer
forall a (m :: * -> *).
Distribution Uniform a =>
a -> a -> RVarT m a
uniformT Integer
0 (Integer
res)
Fixed r -> RVarT m (Fixed r)
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> Fixed r
forall r. Integer -> Fixed r
mkFixed Integer
u)
realStdUniformCDF :: Real a => a -> Double
realStdUniformCDF :: a -> Double
realStdUniformCDF a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 = Double
0
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
1 = Double
1
| Bool
otherwise = a -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac a
x
realStdUniformPDF :: Real a => a -> Double
realStdUniformPDF :: a -> Double
realStdUniformPDF a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
0 = Double
0
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
1 = Double
0
| Bool
otherwise = Double
1
lerp :: Num a => a -> a -> a -> a
lerp :: a -> a -> a -> a
lerp a
x a
y a
a = (a
1a -> a -> a
forall a. Num a => a -> a -> a
-a
a)a -> a -> a
forall a. Num a => a -> a -> a
*a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
y
floatUniform :: Float -> Float -> RVarT m Float
floatUniform :: Float -> Float -> RVarT m Float
floatUniform Float
0 Float
1 = RVarT m Float
forall (m :: * -> *). RVarT m Float
floatStdUniform
floatUniform Float
a Float
b = do
Float
x <- RVarT m Float
forall (m :: * -> *). RVarT m Float
floatStdUniform
Float -> RVarT m Float
forall (m :: * -> *) a. Monad m => a -> m a
return (Float -> Float -> Float -> Float
forall a. Num a => a -> a -> a -> a
lerp Float
a Float
b Float
x)
{-# INLINE doubleUniform #-}
doubleUniform :: Double -> Double -> RVarT m Double
doubleUniform :: Double -> Double -> RVarT m Double
doubleUniform Double
0 Double
1 = RVarT m Double
forall (m :: * -> *). RVarT m Double
doubleStdUniform
doubleUniform Double
a Double
b = do
Double
x <- RVarT m Double
forall (m :: * -> *). RVarT m Double
doubleStdUniform
Double -> RVarT m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> Double -> Double -> Double
forall a. Num a => a -> a -> a -> a
lerp Double
a Double
b Double
x)
realFloatUniform :: RealFloat a => a -> a -> RVarT m a
realFloatUniform :: a -> a -> RVarT m a
realFloatUniform a
0 a
1 = RVarT m a
forall a (m :: * -> *). RealFloat a => RVarT m a
realFloatStdUniform
realFloatUniform a
a a
b = do
a
x <- RVarT m a
forall a (m :: * -> *). RealFloat a => RVarT m a
realFloatStdUniform
a -> RVarT m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a -> a
forall a. Num a => a -> a -> a -> a
lerp a
a a
b a
x)
fixedUniform :: HasResolution r => Fixed r -> Fixed r -> RVarT m (Fixed r)
fixedUniform :: Fixed r -> Fixed r -> RVarT m (Fixed r)
fixedUniform Fixed r
a Fixed r
b = do
Integer
u <- Integer -> Integer -> RVarT m Integer
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform (Fixed r -> Integer
forall r. Fixed r -> Integer
unMkFixed Fixed r
a) (Fixed r -> Integer
forall r. Fixed r -> Integer
unMkFixed Fixed r
b)
Fixed r -> RVarT m (Fixed r)
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> Fixed r
forall r. Integer -> Fixed r
mkFixed Integer
u)
realUniformCDF :: RealFrac a => a -> a -> a -> Double
realUniformCDF :: a -> a -> a -> Double
realUniformCDF a
a a
b a
x
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
a = a -> a -> a -> Double
forall a. RealFrac a => a -> a -> a -> Double
realUniformCDF a
b a
a a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
a = Double
0
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
b = Double
1
| Bool
otherwise = a -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac ((a
xa -> a -> a
forall a. Num a => a -> a -> a
-a
a) a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
ba -> a -> a
forall a. Num a => a -> a -> a
-a
a))
enumUniform :: Enum a => a -> a -> RVarT m a
enumUniform :: a -> a -> RVarT m a
enumUniform a
a a
b = do
Int
x <- Int -> Int -> RVarT m Int
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform (a -> Int
forall a. Enum a => a -> Int
fromEnum a
a) (a -> Int
forall a. Enum a => a -> Int
fromEnum a
b)
a -> RVarT m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> a
forall a. Enum a => Int -> a
toEnum Int
x)
enumUniformCDF :: (Enum a, Ord a) => a -> a -> a -> Double
enumUniformCDF :: a -> a -> a -> Double
enumUniformCDF a
a a
b a
x
| a
b a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
a = a -> a -> a -> Double
forall a. (Enum a, Ord a) => a -> a -> a -> Double
enumUniformCDF a
b a
a a
x
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
a = Double
0
| a
x a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
b = Double
1
| Bool
otherwise = (a -> Double
e2f a
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- a -> Double
e2f a
a) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (a -> Double
e2f a
b Double -> Double -> Double
forall a. Num a => a -> a -> a
- a -> Double
e2f a
a)
where e2f :: a -> Double
e2f = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Double) -> (a -> Int) -> a -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Int
forall a. Enum a => a -> Int
fromEnum
uniform :: Distribution Uniform a => a -> a -> RVar a
uniform :: a -> a -> RVar a
uniform a
a a
b = Uniform a -> RVar a
forall (d :: * -> *) t. Distribution d t => d t -> RVar t
rvar (a -> a -> Uniform a
forall t. t -> t -> Uniform t
Uniform a
a a
b)
uniformT :: Distribution Uniform a => a -> a -> RVarT m a
uniformT :: a -> a -> RVarT m a
uniformT a
a a
b = Uniform a -> RVarT m a
forall (d :: * -> *) t (n :: * -> *).
Distribution d t =>
d t -> RVarT n t
rvarT (a -> a -> Uniform a
forall t. t -> t -> Uniform t
Uniform a
a a
b)
{-# SPECIALIZE stdUniform :: RVar Double #-}
{-# SPECIALIZE stdUniform :: RVar Float #-}
stdUniform :: (Distribution StdUniform a) => RVar a
stdUniform :: RVar a
stdUniform = StdUniform a -> RVar a
forall (d :: * -> *) t. Distribution d t => d t -> RVar t
rvar StdUniform a
forall t. StdUniform t
StdUniform
{-# SPECIALIZE stdUniformT :: RVarT m Double #-}
{-# SPECIALIZE stdUniformT :: RVarT m Float #-}
stdUniformT :: (Distribution StdUniform a) => RVarT m a
stdUniformT :: RVarT m a
stdUniformT = StdUniform a -> RVarT m a
forall (d :: * -> *) t (n :: * -> *).
Distribution d t =>
d t -> RVarT n t
rvarT StdUniform a
forall t. StdUniform t
StdUniform
stdUniformNonneg :: (Distribution StdUniform a, Num a, Eq a) => RVarT m a
stdUniformNonneg :: RVarT m a
stdUniformNonneg = (a -> a) -> RVarT m a -> RVarT m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
forall a. Num a => a -> a
abs RVarT m a
forall a (m :: * -> *). Distribution StdUniform a => RVarT m a
stdUniformT
stdUniformPos :: (Distribution StdUniform a, Num a, Eq a) => RVar a
stdUniformPos :: RVar a
stdUniformPos = RVar a
forall a (m :: * -> *).
(Distribution StdUniform a, Num a, Eq a) =>
RVarT m a
stdUniformPosT
stdUniformPosT :: (Distribution StdUniform a, Num a, Eq a) => RVarT m a
stdUniformPosT :: RVarT m a
stdUniformPosT = (a -> Bool) -> RVarT m a -> RVarT m a
forall (m :: * -> *) a. Monad m => (a -> Bool) -> m a -> m a
iterateUntil (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
0) RVarT m a
forall a (m :: * -> *).
(Distribution StdUniform a, Num a, Eq a) =>
RVarT m a
stdUniformNonneg
data Uniform t =
Uniform !t !t
data StdUniform t = StdUniform
instance Distribution Uniform Integer where rvarT :: Uniform Integer -> RVarT n Integer
rvarT (Uniform Integer
a Integer
b) = Integer -> Integer -> RVarT n Integer
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Integer
a Integer
b
instance CDF Uniform Integer where cdf :: Uniform Integer -> Integer -> Double
cdf (Uniform Integer
a Integer
b) = Integer -> Integer -> Integer -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Integer
a Integer
b
instance Distribution Uniform Int where rvarT :: Uniform Int -> RVarT n Int
rvarT (Uniform Int
a Int
b) = Int -> Int -> RVarT n Int
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Int
a Int
b
instance CDF Uniform Int where cdf :: Uniform Int -> Int -> Double
cdf (Uniform Int
a Int
b) = Int -> Int -> Int -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int
a Int
b
instance Distribution Uniform Int8 where rvarT :: Uniform Int8 -> RVarT n Int8
rvarT (Uniform Int8
a Int8
b) = Int8 -> Int8 -> RVarT n Int8
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Int8
a Int8
b
instance CDF Uniform Int8 where cdf :: Uniform Int8 -> Int8 -> Double
cdf (Uniform Int8
a Int8
b) = Int8 -> Int8 -> Int8 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int8
a Int8
b
instance Distribution Uniform Int16 where rvarT :: Uniform Int16 -> RVarT n Int16
rvarT (Uniform Int16
a Int16
b) = Int16 -> Int16 -> RVarT n Int16
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Int16
a Int16
b
instance CDF Uniform Int16 where cdf :: Uniform Int16 -> Int16 -> Double
cdf (Uniform Int16
a Int16
b) = Int16 -> Int16 -> Int16 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int16
a Int16
b
instance Distribution Uniform Int32 where rvarT :: Uniform Int32 -> RVarT n Int32
rvarT (Uniform Int32
a Int32
b) = Int32 -> Int32 -> RVarT n Int32
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Int32
a Int32
b
instance CDF Uniform Int32 where cdf :: Uniform Int32 -> Int32 -> Double
cdf (Uniform Int32
a Int32
b) = Int32 -> Int32 -> Int32 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int32
a Int32
b
instance Distribution Uniform Int64 where rvarT :: Uniform Int64 -> RVarT n Int64
rvarT (Uniform Int64
a Int64
b) = Int64 -> Int64 -> RVarT n Int64
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Int64
a Int64
b
instance CDF Uniform Int64 where cdf :: Uniform Int64 -> Int64 -> Double
cdf (Uniform Int64
a Int64
b) = Int64 -> Int64 -> Int64 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int64
a Int64
b
instance Distribution Uniform Word where rvarT :: Uniform Word -> RVarT n Word
rvarT (Uniform Word
a Word
b) = Word -> Word -> RVarT n Word
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Word
a Word
b
instance CDF Uniform Word where cdf :: Uniform Word -> Word -> Double
cdf (Uniform Word
a Word
b) = Word -> Word -> Word -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word
a Word
b
instance Distribution Uniform Word8 where rvarT :: Uniform Word8 -> RVarT n Word8
rvarT (Uniform Word8
a Word8
b) = Word8 -> Word8 -> RVarT n Word8
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Word8
a Word8
b
instance CDF Uniform Word8 where cdf :: Uniform Word8 -> Word8 -> Double
cdf (Uniform Word8
a Word8
b) = Word8 -> Word8 -> Word8 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word8
a Word8
b
instance Distribution Uniform Word16 where rvarT :: Uniform Word16 -> RVarT n Word16
rvarT (Uniform Word16
a Word16
b) = Word16 -> Word16 -> RVarT n Word16
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Word16
a Word16
b
instance CDF Uniform Word16 where cdf :: Uniform Word16 -> Word16 -> Double
cdf (Uniform Word16
a Word16
b) = Word16 -> Word16 -> Word16 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word16
a Word16
b
instance Distribution Uniform Word32 where rvarT :: Uniform Word32 -> RVarT n Word32
rvarT (Uniform Word32
a Word32
b) = Word32 -> Word32 -> RVarT n Word32
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Word32
a Word32
b
instance CDF Uniform Word32 where cdf :: Uniform Word32 -> Word32 -> Double
cdf (Uniform Word32
a Word32
b) = Word32 -> Word32 -> Word32 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word32
a Word32
b
instance Distribution Uniform Word64 where rvarT :: Uniform Word64 -> RVarT n Word64
rvarT (Uniform Word64
a Word64
b) = Word64 -> Word64 -> RVarT n Word64
forall a (m :: * -> *). UniformRange a => a -> a -> RVarT m a
integralUniform Word64
a Word64
b
instance CDF Uniform Word64 where cdf :: Uniform Word64 -> Word64 -> Double
cdf (Uniform Word64
a Word64
b) = Word64 -> Word64 -> Word64 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word64
a Word64
b
instance Distribution StdUniform Word8 where rvarT :: StdUniform Word8 -> RVarT n Word8
rvarT StdUniform Word8
_ = RGen -> RVarT n Word8
forall g (m :: * -> *). StatefulGen g m => g -> m Word8
Random.uniformWord8 RGen
RGen
instance Distribution StdUniform Word16 where rvarT :: StdUniform Word16 -> RVarT n Word16
rvarT StdUniform Word16
_ = RGen -> RVarT n Word16
forall g (m :: * -> *). StatefulGen g m => g -> m Word16
Random.uniformWord16 RGen
RGen
instance Distribution StdUniform Word32 where rvarT :: StdUniform Word32 -> RVarT n Word32
rvarT StdUniform Word32
_ = RGen -> RVarT n Word32
forall g (m :: * -> *). StatefulGen g m => g -> m Word32
Random.uniformWord32 RGen
RGen
instance Distribution StdUniform Word64 where rvarT :: StdUniform Word64 -> RVarT n Word64
rvarT StdUniform Word64
_ = RGen -> RVarT n Word64
forall g (m :: * -> *). StatefulGen g m => g -> m Word64
Random.uniformWord64 RGen
RGen
instance Distribution StdUniform Word where rvarT :: StdUniform Word -> RVarT n Word
rvarT StdUniform Word
_ = RVarT n Word
forall a (m :: * -> *). Uniform a => RVarT m a
uniformRVarT
instance Distribution StdUniform Int8 where rvarT :: StdUniform Int8 -> RVarT n Int8
rvarT StdUniform Int8
_ = RVarT n Int8
forall a (m :: * -> *). Uniform a => RVarT m a
uniformRVarT
instance Distribution StdUniform Int16 where rvarT :: StdUniform Int16 -> RVarT n Int16
rvarT StdUniform Int16
_ = RVarT n Int16
forall a (m :: * -> *). Uniform a => RVarT m a
uniformRVarT
instance Distribution StdUniform Int32 where rvarT :: StdUniform Int32 -> RVarT n Int32
rvarT StdUniform Int32
_ = RVarT n Int32
forall a (m :: * -> *). Uniform a => RVarT m a
uniformRVarT
instance Distribution StdUniform Int64 where rvarT :: StdUniform Int64 -> RVarT n Int64
rvarT StdUniform Int64
_ = RVarT n Int64
forall a (m :: * -> *). Uniform a => RVarT m a
uniformRVarT
instance Distribution StdUniform Int where rvarT :: StdUniform Int -> RVarT n Int
rvarT StdUniform Int
_ = RVarT n Int
forall a (m :: * -> *). Uniform a => RVarT m a
uniformRVarT
instance CDF StdUniform Word8 where cdf :: StdUniform Word8 -> Word8 -> Double
cdf StdUniform Word8
_ = Word8 -> Word8 -> Word8 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word8
forall a. Bounded a => a
minBound Word8
forall a. Bounded a => a
maxBound
instance CDF StdUniform Word16 where cdf :: StdUniform Word16 -> Word16 -> Double
cdf StdUniform Word16
_ = Word16 -> Word16 -> Word16 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word16
forall a. Bounded a => a
minBound Word16
forall a. Bounded a => a
maxBound
instance CDF StdUniform Word32 where cdf :: StdUniform Word32 -> Word32 -> Double
cdf StdUniform Word32
_ = Word32 -> Word32 -> Word32 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word32
forall a. Bounded a => a
minBound Word32
forall a. Bounded a => a
maxBound
instance CDF StdUniform Word64 where cdf :: StdUniform Word64 -> Word64 -> Double
cdf StdUniform Word64
_ = Word64 -> Word64 -> Word64 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word64
forall a. Bounded a => a
minBound Word64
forall a. Bounded a => a
maxBound
instance CDF StdUniform Word where cdf :: StdUniform Word -> Word -> Double
cdf StdUniform Word
_ = Word -> Word -> Word -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Word
forall a. Bounded a => a
minBound Word
forall a. Bounded a => a
maxBound
instance CDF StdUniform Int8 where cdf :: StdUniform Int8 -> Int8 -> Double
cdf StdUniform Int8
_ = Int8 -> Int8 -> Int8 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int8
forall a. Bounded a => a
minBound Int8
forall a. Bounded a => a
maxBound
instance CDF StdUniform Int16 where cdf :: StdUniform Int16 -> Int16 -> Double
cdf StdUniform Int16
_ = Int16 -> Int16 -> Int16 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int16
forall a. Bounded a => a
minBound Int16
forall a. Bounded a => a
maxBound
instance CDF StdUniform Int32 where cdf :: StdUniform Int32 -> Int32 -> Double
cdf StdUniform Int32
_ = Int32 -> Int32 -> Int32 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int32
forall a. Bounded a => a
minBound Int32
forall a. Bounded a => a
maxBound
instance CDF StdUniform Int64 where cdf :: StdUniform Int64 -> Int64 -> Double
cdf StdUniform Int64
_ = Int64 -> Int64 -> Int64 -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int64
forall a. Bounded a => a
minBound Int64
forall a. Bounded a => a
maxBound
instance CDF StdUniform Int where cdf :: StdUniform Int -> Int -> Double
cdf StdUniform Int
_ = Int -> Int -> Int -> Double
forall a b. (Integral a, Fractional b) => a -> a -> a -> b
integralUniformCDF Int
forall a. Bounded a => a
minBound Int
forall a. Bounded a => a
maxBound
instance Distribution Uniform Float where rvarT :: Uniform Float -> RVarT n Float
rvarT (Uniform Float
a Float
b) = Float -> Float -> RVarT n Float
forall (m :: * -> *). Float -> Float -> RVarT m Float
floatUniform Float
a Float
b
instance Distribution Uniform Double where rvarT :: Uniform Double -> RVarT n Double
rvarT (Uniform Double
a Double
b) = Double -> Double -> RVarT n Double
forall (m :: * -> *). Double -> Double -> RVarT m Double
doubleUniform Double
a Double
b
instance CDF Uniform Float where cdf :: Uniform Float -> Float -> Double
cdf (Uniform Float
a Float
b) = Float -> Float -> Float -> Double
forall a. RealFrac a => a -> a -> a -> Double
realUniformCDF Float
a Float
b
instance CDF Uniform Double where cdf :: Uniform Double -> Double -> Double
cdf (Uniform Double
a Double
b) = Double -> Double -> Double -> Double
forall a. RealFrac a => a -> a -> a -> Double
realUniformCDF Double
a Double
b
instance Distribution StdUniform Float where rvarT :: StdUniform Float -> RVarT n Float
rvarT StdUniform Float
_ = RVarT n Float
forall (m :: * -> *). RVarT m Float
floatStdUniform
instance Distribution StdUniform Double where rvarT :: StdUniform Double -> RVarT n Double
rvarT StdUniform Double
_ = (Double, Double) -> RVarT n Double
forall a (m :: * -> *). UniformRange a => (a, a) -> RVarT m a
uniformRangeRVarT (Double
0, Double
1)
instance CDF StdUniform Float where cdf :: StdUniform Float -> Float -> Double
cdf StdUniform Float
_ = Float -> Double
forall a. Real a => a -> Double
realStdUniformCDF
instance CDF StdUniform Double where cdf :: StdUniform Double -> Double -> Double
cdf StdUniform Double
_ = Double -> Double
forall a. Real a => a -> Double
realStdUniformCDF
instance PDF StdUniform Float where pdf :: StdUniform Float -> Float -> Double
pdf StdUniform Float
_ = Float -> Double
forall a. Real a => a -> Double
realStdUniformPDF
instance PDF StdUniform Double where pdf :: StdUniform Double -> Double -> Double
pdf StdUniform Double
_ = Double -> Double
forall a. Real a => a -> Double
realStdUniformPDF
instance HasResolution r =>
Distribution Uniform (Fixed r) where rvarT :: Uniform (Fixed r) -> RVarT n (Fixed r)
rvarT (Uniform Fixed r
a Fixed r
b) = Fixed r -> Fixed r -> RVarT n (Fixed r)
forall r (m :: * -> *).
HasResolution r =>
Fixed r -> Fixed r -> RVarT m (Fixed r)
fixedUniform Fixed r
a Fixed r
b
instance HasResolution r =>
CDF Uniform (Fixed r) where cdf :: Uniform (Fixed r) -> Fixed r -> Double
cdf (Uniform Fixed r
a Fixed r
b) = Fixed r -> Fixed r -> Fixed r -> Double
forall a. RealFrac a => a -> a -> a -> Double
realUniformCDF Fixed r
a Fixed r
b
instance HasResolution r =>
Distribution StdUniform (Fixed r) where rvarT :: StdUniform (Fixed r) -> RVarT n (Fixed r)
rvarT ~StdUniform (Fixed r)
StdUniform = RVarT n (Fixed r)
forall r (m :: * -> *). HasResolution r => RVarT m (Fixed r)
fixedStdUniform
instance HasResolution r =>
CDF StdUniform (Fixed r) where cdf :: StdUniform (Fixed r) -> Fixed r -> Double
cdf ~StdUniform (Fixed r)
StdUniform = Fixed r -> Double
forall a. Real a => a -> Double
realStdUniformCDF
instance Distribution Uniform () where rvarT :: Uniform () -> RVarT n ()
rvarT (Uniform ()
_ ()
_) = () -> RVarT n ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
instance CDF Uniform () where cdf :: Uniform () -> () -> Double
cdf (Uniform ()
_ ()
_) = Double -> () -> Double
forall (m :: * -> *) a. Monad m => a -> m a
return Double
1
instance Distribution Uniform Char where rvarT :: Uniform Char -> RVarT n Char
rvarT (Uniform Char
a Char
b) = Char -> Char -> RVarT n Char
forall a (m :: * -> *). Enum a => a -> a -> RVarT m a
enumUniform Char
a Char
b
instance CDF Uniform Char where cdf :: Uniform Char -> Char -> Double
cdf (Uniform Char
a Char
b) = Char -> Char -> Char -> Double
forall a. (Enum a, Ord a) => a -> a -> a -> Double
enumUniformCDF Char
a Char
b
instance Distribution Uniform Bool where rvarT :: Uniform Bool -> RVarT n Bool
rvarT (Uniform Bool
a Bool
b) = Bool -> Bool -> RVarT n Bool
forall a (m :: * -> *). Enum a => a -> a -> RVarT m a
enumUniform Bool
a Bool
b
instance CDF Uniform Bool where cdf :: Uniform Bool -> Bool -> Double
cdf (Uniform Bool
a Bool
b) = Bool -> Bool -> Bool -> Double
forall a. (Enum a, Ord a) => a -> a -> a -> Double
enumUniformCDF Bool
a Bool
b
instance Distribution Uniform Ordering where rvarT :: Uniform Ordering -> RVarT n Ordering
rvarT (Uniform Ordering
a Ordering
b) = Ordering -> Ordering -> RVarT n Ordering
forall a (m :: * -> *). Enum a => a -> a -> RVarT m a
enumUniform Ordering
a Ordering
b
instance CDF Uniform Ordering where cdf :: Uniform Ordering -> Ordering -> Double
cdf (Uniform Ordering
a Ordering
b) = Ordering -> Ordering -> Ordering -> Double
forall a. (Enum a, Ord a) => a -> a -> a -> Double
enumUniformCDF Ordering
a Ordering
b
instance Distribution StdUniform () where rvarT :: StdUniform () -> RVarT n ()
rvarT ~StdUniform ()
StdUniform = () -> RVarT n ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
instance CDF StdUniform () where cdf :: StdUniform () -> () -> Double
cdf ~StdUniform ()
StdUniform = Double -> () -> Double
forall (m :: * -> *) a. Monad m => a -> m a
return Double
1
instance Distribution StdUniform Bool where rvarT :: StdUniform Bool -> RVarT n Bool
rvarT ~StdUniform Bool
StdUniform = RVarT n Bool
forall a (m :: * -> *). Uniform a => RVarT m a
uniformRVarT
instance CDF StdUniform Bool where cdf :: StdUniform Bool -> Bool -> Double
cdf ~StdUniform Bool
StdUniform = Bool -> Double
forall a. (Enum a, Bounded a, Ord a) => a -> Double
boundedEnumStdUniformCDF
instance Distribution StdUniform Char where rvarT :: StdUniform Char -> RVarT n Char
rvarT ~StdUniform Char
StdUniform = RVarT n Char
forall a (m :: * -> *). (Enum a, Bounded a) => RVarT m a
boundedEnumStdUniform
instance CDF StdUniform Char where cdf :: StdUniform Char -> Char -> Double
cdf ~StdUniform Char
StdUniform = Char -> Double
forall a. (Enum a, Bounded a, Ord a) => a -> Double
boundedEnumStdUniformCDF
instance Distribution StdUniform Ordering where rvarT :: StdUniform Ordering -> RVarT n Ordering
rvarT ~StdUniform Ordering
StdUniform = RVarT n Ordering
forall a (m :: * -> *). (Enum a, Bounded a) => RVarT m a
boundedEnumStdUniform
instance CDF StdUniform Ordering where cdf :: StdUniform Ordering -> Ordering -> Double
cdf ~StdUniform Ordering
StdUniform = Ordering -> Double
forall a. (Enum a, Bounded a, Ord a) => a -> Double
boundedEnumStdUniformCDF