-- |
-- Module     : Simulation.Aivika.Trans.Process.Random
-- Copyright  : Copyright (c) 2009-2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.1
--
-- This module defines helper functions, which are useful to hold 
-- the 'Process' computation for a time interval according to some
-- random distribution.
--

module Simulation.Aivika.Trans.Process.Random
       (randomUniformProcess,
        randomUniformProcess_,
        randomUniformIntProcess,
        randomUniformIntProcess_,
        randomTriangularProcess,
        randomTriangularProcess_,
        randomNormalProcess,
        randomNormalProcess_,
        randomLogNormalProcess,
        randomLogNormalProcess_,
        randomExponentialProcess,
        randomExponentialProcess_,
        randomErlangProcess,
        randomErlangProcess_,
        randomPoissonProcess,
        randomPoissonProcess_,
        randomBinomialProcess,
        randomBinomialProcess_,
        randomGammaProcess,
        randomGammaProcess_,
        randomBetaProcess,
        randomBetaProcess_,
        randomWeibullProcess,
        randomWeibullProcess_,
        randomDiscreteProcess,
        randomDiscreteProcess_) where

import Control.Monad
import Control.Monad.Trans

import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Generator
import Simulation.Aivika.Trans.Parameter
import Simulation.Aivika.Trans.Parameter.Random
import Simulation.Aivika.Trans.Process

