module Simulation.Aivika.Signal.Random
(
newRandomSignal,
newRandomUniformSignal,
newRandomUniformIntSignal,
newRandomTriangularSignal,
newRandomNormalSignal,
newRandomLogNormalSignal,
newRandomExponentialSignal,
newRandomErlangSignal,
newRandomPoissonSignal,
newRandomBinomialSignal,
newRandomGammaSignal,
newRandomBetaSignal,
newRandomWeibullSignal,
newRandomDiscreteSignal) where
import Control.Monad
import Control.Monad.Trans
import Simulation.Aivika.Generator
import Simulation.Aivika.Parameter
import Simulation.Aivika.Parameter.Random
import Simulation.Aivika.Simulation
import Simulation.Aivika.Dynamics
import Simulation.Aivika.Event
import Simulation.Aivika.Composite
import Simulation.Aivika.Process
import Simulation.Aivika.Signal
import Simulation.Aivika.Statistics
import Simulation.Aivika.Arrival
newRandomSignal :: Parameter (Double, a)
-> Composite (Signal (Arrival a))
newRandomSignal delay =
do source <- liftSimulation newSignalSource
let loop t0 =
do (delay, a) <- liftParameter delay
when (delay > 0) $
holdProcess delay
t2 <- liftDynamics time
let arrival = Arrival { arrivalValue = a,
arrivalTime = t2,
arrivalDelay =
case t0 of
Nothing -> Nothing
Just t0 -> Just delay }
liftEvent $
triggerSignal source arrival
loop (Just t2)
pid <- liftSimulation newProcessId
liftEvent $
runProcessUsingId pid $
loop Nothing
disposableComposite $
DisposableEvent $
cancelProcessWithId pid
return $ publishSignal source
newRandomUniformSignal :: Double
-> Double
-> Composite (Signal (Arrival Double))
newRandomUniformSignal min max =
newRandomSignal $
randomUniform min max >>= \x ->
return (x, x)
newRandomUniformIntSignal :: Int
-> Int
-> Composite (Signal (Arrival Int))
newRandomUniformIntSignal min max =
newRandomSignal $
randomUniformInt min max >>= \x ->
return (fromIntegral x, x)
newRandomTriangularSignal :: Double
-> Double
-> Double
-> Composite (Signal (Arrival Double))
newRandomTriangularSignal min median max =
newRandomSignal $
randomTriangular min median max >>= \x ->
return (x, x)
newRandomNormalSignal :: Double
-> Double
-> Composite (Signal (Arrival Double))
newRandomNormalSignal mu nu =
newRandomSignal $
randomNormal mu nu >>= \x ->
return (x, x)
newRandomLogNormalSignal :: Double
-> Double
-> Composite (Signal (Arrival Double))
newRandomLogNormalSignal mu nu =
newRandomSignal $
randomLogNormal mu nu >>= \x ->
return (x, x)
newRandomExponentialSignal :: Double
-> Composite (Signal (Arrival Double))
newRandomExponentialSignal mu =
newRandomSignal $
randomExponential mu >>= \x ->
return (x, x)
newRandomErlangSignal :: Double
-> Int
-> Composite (Signal (Arrival Double))
newRandomErlangSignal beta m =
newRandomSignal $
randomErlang beta m >>= \x ->
return (x, x)
newRandomPoissonSignal :: Double
-> Composite (Signal (Arrival Int))
newRandomPoissonSignal mu =
newRandomSignal $
randomPoisson mu >>= \x ->
return (fromIntegral x, x)
newRandomBinomialSignal :: Double
-> Int
-> Composite (Signal (Arrival Int))
newRandomBinomialSignal prob trials =
newRandomSignal $
randomBinomial prob trials >>= \x ->
return (fromIntegral x, x)
newRandomGammaSignal :: Double
-> Double
-> Composite (Signal (Arrival Double))
newRandomGammaSignal kappa theta =
newRandomSignal $
randomGamma kappa theta >>= \x ->
return (x, x)
newRandomBetaSignal :: Double
-> Double
-> Composite (Signal (Arrival Double))
newRandomBetaSignal alpha beta =
newRandomSignal $
randomBeta alpha beta >>= \x ->
return (x, x)
newRandomWeibullSignal :: Double
-> Double
-> Composite (Signal (Arrival Double))
newRandomWeibullSignal alpha beta =
newRandomSignal $
randomWeibull alpha beta >>= \x ->
return (x, x)
newRandomDiscreteSignal :: DiscretePDF Double
-> Composite (Signal (Arrival Double))
newRandomDiscreteSignal dpdf =
newRandomSignal $
randomDiscrete dpdf >>= \x ->
return (x, x)