Ran Wei/Maths Series
中文
Mathematical Foundations for Computer Science and AI — Ran Wei

Limit theorems, concentration, and Monte Carlo

Prove moment bounds and a weak law, qualify CLT and Hoeffding statements, calculate sample sizes, and report Monte Carlo uncertainty with the actual independent sampling units.

10 hours4 sessions3 labs12 exercises + 2 extensions10 quiz questions

By the end you can

  • Calculate mean variation with independent and dependent sampling units.
  • Prove Markov and Chebyshev with thresholds and moments stated.
  • Derive the finite-variance weak law and interpret convergence in probability.
  • State the IID CLT without claiming universal finite-sample accuracy.
  • Apply bounded independent Hoeffding and finite-family union sample sizes.
  • Report Monte Carlo uncertainty and derive a qualified common-random-number comparison.

Before you start

Modules 04 and 23. Continuous integral alternatives require Module 17; the CS branch uses finite events. All three labs use only the Python standard library.

Contents

Study plan

10 hours

Times include practice and are estimates. Split a session when useful. Optional extension exercises add 35 minutes. Progress is stored in this browser and shared between language editions.

1

A sample mean needs an uncertainty contract

A large sample does not automatically justify a small error bar. The relevant quantity is variation of the estimator under a stated sampling mechanism, with dependence, tails and selection included. This lesson proves elementary probability bounds and a finite-variance weak law, states the qualified central limit and Hoeffding theorems, and uses them to report Monte Carlo estimates without converting one reproducible trace into an unconditional accuracy claim.

Retrieval check: Module 04 supplies proof structure; Module 23 supplies expectation, finite moments and covariance. Optional continuous integrals require Module 17; the CS route uses finite-event alternatives throughout. Labs use only the Python standard library and local generators.

2

Sampling assumptions and variation of an average

For observations X₁,…,X_N, define the sample mean M_N=(1/N)ΣX_i. It is a random variable before the sample is realised, and a numerical statistic afterwards. Independent identically distributed sampling, abbreviated IID, means every observation has the same distribution and every finite subcollection factors jointly. Independence alone does not give a common mean, while identical marginals alone do not give independence. A claim about M_N should specify the population quantity it targets and the actual sampling unit.

If each variable has meanμ, linearity gives E[M_N]=μ without independence. For finite variances, Var(M_N)=[ΣVar(X_i)+2Σ_{i<j}Cov(X_i,X_j)]/N². Under IID with varianceσ², all cross terms vanish and Var(M_N)=σ²/N. The standard deviation of this estimator is its standard error, σ/√N. It has the same units as the observed quantity and measures repeated-sample variation, rather than spread of the original observations. Calling the original standard deviation an error bar for the mean omits the averaging calculation.

Worked example
A copied observation does not acquire a smaller variance

Let Z be Bernoulli(.3) and set every X_i=Z. Each marginal has mean.3 and variance.21, but M_N=Z and Var(M_N)=.21 for every N. The independence shortcut would give.21/N and is wrong. Every covariance is.21, so the full formula restores the exact answer. Repeating the same record N times creates N rows but only one random draw.

Clustered copies give an intermediate case. If m independent Bernoulli draws are each copied b times, N=mb rows, and their row mean equals the average of the m original draws. Its variance isσ²/m=bσ²/N. In this explicit equal-size-copy model m is the independent count; a general clustered dataset need not admit the same simple effective-size formula. Shared subjects, prompts, time blocks or devices can introduce covariance requiring a design-specific analysis instead of assuming every row is a new unit.

Non-identically distributed independent variables still obey variance addition: Var(M_N)=Σσ_i²/N², and meanE[M_N]=Σμ_i/N. That mean may target a deliberate mixture, but not automatically one fixed populationμ. If selection changes the μ_i or if an unrepresentative group mixture is sampled, increasing N can concentrate around the wrong target. Sampling variation and bias from a changed target are different quantities; a small standard error does not eliminate selection error.

With negative covariances averaging can vary less than the independent reference, while positive covariances can increase its variance. Independence is therefore a sufficient simplification rather than the definition of “good randomness.” Paired comparisons intentionally introduce dependence within each pair to reduce variation of a difference, as Section6 derives. The pairs themselves must have an appropriate cross-pair sampling contract. A dependence warning should name the actual shared source rather than simply reject every dependent construction.

In a numerical experiment, record whether draws share a generator stream, whether it is reset, and which observations are reused. A fixed local seed makes one run repeatable. Resetting it to the same value for every purported replicate repeats the same stream, while using several different integer seeds does not by itself constitute a proof of statistical independence. Mathematical theorems idealise a stated random mechanism; reproducibility documents the implementation and does not add random information to a copied dataset.

Mean variance under independence and copyingThree model mean variances are sigma squared over N, over independent cluster count m, and sigma squared; copied rows do not add independent information.Rows and independent draws can differN IID drawsVar(M) = σ²/Nm independent draws, b copies eachVar(M) = σ²/m = bσ²/NOne draw copied N timesVar(M) = σ²Adding copies does not remove covariance.
Figure 24.1

IID observations average down variance as1/N. Copies and equal-size clusters preserve shared covariance, so nominal row count can overstate independent information.

Check your understanding

Does mean linearity require independence? Which quantity needs the covariance terms? Does copying records increase the independent sample count?

Show answer

Common-mean linearity is valid without independence. Variance of the mean includes all pair covariances. Copies preserve the shared random draw, so their nominal row count cannot justify an IID standard error.

3

Markov and Chebyshev bounds with complete elementary proofs

