Exercise 1: Weibull inverse transform sampling

5,000
Mathematical idea
Generate N samples from the uniform distribution:
ri ~ U(0, 1),   i = 1, ..., N
Python code
N = 40000 # number of samples r = np.random.rand(N) # Uniform random numbers in [0,1)
Histogram of r
Mean of r
Std dev of r
Min
Max
Mathematical idea
Apply the inverse CDF of the Weibull distribution:

ti = τ · ( −ln(1 − ri) )1/β

with τ = 1.0, β = 1.5. This maps each uniform sample ri to a Weibull-distributed sample ti.
Why does this work?
The Weibull CDF is F(t) = 1 − exp(−(t/τ)β).
Setting r = F(t) and solving for t gives: t = F−1(r) = τ·(−ln(1−r))1/β.
Since r ~ U(0,1), then t = F−1(r) follows the Weibull distribution.
Python code
# Weibull parameters tau = 1.0 beta = 1.5 # Inverse transform sampling t = tau * (-np.log(1 - r))**(1 / beta)
Side-by-side: r (uniform) → t (Weibull)
Mean of t
Std dev of t
Max of t
Python code
delta_t = 0.1 # Bin width edges = np.arange(0, 5+delta_t, delta_t) # Bin edges counts, _ = np.histogram(t, edges) # Count samples in each bin pdf_est = counts / (N * delta_t) # Estimated PDF # Analytical PDF of the Weibull distribution analytic = (beta/tau * (edges/tau)**(beta-1)) * np.exp(-(edges/tau)**beta)
How binning works — step by step
0.50 80
Max absolute error
N samples
Num bins (at Δt=0.1)