You are on page 1of 18

BASIC DEFINITIONS

EG2080 Monte Carlo Methods • An experiment (or trial) is an observation of a


in Engineering phenomenon, the result of which is random.
Theme 2 • The result of an experiment is called its
outcome.
RANDOM VARIABLES • The set of possible outcomes for an exper-
iment is called its sample space.
AND Examples:

RANDOM NUMBERS
- Throwing a die: Integer between 1 and 6.
- Sum of throwing two dice: Integer between 2 and
12.
- The weight of a person: Real number larger than 0.

1 2

NOTATION NOTATION
Random variables Probability distribution
Upper-case Latin letter, for example X, Y, Z. Latin f in lower or upper case (depending on
Sometimes more than one letter is used (for interpretation) and an index showing the corre-
example NI in the Ice-cream Company). sponding symbol of the random variable.
Observation (outcome) of a random variable • Density function: fX, fY, fZ.
Lower-case counterpart of the symbol of the • Distribution function: FX, FY, FZ.
corresponding random variable, for example x, The index makes it easier to differentiate the
probability distributions when one is dealing with
y, z. more than one random variable.
Can sometimes be indexed to differentiate
observations, for example xi, yi, zi.

3 4
NOTATION NOTATION
Statistical properties of a probability distribution Estimates
Lower-case greek letter and an index showing Latin counterpart of the greek symbol that is
the corresponding symbol of the random estimated. Can be upper-case or lower-case
variable: depending on interpretation.
• Expectation value (mean): X , Y , Z . • Estimated expectation value: mX, mY, mZ.
• Standard deviation: X, Y, Z. • Estimated standard deviation: sX, sY, sZ.

5 6

RANDOM VARIABLES - Concept RANDOM VARIABLES


• A random variable is a way to represent a
- Probability Distributions
sample space by assigning one or more
• A probability distribution describes the sample
numerical values to each outcome.
space of a random variable.
• If each outcome produces one value, the
• A probability distribution can be described in
probability distribution is univariate.
several different ways.
• If each outcome produces more than one - Frequency function/density function.
value, the probability distribution is multi- - Distribution function.
variate. - Population (set of units).
• If the sample space is finite or countable
infinite, the random variable is discrete–
otherwise, it is continuous.

7 8
RANDOM VARIABLES RANDOM VARIABLES
- Frequency function - Density Function
Definition 1: The probability of the The probability that the outcome is exactly x is
outcome x for a univariate discrete infinitesimal for a continuous random variable.
Therefore, we use a density function to represent
random variable X is given by the the probability that the outcome is approximately
frequency function fXx, i.e., equal to x.
P(X  x) = fXx. Definition 2: The probability of the
outcomes X for a univariate continuous
random variable X is given by the density
function fXx, i.e.,
P(X  X) =  f X  x  dx.
X
9 10

RANDOM VARIABLES RANDOM VARIABLES


- Frequency and Density - Distribution Function
Functions Definition 3: The probability that the
outcome of a univariate random variable
Lemma: Frequency functions and density
X is less than or equal to some arbitrary
functions have the following property:
level x is given by the distribution
  function FXx, i.e.,
 f X  x  = 1 or  f X  x  dx = 1. PX  xFXx.
x = – –

11 12
RANDOM VARIABLES RANDOM VARIABLES - Density,
- Distribution Function frequency and distribution functions
Lemma: The relation between distri-
Lemma: A distribution function has the
bution functions and frequency/density
following properties:
functions can be written as
• lim F X  x  = 0. x x
x  –
FX  x  =  f X    or F X  x  =  f X    d .
• lim F X  x  = 1.
x  +  = – –
• x1 < x2 FX(x1) < FX(x2). (Increasing)
• lim F X  x + h  = F X  x . (Right-continuous)
h0
+

13 14

RANDOM VARIABLES POPULATIONS


