-- |
-- Module     : Simulation.Aivika.Trans.Signal.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 random signals of events, which are useful
-- for describing the input of the model.
--

module Simulation.Aivika.Trans.Signal.Random
       (-- * Signal of Random Events
        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.Trans.DES
import Simulation.Aivika.Trans.Generator
import Simulation.Aivika.Trans.Parameter
import Simulation.Aivika.Trans.Parameter.Random
import Simulation.Aivika.Trans.Simulation
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Event
import Simulation.Aivika.Trans.Composite
import Simulation.Aivika.Trans.Process
import Simulation.Aivika.Trans.Signal
import Simulation.Aivika.Trans.Statistics
import Simulation.Aivika.Trans.Arrival

-- | Return a signal of random events that arrive with the specified delay.
newRandomSignal :: MonadDES m
                   => Parameter m (Double, a)
                   -- ^ compute a pair of the delay and event of type @a@
                   -> Composite m (Signal m (Arrival a))
                   -- ^ the computation that returns a signal emitting the delayed events
{-# INLINABLE newRandomSignal #-}
newRandomSignal :: Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal Parameter m (Double, a)
delay =
  do SignalSource m (Arrival a)
source <- Simulation m (SignalSource m (Arrival a))
-> Composite m (SignalSource m (Arrival a))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation Simulation m (SignalSource m (Arrival a))
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     let loop :: Maybe Double -> Process m b
loop Maybe Double
t0 =
           do (Double
delay, a
a) <- Parameter m (Double, a) -> Process m (Double, a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
ParameterLift t m =>
Parameter m a -> t m a
liftParameter Parameter m (Double, a)
delay
              Bool -> Process m () -> Process m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Double
delay 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
delay
              Double
t2 <- Dynamics m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
              let arrival :: Arrival a
arrival = Arrival :: forall a. a -> Double -> Maybe Double -> Arrival a
Arrival { arrivalValue :: a
arrivalValue = a
a,
                                      arrivalTime :: Double
arrivalTime  = Double
t2,
                                      arrivalDelay :: Maybe Double
arrivalDelay =
                                        case Maybe Double
t0 of
                                          Maybe Double
Nothing -> Maybe Double
forall a. Maybe a
Nothing
                                          Just t0 -> Double -> Maybe Double
forall a. a -> Maybe a
Just Double
delay }
              Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
                SignalSource m (Arrival a) -> Arrival a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal SignalSource m (Arrival a)
source Arrival a
arrival
              Maybe Double -> Process m b
loop (Double -> Maybe Double
forall a. a -> Maybe a
Just Double
t2)
     ProcessId m
pid <- Simulation m (ProcessId m) -> Composite m (ProcessId m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation Simulation m (ProcessId m)
forall (m :: * -> *). MonadDES m => Simulation m (ProcessId m)
newProcessId
     Event m () -> Composite m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Composite m ()) -> Event m () -> Composite m ()
forall a b. (a -> b) -> a -> b
$
       ProcessId m -> Process m () -> Event m ()
forall (m :: * -> *).
MonadDES m =>
ProcessId m -> Process m () -> Event m ()
runProcessUsingId ProcessId m
pid (Process m () -> Event m ()) -> Process m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Maybe Double -> Process m ()
forall b. Maybe Double -> Process m b
loop Maybe Double
forall a. Maybe a
Nothing
     DisposableEvent m -> Composite m ()
forall (m :: * -> *).
Monad m =>
DisposableEvent m -> Composite m ()
disposableComposite (DisposableEvent m -> Composite m ())
-> DisposableEvent m -> Composite m ()
forall a b. (a -> b) -> a -> b
$
       Event m () -> DisposableEvent m
forall (m :: * -> *). Event m () -> DisposableEvent m
DisposableEvent (Event m () -> DisposableEvent m)
-> Event m () -> DisposableEvent m
forall a b. (a -> b) -> a -> b
$
       ProcessId m -> Event m ()
forall (m :: * -> *). MonadDES m => ProcessId m -> Event m ()
cancelProcessWithId ProcessId m
pid
     Signal m (Arrival a) -> Composite m (Signal m (Arrival a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Signal m (Arrival a) -> Composite m (Signal m (Arrival a)))
-> Signal m (Arrival a) -> Composite m (Signal m (Arrival a))
forall a b. (a -> b) -> a -> b
$ SignalSource m (Arrival a) -> Signal m (Arrival a)
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal SignalSource m (Arrival a)
source

-- | Create a new signal with random delays distributed uniformly.
newRandomUniformSignal :: MonadDES m
                          => Double
                          -- ^ the minimum delay
                          -> Double
                          -- ^ the maximum delay
                          -> Composite m (Signal m (Arrival Double))
                          -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomUniformSignal #-}
newRandomUniformSignal :: Double -> Double -> Composite m (Signal m (Arrival Double))
newRandomUniformSignal Double
min Double
max =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)

-- | Create a new signal with integer random delays distributed uniformly.
newRandomUniformIntSignal :: MonadDES m
                             => Int
                             -- ^ the minimum delay
                             -> Int
                             -- ^ the maximum delay
                             -> Composite m (Signal m (Arrival Int))
                             -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomUniformIntSignal #-}
newRandomUniformIntSignal :: Int -> Int -> Composite m (Signal m (Arrival Int))
newRandomUniformIntSignal Int
min Int
max =
  Parameter m (Double, Int) -> Composite m (Signal m (Arrival Int))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Int) -> Composite m (Signal m (Arrival Int)))
-> Parameter m (Double, Int)
-> Composite m (Signal m (Arrival 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 Parameter m Int
-> (Int -> Parameter m (Double, Int)) -> Parameter m (Double, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x ->
  (Double, Int) -> Parameter m (Double, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x, Int
x)

-- | Create a new signal with random delays having the triangular distribution.
newRandomTriangularSignal :: MonadDES m
                             => Double
                             -- ^ the minimum delay
                             -> Double
                             -- ^ the median of the delay
                             -> Double
                             -- ^ the maximum delay
                             -> Composite m (Signal m (Arrival Double))
                             -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomTriangularSignal #-}
newRandomTriangularSignal :: Double
-> Double -> Double -> Composite m (Signal m (Arrival Double))
newRandomTriangularSignal Double
min Double
median Double
max =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)

-- | Create a new signal with random delays distributed normally.
newRandomNormalSignal :: MonadDES m
                         => Double
                         -- ^ the mean delay
                         -> Double
                         -- ^ the delay deviation
                         -> Composite m (Signal m (Arrival Double))
                         -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomNormalSignal #-}
newRandomNormalSignal :: Double -> Double -> Composite m (Signal m (Arrival Double))
newRandomNormalSignal Double
mu Double
nu =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)

-- | Create a new signal with random delays having the lognormal distribution.
newRandomLogNormalSignal :: MonadDES m
                            => 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
                            -> Composite m (Signal m (Arrival Double))
                            -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomLogNormalSignal #-}
newRandomLogNormalSignal :: Double -> Double -> Composite m (Signal m (Arrival Double))
newRandomLogNormalSignal Double
mu Double
nu =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)

-- | Return a new signal with random delays distibuted exponentially with the specified mean
-- (the reciprocal of the rate).
newRandomExponentialSignal :: MonadDES m
                              => Double
                              -- ^ the mean delay (the reciprocal of the rate)
                              -> Composite m (Signal m (Arrival Double))
                              -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomExponentialSignal #-}
newRandomExponentialSignal :: Double -> Composite m (Signal m (Arrival Double))
newRandomExponentialSignal Double
mu =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall a b. (a -> b) -> a -> b
$
  Double -> Parameter m Double
forall (m :: * -> *). MonadComp m => Double -> Parameter m Double
randomExponential Double
mu Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)
         
