Learn more from fewer runsLesson 45 of 76 · 8 min

Give every part of the domain a turn

Construct a stratified estimator with correct stratum weights.

Stratification divides a sampling domain into known pieces, samples within each piece and combines their estimates with the correct weights. For equal-width intervals under a uniform distribution, each stratum has equal probability weight.

Compare ordinary uniform sampling with one random point from each of n equal intervals. Every replicate has the same evaluation budget. Independent replicates let you estimate the spread of the resulting estimators without pretending the stratified points are ordinary iid uniform draws.

The improvement depends on the integrand and stratification. If strata have unequal probability or receive unequal sample counts, the combination must retain their weights. A raw average of all sampled values can otherwise target the wrong distribution.

IhI_h is stratum h, one piece of the domain. ⋃\bigcup joins all pieces; whw_h is the piece's probability weight and fˉh\bar f_h is its sample function mean.

Give every stratum its own draw
  1. Partition the domain
    [0,1]=⋃hIh[0,1]=\bigcup_h I_h
  2. Sample inside each part
    Uh∼U(Ih)U_h\sim U(I_h)
  3. Weight the stratum means
    μ^=∑hwhfˉh\widehat\mu=\sum_h w_h\bar f_h
Reference illustration. Stratum weights represent their target probability or domain mass. Equal weights are justified for this source’s equal-width uniform strata, not every stratification.

Will one draw in every equal-width interval leave the same gaps as ordinary random draws?

Write a prediction (optional)

Seeded teaching simulation

Select Run Python below with the code unchanged.

Tools
About Python ↗

The code is editable. Press Ctrl+Enter or ⌘+Enter to run Python from the editor.

Published example output

This result comes from the original Python. Your runs appear above. Build environment ↗

Exact expectation: 0.3333333333333333
SD across ordinary estimates: 0.029888
SD across stratified estimates: 0.000338
Evaluations per estimate: 100

Read the first result

The comparison uses equal evaluations per estimate. Replicate-level spread is the relevant numerical-error evidence here.

Try an edit

Replace rng.random((repetitions, n))**2 with rng.random((repetitions, n)) > .973 and stratified_u**2 with stratified_u > .973 and print("Exact expectation:", 1/3) with print("Exact expectation:", 1-.973). Select Run Python again. Read Evaluations per estimate and compare SD across ordinary estimates and SD across stratified estimates for the new indicator.

Back to the Python editor

Scope. The example is one-dimensional with equal strata. High-dimensional or poorly chosen strata need separate analysis.

Try a fresh case

Two strata have probabilities 0.9 and 0.1, but you sample equally many draws in each. How should their mean estimates be combined?

Choose an answer
Need a hint?
Hint 1

Identify the population weight of each stratum.

Hint 2

Do not confuse deliberate allocation with target probability.

Your notes