For nonnegative W with finite expectation and t>0, Markov’s inequality is P(W≥t)≤E[W]/t. Prove pointwise that W≥t1{W≥t}; expectation and nonnegativity give E[W]≥tP(W≥t), then divide by positive t. No independence is required. A bound greater than one can be clipped to one for reporting. The threshold must be positive: dividing by zero is unavailable, and a negative-variable mean cannot replace the nonnegative variable required by the proof.

Apply Markov to W=(X−μ)² for finite-variance X and positiveε. The event W≥ε² is exactly |X−μ|≥ε, so P(|X−μ|≥ε)≤Var(X)/ε². This is Chebyshev’s inequality. Its proof uses a second moment but no Gaussian shape or sampling independence. Independence matters only when a preceding calculation replaces the variance of a sum by the independent formula. If variance is infinite, the bound supplies no finite accuracy information; a tiny empirical variance does not justify substituting a finite population variance.

P(∣X−E[X]∣≥ε)≤Var⁡(X)ε2,ε>0.P(|X-E[X]|\geq\varepsilon)\leq\frac{\operatorname{Var}(X)}{\varepsilon^2},\qquad \varepsilon>0.
Worked example
Chebyshev controls an IID Bernoulli mean with a known variance

For IID Bernoulli(.5), σ²=.25. With N=1000 and ε=.05, Var(M_N)=.00025, so deviation probability is at most.00025/.0025=.1. If p is unknown, Bernoulli variance p(1−p)≤1/4 gives the same worst-case bound. This is a finite-sample probability guarantee under independence and common p, not a statement that each realised error is at most.05.

To make the bound at mostδ, with0<δ<1, choose N≥σ²/(δε²). For Bernoulli without known p use N≥1/(4δε²). At ε=.05,δ=.05 the sufficient size is2000. This is a conservative sufficient requirement derived from only a variance bound; it is not a lower bound on what every estimator or every particular distribution needs. A sharper model-specific calculation may obtain a smaller valid requirement, while violating the sampling assumptions can invalidate the requirement entirely.

Chebyshev can also be sharp for a specified moment-only statement. Let X be0 with probability1−q and ±a each with probabilityq/2, where0<q≤1. Mean is0 and varianceqa². At thresholda, the deviation probabilityq exactly equals variance/a². Thus a universally sharper coefficient cannot be obtained solely by pretending every finite-variance variable is close to Gaussian. Additional tail, support or distribution information can improve a bound, but must be stated as an additional assumption.

A probability guarantee differs from a deterministic error bound. Chebyshev allows exceptional samples with probability at mostδ when a selected threshold meets its bound. A numerical quadrature theorem can instead bound truncation error deterministically for every function satisfying its derivative assumptions. Both need valid assumptions and correct units, but their quantifiers differ. A Monte Carlo report should not write “error guaranteed≤ε” when its theorem gives only P(error≥ε)≤δ.

Union bounds combine several deviation guarantees without assuming their events are independent. If m specified estimates each fail their accuracy condition with probability at mostδ/m, the chance any fails is at mostδ. The estimates may use overlapping records, provided each individual guarantee remains valid. Choosing which estimates to report after inspecting outcomes introduces another selection issue: a fixed list theorem cannot silently cover an unbounded adaptive search. Section5 develops a finite specified family, while later learning theory handles broader model selection.

Bounds can be valid and uninformative at small sample sizes. For N=20,ε=.2 and Bernoulli worst variance.25, Chebyshev gives.3125. For smallerε the raw bound can exceed one, correctly indicating that these assumptions do not establish a useful small failure probability. Report that limitation directly rather than label the bound “wrong” or replace it with a visually attractive error band lacking a theorem. A loose valid upper bound and an actual tail probability answer different questions.

Check your understanding

Which pointwise inequality proves Markov? Does Chebyshev require Gaussian observations? What does a sufficient sample-size bound fail to establish?

Show answer

W≥t1{W≥t} for nonnegative W and positive t. Chebyshev only needs the relevant finite variance. A sufficient size is neither a necessary minimum nor a deterministic guarantee for every realised sample.

4

A finite-variance weak law and its convergence meaning

For IID X_i with finite meanμ and varianceσ², Chebyshev applied to their mean gives P(|M_N−μ|≥ε)≤σ²/(Nε²)→0 for every fixedε>0. This proves the finite-variance weak law of large numbers: M_N converges toμ in probability. The quantifiedε is fixed while N grows; its associated tail probability tends to zero. The proof is complete here and does not infer a theorem from the shape of one simulated trace.

Convergence in probability says that increasingly large experiments have a decreasing probability of a fixed-size deviation in the limiting sense. It does not say every finite error decreases, that no bad sample occurs, or that a realised trace eventually follows an exact deterministic tolerance rule. Almost-sure convergence concerns the probability that an entire infinite sample path has a limiting value and is a different statement. Strong-law results exist under appropriate assumptions, but this elementary Chebyshev proof establishes only the stated weak law.

Worked example
A sample-size ratio describes variation, not a monotone trace

For an IID estimate with finite variance, N=100 gives standard errorσ/10 and N=400 givesσ/20. Quadrupling N halves the standard error. A particular400-observation estimate can still be farther fromμ than the corresponding100-observation estimate. The standard error describes a distribution across repeated samples, while the realised error is one outcome from that distribution.

The weak-law variance argument needs less than full IID if a replacement variance bound is available. Suppose common-mean finite-variance variables have all pair covariances zero and variances bounded byC. Then Var(M_N)≤C/N, so the same Chebyshev proof gives convergence in probability. Pairwise uncorrelatedness does not imply mutual independence or establish the IID CLT stated next. More generally any unbiased mean estimator whose variance tends to zero obeys this probability convergence proof; whether that variance actually vanishes is the essential obligation.