-- | Return a new signal with random delays having the Erlang distribution with the specified
-- scale (the reciprocal of the rate) and shape parameters.
newRandomErlangSignal :: MonadDES m
                         => Double
                         -- ^ the scale (the reciprocal of the rate)
                         -> Int
                         -- ^ the shape
                         -> Composite m (Signal m (Arrival Double))
                         -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomErlangSignal #-}
newRandomErlangSignal :: Double -> Int -> Composite m (Signal m (Arrival Double))
newRandomErlangSignal Double
beta Int
m =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)

-- | Return a new signal with random delays having the Poisson distribution with
-- the specified mean.
newRandomPoissonSignal :: MonadDES m
                          => Double
                          -- ^ the mean delay
                          -> Composite m (Signal m (Arrival Int))
                          -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomPoissonSignal #-}
newRandomPoissonSignal :: Double -> Composite m (Signal m (Arrival Int))
newRandomPoissonSignal Double
mu =
  Parameter m (Double, Int) -> Composite m (Signal m (Arrival Int))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Int) -> Composite m (Signal m (Arrival Int)))
-> Parameter m (Double, Int)
-> Composite m (Signal m (Arrival Int))
forall a b. (a -> b) -> a -> b
$
  Double -> Parameter m Int
forall (m :: * -> *). MonadComp m => Double -> Parameter m Int
randomPoisson Double
mu Parameter m Int
-> (Int -> Parameter m (Double, Int)) -> Parameter m (Double, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x ->
  (Double, Int) -> Parameter m (Double, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x, Int
x)

-- | Return a new signal with random delays having the binomial distribution with the specified
-- probability and trials.
newRandomBinomialSignal :: MonadDES m
                           => Double
                           -- ^ the probability
                           -> Int
                           -- ^ the number of trials
                           -> Composite m (Signal m (Arrival Int))
                           -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomBinomialSignal #-}
newRandomBinomialSignal :: Double -> Int -> Composite m (Signal m (Arrival Int))
newRandomBinomialSignal Double
prob Int
trials =
  Parameter m (Double, Int) -> Composite m (Signal m (Arrival Int))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Int) -> Composite m (Signal m (Arrival Int)))
