Solution to COMP9334 Revision Questions for Week 4B 2
Question 1
We first work out the formula that we should use to generate random numbers with the Weibull distribution using the inverse transform method. Assuming that y and u are related by y = F−1(u), we have
y = F−1(u) (1) ⇔u = F(y) (2) ⇔u = 1−exp(−αyβ) (3)
log(1−u)β1
⇔y=−α (4)
Therefore we can use the relation
log(1−u)β1
−α (5)
where u is uniformly distributed over [0, 1] to generate the Weibull distribution.
By using the above formula, 10,000 ( = n) numbers that are Weibull distributed are gen-
erated. Figure 1 shows a histogram of the 10,000 numbers sorted into 50 equally spaced bin.
We have also derived the expected number of random numbers in each bin and plotted
it as the red curve in Figure 1. Note that the histogram consists of 50 equally spaced bin
spanning [0, ymax] where ymax is the largest number generated. Define δ = ymax , then the k-th 50
bin spans the range [(k − 1)δ, kδ].
The probability that a number with Weibull distribution falls within the range [(k−1)δ, kδ] is (F (kδ) − F ((k − 1)δ)). (Note: You can prove this by using the definition of cumulative density function.) If n random numbers are generated, then the expected number of random numbers in the k-th bin is n(F (kδ) − F ((k − 1)δ))
1
Figure 1: Histogram of 10000 random numbers with Weibull distribution. The red curve shows the expected distribution.
2