The all-copy example violates that obligation: Var(M_N)=σ² does not tend to zero. For Bernoulli(.3) copies andε=.1, every possible mean is0 or1 and differs from.3 by at least.3, so the deviation probability is1 for every N. Identical marginals and an infinite row count therefore do not supply the weak law. A nonzero common bias also prevents convergence to the intended target even if variance around the biased mean shrinks.

When the model has an infinite variance, this proof is unavailable. Some finite-mean distributions still satisfy other law-of-large-numbers theorems, but one cannot applyσ²/(Nε²) with an invented finiteσ². A variable with undefined mean has no such targetμ to substitute. Module23’s moment examples distinguish these cases. State the theorem version actually used rather than summarise every large-sample statement as “averages always work.”

For a fixedε,δ specification the Chebyshev formula provides a concrete finite size before any limit is invoked. The asymptotic weak law instead says some sufficiently large size exists for each target, without claiming the conservative bound is tight. In practice a stopping rule based on the observed estimate changes the experiment. A fixed-N guarantee cannot automatically be applied at a random data-dependent stopping time; valid sequential procedures need their own analysis. The course labs use fixed checkpoints for illustration and do not turn a lucky checkpoint into a theorem.

Replication can help inspect an implementation. If separate simulated datasets follow the same IID mechanism, their sample means should show variation consistent with the model in aggregate. Repeatedly resetting an identical generator stream instead creates the same dataset and reports zero between-run variation. That observation diagnoses the replication protocol, not a miraculous elimination of population uncertainty. Store seeds and their role, and distinguish one long cumulative trace from many independent replicate experiments.

Check your understanding

Which convergence does the variance proof establish? Must realised error decrease at every N? Can pairwise uncorrelated bounded variances support this weak-law proof without supporting the IID CLT?

Show answer

Convergence in probability for every fixed positive tolerance. Realised errors can fluctuate. A variance≤C/N is sufficient for this Chebyshev weak law, while the IID CLT has additional distributional assumptions.

5

The central limit theorem standardises means not observations

Fixed tolerance and standardised limitsThe weak law fixes tolerance and sends the tail probability to zero; the CLT divides mean fluctuations by standard error for a standard Gaussian limit.Weak law and CLT use different scalesFix ε > 0, increase NP(|M_N − μ| ≥ ε) ≤ σ²/(Nε²) → 0Rescale fluctuations, not raw observationsZ_N = √N(M_N − μ)/σ ⇒ N(0,1)CLT: IID, 0 < σ² < ∞; no finite error rate stated here.
Figure 24.2

The finite-variance weak law sends each fixed-tolerance tail probability to zero. The CLT rescales fluctuations by the changing standard error; these two limits answer different questions.

The standard IID finite-variance central limit theorem assumes a common meanμ and0<σ²<∞. It states that Z_N=√N(M_N−μ)/σ converges in distribution to a standard Gaussian: for every realz, P(Z_N≤z)→Φ(z). This is a named theorem, not proved by the variance identity alone. The MIT CLT materials give its qualified statement. It applies to the standardised mean or sum, while the individual X_i retain their original distributions.

ZN=N(MN−μ)σ,P(ZN≤z)⟶Φ(z).Z_N=\frac{\sqrt N(M_N-\mu)}{\sigma},\qquad P(Z_N\leq z)\longrightarrow\Phi(z).

For suitable large-N approximation, M_N is approximately Gaussian with meanμ and varianceσ²/N, so a band of about1.96σ/√N aroundμ contains about95% of its sampling distribution. The word “about” matters: the theorem as stated supplies no universal finite-N error bound or exact95% coverage. Discreteness, skewness and rare events can make convergence slow or a particular approximation poor. Replacing knownσ by an estimated standard deviation introduces further reasoning, explored in later estimation and inference modules.

Worked example
A rare Bernoulli mean can be mostly zero despite finite variance

For p=.01 and N=20, the success count is Binomial(20,.01) and P(no success)=.99²⁰≈.817907. Most means are exactly0, with occasional jumps of.05. A smooth Gaussian approximation cannot accurately represent that large atom. The original observations remain binary even as N grows. In Lab1 the finite fraction inside a1.96-known-SE band is not automatically.95; the exact discrete law explains why a visually convenient Gaussian claim needs qualification.

The normalised standard deviation is1 for Z_N, not for M_N; forgetting√N or usingσ² in place ofσ changes the approximation’s units and scale. Ifσ²=0, observations equalμ almost surely and no nondegenerate standardisation is defined. If variance is infinite, this finite-variance CLT is unavailable. Other limit laws can arise under different assumptions. A long sample or a bell-shaped histogram does not substitute for checking which mean, variance and dependence model justify the theorem.

When X_i themselves are Gaussian and independent, their mean is exactly Gaussian for every N, a special stronger result of that family. For general finite-variance observations the CLT is asymptotic. Finite-sample normal-approximation error theorems need additional moment or distribution information; we do not claim a single threshold such as “N≥30” certifies accuracy for every population. Rare Bernoulli counts depend on both Np and N(1−p), and even common rules based on those counts are heuristics unless coupled to an appropriate error analysis.

Discrete event boundaries need attention when using a continuous approximation. For an integer count K, a continuity correction can replace a boundary between adjacent counts by a half-integer in the Gaussian approximation. It is an approximation technique, not an exact event identity or a universal coverage repair. Exact binomial calculations are available for the small examples and can reveal the residual discrepancy. Keep exact support and strict/non-strict threshold conventions visible before translating to an approximate continuous curve.

