Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Quality Control Sampling | Probability & Statistics
Mathematics for Data Science

bookChallenge: Quality Control Sampling

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
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)=1σ2πe(xμ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x - \mu)^2}{2\sigma^2}}

Standard deviation from variance:

σ=variance\sigma = \sqrt{\text{variance}}

Binomial distribution PMF:

P(X=k)=(nk)nk(1n)nk,where(nk)=n!k!(nk)!P(X = k) = \begin{pmatrix}n\\k\end{pmatrix}n^k(1-n)^{n-k},\quad \text{where}\begin{pmatrix}n\\k\end{pmatrix} = \frac{n!}{k!(n-k)!}

Uniform distribution PDF:

f(x)=1baforaxbf(x) = \frac{1}{b-a}\quad \text{for}\quad a \le x \le b
Opgave

Swipe to start coding

  1. Complete the starter code below by filling in the blanks (____) using the concepts/formulas above.
  2. Use only random and math modules.
  3. Implement three functions to generate 1000 samples from each distribution (Normal: using random.gauss(); Binomial: simulating n Bernoulli trials; Uniform: scaling random.random()).
  4. Plot histograms for each distribution (plotting code given, just complete the sampling functions and parameters).
  5. Retain all comments exactly as shown, they explain each step.
  6. No use of numpy random functions or external sampling libraries.

Løsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 5. Kapitel 12
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Can you explain how to use these distributions for simulating the production process?

What are typical parameter values for each distribution in this context?

Can you provide an example of how to calculate probabilities using these formulas?

close

Awesome!

Completion rate improved to 1.89

bookChallenge: Quality Control Sampling

Stryg for at vise menuen

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
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)=1σ2πe(xμ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x - \mu)^2}{2\sigma^2}}

Standard deviation from variance:

σ=variance\sigma = \sqrt{\text{variance}}

Binomial distribution PMF:

P(X=k)=(nk)nk(1n)nk,where(nk)=n!k!(nk)!P(X = k) = \begin{pmatrix}n\\k\end{pmatrix}n^k(1-n)^{n-k},\quad \text{where}\begin{pmatrix}n\\k\end{pmatrix} = \frac{n!}{k!(n-k)!}

Uniform distribution PDF:

f(x)=1baforaxbf(x) = \frac{1}{b-a}\quad \text{for}\quad a \le x \le b
Opgave

Swipe to start coding

  1. Complete the starter code below by filling in the blanks (____) using the concepts/formulas above.
  2. Use only random and math modules.
  3. Implement three functions to generate 1000 samples from each distribution (Normal: using random.gauss(); Binomial: simulating n Bernoulli trials; Uniform: scaling random.random()).
  4. Plot histograms for each distribution (plotting code given, just complete the sampling functions and parameters).
  5. Retain all comments exactly as shown, they explain each step.
  6. No use of numpy random functions or external sampling libraries.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

close

Awesome!

Completion rate improved to 1.89
Sektion 5. Kapitel 12
single

single

some-alt