simulation notes
simulation notes
Advantages of CLCG
Example: If we flip a coin, we know in advance that it will either come up heads or tails, but we cannot
predict before any given experiment which of these outcomes will occur.
Example: If we flip a coin, we know in advance that it will either come up heads or tails, but we cannot
predict before any given experiment which of these outcomes will occur.
Counter Example: Suppose I throw a ball many times at exactly the same angle and speed and under
exactly the same conditions. Every time we run this experiment, the ball will land in exactly the same
place: we can predict exactly what is going to happen. This is a deterministic system.
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 2 / 49
Example: Combining 3 LCGs
Advantages of CLCG
Some other examples of randomness are number of boys/girls in a classroom, number of typos in a page,
height of students in a class etc.
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 3 / 49
Example: Combining 3 LCGs
Advantages of CLCG
Notion of Probability
Probability
Probability theory is the mathematical study of random phenomena.
The outcome of a random event cannot be determined before it occurs, but it may be any one of
several possible outcomes.
The analysis of events governed by probability is called statistics.
Mathematically, the probability that an event will occur is expressed as a number between 0 and 1.
Notion of Probability
Probability
Probability theory is the mathematical study of random phenomena.
The outcome of a random event cannot be determined before it occurs, but it may be any one of
several possible outcomes.
The analysis of events governed by probability is called statistics.
Mathematically, the probability that an event will occur is expressed as a number between 0 and 1.
Let us consider the following case: Assume the probability of event A is represented by P (A). Then find
the values of P(A) for the following scenarios:
Event A will most probably not occur
The notion of probability refers to the concept and framework used to quantify uncertainty and the lik
Small chance of event A occurring
elihood of events occurring. It provides a mathematical foundation for reasoning about situations wh
ere outcomes are uncertain. Here are the key aspects of the notion of probability:
50-50 chance of event A occurring
high chance of event A happening
Event A will most definitely happen.
Note that, the sum of probabilities for all possible outcomes is equal to one. For example, if an experiment
can have three possible outcomes (A, B, and C), then P(A) + P(B) + P(C) = 1.
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 4 / 49
Example: Combining 3 LCGs
Advantages of CLCG
n = 6, na = 1.
Thus, the probability is
1
P(A) =
6
Ex 2: A fair coin is tossed twice. What is the probability of getting two heads? Here,
Ω = {HH, TT, HT, TH } and A = HH. Then we can get
n = 4, na = 1.
Thus, the probability is
1
P(A) =
4
Sample Space
The sample space Ω is the set of all possible outcomes of a random experiment.
Ex 1: Consider the random experiment of waiting for a bus that will arrive at a random time in the future.
In this case, the outcome of the experiment can be any real number t ≥ 0 (t = 0 means the bus comes
immediately, t = 1.5 means the bus comes after 1.5 hours, etc.) We can therefore define the sample space as
Ω = [0, +∞[
Ex 2: Roll a dice with six sides to see if an odd or even side appears. The the sample space is
Ω = {1, 2, 3, 4, 5, 6}
{ (1, 6), (2, 5), (3, 4), (4, 3), (5, 2), (6, 1) } ⊂ Ω
We cannot predict in advance whether this event will occur, but we can determine whether it has occurred
once the outcome of the experiment is known.
Ex 2: Drawing 4 cards from a deck: Events include all spades, sum of the 4 cards is (assuming face cards
have a value of zero), a sequence of integers, a hand with a 2, 3, 4 and 5. Can you identify some more
events?
{ (1, 6), (2, 5), (3, 4), (4, 3), (5, 2), (6, 1) } ⊂ Ω
We cannot predict in advance whether this event will occur, but we can determine whether it has occurred
once the outcome of the experiment is known.
Ex 2: Drawing 4 cards from a deck: Events include all spades, sum of the 4 cards is (assuming face cards
have a value of zero), a sequence of integers, a hand with a 2, 3, 4 and 5. Can you identify some more
events?
Let us now see the different types of events:
Exhaustive Events
A set of events is said to be exhaustive, if it includes all the possible event.
Ex: In tossing a coin, the outcome can be either Head or Tail and there is no other possible outcome. So,
the set of events {H, T } is exhaustive.
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 7 / 49
Example: Combining 3 LCGs
Advantages of CLCG
Ex: In tossing a coin, both head and tail cannot happen simultaneously.
Ex: In tossing a coin, the coming of the head or the tail is equally likely.
Independent Event
Two events are said to be independent, if happening or failure of one does not affect the happening or
failure of the other. Otherwise, the events are said to be dependent.
Ex: For example, if we flip a coin in the air and get the outcome as Head, then again if we flip the coin but
this time we get the outcome as Tail.
Ex: driving and listening to the radio, even numbers and prime numbers on a die, losing a game and
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 8 / 49
Example: Combining 3 LCGs
Advantages of CLCG
If two events are independent then their joint probability of occurring is:
If two events are Non-mutually exclusive then their probability of occurring is:
Probability measure
A probability measure is an assignment of a number P(A) to every event A such that the following rules are
satisfied:
0 ≤ P(A) ≤ 1 (probability is a ”degree of confidence”).
P(Ω) = 1 (we are certain that something will happen).
Random Variable
Definition
A random variable taking values in D (set of values) is a function X that assigns a value X(w) ∈ D to every
possible outcome w ∈ Ω (sample space).
A random variable is thus a function that maps outcomes of a random experiment to real numbers.
A (real-valued) random variable, often denoted by X(or some other capital letter), is a function
mapping a probability space (S; P) into the real line R.
A random variable is a function that assigns a numerical value to each outcome of a random experimen
Random Variable
Definition
A random variable taking values in D (set of values) is a function X that assigns a value X(w) ∈ D to every
possible outcome w ∈ Ω (sample space).
A random variable is thus a function that maps outcomes of a random experiment to real numbers.
A (real-valued) random variable, often denoted by X(or some other capital letter), is a function
mapping a probability space (S; P) into the real line R.
Ex: We flip three coins. A good sample space for this problem is
Ω = {HHH, THH, HTH, HHT, TTH, THT, HTT, TTT }
Let X be the total number of heads that are flipped in this experiment. Then X is a random variable that can
be defined explicitly as follows:
X (HHH) = 3, X (THH) = X (HTH) = X (HHT ) = 2, X (TTH) = X (THT ) = X (HTT ) = 1, X (TTT ) = 0.
In principle, random variables can take values
Dr. Jagat Jyoti Rath
in an arbitrary set D.
Modeling & Simulation: Random Numbers 10 / 49
Example: Combining 3 LCGs
Advantages of CLCG
Random Variables
Random Data
A random source of data produces data that is characterized by the unknown true value of 𝜃o of the
variable 𝜃 to be estimated and also is function of a random variable.
Random Variables
Random Data
A random source of data produces data that is characterized by the unknown true value of 𝜃o of the
variable 𝜃 to be estimated and also is function of a random variable.
Ex: The suit of a randomly drawn card is discrete (it can only take four possible values), and the number of
customers that arrive at a store in a given day is also discrete. However, the height of a random person can
take any value which is not a countable set, and this is therefore not a discrete random variable. The latter
type of random variable is called continuous.
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 11 / 49
Example: Combining 3 LCGs
Advantages of CLCG
Expectation or Mean
Let X : Ω → D be a discrete random variable, and let 𝜑 : D → R be a function. The expectation of 𝜑 (X)
is defined as ∑︁
E[ 𝜑 (X) ] = 𝜑 (i)P{X = i}
i∈D
If X has a numerical value, then E[X] can be defined by choosing 𝜑 (i) = i.
Expectation or Mean
Let X : Ω → D be a discrete random variable, and let 𝜑 : D → R be a function. The expectation of 𝜑 (X)
is defined as ∑︁
E[ 𝜑 (X) ] = 𝜑 (i)P{X = i}
i∈D
If X has a numerical value, then E[X] can be defined by choosing 𝜑 (i) = i.
Expectation or Mean
Let X : Ω → D be a discrete random variable, and let 𝜑 : D → R be a function. The expectation of 𝜑 (X)
is defined as ∑︁
E[ 𝜑 (X) ] = 𝜑 (i)P{X = i}
i∈D
If X has a numerical value, then E[X] can be defined by choosing 𝜑 (i) = i.
What does it mean when we say E[X] = 2.084 in the previous example? Do we “expect” to see any
household to have 2.084 TVs?
What does it mean when we say E[X] = 2.084 in the previous example? Do we “expect” to see any
household to have 2.084 TVs?
The correct answer is that the expected value should be interpreted as a long-run average. If x1 , x2 , . . . , xn
be n realizations of X, then we expect
Var[X ] := E[ (X − E[X ] ) 2 ]
That is, Var[X] is the mean square difference between X and E[X]
The larger the variance Var[X], the “more random” is the random variable X.
Properties
Var[X ] ≥ 0
Consider the previous example of TVs in a household. We can compute the variance of X as:
The variance can be interpreted as the long-run average of squared deviations from the mean.
Thus the parameter Var is a measure of the extent of variability in successive realizations of X.
Ex: Consider a fair dice is rolled once and X be the resulting number. Find the mean and variance of X.
Distribution
let X : Ω → D be a discrete random variable. The collection (P{X = i} )i∈D is called the distribution of X.
Note that, It is perfectly possible, and very common, for different random variables to have the same
distribution.
Distribution
let X : Ω → D be a discrete random variable. The collection (P{X = i} )i∈D is called the distribution of X.
Note that, It is perfectly possible, and very common, for different random variables to have the same
distribution.
Ex: If we throw two dice, Let X be the outcome of the first die, and Y be the outcome of the second die,
Then X and Y are different random variables. But X and Y have the same distribution, as each die is
equally likely to yield every outcome P{X = i} = P{Y = i} = 1/ 6 for 1 ≤ i ≤ 6.
Distribution
let X : Ω → D be a discrete random variable. The collection (P{X = i} )i∈D is called the distribution of X.
Note that, It is perfectly possible, and very common, for different random variables to have the same
distribution.
Ex: If we throw two dice, Let X be the outcome of the first die, and Y be the outcome of the second die,
Then X and Y are different random variables. But X and Y have the same distribution, as each die is
equally likely to yield every outcome P{X = i} = P{Y = i} = 1/ 6 for 1 ≤ i ≤ 6.
For two random variables, X is independent of Y if conditioning on the outcome of Y does not affect the
distribution of X i.e.
Independent variable
If X : Ω → DX and Y : Ω → DY are two discrete random variables, then X and Y are independent iff
Random Variable
Uniform distribution
Let X be a random variable that is equally likely to take any value in [0, 1] i.e. P{X ∈ A} = length(A) for A
⊂ [0, 1]. We then say that X is uniformly distributed in the interval [0, 1].
Random Variable
Uniform distribution
Let X be a random variable that is equally likely to take any value in [0, 1] i.e. P{X ∈ A} = length(A) for A
⊂ [0, 1]. We then say that X is uniformly distributed in the interval [0, 1].
The CDF (or the Probability Distribution Function) has the following properties:
0 ≤ FX (x) ≤ 1
FX (x) is a non-decreasing function of X.
FX (−∞) = 0, FX (∞) = 1
P(X > x) = P(x < X < ∞) = 1 − FX (x)
Random Variable
Uniform distribution
Let X be a random variable that is equally likely to take any value in [0, 1] i.e. P{X ∈ A} = length(A) for A
⊂ [0, 1]. We then say that X is uniformly distributed in the interval [0, 1].
The CDF (or the Probability Distribution Function) has the following properties:
0 ≤ FX (x) ≤ 1
FX (x) is a non-decreasing function of X.
FX (−∞) = 0, FX (∞) = 1
P(X > x) = P(x < X < ∞) = 1 − FX (x)
Ex: Consider the random variable X defined by the following CDF
n 0; x < −2
FX (x) = 1 1
8 x + 4 ; −2 ≤ x < 0
1; x ≥ 0
Find P{X = 0}, P{X ≤ 0},P{X > 2}
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 18 / 49
Example: Combining 3 LCGs
Advantages of CLCG
Mathematically, the PDF f (x) of a continuous random variable X is the derivative of the cumulative
distribution function FX (x) i.e.
d
f (x) = Fx (x)
dx
Mathematically, the PDF f (x) of a continuous random variable X is the derivative of the cumulative
distribution function FX (x) i.e.
d
f (x) = Fx (x)
dx
If a function f (x) is a probability density function then it must obey two conditions:
The
∫ total probability for all possible values of the continuous random variable X is 1 i.e.
f (x)dx = 1
The probability density function can never be negative
Since the CDF always a non-decreasing function of X. Hence its derivative f (x) i.e the PDF will never be
negative.
Therefore, the area under the density in an interval corresponds to the probability that the random variable
will be in that interval.
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 19 / 49
Example: Combining 3 LCGs
Advantages of CLCG
Subsequently, the probability density function of the Gaussian Random Variable can be computed as:
1 −0.5( x− 𝜇 ) 2
fx (x) = e 𝜎 ; −∞ ≤ x ≤ ∞
2𝜋 𝜎
𝜇 > 0, 𝜎 > 0 are real numbers. A graphical illustration of the Gaussian random variable PDF is :
Let P = {Ω, Pr (·) } be a probability-space model for a experiment, and let {x(t, 𝜔) : 𝜔 ∈ Ω} be an
assignment of deterministic wave forms—functions of t—to the sample points 𝜔. Then this experiment
creates a random process X(t,:) as shown below:
Mean function
The mean function, 𝜇X (t), of a random process, X(t), is a deterministic function of time whose value at an
arbitrary specific time, t = t1 , is the mean value of the random variable x(t1 ). Thus, we can write:
Auto-correlation
For a random process X(t), the auto-correlation function or, simply, the correlation function, RXX (t1 , t2 ), is
defined as
RXX (t1 , t2 ) = E[X (t1 )X (t2 ) ]
Auto-covariance
For a random process X(t), the auto-covariance function or, simply, the covariance function, KXX (t1 , t2 ), is
defined as
Ex: Let X (t), t ∈ [0, ∞) be defined as X (t) = A + Bt, for all t ∈ [0, ∞) where A and B are independent
normal random variables N(1,1). Find the correlation functions and covariance functions of these random
variables.
We can easily characterize a Gaussian random process completely by its mean and covariance i.e.
𝜇x (t) ≡ E[x(t) ]; −∞ < t < ∞
Kxx (t, s) ≡ E[Δx(t)Δx(s) ]; −∞ < t, s < ∞
where Δx = x(t) − 𝜇x (t) and Kxx is the covariance.
We can easily characterize a Gaussian random process completely by its mean and covariance i.e.
𝜇x (t) ≡ E[x(t) ]; −∞ < t < ∞
Kxx (t, s) ≡ E[Δx(t)Δx(s) ]; −∞ < t, s < ∞
where Δx = x(t) − 𝜇x (t) and Kxx is the covariance.
Let x(t) be a GRP with mean function 𝜇x (t) and covariance function Kxx (t, s). Then to completely
characterize its probability density, we need only its the mean vector and covariance matrix given as:
𝜇x (t1 ) Kxx (t1 , t1 ) Kxx (t1 , t2 ) . . . Kxx (t1 , tN )
𝜇x (t2 ) Kxx (t2 , t1 ) Kxx (t2 , t2 ) . . . Kxx (t2 , tN )
Mx = · ; Gx = · · ... ·
· · · . . . ·
𝜇x (tN ) Kxx (tN , t1 ) Kxx (tN , t2 ) . . . Kxx (tN , tN )
Note that a GRP is stationary in i.e. for arbitrary t, the random vector x has the same probability density
function as the random vector x̄ defined as follows
T
x̄ ≡ x(0) x(t2 − t1 ) . . . x(tN −t1 )
Thus, its complete statistical characterization is time invariant.
Dr. Jagat Jyoti Rath Modeling & Simulation: Random Numbers 28 / 49
Example: Combining 3 LCGs
Advantages of CLCG
A uniform distribution means that every number within a specified range has an equal probability of being
selected.
A uniform distribution means that every number within a specified range has an equal probability of being
selected.
E[Ri ] =
This means that the likelihood of drawing any number in the range [0,1] is the same. For example:
A number like 0.25 has the same chance of occurring as 0.75.
When a large number of samples are generated, their histogram will appear flat, showing uniformity.
The value of one random number does not affect the next one i.e. they are independent.
This means the probability of drawing the next number does not depend on past numbers.
The value of one random number does not affect the next one i.e. they are independent.
This means the probability of drawing the next number does not depend on past numbers.
The value of one random number does not affect the next one i.e. they are independent.
This means the probability of drawing the next number does not depend on past numbers.
Ri = Xi /m ; i = 1, 2, . . .
Ex: Use X0 = 27, a = 17, c = 43, and m = 100. Generate Xi and Ri using LCM method.
Maximum Period
The length of the cycle before repetition is called the period, and a good PRNG(Pseudo random number
generator) has a very long period.
Achieved by proper choice of a, c, m, and X0
Pseudorandom number generators (PRNGs) produce sequences that appear random but can be
reproduced if the initial seed X0 is known.
The generator should be computationally efficient and generate numbers quickly, especially in
high-performance applications like simulations and cryptography.
The generator should be able to produce numbers in various ranges and formats (integers, floats,
etc.) as required.
The LCM has full period if and only if the following three conditions hold:
Modulus and Multiplier Condition (m and a)
1 The modulus m and multiplier a must be relatively prime i.e. the greatest common divider must be 1
2 This ensures that a does not introduce any common factors with m, which could reduce the number of
unique values generated.
3 It helps in spreading numbers evenly across the full range of m.
Prime Factor Condition: The multiplier a must be chosen such that for given conditions of c as
follows:
1 When the modulus m is prime and the increment c = 0.
2 When the modulus m is power of 2 i.e. m = 2b and the increment c = 0.
3 When the modulus m is power of 2 i.e. m = 2b and the increment c ≠ 0.
Seed Condition : The initial seed X0 must be co-prime to m i.e. they have no common factors other
than 1. Thus, the sequence can reach all possible states before repeating.
where:
Xn,1 and Xn,2 are generated by two independent LCGs:
The final result is obtained by subtracting the two generators’ outputs and reducing it modulo m
(usually m = m1 − 1).
where:
Xn,i is generated by the i-th independent LCG:
LCG 2:
Xn+1,2 = (40692Xn,2 ) mod 2147483399
LCG 3:
Xn+1,3 = (40692Xn,3 ) mod 2147483087
lcm(m1 − 1, m2 − 1, m3 − 1)
i.e. the least common multiplier, which can be significantly larger than the period of individual LCGs.
This ensures that the full cycle of all generators aligns before repeating, resulting in a longer period and
better randomness.
Frequency tests: Kolmogorov-Smirnov Test and Chi-Square Test to check if the distribution
generated by the sequence of random numbers is similar to the uniform distribution.
Autocorrelation Tests: Tests the correlation between the generated random numbers and compares
the sample correlation to expected correlation of zero.
Kolmogorov-Smirnov Test
The Kolmogorov-Smirnov (K-S) Test is a non-parametric statistical test that compares two distributions to
determine if they differ significantly.
One-Sample K-S Test: Compares a sample with a theoretical (expected) distribution
Two-Sample K-S Test: Compares two independent samples to check if they come from the same
distribution.
Kolmogorov-Smirnov Test
Kolmogorov-Smirnov Test
Kolmogorov-Smirnov Test
Chi-Square Test
Autocorrelation Test
Autocorrelation Test
Autocorrelation Test
Autocorrelation Test
Autocorrelation Test
Autocorrelation Test