An asymptotic95% statement is also not a posterior probability that the population mean lies in a particular realised interval. Its interpretation concerns repeated sampling of an estimator under a specified population. Module26 develops confidence coverage carefully, while Module25 introduces Bayesian posterior uncertainty. This lesson distinguishes a theorem about a sampling distribution from a claim about an unknown fixed parameter after data are seen, so later inferential statements have the correct foundation.

CLT reasoning should be tested with independent replicates of the mean, not by plotting all raw observations and expecting them to become Gaussian. Lab1 compares fair and rare Bernoulli sample means at two sizes. The experiment can illustrate the predicted standard errors and shape differences, but cannot prove a theorem or establish a universal approximation error. The finite-count explorer next offers a complete model calculation alongside genuine upper bounds, avoiding reliance on a smooth visual alone.

Check your understanding

Which variable becomes approximately Gaussian in the theorem? Does finite variance give a universal finite-N error rate here? What prevents standardisation for a degenerate variable?

Show answer

The standardised sample mean, not each raw observation. The stated theorem gives asymptotic distributional convergence without a universal finite-size accuracy guarantee. Zero variance makes division byσ unavailable and corresponds to a constant mean almost surely.

6

Hoeffding bounds sample sizes and finite simultaneous claims

A bounded-independent-variable theorem gives a stronger finite-size bound than moment information alone in many regimes. For independent X_i with deterministic a_i≤X_i≤b_i and positiveΣ(b_i−a_i)², Hoeffding bounds P(|Σ(X_i−E[X_i])|≥t) by2exp(−2t²/Σ(b_i−a_i)²), t>0. This qualified named theorem is documented in MIT’s probability notes. If every range is zero, the sum is deterministic and positive-threshold deviations have probability zero.

For IID observations in[0,1], substitute t=Nε and total squared rangesN to obtain P(|M_N−μ|≥ε)≤2exp(−2Nε²). Clamp the displayed upper bound at one. Boundedness provides finite moments, but independence remains an essential assumption. Identical distributions are unnecessary for the general sum bound; without them the centred mean targets the average of individual means. Rescaling a common range[a,b] multiplies the required squared tolerance scale by(b−a)².

P(∣MN−μ∣≥ε)≤2e−2Nε2for IID values in [0,1].P(|M_N-\mu|\geq\varepsilon)\leq2e^{-2N\varepsilon^2}\quad\text{for IID values in }[0,1].
Worked example
A sufficient bounded-data size beats a variance-only size here

For ε=.05 andδ=.05, solve2exp(−2Nε²)≤δ to get N≥log(2/δ)/(2ε²)=log40/.005≈737.776, so N=738 suffices. The worst-variance Chebyshev requirement was2000. Neither number is a necessary minimum for every Bernoulli p, and neither applies to arbitrary dependent copies. Natural logarithms match the exponential base in the formula.

For m specified[0,1]-valued estimates each based on N appropriate independent observations, apply the individual bound and then a union bound: probability any mean deviates byε is at most2mexp(−2Nε²). The estimates may be dependent on each other; the union step needs no cross-estimate independence. To guarantee at mostδ, choose N≥log(2m/δ)/(2ε²). With m=20,ε=.05,δ=.05, N=1337 is a sufficient integer size. The list must be specified or otherwise covered by the theorem before claiming simultaneous validity.

Checking one fixed model and then selecting among many based on the same outcomes changes the claim. The finite-family union argument can protect an entire specified list, but the original single-model guarantee cannot automatically follow a chosen winner. Later Module30 applies this distinction to learning and generalisation. Likewise inspecting infinitely many checkpoints is not covered by one fixed-Nδ statement; a valid union allocation or sequential method must cover the events actually inspected.

A Hoeffding radius at confidence level1−δ is ε_N=√[log(2/δ)/(2N)] for[0,1] observations. It does not use an estimated variance, so it remains positive when a Bernoulli sample has zero successes. At N=100,δ=.05 the radius is about.135810. A plug-in standard error√[p_hat(1−p_hat)/N] instead becomes zero at p_hat=0; that alone does not certify p=0 or eliminate uncertainty. Under a synthetic p=.001 model,100 zero observations occur with probability.999¹⁰⁰≈.904792.

Interactive
Tail probability and valid upper boundsFor twenty fair Bernoulli draws the mean deviation tail at least point two is approximately point1153, below Chebyshev point3125 and Hoeffding approximately point4038.The same IID Bernoulli(.5) eventN=20; ε=.20; |M−.5| ≥ .20Finite-model tail0.115318Chebyshev0.312500Hoeffding0.403793An upper bound is not the actual probability; check its conditions.
Figure 24.3

Chebyshev uses a variance bound, while Hoeffding uses independent bounded observations. Both upper bounds can exceed the actual finite-model tail and should be clipped at one for reporting.

The explorer compares IID Bernoulli means with rows copied from one common Bernoulli draw. It evaluates the finite-model deviation probability numerically and displays Chebyshev using the actual variance. Hoeffding’s N-observation expression is shown only for the independent mode. The shaded tail includes equality at the tolerance boundary; integer-percent inputs let the event be checked through an exact integer inequality before its masses are summed in floating-point arithmetic.

Different bounds can be tighter in different regimes. At small N or large known-variance advantages, Chebyshev can outperform a generic bounded Hoeffding bound; at larger N a bounded exponential guarantee often improves on the1/N variance bound. Compare valid numerical bounds for the same event and assumptions, rather than assert that one named inequality is always numerically best. An exact finite model can additionally compute the actual tail, while the general theorem offers a guarantee without knowing all those masses.

Check your understanding