-- | Hold the process for a random time interval distributed uniformly.
randomUniformProcess :: MonadDES m
                        => Double
                        -- ^ the minimum time interval
                        -> Double
                        -- ^ the maximum time interval
                        -> Process m Double
                        -- ^ a computation of the time interval
                        -- for which the process was actually held
{-# INLINABLE randomUniformProcess #-}
randomUniformProcess :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m Double
randomUniformProcess Double
min Double
max =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomUniform Double
min Double
max
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t

-- | Hold the process for a random time interval distributed uniformly.
randomUniformProcess_ :: MonadDES m
                         => Double
                         -- ^ the minimum time interval
                         -> Double
                         -- ^ the maximum time interval
                         -> Process m ()
{-# INLINABLE randomUniformProcess_ #-}
randomUniformProcess_ :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomUniformProcess_ Double
min Double
max =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomUniform Double
min Double
max
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t

-- | Hold the process for a random time interval distributed uniformly.
randomUniformIntProcess :: MonadDES m
                           => Int
                           -- ^ the minimum time interval
                           -> Int
                           -- ^ the maximum time interval
                           -> Process m Int
                           -- ^ a computation of the time interval
                           -- for which the process was actually held
{-# INLINABLE randomUniformIntProcess #-}
randomUniformIntProcess :: forall (m :: * -> *). MonadDES m => Int -> Int -> Process m Int
randomUniformIntProcess Int
min Int
max =
  do Int
t <- Parameter m Int -> Process m Int
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Int -> Process m Int)
-> Parameter m Int -> Process m Int
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Parameter m Int
forall (m :: * -> *). MonadComp m => Int -> Int -> Parameter m Int
randomUniformInt Int
min Int
max
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess (Double -> Process m ()) -> Double -> Process m ()
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
t
     Int -> Process m Int
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
t

-- | Hold the process for a random time interval distributed uniformly.
randomUniformIntProcess_ :: MonadDES m
                            => Int
                            -- ^ the minimum time interval
                            -> Int
                            -- ^ the maximum time interval
                            -> Process m ()
{-# INLINABLE randomUniformIntProcess_ #-}
randomUniformIntProcess_ :: forall (m :: * -> *). MonadDES m => Int -> Int -> Process m ()
randomUniformIntProcess_ Int
min Int
max =
  do Int
t <- Parameter m Int -> Process m Int
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Int -> Process m Int)
-> Parameter m Int -> Process m Int
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Parameter m Int
forall (m :: * -> *). MonadComp m => Int -> Int -> Parameter m Int
randomUniformInt Int
min Int
max
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess (Double -> Process m ()) -> Double -> Process m ()
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
t

-- | Hold the process for a random time interval having the triangular distribution.
randomTriangularProcess :: MonadDES m
                           => Double
                           -- ^ the minimum time interval
                           -> Double
                           -- ^ a median of the time interval
                           -> Double
                           -- ^ the maximum time interval
                           -> Process m Double
                           -- ^ a computation of the time interval
                           -- for which the process was actually held
{-# INLINABLE randomTriangularProcess #-}
randomTriangularProcess :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Double -> Process m Double
randomTriangularProcess Double
min Double
median Double
max =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Double -> Parameter m Double
randomTriangular Double
min Double
median Double
max
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t

-- | Hold the process for a random time interval having the triangular distribution.
randomTriangularProcess_ :: MonadDES m
                            => Double
                            -- ^ the minimum time interval
                            -> Double
                            -- ^ a median of the time interval
                            -> Double
                            -- ^ the maximum time interval
                            -> Process m ()
{-# INLINABLE randomTriangularProcess_ #-}
randomTriangularProcess_ :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Double -> Process m ()
randomTriangularProcess_ Double
min Double
median Double
max =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Double -> Parameter m Double
randomTriangular Double
min Double
median Double
max
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t

-- | Hold the process for a random time interval distributed normally.
randomNormalProcess :: MonadDES m
                       => Double
                       -- ^ the mean time interval
                       -> Double
                       -- ^ the time interval deviation
                       -> Process m Double
                       -- ^ a computation of the time interval
                       -- for which the process was actually held
{-# INLINABLE randomNormalProcess #-}
randomNormalProcess :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m Double
randomNormalProcess Double
mu Double
nu =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomNormal Double
mu Double
nu
     Bool -> Process m () -> Process m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Double
t Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
0) (Process m () -> Process m ()) -> Process m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t
         
-- | Hold the process for a random time interval distributed normally.
randomNormalProcess_ :: MonadDES m
                        => Double
                        -- ^ the mean time interval
                        -> Double
                        -- ^ the time interval deviation
                        -> Process m ()
{-# INLINABLE randomNormalProcess_ #-}
randomNormalProcess_ :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomNormalProcess_ Double
mu Double
nu =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomNormal Double
mu Double
nu
     Bool -> Process m () -> Process m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Double
t Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
0) (Process m () -> Process m ()) -> Process m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t

-- | Hold the process for a random time interval having the lognormal distribution.
randomLogNormalProcess :: MonadDES m
                          => Double
                          -- ^ the mean for a normal distribution
                          -- which this distribution is derived from
                          -> Double
                          -- ^ the deviation for a normal distribution
                          -- which this distribution is derived from
                          -> Process m Double
                          -- ^ a computation of the time interval
                          -- for which the process was actually held
{-# INLINABLE randomLogNormalProcess #-}
randomLogNormalProcess :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m Double
randomLogNormalProcess Double
mu Double
nu =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomLogNormal Double
mu Double
nu
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t

-- | Hold the process for a random time interval having the lognormal distribution.
randomLogNormalProcess_ :: MonadDES m
                           => Double
                           -- ^ the mean for a normal distribution
                           -- which this distribution is derived from
                           -> Double
                           -- ^ the deviation for a normal distribution
                           -- which this distribution is derived from
                           -> Process m ()
{-# INLINABLE randomLogNormalProcess_ #-}
randomLogNormalProcess_ :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomLogNormalProcess_ Double
mu Double
nu =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomLogNormal Double
mu Double
nu
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
         
-- | Hold the process for a random time interval distributed exponentially
-- with the specified mean (the reciprocal of the rate).
randomExponentialProcess :: MonadDES m
                            => Double
                            -- ^ the mean time interval (the reciprocal of the rate)
                            -> Process m Double
                            -- ^ a computation of the time interval
                            -- for which the process was actually held
{-# INLINABLE randomExponentialProcess #-}
randomExponentialProcess :: forall (m :: * -> *). MonadDES m => Double -> Process m Double
randomExponentialProcess Double
mu =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Parameter m Double
forall (m :: * -> *). MonadComp m => Double -> Parameter m Double
randomExponential Double
mu
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t
         
-- | Hold the process for a random time interval distributed exponentially
-- with the specified mean (the reciprocal of the rate).
randomExponentialProcess_ :: MonadDES m
                             => Double
                             -- ^ the mean time interval (the reciprocal of the rate)
                             -> Process m ()
{-# INLINABLE randomExponentialProcess_ #-}
randomExponentialProcess_ :: forall (m :: * -> *). MonadDES m => Double -> Process m ()
randomExponentialProcess_ Double
mu =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Parameter m Double
forall (m :: * -> *). MonadComp m => Double -> Parameter m Double
randomExponential Double
mu
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
         
-- | Hold the process for a random time interval having the Erlang distribution with
-- the specified scale (the reciprocal of the rate) and shape parameters.
randomErlangProcess :: MonadDES m
                       => Double
                       -- ^ the scale (the reciprocal of the rate)
                       -> Int
                       -- ^ the shape
                       -> Process m Double
                       -- ^ a computation of the time interval
                       -- for which the process was actually held
{-# INLINABLE randomErlangProcess #-}
randomErlangProcess :: forall (m :: * -> *).
MonadDES m =>
Double -> Int -> Process m Double
randomErlangProcess Double
beta Int
m =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Int -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Int -> Parameter m Double
randomErlang Double
beta Int
m
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t

-- | Hold the process for a random time interval having the Erlang distribution with
-- the specified scale (the reciprocal of the rate) and shape parameters.
randomErlangProcess_ :: MonadDES m
                        => Double
                        -- ^ the scale (the reciprocal of the rate)
                        -> Int
                        -- ^ the shape
                        -> Process m ()
{-# INLINABLE randomErlangProcess_ #-}
randomErlangProcess_ :: forall (m :: * -> *). MonadDES m => Double -> Int -> Process m ()
randomErlangProcess_ Double
beta Int
m =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Int -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Int -> Parameter m Double
randomErlang Double
beta Int
m
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t

-- | Hold the process for a random time interval having the Poisson distribution with
-- the specified mean.
randomPoissonProcess :: MonadDES m
                        => Double
                        -- ^ the mean time interval
                        -> Process m Int
                        -- ^ a computation of the time interval
                        -- for which the process was actually held
{-# INLINABLE randomPoissonProcess #-}
randomPoissonProcess :: forall (m :: * -> *). MonadDES m => Double -> Process m Int
randomPoissonProcess Double
mu =
  do Int
t <- Parameter m Int -> Process m Int
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Int -> Process m Int)
-> Parameter m Int -> Process m Int
forall a b. (a -> b) -> a -> b
$ Double -> Parameter m Int
forall (m :: * -> *). MonadComp m => Double -> Parameter m Int
randomPoisson Double
mu
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess (Double -> Process m ()) -> Double -> Process m ()
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
t
     Int -> Process m Int
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
t

-- | Hold the process for a random time interval having the Poisson distribution with
-- the specified mean.
randomPoissonProcess_ :: MonadDES m
                         => Double
                         -- ^ the mean time interval
                         -> Process m ()
{-# INLINABLE randomPoissonProcess_ #-}
randomPoissonProcess_ :: forall (m :: * -> *). MonadDES m => Double -> Process m ()
randomPoissonProcess_ Double
mu =
  do Int
t <- Parameter m Int -> Process m Int
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Int -> Process m Int)
-> Parameter m Int -> Process m Int
forall a b. (a -> b) -> a -> b
$ Double -> Parameter m Int
forall (m :: * -> *). MonadComp m => Double -> Parameter m Int
randomPoisson Double
mu
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess (Double -> Process m ()) -> Double -> Process m ()
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
t

-- | Hold the process for a random time interval having the binomial distribution
-- with the specified probability and trials.
randomBinomialProcess :: MonadDES m
                         => Double
                         -- ^ the probability
                         -> Int
                         -- ^ the number of trials
                         -> Process m Int
                         -- ^ a computation of the time interval
                         -- for which the process was actually held
{-# INLINABLE randomBinomialProcess #-}
randomBinomialProcess :: forall (m :: * -> *). MonadDES m => Double -> Int -> Process m Int
randomBinomialProcess Double
prob Int
trials =
  do Int
t <- Parameter m Int -> Process m Int
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Int -> Process m Int)
-> Parameter m Int -> Process m Int
forall a b. (a -> b) -> a -> b
$ Double -> Int -> Parameter m Int
forall (m :: * -> *).
MonadComp m =>
Double -> Int -> Parameter m Int
randomBinomial Double
prob Int
trials
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess (Double -> Process m ()) -> Double -> Process m ()
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
t
     Int -> Process m Int
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Int
t

-- | Hold the process for a random time interval having the binomial distribution
-- with the specified probability and trials.
randomBinomialProcess_ :: MonadDES m
                          =>Double
                          -- ^ the probability
                          -> Int
                          -- ^ the number of trials
                          -> Process m ()
{-# INLINABLE randomBinomialProcess_ #-}
randomBinomialProcess_ :: forall (m :: * -> *). MonadDES m => Double -> Int -> Process m ()
randomBinomialProcess_ Double
prob Int
trials =
  do Int
t <- Parameter m Int -> Process m Int
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Int -> Process m Int)
-> Parameter m Int -> Process m Int
forall a b. (a -> b) -> a -> b
$ Double -> Int -> Parameter m Int
forall (m :: * -> *).
MonadComp m =>
Double -> Int -> Parameter m Int
randomBinomial Double
prob Int
trials
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess (Double -> Process m ()) -> Double -> Process m ()
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
t

-- | Hold the process for a random time interval having the Gamma distribution
-- with the specified shape and scale.
randomGammaProcess :: MonadDES m
                      => Double
                      -- ^ the shape
                      -> Double
                      -- ^ the scale (a reciprocal of the rate)
                      -> Process m Double
                      -- ^ a computation of the time interval
                      -- for which the process was actually held
{-# INLINABLE randomGammaProcess #-}
randomGammaProcess :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m Double
randomGammaProcess Double
kappa Double
theta =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomGamma Double
kappa Double
theta
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t

-- | Hold the process for a random time interval having the Gamma distribution
-- with the specified shape and scale.
randomGammaProcess_ :: MonadDES m
                       => Double
                       -- ^ the shape
                       -> Double
                       -- ^ the scale (a reciprocal of the rate)
                       -> Process m ()
{-# INLINABLE randomGammaProcess_ #-}
randomGammaProcess_ :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomGammaProcess_ Double
kappa Double
theta =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomGamma Double
kappa Double
theta
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t

-- | Hold the process for a random time interval having the Beta distribution
-- with the specified shape parameters (alpha and beta).
randomBetaProcess :: MonadDES m
                     => Double
                     -- ^ the shape (alpha)
                     -> Double
                     -- ^ the shape (beta)
                     -> Process m Double
                     -- ^ a computation of the time interval
                     -- for which the process was actually held
{-# INLINABLE randomBetaProcess #-}
randomBetaProcess :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m Double
randomBetaProcess Double
alpha Double
beta =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomBeta Double
alpha Double
beta
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t

-- | Hold the process for a random time interval having the Beta distribution
-- with the specified shape parameters (alpha and beta).
randomBetaProcess_ :: MonadDES m
                      => Double
                      -- ^ the shape (alpha)
                      -> Double
                      -- ^ the shape (beta)
                      -> Process m ()
{-# INLINABLE randomBetaProcess_ #-}
randomBetaProcess_ :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomBetaProcess_ Double
alpha Double
beta =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomBeta Double
alpha Double
beta
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t

-- | Hold the process for a random time interval having the Weibull distribution
-- with the specified shape and scale.
randomWeibullProcess :: MonadDES m
                        => Double
                        -- ^ the shape
                        -> Double
                        -- ^ the scale
                        -> Process m Double
                        -- ^ a computation of the time interval
                        -- for which the process was actually held
{-# INLINABLE randomWeibullProcess #-}
randomWeibullProcess :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m Double
randomWeibullProcess Double
alpha Double
beta =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomWeibull Double
alpha Double
beta
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t

-- | Hold the process for a random time interval having the Weibull distribution
-- with the specified shape and scale.
randomWeibullProcess_ :: MonadDES m
                         => Double
                         -- ^ the shape
                         -> Double
                         -- ^ the scale
                         -> Process m ()
{-# INLINABLE randomWeibullProcess_ #-}
randomWeibullProcess_ :: forall (m :: * -> *).
MonadDES m =>
Double -> Double -> Process m ()
randomWeibullProcess_ Double
alpha Double
beta =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Parameter m Double
forall (m :: * -> *).
MonadComp m =>
Double -> Double -> Parameter m Double
randomWeibull Double
alpha Double
beta
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t

-- | Hold the process for a random time interval having the specified discrete distribution.
randomDiscreteProcess :: MonadDES m
                         => DiscretePDF Double
                         -- ^ the discrete probability density function
                         -> Process m Double
                         -- ^ a computation of the time interval
                         -- for which the process was actually held
{-# INLINABLE randomDiscreteProcess #-}
randomDiscreteProcess :: forall (m :: * -> *).
MonadDES m =>
DiscretePDF Double -> Process m Double
randomDiscreteProcess DiscretePDF Double
dpdf =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ DiscretePDF Double -> Parameter m Double
forall (m :: * -> *) a.
MonadComp m =>
DiscretePDF a -> Parameter m a
randomDiscrete DiscretePDF Double
dpdf
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t
     Double -> Process m Double
forall a. a -> Process m a
forall (m :: * -> *) a. Monad m => a -> m a
return Double
t

-- | Hold the process for a random time interval having the specified discrete distribution.
randomDiscreteProcess_ :: MonadDES m
                          => DiscretePDF Double
                          -- ^ the discrete probability density function
                          -> Process m ()
{-# INLINABLE randomDiscreteProcess_ #-}
randomDiscreteProcess_ :: forall (m :: * -> *).
MonadDES m =>
DiscretePDF Double -> Process m ()
randomDiscreteProcess_ DiscretePDF Double
dpdf =
  do Double
t <- Parameter m Double -> Process m Double
forall a. Parameter m a -> Process m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter (Parameter m Double -> Process m Double)
-> Parameter m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ DiscretePDF Double -> Parameter m Double
forall (m :: * -> *) a.
MonadComp m =>
DiscretePDF a -> Parameter m a
randomDiscrete DiscretePDF Double
dpdf
     Double -> Process m ()
forall (m :: * -> *). MonadDES m => Double -> Process m ()
holdProcess Double
t