User:StevenJYang/Stochastic simulation

A stochastic simulation is a simulation of a system that has variables that can change stochastically (randomly) with individual probabilities. Realizations of these random variables are generated and inserted into a model of the system. Outputs of the model are recorded, and then the process is repeated with a new set of random values.

These steps are repeated until a sufficient amount of data is gathered. In the end, the distribution of the outputs shows the most probable estimates as well as a frame of expectations regarding what ranges of values the variables are more or less likely to fall in.

Often random variables used in simulations are created on a computer with a random number generator (RNG). RNGs on computers can be either a pseudo-random number generator or a hardware random number generator. Both of these random number generators output realizations of the uniform distribution U(0,1) where all intervals of equal length between zero and one are equally probable. The outputs of the random number generator are then transformed into random variables with probability distributions that are used in the system model.

Bernoulli distribution
A random variable X is Bernoulli-distributed with parameter p if it has two possible outcomes usually encoded 1 (success or default) or 0 (failure or survival) where the probabilities of success and failure are $$P(X = 1) = p$$ and $$P(X = 0) = 1 - p$$ where $$0 \leq p \leq 1$$.

To produce a random variable X with a Bernoulli distribution from a U(0,1) uniform distribution made by a random number generator, we define

$$X = \begin{cases} 1, & \text{if } 0 \leq U < p \\ 0, & \text{if } 1 \geq U \geq 0 \end{cases} $$

such that the probability for$$P(X = 1) = P(0 \leq U < p) = p$$and $$P(X = 0) = P(1 \geq U \geq p) = 1 - p$$.

Example: Toss of coin
Define X = 1 if head comes up and X = 0 if tail comes up For a fair coin, both realizations are equally likely. We can generate realizations of this random variable X from a U(1,0) uniform distribution provided by a random number generator (RNG) by having X = 1 if the RNG outputs a value between 0 and 0.5 and X = 0 if the RNG outputs a value between 0.5 and 1. P (X = 1) = P(0 ≤ U < 1/2) = 1/2

P (X = 0) = P(1 ≥ U ≥ 1/2) = 1/2 Of course, for other systems, the two outcomes may not be equally likely (e.g. unfair coin, success of medical treatment).

Binomial distribution
Main article: Binomial distribution

A binomial distributed random variable Y with parameters n and p is obtained as the sum of n independent and identically Bernoulli-distributed random variables X1, X2, ..., Xn

Example: A coin is tossed three times. Find the probability of getting exactly two heads. This problem can be solved by looking at the sample space. There are three ways to get two heads. HHH, HHT, HTH, THH, TTH, THT, HTT, TTT The answer is 3/8 (= 0.375).

Poisson distribution
Main article: Poisson distribution

A poison process is a process where events occur randomly in time or space. The probability distribution for poisson processes with constant rate λ per time interval is given by the following equation.

$$P(k \text{ events in interval}) = \frac{\lambda^k e^{-\lambda}}{k!}$$

Defining $$N(t)$$ as the number of events that occur in the time interval $$[0,t]$$ the probability distribution of $$k$$ events that occur before time $$t$$ is given by

$$P(N(t) = k) = \frac{(t\lambda)^{k}}{k!}e^{-t\lambda}$$

It can be shown that inter-arrival times for events is exponentially distributed with a cumulative distribution function (CDF) of $$F(t) = 1 - e^{\frac{-t}{\lambda}}$$. The inverse of the exponential CDF is given by

$$t = -ln(1 - u)/\lambda$$

where $$u$$ is an $$U(0,1)$$ uniformly distributed random variable.

Simulating a Poisson process with a constant rate $$\lambda$$ for the number of events $$N$$ that occur up to time $$T$$ can be carried out with the following algorithm.


 * 1) Begin with $$N = 0$$ and $$t = 0$$
 * 2) Generate random variable $$u$$ from $$U(0,1)$$ uniform distribution
 * 3) Update the time with $$t = t - ln(1 - u)/\lambda$$
 * 4) If $$t > T$$, then stop. Else continue to step 5.
 * 5) $$N = N + 1$$, and $$t_n = t$$
 * 6) Continue to step 2

The Poisson distribution depends on only one parameter, λ, and can be interpreted as an approximation to the binomial distribution when the parameter p is a small number. A poisson-distributed random variable is usually used to describe the random number of events occurring over a certain time interval.

Typical example problem: If 3% of the electric bulbs manufactured by a company are defective find the probability that in a sample of 100 bulbs exactly 5 bulbs are defective. ( Given e-0.25= 0.7788 )