liveBook · Manning

Trial

As explained in Statistics Every Programmer Needs

A trial is one execution of a simulated experiment that produces a possible system outcome.

A trial is one execution of a simulated experiment. It samples values for the model variables and produces one possible system outcome, preserving variability that deterministic calculations conceal. section 9.2

Monte Carlo trials follow a repeatable workflow:

  • Sample random values according to the defined probability distribution. section 9.2
  • Map each sampled value to an outcome using cumulative-probability intervals. section 9.2
  • Aggregate trial outcomes to estimate distributions, averages, variability, and risk. section 9.2
  • Increase the trial count when greater stability and statistical reliability are needed, while recognizing diminishing returns. section 9.4

Absenteeism staffing

A call-center trial maps one random digit to a Poisson-distributed absentee count. A digit of 73 maps to k = 3, suggesting three additional associates for that scenario. Across 10 trials, the mean staffing requirement is 2.4. section 9.3.5

>>> np.random.seed(1)     #1
>>> num_trials = 500     #2
>>> normalized_probabilities = \
>>>     probabilities / probabilities.sum()    #3
>>> simulated_values = np.random.choice(k_values,     #4
>>>                      size = num_trials,     #5
>>>                      p = normalized_probabilities)     #6
>>> unique, counts = \
>>>     np.unique(simulated_values,     #7
>>>                 return_counts = True)   #8
>>> simulated_counts = \
>>>     dict(zip(unique, counts))       #9
>>> simulated_percentages = \
>>>     {k: (v / num_trials) * 100 for k, \
>>>     v in simulated_counts.items()}     #10

Inspect the NumPy implementation for reproducible random sampling, probability normalization, trial counts, and outcome frequencies. section 9.4

How Statistics Every Programmer Needs covers it

How deep it goes
Explains sampling, interval mapping, aggregation, and scaling, but does not derive simulation theory or implementation internals.
Examples
Demonstrates absentee-staffing trials using random digits mapped to Poisson counts and summarized across 10 or 500 executions.
What it assumes
Assumes basic probability distributions and random sampling while teaching cumulative intervals, trial generation, and result aggregation.
What you can do after
Evaluate/understand simulated variability by generating trials, aggregating outcomes, and comparing staffing or risk scenarios.
How it connects
Connects trials to Monte Carlo simulation, probability distributions, cumulative distributions, random variables, and Poisson distributions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.