Section 5. Chapter 12
single
Challenge: Quality Control Sampling
Swipe to show menu
You are the quality control manager at a rod manufacturing factory. You need to simulate measurements and defect counts using three different probability distributions to model your production process:
- Normal distribution for rod weights (continuous);
- Binomial distribution for the number of defective rods in batches (discrete);
- Uniform distribution for rod length tolerances (continuous).
Note
Your task is to translate the formulas and concepts from your lecture into Python code. You must NOT use built-in numpy random sampling functions (e.g., np.random.normal) or any other library's direct sampling methods for the distributions. Instead, implement sample generation manually using the underlying principles and basic Python (e.g., random.random(), random.gauss()).
Formulas to Use
Normal distribution PDF:
f(x)=σ2π1e−2σ2(x−μ)2Standard deviation from variance:
σ=varianceBinomial distribution PMF:
P(X=k)=(nk)nk(1−n)n−k,where(nk)=k!(n−k)!n!Uniform distribution PDF:
f(x)=b−a1fora≤x≤bTask
Swipe to start coding
- Set the parameters for the Normal distribution: assign
200to the mean (mu) and25to thevariance. - Calculate the standard deviation (
sigma) from the givenvarianceusing themath.sqrt()function. - Set the parameters for the Binomial distribution: assign 20 to the number of inspected rods per batch (
n) and 0.05 to the probability of a rod being defective (p). - Set the parameters for the Uniform distribution: assign 49.5 to the minimum rod length (
a) and 50.5 to the maximum length (b). - Implement three functions to generate 1000 samples for each distribution using only the
randomandmathmodules:sample_normal: userandom.gauss().sample_binomial: simulatenindependent Bernoulli trials (increment success ifrandom.random() < p).sample_uniform: scalerandom.random()to the range[a, b].
- Run the code to plot the histograms and visualize your factory's data. Do not use
numpyrandom functions or any external sampling libraries.
Solution
Everything was clear?
Thanks for your feedback!
Section 5. Chapter 12
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat