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