Which assumptions support Hoeffding’s finite bound? Does a union over estimates require those estimates to be independent? Does zero plug-in SE establish zero population uncertainty?

Show answer

Independent draws and stated deterministic bounds, with the appropriate target mean. The union step needs no independence between failure events. An all-zero sample can be very probable under a nonzero rare rate, so its zero plug-in SE supplies no exact certainty.

7

Monte Carlo reports seeds and variance reduction by pairing

Monte Carlo estimates an expectation by sample averaging under a specified sampling mechanism. For a finite event A, average its indicator to estimate p=P(A); under IID sampling it is unbiased and has variance p(1−p)/N. A plug-in SE estimates its variation but needs its own interpretation at boundaries and small counts. If p is known in a synthetic experiment, the model SE is available for comparison; if p is unknown in an application, it cannot be inserted as though known.

Optional continuous branch requiring Module17: for I=∫_a^b h(x)dx and U uniform(a,b), I=(b−a)E[h(U)]. With IID U_i and finite Var(h(U)), estimator I_hat=(b−a)Σh(U_i)/N has variance(b−a)²Var(h(U))/N. For h(x)=x² on[0,1], I=1/3 and Var(U²)=1/5−1/9=4/45. The CS alternative uses the finite-event estimator and the same mean-variance logic without an integral prerequisite.

Worked example
Common random numbers reduce variation of this difference

Let A=1{U<.6}, B=1{U<.55} using the same ideal uniform U. Their means are.6,.55, so E[A−B]=.05. The difference is1 only when.55≤U<.6, giving variance.05(.95)=.0475. With independent uniforms for A and B, variance is.6(.4)+.55(.45)=.4875. For10000 independent pairs, SEs are about.002179 and.006982 respectively. Both estimate the same difference; positive within-pair covariance reduces its variance.

The general paired identity is Var(A−B)=Var(A)+Var(B)−2Cov(A,B). Pairing helps relative to independent marginals when covariance is positive, harms when negative, and gives no change when zero. It is not a universal improvement from reusing randomness. Preserve each method’s intended marginal distribution and make pairs independent across replications before applying the usual pair-mean SE. In empirical comparisons, pairing by the same input can similarly reduce nuisance variation when the design and analysis treat the pair as the unit.

Report the estimator, target, sample count of actual independent units, seed protocol, variance assumptions, uncertainty quantity and any theorem or approximation used. An estimated standard error is different from a distribution-free radius and from an actual realised absolute error known only in a synthetic test. If deterministic numerical approximation is also used inside each simulation, its bias or truncation error contributes separately; increasing random sample count cannot remove a persistent inner-solver bias.

Absolute and relative tolerances also demand different sample sizes. For an IID Bernoulli event, dividing the known standard error by a nonzero rate gives relative SE equal to the square root of (1−p)/(Np). A fixed absolute tolerance can be quite large relative to a rare target: an absolute error of .005 is half a rate of .01, although it is only one hundredth of a rate of .5. When p is zero, this relative expression is undefined rather than an invitation to divide a zero estimate by zero. State the desired error scale before choosing N, and do not switch from an absolute probability theorem to a relative guarantee without a separate derivation.

The cost comparison for a variance reduction method should include computational work. If one paired replication needs two simulator evaluations, compare its variance at a fixed evaluation budget with the independent alternative using the same budget. A method with smaller per-replication variance may have expensive coupling, storage or evaluation costs. In the threshold example both alternatives require two indicator evaluations per pair, making the derived variance comparison directly meaningful at equal pair counts. For another simulator, record the budget and preserved target explicitly before claiming improved efficiency. Reproducibility includes these design choices as well as the seed: the same random integers cannot rescue an estimator aimed at a changed quantity.

Qualified common-random-number benefitWith preserved marginals, independent difference variance point4875 falls to point0475 with shared uniforms and positive covariance point22; this benefit is not universal.Preserve marginals, then compare difference varianceVar(A−B) = Var(A)+Var(B)−2Cov(A,B)Independent thresholds .60 and .55.24 + .2475 = .4875Shared U, within-pair Cov=.22.4875 − .44 = .0475Pairs still need independence; negative Cov increases difference variance.
Figure 24.4

Pairing subtracts twice the within-pair covariance from difference variance. Repeated copies of an entire stream add no independent replications.

Lab1 examines repeated means, Lab2 reports finite-event and optional integral estimates, and Lab3 exposes repeated seeds, copied clusters and zero plug-in error bars. Its common-random-number example is a valid deliberate coupling with explicitly preserved marginals. A reproducible script can therefore support a precise experimental claim, while the associated theorem still depends on the mathematical sampling assumptions. Keep numerical evidence, a named limit theorem and a finite probability guarantee separate.

Check your understanding

What distinguishes Monte Carlo error from quadrature truncation? When does pairing reduce a difference variance? What sample count belongs in a copied-cluster error formula?

Show answer

Monte Carlo error varies with random draws; deterministic truncation needs an approximation bound. Positive within-pair covariance reduces the difference variance with unchanged marginals. The explicit equal-copy model averages independent clusters, so it uses the number of original draws rather than copied rows.

8

Common misconceptions

Claim Repair
Every row is a new independent observation. Copies and clusters retain covariance.
Chebyshev requires Gaussian data. Finite variance and a positive threshold suffice.
The weak law makes every error shrink monotonically. It states convergence in probability.
The CLT changes raw observations into Gaussians. It concerns standardised means or sums.
A universal N≥30 certifies the CLT approximation. Distribution shape and extra error assumptions matter.
Hoeffding applies to arbitrary dependent copies. Its independent-draw assumption must be checked.
Zero estimated SE proves zero uncertainty. Boundary samples can occur under a nonzero rate.
Pairing always reduces variance. The covariance sign determines its effect.
9