- Multivariate Distributions For analysis of Monte Carlo simulation it can be
convenient to consider observations of random
The definitions 1–3 can easily be extended to
variables as equivalent to selecting an individual
the multivariate case.
from a population.
Examples:
• The random variable X can be represented by
- Discrete, three-dimensional distribution:
the population X.
P((X, Y, Z) = (x, y, z)) = fX, Y, Z(x, y, z).
• An individual in the population X is referred to
- Continuous, two-dimensional distribution: as a unit.
x y
• Unit i is associated to the value x i. The values
P(X  x, Y  y) = FX, Y(x, y) =   f X  Y     d d . of the units do not have to be unique, i.e, it is
– –
possible that x i = x j for two units i and j.

15 16
POPULATIONS EXAMPLE 2 - Discrete r.v.
• The population X has the units x 1, …, x N, i.e., Let X be the result of throwing a fair six-sided
X is a set with N elements. die once.
• It is possible that N is infinite. a) State the frequency function fX(x).
• A random observation of X is equivalent to b) State the distribution function FX(x).
randomly selecting a unit from the population c) Enumerate the population X.
X.
• The probability of selecting a particular unit is
1/N. Hence,
N x  X: x  x 
i i
FX(x) = ---------------------------------- . (1)
N

17 18

EXAMPLE 2 - Discrete r.v. EXAMPLE 2 - Discrete r.v.


Solution: Solution (cont.)
a) FX b) FX
1  0 x  1, 1
1  6 1  x  2,

x 2  6 2  x  3, x

1 2 3 4 5 6 FX  x  =  3  6 3  x  4, 1 2 3 4 5 6
1 
4  6 4  x  5,
x
 --- x = 1 2 3 4 5 6, ---
fX  x  =  6 5  6 5  x  6,
0 all other x. 
  1 6  x.

19 20
EXAMPLE 2 - Discrete r.v. EXAMPLE 3 - Continuous r.v.
Solution (cont.) Let X be a random variable which is uniformly
distributed between 10 and 20.
c) X = {1, 2, 3, 4, 5, 6}.
a) State the frequency function fX(x).
1 5 b) State the distribution function FX(x).
2 3 c) Enumerate the population X.
4 6

21 22

EXAMPLE 3 - Continuous r.v. EXAMPLE 3 - Continuous r.v.


Solution: fX Solution (cont.) FX
a) 1
b) 1

x x
5 10 15 20 25 30 5 10 15 20 25 30

 0. 1 10  x  20,  0 x  10,
fX(x) =  
 0 all other x. FX(x) =  0. 1 x – 1 10  x  20,

 1 20  x.

23 24
EXAMPLE 3 - Continuous r.v. EXPECTATION VALUE
Solution (cont.) The expectation value of a random variable is
c) The population has one unit for each real the mean of the all possible outcomes weighted
number between 10 and 20. according to their probability:
Definition 4: The expectation value of the
random variable X is given by

E X =  xf X  x  (discrete),
x = –

25 26

EXPECTATION VALUE EXPECTATION VALUE


Definition 4 (cont.) Not all random variables have an expectation
 value!
Example (St. Petersburg paradox): A player tosses a coin
EX =  xf X  x  dx (continuous), until a tail appears. If a tail is obtained for the first time in
– the j:th trial, the player wins j – 1 €.

or Let X be the payout when playing this game. The proba-


bility that trial j is the first trial where the tail appears is
N –j, j…. Hence we get
1
E  X  = ----  x i (population).  
1
N EX =  2 –j  2j – 1 =  --- .
i=1 2
j=1 j=1

27 28
VARIANCE VARIANCE
The expectation value provided important infor- A common measure of the spread is the
mation about a random variable, but in many variance, i.e., the expected quadratic deviation
cases we need to know more than the expected from the expectation value.
average, for example the spread.
Definition 5: The variance of the random
fX fX
variable X is given by
 
Var  X  = E   X – E  X   2  
 
 E  X 2  –  E  X   2 (general),
x x 
2
    Var  X  =  x – EX fX  x 
x = – (discrete),

29 30

VARIANCE STANDARD DEVIATION


Definition 5 (cont.) It is in many cases convenient to have a
 measure of the spread which has the same unit
Var  X  =
2 as the expectation value. Therefore, the notion
 x – EX f X  x  dx
standard deviation has been introduced:
– (continuous),
Definition 6: The standard deviation of
or the random variable X is given by
N
1
Var  X  = ---- X = Var  X .
N   x i – E X 2
i=1 (population).

