Zufallszahlgeneratoren und Hacker-Statistik

Statistical Thinking in Python (Teil 1)

Justin Bois

Teaching Professor at the California Institute of Technology

Hacker-Statistik

  • Verwendet simulierte Wiederholungen, um Wahrscheinlichkeiten zu berechnen.
Statistical Thinking in Python (Teil 1)

  ch3-2.004.png

1 Bild: Künstler unbekannt
Statistical Thinking in Python (Teil 1)

ch3-2.005.png

1 Bild: Heritage Auction
Statistical Thinking in Python (Teil 1)

Münzwürfe simulieren

ch3-2.010.png

Statistical Thinking in Python (Teil 1)

Bernoulli-Versuche

  • Ein Experiment mit zwei Optionen: „Erfolg“ (True) und „Misserfolg“ (False).
Statistical Thinking in Python (Teil 1)

Das Modul np.random

import numpy as np
rng = np.random.default_rng()

rng
Generator(PCG64) at 0x7F9433D38120
Statistical Thinking in Python (Teil 1)

Zufalls-Seed

  • Ganzzahl für den Zufallsalgorithmus
  • Sampler nur manuell seeden, wenn du Reproduzierbarkeit brauchst
  • Angegeben mit rng = np.random.default_rng(seed)
Statistical Thinking in Python (Teil 1)

4 Münzwürfe simulieren

rng = np.random.default_rng(42)

random_numbers = rng.random(size=4)
random_numbers
array([0.77395605, 0.43887844, 0.85859792, 0.69736803])
heads = random_numbers < 0.5
heads
array([False,  True, False, False])
np.sum(heads)
1
Statistical Thinking in Python (Teil 1)

4 Münzwürfe simulieren

n_all_heads = 0  # Anzahl der Versuche mit 4×Kopf
for _ in range(10000):
     heads = np.random.random(size=4) < 0.5
     n_heads = np.sum(heads)
     if n_heads == 4:
         n_all_heads += 1

n_all_heads / 10000
0.0607
Statistical Thinking in Python (Teil 1)

Wahrscheinlichkeiten in der Hacker-Statistik

  • Festlegen, wie die Daten simuliert werden
  • Sehr oft simulieren
  • Wahrscheinlichkeit ≈ Anteil der Versuche mit dem interessierenden Ergebnis
Statistical Thinking in Python (Teil 1)

Lass uns üben!

Statistical Thinking in Python (Teil 1)

Preparing Video For Download...