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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Double -> m Double
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 =
(Run m -> m Int) -> Parameter m Int
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Int) -> Parameter m Int)
-> (Run m -> m Int) -> Parameter m Int
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Int -> Int -> m Int
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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Double -> Double -> m Double
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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Double -> m Double
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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Double -> m Double
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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> m Double
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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Int -> m Double
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 =
(Run m -> m Int) -> Parameter m Int
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Int) -> Parameter m Int)
-> (Run m -> m Int) -> Parameter m Int
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> m Int
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 =
(Run m -> m Int) -> Parameter m Int
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Int) -> Parameter m Int)
-> (Run m -> m Int) -> Parameter m Int
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Int -> m Int
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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Double -> m Double
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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Double -> m Double
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 =
(Run m -> m Double) -> Parameter m Double
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m Double) -> Parameter m Double)
-> (Run m -> m Double) -> Parameter m Double
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> Double -> Double -> m Double
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 =
(Run m -> m a) -> Parameter m a
forall (m :: * -> *) a. (Run m -> m a) -> Parameter m a
Parameter ((Run m -> m a) -> Parameter m a)
-> (Run m -> m a) -> Parameter m a
forall a b. (a -> b) -> a -> b
$ \Run m
r ->
let g :: Generator m
g = Run m -> Generator m
forall (m :: * -> *). Run m -> Generator m
runGenerator Run m
r
in Generator m -> DiscretePDF a -> m a
forall a. Generator m -> DiscretePDF a -> m a
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 <- Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomUniform Double
0 Double
1
Bool -> Parameter m Bool
forall a. a -> Parameter m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x Double -> Double -> Bool
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 <- Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomUniform Double
0 Double
1
Bool -> Parameter m Bool
forall a. a -> Parameter m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
p)