Three reproducible labs

Lab1 · Repeated means and finite-sample shapes

Download lab1_repeated_sample_means.py

"""Repeated IID Bernoulli means: exact variance, finite-sample discreteness."""
from math import sqrt
import random

if __name__ == "__main__":
    generator = random.Random(24024)
    repeats = 3000
    for p in (.5, .01):
        for n in (20, 1000):
            means = [sum(generator.random() < p for _ in range(n))/n for _ in range(repeats)]
            empirical_mean = sum(means)/repeats
            empirical_sd = sqrt(sum((x-empirical_mean)**2 for x in means)/(repeats-1))
            exact_sd = sqrt(p*(1-p)/n)
            zeros = sum(x == 0 for x in means)/repeats
            within = sum(abs(x-p) <= 1.96*exact_sd for x in means)/repeats
            print("p=%.2f n=%4d mean=%.6f empiricalSD=%.6f exactSD=%.6f zeroFraction=%.6f exactPzero=%.6f" % (
                p, n, empirical_mean, empirical_sd, exact_sd, zeros, (1-p)**n))
            print("  fraction within1.96 known SD: %.6f (a finite check, not guaranteed95%%)" % within)
    print("Original observations stay Bernoulli; CLT concerns standardised sample means.")
    print("Rare p=.01,n20 is mostly zero and poorly represented by a smooth Gaussian.")
Output
p=0.50 n=  20 mean=0.501250 empiricalSD=0.111744 exactSD=0.111803 zeroFraction=0.000000 exactPzero=0.000001
  fraction within1.96 known SD: 0.959667 (a finite check, not guaranteed95%)
p=0.50 n=1000 mean=0.500040 empiricalSD=0.016054 exactSD=0.015811 zeroFraction=0.000000 exactPzero=0.000000
  fraction within1.96 known SD: 0.943667 (a finite check, not guaranteed95%)
p=0.01 n=  20 mean=0.009617 empiricalSD=0.021684 exactSD=0.022249 zeroFraction=0.823000 exactPzero=0.817907
  fraction within1.96 known SD: 0.985667 (a finite check, not guaranteed95%)
p=0.01 n=1000 mean=0.010042 empiricalSD=0.003122 exactSD=0.003146 zeroFraction=0.000000 exactPzero=0.000043
  fraction within1.96 known SD: 0.966000 (a finite check, not guaranteed95%)
Original observations stay Bernoulli; CLT concerns standardised sample means.
Rare p=.01,n20 is mostly zero and poorly represented by a smooth Gaussian.

Predict each model SE, rare no-success probability and support spacing. The within1.96-SE fraction is a finite diagnostic, not an exact95% theorem. The raw draws remain Bernoulli.

Lab2 · Monte Carlo estimate and uncertainty quantities

Download lab2_monte_carlo_error.py

"""Finite-event Monte Carlo; optional continuous integration requires Module17."""
from math import sqrt, log
import random

if __name__ == "__main__":
    generator = random.Random(24242)
    hits = 0
    sum_square = 0.0
    for n in range(1, 10001):
        # A weighted finite event with total mass .3, represented by a threshold.
        hits += generator.random() < .3
        u = generator.random()
        sum_square += u*u
        if n in (100, 1000, 10000):
            estimate = hits/n
            plugin_se = sqrt(estimate*(1-estimate)/n)
            known_se = sqrt(.3*.7/n)
            radius = sqrt(log(2/.05)/(2*n))
            print("CS finite event N=%5d estimate=%.6f exact=.3 estimatedSE=%.6f modelSE=%.6f Hoeffding95%%radius=%.6f" % (
                n, estimate, plugin_se, known_se, radius))
            integral = sum_square/n
            print("AI integral x^2 on[0,1] N=%5d estimate=%.6f exact=1/3 modelSE=%.6f" % (
                n, integral, sqrt((4/45)/n)))
    print("Quadrupling N halves the IID standard error, not necessarily one realised error.")
    print("Monte Carlo sampling error differs from deterministic quadrature truncation error.")
Output
CS finite event N=  100 estimate=0.230000 exact=.3 estimatedSE=0.042083 modelSE=0.045826 Hoeffding95%radius=0.135810
AI integral x^2 on[0,1] N=  100 estimate=0.384036 exact=1/3 modelSE=0.029814
CS finite event N= 1000 estimate=0.284000 exact=.3 estimatedSE=0.014260 modelSE=0.014491 Hoeffding95%radius=0.042947
AI integral x^2 on[0,1] N= 1000 estimate=0.332519 exact=1/3 modelSE=0.009428
CS finite event N=10000 estimate=0.298600 exact=.3 estimatedSE=0.004576 modelSE=0.004583 Hoeffding95%radius=0.013581
AI integral x^2 on[0,1] N=10000 estimate=0.330839 exact=1/3 modelSE=0.002981
Quadrupling N halves the IID standard error, not necessarily one realised error.
Monte Carlo sampling error differs from deterministic quadrature truncation error.

CS readers use the finite event; AI readers also derive the continuous integral and variance. Distinguish model SE, plug-in SE, Hoeffding radius and realised error. Explain why quadrupling samples halves a standard error without ordering all realised errors.

Lab3 · Copied seeds clusters and common randomness

Download lab3_dependence_seeds_and_pairing.py

"""Copied streams, clustered observations, zero estimated SE and common random numbers."""
from math import sqrt, log
import random

