-- |
-- Module     : Simulation.Aivika.Net.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 network computations that
-- hold the current process for the corresponding time interval,
-- when processing every input element.
--

module Simulation.Aivika.Net.Random
       (randomUniformNet,
        randomUniformIntNet,
        randomTriangularNet,
        randomNormalNet,
        randomLogNormalNet,
        randomExponentialNet,
        randomErlangNet,
        randomPoissonNet,
        randomBinomialNet,
        randomGammaNet,
        randomBetaNet,
        randomWeibullNet,
        randomDiscreteNet) where

import Simulation.Aivika.Generator
import Simulation.Aivika.Process
import Simulation.Aivika.Process.Random
import Simulation.Aivika.Net

-- | When processing every input element, hold the process
-- for a random time interval distributed uniformly.
randomUniformNet :: Double
                    -- ^ the minimum time interval
                    -> Double
                    -- ^ the maximum time interval
                    -> Net a a
randomUniformNet :: forall a. Double -> Double -> Net a a
randomUniformNet Double
min Double
max =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomUniformIntNet :: Int
                       -- ^ the minimum time interval
                       -> Int
                       -- ^ the maximum time interval
                       -> Net a a
randomUniformIntNet :: forall a. Int -> Int -> Net a a
randomUniformIntNet Int
min Int
max =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomTriangularNet :: Double
                       -- ^ the minimum time interval
                       -> Double
                       -- ^ the median of the time interval
                       -> Double
                       -- ^ the maximum time interval
                       -> Net a a
randomTriangularNet :: forall a. Double -> Double -> Double -> Net a a
randomTriangularNet Double
min Double
median Double
max =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomNormalNet :: Double
                   -- ^ the mean time interval
                   -> Double
                   -- ^ the time interval deviation
                   -> Net a a
randomNormalNet :: forall a. Double -> Double -> Net a a
randomNormalNet Double
mu Double
nu =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomLogNormalNet :: Double
                      -- ^ the mean of a normal distribution which
                      -- this distribution is derived from
                      -> Double
                      -- ^ the deviation of a normal distribution which
                      -- this distribution is derived from
                      -> Net a a
randomLogNormalNet :: forall a. Double -> Double -> Net a a
randomLogNormalNet Double
mu Double
nu =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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).
randomExponentialNet :: Double
                        -- ^ the mean time interval (the reciprocal of the rate)
                        -> Net a a
randomExponentialNet :: forall a. Double -> Net a a
randomExponentialNet Double
mu =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomErlangNet :: Double
                   -- ^ the scale (the reciprocal of the rate)
                   -> Int
                   -- ^ the shape
                   -> Net a a
randomErlangNet :: forall a. Double -> Int -> Net a a
randomErlangNet Double
beta Int
m =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomPoissonNet :: Double
                    -- ^ the mean time interval
                    -> Net a a
randomPoissonNet :: forall a. Double -> Net a a
randomPoissonNet Double
mu =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomBinomialNet :: Double
                     -- ^ the probability
                     -> Int
                     -- ^ the number of trials
                     -> Net a a
randomBinomialNet :: forall a. Double -> Int -> Net a a
randomBinomialNet Double
prob Int
trials =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomGammaNet :: Double
                  -- ^ the shape
                  -> Double
                  -- ^ the scale (a reciprocal of the rate)
                  -> Net a a
randomGammaNet :: forall a. Double -> Double -> Net a a
randomGammaNet Double
kappa Double
theta =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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).
randomBetaNet :: Double
                 -- ^ shape (alpha)
                 -> Double
                 -- ^ shape (beta)
                 -> Net a a
randomBetaNet :: forall a. Double -> Double -> Net a a
randomBetaNet Double
alpha Double
beta =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomWeibullNet :: Double
                    -- ^ shape
                    -> Double
                    -- ^ scale
                    -> Net a a
randomWeibullNet :: forall a. Double -> Double -> Net a a
randomWeibullNet Double
alpha Double
beta =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net 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.
randomDiscreteNet :: DiscretePDF Double
                     -- ^ the discrete probability density function
                     -> Net a a
randomDiscreteNet :: forall a. DiscretePDF Double -> Net a a
randomDiscreteNet DiscretePDF Double
dpdf =
  Process () -> Net a a
forall a. Process () -> Net a a
withinNet (Process () -> Net a a) -> Process () -> Net a a
forall a b. (a -> b) -> a -> b
$
  DiscretePDF Double -> Process ()
randomDiscreteProcess_ DiscretePDF Double
dpdf