-> Parameter m (Double, Int)
-> Composite m (Signal m (Arrival 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 Parameter m Int
-> (Int -> Parameter m (Double, Int)) -> Parameter m (Double, Int)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Int
x ->
  (Double, Int) -> Parameter m (Double, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x, Int
x)

-- | Return a new signal with random delays having the Gamma distribution by the specified
-- shape and scale.
newRandomGammaSignal :: MonadDES m
                        => Double
                        -- ^ the shape
                        -> Double
                        -- ^ the scale (a reciprocal of the rate)
                        -> Composite m (Signal m (Arrival Double))
                        -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomGammaSignal #-}
newRandomGammaSignal :: Double -> Double -> Composite m (Signal m (Arrival Double))
newRandomGammaSignal Double
kappa Double
theta =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)

-- | Return a new signal with random delays having the Beta distribution by the specified
-- shape parameters (alpha and beta).
newRandomBetaSignal :: MonadDES m
                       => Double
                       -- ^ the shape (alpha)
                       -> Double
                       -- ^ the shape (beta)
                       -> Composite m (Signal m (Arrival Double))
                       -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomBetaSignal #-}
newRandomBetaSignal :: Double -> Double -> Composite m (Signal m (Arrival Double))
newRandomBetaSignal Double
alpha Double
beta =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)

-- | Return a new signal with random delays having the Weibull distribution by the specified
-- shape and scale.
newRandomWeibullSignal :: MonadDES m
                          => Double
                          -- ^ shape
                          -> Double
                          -- ^ scale
                          -> Composite m (Signal m (Arrival Double))
                          -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomWeibullSignal #-}
newRandomWeibullSignal :: Double -> Double -> Composite m (Signal m (Arrival Double))
newRandomWeibullSignal Double
alpha Double
beta =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)

-- | Return a new signal with random delays having the specified discrete distribution.
newRandomDiscreteSignal :: MonadDES m
                           => DiscretePDF Double
                           -- ^ the discrete probability density function
                           -> Composite m (Signal m (Arrival Double))
                           -- ^ the computation of signal emitting random events with the delays generated
{-# INLINABLE newRandomDiscreteSignal #-}
newRandomDiscreteSignal :: DiscretePDF Double -> Composite m (Signal m (Arrival Double))
newRandomDiscreteSignal DiscretePDF Double
dpdf =
  Parameter m (Double, Double)
-> Composite m (Signal m (Arrival Double))
forall (m :: * -> *) a.
MonadDES m =>
Parameter m (Double, a) -> Composite m (Signal m (Arrival a))
newRandomSignal (Parameter m (Double, Double)
 -> Composite m (Signal m (Arrival Double)))
-> Parameter m (Double, Double)
-> Composite m (Signal m (Arrival 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 Parameter m Double
-> (Double -> Parameter m (Double, Double))
-> Parameter m (Double, Double)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Double
x ->
  (Double, Double) -> Parameter m (Double, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x, Double
x)