if __name__ == "__main__":
    n, repeats, p = 1000, 30, .3
    means = []
    for _ in range(repeats):
        generator = random.Random(24)  # Intentional fault: identical stream each time.
        means.append(sum(generator.random() < p for _ in range(n))/n)
    print("copied-seed blocks: unique means=%d mean=%.6f" % (len(set(means)), means[0]))
    print("wrong R*N independence SE=%.6f actual copied-block model SE=%.6f" % (
        sqrt(p*(1-p)/(repeats*n)), sqrt(p*(1-p)/n)))
    assert len(set(means)) == 1
    generator = random.Random(24343)
    clusters, copies = 100, 10
    distinct = [int(generator.random() < p) for _ in range(clusters)]
    records = [x for x in distinct for _ in range(copies)]
    print("cluster copies: nominalN=%d independentClusters=%d mean=%.6f" % (
        len(records), clusters, sum(records)/len(records)))
    print("wrong row SE=%.6f correct cluster model SE=%.6f" % (
        sqrt(p*(1-p)/len(records)), sqrt(p*(1-p)/clusters)))
    N = 100
    print("rare-event all-zero dataset: estimatedSE=0; model p=.001 gives P(all0)=%.6f" % (.999**N))
    print("bounded independent Hoeffding95%%radius=%.6f despite zero plug-in SE" % sqrt(log(40)/(2*N)))
    a, b = .6, .55
    paired_variance = (a-b)*(1-a+b)
    independent_variance = a*(1-a)+b*(1-b)
    paired, separate = [], []
    for _ in range(10000):
        u = generator.random()
        paired.append(int(u<a)-int(u<b))
        separate.append(int(generator.random()<a)-int(generator.random()<b))
    print("common-random-number difference mean=%.6f independent difference mean=%.6f target=.05" % (
        sum(paired)/len(paired), sum(separate)/len(separate)))
    print("exact per-pair variance: common=%.6f independent=%.6f" % (paired_variance, independent_variance))
    print("exact N10000 SE: common=%.6f independent=%.6f" % (
        sqrt(paired_variance/10000), sqrt(independent_variance/10000)))
    print("PASS: replication is not new information; pairing helps here through positive covariance")
Output
copied-seed blocks: unique means=1 mean=0.305000
wrong R*N independence SE=0.002646 actual copied-block model SE=0.014491
cluster copies: nominalN=1000 independentClusters=100 mean=0.220000
wrong row SE=0.014491 correct cluster model SE=0.045826
rare-event all-zero dataset: estimatedSE=0; model p=.001 gives P(all0)=0.904792
bounded independent Hoeffding95%radius=0.135810 despite zero plug-in SE
common-random-number difference mean=0.048200 independent difference mean=0.046100 target=.05
exact per-pair variance: common=0.047500 independent=0.487500
exact N10000 SE: common=0.002179 independent=0.006982
PASS: replication is not new information; pairing helps here through positive covariance

Identify the actual independent units before accepting an error bar. Repair the zero-SE certainty claim and derive the positive-covariance benefit in the specified paired model.

10

Fourteen exercises with full solutions

Exercises1–12 are required. Optional Exercises13–14 add35 minutes beyond the ten-hour schedule; continuous alternatives require Module17 and occupy the same time.

Exercise 1★★★calculation6 min

For IID Bernoulli(.3), N=1000, give mean variance and SE. What if all rows copy one draw?

Show solution

IID variance.21/1000=.00021, SE≈.014491. Copies have variance.21 and SE≈.458258 for every row count because their mean is the original draw.

Exercise 2★★★calculation6 min

Use Chebyshev for IID Bernoulli(.5), N=1000, ε=.05. Give a size sufficient for failure bound.05.

Show solution

Variance.25/1000 and threshold square.0025 give bound.1. Sufficient N≥.25/(.05·.0025)=2000. This is a probability bound under IID, not an exact necessary minimum.

Exercise 3★★★calculation6 min

For IID[0,1] observations, ε=.05,δ=.05, calculate a Hoeffding sufficient integer size.

Show solution

N≥log40/.005≈737.776, so738. Natural log matches the exponential formula; bounds and independence are required.

Exercise 4★★★calculation6 min

What happens to IID SE when N quadruples? For Bernoulli(.01), N=20, give the exact no-success probability.

Show solution

SE halves. P(no success)=.99²⁰≈.817907, showing a large zero atom and a poor small-sample smooth approximation. One realised error need not halve.

Exercise 5★★★proof14 min

Prove Markov and Chebyshev with all sign, moment and threshold assumptions.

Show solution

For W≥0 and t>0, W≥t1{W≥t}; average and divide to obtain P≤EW/t. For finite-variance X apply it to W=(X−EX)²,t=ε²,ε>0. This gives the deviation bound without Gaussian shape or independence. The latter may be needed to compute the variance of a mean.

Exercise 6★★★proof14 min

Derive the IID mean variance and the finite-variance weak law.

Show solution

Linearity gives meanμ; variance expansion with zero independent covariances givesσ²/N. Chebyshev yields P(|M_N−μ|≥ε)≤σ²/(Nε²)→0 for every fixed positiveε. This is convergence in probability, not a monotone-path or strong-law proof.

Exercise 7★★★proof14 min

Derive the finite-family Hoeffding guarantee from its individual theorem and a union bound.

Show solution

For m specified valid estimates, union failure≤Σ2exp(−2Nε²)=2mexp(−2Nε²). Solving≤δ gives N≥log(2m/δ)/(2ε²). Failure events need not be independent, but each individual draw contract and the specified family must be valid.

Exercise 8★★★application10 min

For m=20,ε=.05,δ=.05, give a simultaneous sufficient size and explain what an adaptive unlisted search changes.

Show solution