31 32
COVARIANCE COVARIANCE
For multivariate distributions it is sometimes A covariance matrix, X, states the covariance
necessary to describe how the random variables between all random variables in a multivariate
interact: distribution:
Definition 7: The covariance of two X =
random variables X and Y is given by
Var  X 1  Cov  X 1 X 2  … Cov  X 1 X k 
Cov  X Y  = E   X – E  X    Y – E  Y    =
= E  XY  – E  X E  Y . Cov  X 2 X 1  Var  X 2 
=


Cov  X Y  = Cov  Y X ,


Lemma:
Cov  X X  = Var  X . Cov  X k X 1  Var  X k 

33 34

CORRELATION COEFFICIENT CORRELATION COEFFICIENT


The covariance is an absolute measure of the We can conclude from definition 8 that the
interaction between two random variables. correlation coefficient always is in the interval
Sometimes it is preferable to use a relative –.
measure: • X, Y X and Y positively correlated
Definition 8: The correlation coefficient of If the outcome of X is low then it is likely that the
outcome of Y is also low and vice versa.
two random variables X and Y is given by
• X, Y X and Y are negatively correlated.
Cov  X Y  If the outcome of X is low then it is likely that the
 X Y = ----------------------------------------- . outcome of Y is high and vice versa.
Var  X Var  Y 
• X, Y CovXY  X and Y uncorre-
lated

35 36
INDEPENDENT RANDOM INDEPENDENT RANDOM
VARIABLES VARIABLES
A very important special case when studying Theorem 1: If X and Y are independent
multivariate distributions is when the random then
variables are independent.
E[XY] = E[X]E[Y].
Definition 9: X and Y are independent
Theorem 2: If X and Y are independent
random variables if it holds for each x and
then they are also uncorrelated.
y that
fX, Y(x, y) = fX(x)fY(y)  FX, Y(x, y) = FX(x)FY(y). Warning! Correlations are easily misunderstood!

37 38

CORRELATIONS ARITHMETICAL OPERATIONS


• X and Y being uncorrelated does not have to Theorem 3:
imply that they are independent. i) E  aX  = aE  X 
Example: Y uniformly distributed between –1 and 1, 
X = Y2 X, Y = 0, although X is dependent of Y.
ii) E  g  X   =  g  x fX  x  dx (continuous),
• A correlation only indicates that there is a
relation, but does not say anything about the –
cause of the relation. Eg X  =  g  x f X  x  (discrete),
Example: X = 1if a driver wears pants, otherwise 0, x
Y = 1 if driver involved in an accident, otherwise 0. N
The conclusion if X,Y > 0 should not be that wearing 1
pants increases the risk of traffic accidents. In reality
E  g  X   = ----  g  x i  (population).
N
such a correlation would probably be due to a more i=1
indirect relation.

39 40
ARITHMETICAL OPERATIONS ARITHMETICAL OPERATIONS
Theorem 3 (cont.) Theorem 3 (cont.)
iii) E[X + Y] = E[X] + E[Y] N
1
  E  g  X Y   = ----  g  x i y i 
N
iv) E  g  X Y   =   g  x y f XY  x y  dx dy i=1
(population)
– –
(continuous), Theorem 4:
E  g  X Y   =   g  x y f XY  x y  i) Var  aX  = a 2 Var  X 
x y
(discrete). ii) Var  X + Y  =
= Var  X  + Var  Y  + 2Cov  X Y 

41 42

ARITHMETICAL OPERATIONS ARITHMETICAL OPERATIONS


Theorem 4 (cont.) Theorem 5: If X and Y are independent
random variables and Z = X + Y then the
iii) Var  X – Y  =
probability distribution of Z can be calcu-
= Var  X  + Var  Y  – 2Cov  X Y  lated using a convolution formula, i.e.,
k k k

iv) Var  Xi =   Cov  X i X j 
fZ(x) =  f X  t f Y  x – t  dt
i=1 i = 1j = 1
–
or
fZ(x) =  f X  t f Y  x – t .
t

