module Simulation.Aivika.Trans.Parameter.Random
(randomUniform,
randomUniformInt,
randomTriangular,
randomNormal,
randomLogNormal,
randomExponential,
randomErlang,
randomPoisson,
randomBinomial,
randomGamma,
randomBeta,
randomWeibull,
randomDiscrete,
randomTrue,
randomFalse) where
import Control.Monad.Trans
import Simulation.Aivika.Trans.Generator
import Simulation.Aivika.Trans.Comp
import Simulation.Aivika.Trans.Internal.Specs
import Simulation.Aivika.Trans.Internal.Parameter
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Dynamics.Memo.Unboxed
randomUniform :: MonadComp m
=> Double
-> Double
-> Parameter m Double
{-# INLINE randomUniform #-}
randomUniform :: forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomUniform Double
min Double
max =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Double -> m Double
generateUniform Generator m
g Double
min Double
max
randomUniformInt :: MonadComp m
=> Int
-> Int
-> Parameter m Int
{-# INLINE randomUniformInt #-}
randomUniformInt :: forall (m :: * -> *). MonadComp m => Int -> Int -> Parameter m Int
randomUniformInt Int
min Int
max =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Int -> Int -> m Int
generateUniformInt Generator m
g Int
min Int
max
randomTriangular :: MonadComp m
=> Double
-> Double
-> Double
-> Parameter m Double
{-# INLINE randomTriangular #-}
randomTriangular :: forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Double -> Parameter m Double
randomTriangular Double
min Double
median Double
max =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Double -> Double -> m Double
generateTriangular Generator m
g Double
min Double
median Double
max
randomNormal :: MonadComp m
=> Double
-> Double
-> Parameter m Double
{-# INLINE randomNormal #-}
randomNormal :: forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomNormal Double
mu Double
nu =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Double -> m Double
generateNormal Generator m
g Double
mu Double
nu
randomLogNormal :: MonadComp m
=> Double
-> Double
-> Parameter m Double
{-# INLINE randomLogNormal #-}
randomLogNormal :: forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomLogNormal Double
mu Double
nu =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Double -> m Double
generateLogNormal Generator m
g Double
mu Double
nu
randomExponential :: MonadComp m
=> Double
-> Parameter m Double
{-# INLINE randomExponential #-}
randomExponential :: forall (m :: * -> *). MonadComp m => Double -> Parameter m Double
randomExponential Double
mu =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> m Double
generateExponential Generator m
g Double
mu
randomErlang :: MonadComp m
=> Double
-> Int
-> Parameter m Double
{-# INLINE randomErlang #-}
randomErlang :: forall (m :: * -> *).
MonadComp m =>
Double -> Int -> Parameter m Double
randomErlang Double
beta Int
m =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Int -> m Double
generateErlang Generator m
g Double
beta Int
m
randomPoisson :: MonadComp m
=> Double
-> Parameter m Int
{-# INLINE randomPoisson #-}
randomPoisson :: forall (m :: * -> *). MonadComp m => Double -> Parameter m Int
randomPoisson Double
mu =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> m Int
generatePoisson Generator m
g Double
mu
randomBinomial :: MonadComp m
=> Double
-> Int
-> Parameter m Int
{-# INLINE randomBinomial #-}
randomBinomial :: forall (m :: * -> *).
MonadComp m =>
Double -> Int -> Parameter m Int
randomBinomial Double
prob Int
trials =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Int -> m Int
generateBinomial Generator m
g Double
prob Int
trials
randomGamma :: MonadComp m
=> Double
-> Double
-> Parameter m Double
{-# INLINE randomGamma #-}
randomGamma :: forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomGamma Double
kappa Double
theta =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Double -> m Double
generateGamma Generator m
g Double
kappa Double
theta
randomBeta :: MonadComp m
=> Double
-> Double
-> Parameter m Double
{-# INLINE randomBeta #-}
randomBeta :: forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomBeta Double
alpha Double
beta =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Double -> m Double
generateBeta Generator m
g Double
alpha Double
beta
randomWeibull :: MonadComp m
=> Double
-> Double
-> Parameter m Double
{-# INLINE randomWeibull #-}
randomWeibull :: forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomWeibull Double
alpha Double
beta =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *).
MonadGenerator m =>
Generator m -> Double -> Double -> m Double
generateWeibull Generator m
g Double
alpha Double
beta
randomDiscrete :: MonadComp m => DiscretePDF a -> Parameter m a
{-# INLINE randomDiscrete #-}
randomDiscrete :: forall (m :: * -> *) a.
MonadComp m =>
DiscretePDF a -> Parameter m a
randomDiscrete DiscretePDF a
dpdf =
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in forall (m :: * -> *) a.
MonadGenerator m =>
Generator m -> DiscretePDF a -> m a
generateDiscrete Generator m
g DiscretePDF a
dpdf
randomTrue :: MonadComp m
=> Double
-> Parameter m Bool
{-# INLINE randomTrue #-}
randomTrue :: forall (m :: * -> *). MonadComp m => Double -> Parameter m Bool
randomTrue Double
p =
do Double
x <- forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomUniform Double
0 Double
1
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x forall a. Ord a => a -> a -> Bool
<= Double
p)
randomFalse :: MonadComp m
=> Double
-> Parameter m Bool
{-# INLINE randomFalse #-}
randomFalse :: forall (m :: * -> *). MonadComp m => Double -> Parameter m Bool
randomFalse Double
p =
do Double
x <- forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomUniform Double
0 Double
1
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x forall a. Ord a => a -> a -> Bool
> Double
p)