N≥log800/.005≈1336.923, so1337. The bound covers the specified twenty estimates jointly. An unlisted adaptive search is a different collection of events and requires a justified covering or selection analysis.

Exercise 9★★★application10 min

CS: estimate finite-event p=.3 with10000 IID indicators and give known SE. AI alternative: estimate ∫_0^1 x²dx and give model variance/SE.

Show solution

CS SE√(.21/10000)≈.004583. AI target1/3, per-draw variance4/45, estimator variance4/(45·10000), SE≈.002981. Both are model-known repeated-sample quantities; estimated SE and actual realised error are different.

Exercise 10★★★application10 min

Derive the paired and independent variances for thresholds.6 and.55, and state when common randomness helps.

Show solution

Shared U gives difference indicator on[.55,.6), variance.05(.95)=.0475. Separate draws give.24+.2475=.4875. The positive covariance.55−.6(.55)=.22 subtracts.44. Pairing helps here; a negative covariance would increase variance. Independent pairs remain required across replications.

Exercise 11★★★diagnosis10 min

Thirty datasets reset the same seed and their identical means have zero between-run SD. A report treats all30000 rows as independent. Repair it.

Show solution

Each1000-row block is a copy of the same draw sequence, so the aggregate mean has the original1000-sample variation. Under Bernoulli(.3), correct model SE√(.21/1000)≈.014491, rather than√(.21/30000)≈.002646. Zero replicate variation diagnoses copied streams, not certainty.

Exercise 12★★★diagnosis10 min

All100 observed indicators are zero, so a zero plug-in SE is reported as proof p=0 and exact CLT coverage. Repair both.

Show solution

At p=.001 the data occur with probability.999¹⁰⁰≈.904792. The zero estimate does not prove a zero rate. A distribution-free bounded independent radius atδ=.05 is√(log40/200)≈.135810. The stated CLT has no universal finite-N exact95% coverage guarantee, particularly at rare-event boundaries.

Exercise 13★★★extension15 min

Show that common-mean pairwise uncorrelated variables with variance at mostC satisfy this weak-law proof. Explain why that is not the IID CLT theorem.

Show solution

Variance of their average is at mostNC/N²=C/N; Chebyshev gives tail≤C/(Nε²)→0. Pairwise uncorrelatedness need not imply joint independence or identical laws, so the stated IID CLT assumptions do not follow from this argument.

Exercise 14★★★extension20 min

CS: derive variance of a mean from m independent draws copied b times each. AI alternative: compare independent and antithetic estimators of ∫_0^1 x dx.

Show solution

CS: row mean equals the m-draw mean, varianceσ²/m=bσ²/N forN=mb. AI: independent U averages have variance1/(12N). An antithetic pair average(U+(1−U))/2=.5 exactly for every U, eliminating sampling variance for this linear integrand. This special negative-covariance sum construction does not guarantee the same gain for every integrand or simulation cost.

11

Ten-question self-check

1
Which assumption removes the covariance terms from the IID mean variance?
2
What does Chebyshev require?
3
What convergence does the elementary weak-law proof establish?
4
What is standardised in the IID CLT?
5
Does the stated CLT provide exact95% finite coverage for every N≥30?
6
Does the union step over several valid estimates need cross-estimate independence?
7
What does quadrupling IID sample size do to standard error?
8
A zero-success sample has zero plug-in SE. What follows?
9
When does pairing reduce a difference variance with unchanged marginals?
Show answer

For IID indicators with common ratep, estimate is their mean, variancep(1−p)/N and SE√[p(1−p)/N]. Chebyshev worst-case size is1/(4δε²), or bounded Hoeffding size log(2/δ)/(2ε²). N counts independent draws, not duplicated rows; a local seed documents a trace while copied streams add no replications. A zero-success estimate can occur at nonzero p, and the stated CLT is asymptotic rather than an exact finite error certificate. Report the failure probability and all model assumptions with the tolerance.

12

Reading with a purpose

Use MIT’s weak-law lesson and CLT lesson. The qualified Hoeffding statement is in MIT’s probability notes. The elementary bounds and mean/covariance applications above are derived in full here.

When Selection and question
Session1 · 15 minutes Mean variation and weak law: what variance calculation makes the probability bound vanish?
Session4 · 15 minutes CLT and bounded concentration: which statements are asymptotic and which are finite-size guarantees?
13

Retrieval exit task and next step

Prove Markov, Chebyshev and the finite-variance weak law; state CLT and Hoeffding with assumptions; calculate sample sizes and a Monte Carlo uncertainty report. Derive how deliberate pairing or accidental copying changes variation.

Exit task: at ε=.05,δ=.05 compare sufficient Bernoulli sizes2000 and738, then explain why neither IID formula applies to N copies of one draw. Distinguish standard error from actual realised error and a deterministic numerical bound.

Ready to move on: you can assess sampling statements and report a justified estimator. Estimation next derives likelihood, bias, variance and Bayesian parameter updating rather than treating all model rates as known. See the course overview.

14

Notation and bilingual terminology

Term or notation Meaning 中文
IID / sampling unit Independent identical laws / actual independent draw 独立同分布、抽样单位
M_N / SE Sample mean / estimator standard deviation 样本均值、标准误
ε / δ Error tolerance / failure-probability bound 容差、失败概率
Weak law / CLT Probability convergence / distributional standardisation limit 弱大数法则、中心极限定理
Chebyshev / Hoeffding Variance bound / bounded independent concentration 切比雪夫、Hoeffding界
Monte Carlo / quadrature Random expectation estimate / numerical integral approximation 蒙特卡洛、数值求积
Pairing / copied stream Deliberate within-pair coupling / repeated random sequence 配对、复制流