Week10 practice 1

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา

Generating Poisson and exponential random variables

Most programming languages provide library functions for generating uniform continuous random variable in the range (0,1). However, they often do not provide any functions for generating more complicated types of random variables.

Poisson random variables

Given a uniform random variable in (0,1), we can generate Poisson and exponential random variables based on their cumulative distribution function. Here is a simple idea. Let's consider, as an example, generating a Poisson random variable with parameter . Using the definition of Poisson random variables, we have its pmf as in the following list (for the first few values):

  • f(0) = 0.006738
  • f(1) = 0.033690
  • f(2) = 0.084224
  • f(3) = 0.140374
  • f(4) = 0.175467
  • f(5) = 0.175467
  • f(6) = 0.146223
  • f(7) = 0.104445
  • f(8) = 0.065278
  • f(9) = 0.036266

With this we can compute cdf :

  • F(0) = 0.006738
  • F(1) = 0.040428
  • F(2) = 0.124652
  • F(3) = 0.265026
  • F(4) = 0.440493
  • F(5) = 0.615961
  • F(6) = 0.762183
  • F(7) = 0.866628
  • F(8) = 0.931906
  • F(9) = 0.968172
  • ...
  • F(17) = 0.999995
  • F(18) = 0.999999
  • F(19) = 1.000000
  • F(20) = 1.000000

Note: note that F(9) on the list above is not even close to 1, so in order the generate the Poisson r.v., we need to generate up to, say, F(19) or F(20).

It is not hard to use this list together with a uniform random variable in range (0,1) to generate a Poisson random variable. Suppose that we generate a uniform r.v. and get 0.3. Note that that value falls in the range F(3) and F(4) in the above list. We then say that our Poisson r.v. is 4.

Exponential random variables

For exponential random variables, it is much easier because we have a simple closed form for its cdf. We know that for an exponential random variable X with parameter , its cdf is given by

Given a uniform random variable in the range (0,1), U, we can find x such that F(x) = U by taking the inverse, i.e.,

Simulations

Relationships