43 44
PROBABILITY DISTRIBUTIONS RANDOM NUMBERS
• Probability distributions can be defined • A random number generator is necessary to
arbitrarily, but there are also general proba- create random samples for a computer
bility distributions which appear in many simulation.
practical applications. • A random number generator is a mathe-
• Density function, distribution functions, matical function that generate a sequence of
expectation values and variances for many numbers.
general probability distributions can be found
in mathematical handbooks. The English
version of Wikipedia also provides a lot of
information.

45 46

RANDOM NUMBERS RANDOM NUMBERS


• Modern programming languages have built-in • Starting with a certain seed, X0, the equation
functions for generating random numbers (2) will generate a deterministic sequence of
from U-distributions and some other numbers, {Xi}.
distributions. • The sequence will eventually repeat itself (at
• The underlying formula behind the most least after m numbers).
common random number generators is the • The sequence Ui = Xi/m will imitate a real
following: sequence of U(0, 1)-distributed random
Xi + 1 = aXi (mod m).* (2) numbers if the constants a and m are chosen
appropriately.
Example: a = 75 = 16 807 and m = 231 – 1.
* The operator mod m denotes the remainder when
dividing by m.

47 48
RANDOM NUMBERS RANDOM NUMBERS
• The designation pseudo-random numbers is A good random number generator will generate
sometimes used to stress that the sequence a sequence of random numbers which
of numbers is actually deterministic. • is as long as possible (before it repeats itself)
• One method to make it more or less impos- • is distributed as close to a U(0, 1)-distribution
sible to predict a sequence of pseudo-random as possible
numbers it to use the internal clock of the
• has a negligible correlation between the
computer as seed.
numbers in the sequence.
• An advantage of pseudo-random numbers is
that a simulation can be recreated by using
the same seed again.

49 50

RANDOM NUMBERS INVERSE TRANSFORM


How do we generate the inputs Y to a computer
METHOD
simulation?
Theorem 6: If a random variable U is
• A pseudo-random number generator provides U(0, 1)-distributed then Y F Y– 1  U  has
U(0, 1)-distributed random numbers. the distribution function FYx.
• Y generally has some other distribution. FY
There are several methods to transform U(0, 1)- 
distributed random numbers to an arbitrary
U
distribution. 
In this course we will use the inverse transform
x
method.
Y
51 52
EXAMPLE 4 - Inverse transform EXAMPLE 4 - Inverse transform
method method
A pseudo-random number generator providing Solution:
U(0, 1)-distributed random numbers has
a) Graphic solution:
generated the value U = 0.40.
FY
a) Transform U to a result of throwing a fair six-
sided die. 1

b) Transform U to a result from a U(10, 20)- U


distribution. x
2 4 6
Y
In the general case, a discrete inverse distribution func-
tion can be calculated using a search algorithm.

53 54

EXAMPLE 4 - Inverse transform NORMALLY DISTRIBUTED


method RANDOM NUMBERS
Solution (cont.) The normal distribution does not have an
b) The inverse distribution function is given by inverse distribution function! However, it is
possible to use an approximation:*
 10 x  0, Theorem 7: If a random variable U is

F Y– 1  x  =  10x + 10 0  x  1, U(0, 1)-distributed then Y is N(0, 1)-dis-
 tributed if Y is calculated as follows:
 20 1  x.

 Y = F Y– 1  0. 4  = 14.
* This method is therefore referred to as the “ap-
proximative inverse transform method”.

55 56
NORMALLY DISTRIBUTED NORMALLY DISTRIBUTED
RANDOM NUMBERS RANDOM NUMBERS
Theorem 7 (cont.) Theorem 7 (cont.)

 U if   U    , c0 + c1 t + c2 t2
Q= z=t– --------------------------------------------------
1 – U if    U  , 1 + d1 t + d2 t2 + d3 t 3
c0=2.515 517, d1 = 1.432 788,
t – 2 ln Q ,
c1=0.802 853, d2 = 0.189 269,
c2=0.010 328, d3 = 0.001 308,

57 58

NORMALLY DISTRIBUTED CORRELATED RANDOM


RANDOM NUMBERS NUMBERS
Theorem 7 (cont.) • It is convenient if the inputs Y in a computer
simulation are independent, because then the
 –z if 0  U    , random variables can be generated
 separately.
