2G1503 Simulation and Modeling Exercise #3 Ali Ghodsi [email protected] 1 Statistics (chapter 5) PDF 1/3 • Probability Density Function (PDF) – For continous domains, function is usually called f • Ex: range Rx = ℝ any real number – Swedish: täthetsfunktion • Probability Mass Funktion (PMF) – For discrete domains, function is usually called p • Ex: range Rx = { 1, 2, 3, 4, 5, 6 } for a dice – Swedish: frekvenskfunktion • Cumulative Distribution Function (CDF) derived from the PDF/PMF – Swedish: fördelningsfunktion – For the PDF: x – F ( x) = ∫ f (t )dt −∞ – – For the CDF: – F ( x) = p( y ) ∑ y≤ x 2 1 Statistics (chapter 5) PDF 2/3 • Probability Density Function (PDF) – Satisfies: a ) f ( x ) ≥ 0 for all x b) ∫ f ( x )dx = 1 Rx ∞ = ∫ f ( x )dx = 1 −∞ c ) f ( x ) = 0 if x not in Rx • Probability Mass Funktion (PMF) – Satisfies: a ) p ( x ) ≥ 0 for all x in Rx b) ∑ p(x) = 1 x ∈ Rx 3 Statistics (chapter 5) PDF 3/3 • Cumulative Distribution Function (CDF) derived from the PDF/PMF – Satisfies: a) F is non − decreasing, a ≤ b ⇒ F (a ) ≤ F (b) b) lim x → ∞ F ( x) = 1 c) lim x → −∞ F ( x) = 0 4 2 Inverse Transform Technique • To generate variates (sampling from a distribution) according to a pdf f 1. 2. 3. 4. Calculate the CDF for the PDF: F(X) Set F(X) = R, and define the Range Calculate the inverse, F-1, of F Generate random numbers [0,1) and use the inverse F-1, to generate variates 5 Random Variates: exponential pdf • Create random variates according to the pdf f(x)=λe-λx 1. F(x) = 1 - e-λx for x≥0 0 for x<0 2. F(x)=R, the range is x≥0 3. Calculate F-1, -ln(1-R)/ λ 4. Use random numbers on [0,1) to sample. Ex: 0.3 : -ln(1-0.3)/ λ 6 3 Random Variates: triangular 1/4 • Generate random variates accoring to the triangular distribution: f(x) = x, 0≤x≤1 2-x, 1<x≤2 7 Random Variates: triangular 2/4 Calculate CDF: x2 + C1 , 0 ≤ x ≤1 0 ≤ x ≤1 x, CDF : F ( x) = 2 2 f ( x) = x − 2, 1 < x ≤ 2 2 x − x + C 2 , 1 < x ≤ 2 2 C1 and C2 need to be calculated : C1 = 0, since we know that F (0) = 0 We know that F (1) = 2 *1 − 12 1 x2 1 + 0 = . So when x = 1 we have, 2 x − + C2 = 2 2 2 2 12 1 + C2 = ⇒ C2 = − 1 2 2 8 4 Random Variates: triangular 3/4 Calculate the inverse function F-1 : x2 , when 0 ≤ x ≤ 1 2 x2 = 2R x = ± 2R ⇒ R = F −1 ( r ) = R = 2x − 2r when 1 (x − 4 x + 2 ) 2 2 − 2 R = ( x − 2) 2 F F ( 0 ) ≤ r ≤ F (1) complete square (kvadratkomplettering) x2 − 1, when 0 ≤ x ≤ 1 2 R =− −1 Choose plus, as F-1 shouldn’t be negative (r ) = 2 − 2 − 2r ( ) ⇒ 1 ( x − 2)2 − 4 + 2 2 Choose minus, x = 2 ± 2 − 2R when F (1) ≤ r ≤ F ( 2 ) ⇒ R =− as F-1(0.5)=1 9 Random Variates: triangular 4/4 Calculate the inverse function F-1 : 1 2r , 0≤r ≤ 2 F −1 (r ) = 1 2 − 2 − 2 r < r ≤1 2 Generate random numbers, R1, ..., Rn, uniformly distributed on [0,1) F-1(R1),..., F-1(Rn), will be the sample from the specified triangular distribution 10 5
© Copyright 2026 Paperzz