-- |
-- Module     : Simulation.Aivika.Processor.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 some useful random processors that
-- hold the current process for the corresponding time interval,
-- when processing every input element.
--

module Simulation.Aivika.Processor.Random
       (randomUniformProcessor,
        randomUniformIntProcessor,
        randomTriangularProcessor,
        randomNormalProcessor,
        randomLogNormalProcessor,
        randomExponentialProcessor,
        randomErlangProcessor,
        randomPoissonProcessor,
        randomBinomialProcessor,
        randomGammaProcessor,
        randomBetaProcessor,
        randomWeibullProcessor,
        randomDiscreteProcessor) where

import Simulation.Aivika.Generator
import Simulation.Aivika.Process
import Simulation.Aivika.Process.Random
import Simulation.Aivika.Processor

-- | When processing every input element, hold the process
-- for a random time interval distributed uniformly.
randomUniformProcessor :: Double
                          -- ^ the minimum time interval
                          -> Double
                          -- ^ the maximum time interval
                          -> Processor a a
randomUniformProcessor :: Double -> Double -> Processor a a
randomUniformProcessor Double
min Double
max =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process ()
randomUniformProcess_ Double
min Double
max

-- | When processing every input element, hold the process
-- for a random time interval distributed uniformly.
randomUniformIntProcessor :: Int
                             -- ^ the minimum time interval
                             -> Int
                             -- ^ the maximum time interval
                             -> Processor a a
randomUniformIntProcessor :: Int -> Int -> Processor a a
randomUniformIntProcessor Int
min Int
max =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Int -> Int -> Process ()
randomUniformIntProcess_ Int
min Int
max

-- | When processing every input element, hold the process
-- for a random time interval having the triangular distribution.
randomTriangularProcessor :: Double
                             -- ^ the minimum time interval
                             -> Double
                             -- ^ the median of the time interval
                             -> Double
                             -- ^ the maximum time interval
                             -> Processor a a
randomTriangularProcessor :: Double -> Double -> Double -> Processor a a
randomTriangularProcessor Double
min Double
median Double
max =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Double -> Process ()
randomTriangularProcess_ Double
min Double
median Double
max

-- | When processing every input element, hold the process
-- for a random time interval distributed normally.
randomNormalProcessor :: Double
                         -- ^ the mean time interval
                         -> Double
                         -- ^ the time interval deviation
                         -> Processor a a
randomNormalProcessor :: Double -> Double -> Processor a a
randomNormalProcessor Double
mu Double
nu =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process ()
randomNormalProcess_ Double
mu Double
nu
         
-- | When processing every input element, hold the process
-- for a random time interval having the lognormal distribution.
randomLogNormalProcessor :: 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
                            -> Processor a a
randomLogNormalProcessor :: Double -> Double -> Processor a a
randomLogNormalProcessor Double
mu Double
nu =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process ()
randomLogNormalProcess_ Double
mu Double
nu

-- | When processing every input element, hold the process
-- for a random time interval distributed exponentially
-- with the specified mean (the reciprocal of the rate).
randomExponentialProcessor :: Double
                              -- ^ the mean time interval (the reciprocal of the rate)
                              -> Processor a a
randomExponentialProcessor :: Double -> Processor a a
randomExponentialProcessor Double
mu =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Process ()
randomExponentialProcess_ Double
mu
         
-- | When processing every input element, hold the process
-- for a random time interval having the Erlang distribution with
-- the specified scale (the reciprocal of the rate) and shape parameters.
randomErlangProcessor :: Double
                         -- ^ the scale (the reciprocal of the rate)
                         -> Int
                         -- ^ the shape
                         -> Processor a a
randomErlangProcessor :: Double -> Int -> Processor a a
randomErlangProcessor Double
beta Int
m =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Int -> Process ()
randomErlangProcess_ Double
beta Int
m

-- | When processing every input element, hold the process
-- for a random time interval having the Poisson distribution
-- with the specified mean.
randomPoissonProcessor :: Double
                          -- ^ the mean time interval
                          -> Processor a a
randomPoissonProcessor :: Double -> Processor a a
randomPoissonProcessor Double
mu =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Process ()
randomPoissonProcess_ Double
mu

-- | When processing every input element, hold the process
-- for a random time interval having the binomial distribution
-- with the specified probability and trials.
randomBinomialProcessor :: Double
                           -- ^ the probability
                           -> Int
                           -- ^ the number of trials
                           -> Processor a a
randomBinomialProcessor :: Double -> Int -> Processor a a
randomBinomialProcessor Double
prob Int
trials =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Int -> Process ()
randomBinomialProcess_ Double
prob Int
trials

-- | When processing every input element, hold the process
-- for a random time interval having the Gamma distribution
-- with the specified shape and scale.
randomGammaProcessor :: Double
                        -- ^ the shape
                        -> Double
                        -- ^ the scale (a reciprocal of the rate)
                        -> Processor a a
randomGammaProcessor :: Double -> Double -> Processor a a
randomGammaProcessor Double
kappa Double
theta =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process ()
randomGammaProcess_ Double
kappa Double
theta

-- | When processing every input element, hold the process
-- for a random time interval having the Beta distribution
-- with the specified shape parameters (alpha and beta).
randomBetaProcessor :: Double
                       -- ^ shape (alpha)
                       -> Double
                       -- ^ shape (beta)
                       -> Processor a a
randomBetaProcessor :: Double -> Double -> Processor a a
randomBetaProcessor Double
alpha Double
beta =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process ()
randomBetaProcess_ Double
alpha Double
beta

-- | When processing every input element, hold the process
-- for a random time interval having the Weibull distribution
-- with the specified shape and scale.
randomWeibullProcessor :: Double
                          -- ^ shape
                          -> Double
                          -- ^ scale
                          -> Processor a a
randomWeibullProcessor :: Double -> Double -> Processor a a
randomWeibullProcessor Double
alpha Double
beta =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  Double -> Double -> Process ()
randomWeibullProcess_ Double
alpha Double
beta

-- | When processing every input element, hold the process
-- for a random time interval having the specified discrete distribution.
randomDiscreteProcessor :: DiscretePDF Double
                           -- ^ the discrete probability density function
                           -> Processor a a
randomDiscreteProcessor :: DiscretePDF Double -> Processor a a
randomDiscreteProcessor DiscretePDF Double
dpdf =
  Process () -> Processor a a
forall a. Process () -> Processor a a
withinProcessor (Process () -> Processor a a) -> Process () -> Processor a a
forall a b. (a -> b) -> a -> b
$
  DiscretePDF Double -> Process ()
randomDiscreteProcess_ DiscretePDF Double
dpdf