Y =  0 if U =   ,
 • However, it is also possible to generate corre-
 z if    U  .
lated random numbers.
- Correlated normally distributed numbers.
- General method.

59 60
CORRELATED RANDOM CORRELATED RANDOM
NUMBERS - Normal distribution NUMBERS - Normal distribution
Theorem 8: Let X = [X1, …, XK]T be a vec- Theorem 8 (cont.)
tor of independent N(0, 1)-distributed
components. Let B =1/2, i.e., let i and B = P1/2PT.
gi be the i:th eigenvalue and the i:th Then Y =  + BX is a random vector where
eigenvector of  and define the following the elements are normally distributed
matrices: with the mean  and the covariance ma-
P = [g1, …, gK], trix .

 = diag(1, …, K),

61 62

CORRELATED RANDOM CORRELATED RANDOM


NUMBERS - General method NUMBERS - General method
Consider a multivariate distribution • Step 4. Randomise the value of the k:th
Y = [Y1, …, YK] with the density function fY. element according to the conditional
• Step 1. Calculate the density function of the probability distribution obtained from
first element, fY1. f Yk |  Y
1   Y k – 1  =   1    k – 1  .
• Step 2. Randomise the value of the first
• Step 5. Repeat step 3–4 until all elements
element according to fY1.
have been randomised.
• Step 3. Calculate the conditional density
function of the next element, i.e.,
f Yk |  Y
1  Y k – 1  =   1   k – 1  .

63 64
CORRELATED RANDOM CORRELATED RANDOM
NUMBERS - Alternative method NUMBERS - Alternative method
• This method is only applicable to discrete Original distribution function: FY1, Y2y1, y2is the
probability distributions. probability that Y1  y1 and Y2  y2.
However, a continuous probability distribution
Modified distribution function: Arrange all units
can of course be approximated by a discrete
distribution. in the population in an ordered list; FY1, Y2n is
now the probability to select one of the n first
• The idea is to use a modified distribution
units in the list.
function for the inverse transform method.
The order of the list might influence the efficiency
of some variance reduction techniques!

65 66

EXAMPLE 5 - Correlated discrete EXAMPLE 5 - Correlated discrete


random numbers random numbers
Consider the multivariate y2 a) Apply the general method to randomise
probability distribution fY1, Y2    values of Y1 and Y2 using the two independent

to the right.    random numbers U1 = 0.15 and U2 = 0.62 from a

According to the definition, we U(0, 1)-distribution.
  
have Y1, Y2  0.4.  b) Apply the alternative method to randomise
y1 values of Y1 and Y2 using the random number
   U1 = 0.12 from a U(0, 1)-distribution.

67 68
EXAMPLE 5 - Correlated discrete EXAMPLE 5 - Correlated discrete
random numbers random numbers
Solution: a) The probability y2 Solution (cont.) The condi- y2
distribution of the first    tional distribution of Y1 is now    

element is given by    given by   
 
f Y1  y 1  =  f Y1 Y2  y 1  2     f Y1 Y2  1 y 2    
 
Y 1 = 1  y 2  
f Y2 ------------------------------- 
2 y1 f Y1  1  y1

 0. 2 y 1 = 1,      
  0. 5 y 2 = 1,
=  0. 35 y 1 = 2,  Y1 = F Y1
– 1  0. 15  = 1. 
 =  0. 25 y 2 = 2,  Y2 = F Y2
–1
Y 1 = 1  0. 62  = 2.
  45 y 1 = 3. 
 0. 25 y 2 = 3.
69 70

EXAMPLE 5 - Correlated discrete EXAMPLE 5 - Correlated discrete


random numbers random numbers
Solution: b) Assume that units are listed as Solution(cont.) FY
follows: The modified 1
Number 1 2 3 4 5 6 7 8 9 distribution
Unit function is
Y1 1 1 2 1 2 3 2 3 3 shown to the 0.5
Y2 1 2 1 3 2 1 3 2 3 right.
U n
The value
U = 0.12 corre- 1 2 3 4 5 6 7 8 9 unit
sponds to the second unit, i.e., Y1 = 1 and
Y 2 = 2.

71 72

You might also like