Learn
Lesson · Simulation and Variance Reduction · Moving the covariance

Control Variates

Take a second quantity C measured on the same run whose expectation is known, and report X − b(C − E[C]). The correction has expectation zero, so the estimator is unbiased at every b, and its variance is a quadratic in b whose vertex sits at b* = Cov(X, C)/Var C. There the variance has been multiplied by 1 − ρ². The condition is the known mean, not the correlation — and a control with a known mean and no correlation buys almost nothing.

X − b(C − E[C]) unbiased for E[X] at EVERY b, because E[C − E[C]] = 0 Var = Var X − 2b Cov(X, C) + b² Var C a quadratic in b, opening upward b* = Cov(X, C) / Var C its vertex, by completing the square at b*: Var X × (1 − ρ²) with ρ² = Cov² / (Var X · Var C), an exact rational arrivals as the control: ρ² = 0.457615, 1.530750 becomes 0.830256 b = 0 and b = 2b* give exactly the same variance; b = −b* is worse than no control
One correction, one quadratic, and its vertex

Core ideas

What this lesson establishes

Three ideas. The first is why the estimator stays honest at every b, the second is how the best b is found, and the third is the condition people substitute something easier for.

1

The correction has expectation zero, so nothing is risked

E[C − E[C]] = 0 by definition, so E[X − b(C − E[C])] = E[X] for every b, good or bad. A control variate cannot bias the estimate; the only thing at stake is the variance, and the worst outcome is a variance larger than you started with.

2

The variance is a quadratic, so the best b is a vertex and not a search

Var X − 2b Cov(X, C) + b² Var C opens upward, so completing the square puts its minimum at b* = Cov/Var C, and the minimum value is Var X (1 − ρ²). Both b* and ρ² are ratios of exact sample quantities, so the optimum is computed rather than tuned.

3

The condition is a KNOWN mean, not a strong correlation

A control whose mean you estimated from the same run puts back exactly the error it was brought in to remove. Correlation decides how much the control is worth; a known mean decides whether it is a control at all. The two get confused because the second is usually easy and the first is usually the reason a candidate fails.

The material

A companion with a known mean, and the coefficient that uses it

Why the correction is free, where the best coefficient is, what it buys, and what happens when the coefficient is wrong.

Definition · Control variate

A control variate for an estimator X is a second quantity C, measured on the same run, whose expectation E[C] is known exactly. The controlled estimator is X − b(C − E[C]) for a coefficient b chosen by the experimenter.

The word known is the whole definition. E[C] has to be a number you can write down before the run: the number of slots times the arrival probability, the expected number of coin flips that come up heads, the mean of a distribution you are sampling from. A quantity whose mean you would have to estimate is not a control variate, whatever its correlation with X.

Theorem · The optimal coefficient and what it achieves

Var(X − b(C − E[C])) = Var X − 2b Cov(X, C) + b² Var C, a quadratic in b with positive leading coefficient. Its minimum is at b* = Cov(X, C)/Var C, and the value there is Var X · (1 − ρ²) where ρ² = Cov(X, C)²/(Var X · Var C).

The variance of X − bD with D = C − E[C] is Var X − 2b Cov(X, D) + b² Var D, and Var D = Var C, Cov(X, D) = Cov(X, C), because subtracting a constant changes neither.

Complete the square: Var C (b − Cov/Var C)² + Var X − Cov²/Var C. The first term is non-negative and vanishes at b = Cov/Var C, so that is the minimiser.

The value there is Var X − Cov²/Var C, which is Var X (1 − Cov²/(Var X · Var C)) = Var X (1 − ρ²).

□

Rho is irrational and rho squared is not

ρ = Cov(X, C)/(σ_X σ_C) is a covariance divided by a product of two square roots, and it is irrational at almost any data. ρ² is Cov²/(Var X · Var C), a ratio of three exact rationals, so the reduction factor 1 − ρ² is exact even where ρ is not. That is why this page prints ρ² everywhere and ρ once, with the rounding named — and ρ is the third and last of the three quantities on this course that are genuinely irrational.

What ρ adds over ρ² is its sign, and here the sign has already been used: it is inside b*. A negatively correlated control works exactly as well as a positively correlated one, because b* comes out negative and the correction changes direction with it. That is the difference from the previous technique, where the sign could not be chosen and therefore decided everything.

The measurement

Example · The arrivals as a control for the queue's occupancy

X is the time-average number in system over a run of two hundred slots; C is the number of arrivals in that run. C is a sum of two hundred indicators of probability 2/5, so E[C] = 80 exactly — known, not estimated — and the arrivals plainly drive the queue. Over twenty-four replications: Cov(X, C) = 172147/27600 ≈ 6.23721, Var C = 3832/69 ≈ 55.5362, so b* = 172147/1532800 ≈ 0.1123.

X = time average in system, C = arrivals, E[C] = 200 × 2/5 = 80 24 replications of 200 slots, seed 1 Var X 1.530750 Cov(X, C) 6.23721 Var C 55.5362 b* = Cov/Var C 0.1123 ρ² 0.457615 exact, shown to 6 places 1 − ρ² 0.542385 exact, shown to 6 places variance at b* 0.830256 ρ ≈ 0.6765 (rounded) 1.530750 × 0.542385 = 0.830255… the factor does the work

Just over forty-five per cent of the variance removed, from a quantity that was already being recorded and cost nothing to collect. That is a typical result for a good control, and it compares well with buying it: the same reduction from more runs would take about 1/0.542, nearly twice the replications.

Both ways the coefficient can be wrong

The parabola rises on both sides of b*, and it rises symmetrically. At b = 0 the variance is 1.530750, which is the uncontrolled value — correctly, since b = 0 is no control. At b = 2b* it is 1.530750 again, exactly: overshooting the optimum by a factor of two throws away the entire benefit and leaves you no worse off than not having bothered. At b = −b*, the right magnitude with the wrong sign, it is 3.632232 — more than twice the uncontrolled variance, and the one outcome that is actively bad.

Example · A control with a known mean and no correlation

The panel's second companion counts, out of two hundred draws from a stream the queue never reads, how many fall below 1/2. Its mean is exactly 100, every bit as firmly known as the arrivals' 80, and it has almost nothing to do with the queue: ρ² = 0.074965, so 1 − ρ² = 0.925035 and the variance falls only from 1.530750 to 1.415997. A known mean is necessary and it is not sufficient.

The reverse case — a strongly correlated quantity whose mean is not known — is not a weaker control; it is not a control. Substituting an estimate of E[C] from the same replications makes the correction correlated with the very error it was supposed to cancel, and the estimator stops being unbiased. That failure does not show up in any variance figure on the page, which is what makes it worth stating as a condition rather than as advice.

The control does not have to be the target in disguise, either. Any quantity that moves with X and has a known mean will do, and the arrivals are a good example precisely because they are an input rather than an output: their mean is known from the model specification and needs no analysis of the queue at all.

Interactive

Control variates

A companion with a known mean, and the variance multiplied by 1 − ρ²

The variance is a quadratic in bits vertex is b* = Cov(X, C) / Var C, and at the vertex the variance has been multiplied by 1 − ρ²
the variance at bthe vertex, at b*the b you chosethe variance with no control at all

Method

Choosing and using a control variate

Five steps, and the first one disqualifies most of the candidates people reach for.

1

Write down E[C] before the run, or reject the candidate

If you cannot state the control's expectation from the model specification — 200 × 2/5 = 80, and nothing measured — then it is not a control variate. Estimating E[C] from the same replications reintroduces exactly the error the control was for, and no figure on the page will show it.

2

Collect C on every replication alongside X

It is usually free: the arrival count was already being computed. A control that costs a second simulation run has to be worth more than the runs it displaces, which is a much harder test to pass.

3

Compute Cov(X, C), Var C, and b* as exact fractions

b* = Cov/Var C. No search and no tuning: the variance is a quadratic and its vertex is an arithmetic expression in quantities you already have.

4

Report 1 − ρ² as the reduction, and report it as exact

ρ² is a ratio of three exact rationals even though ρ is not, so the factor 1 − ρ² can be printed in full. It is the honest headline: 0.542385 says what the control did, and 0.6765 for ρ is a rounded decimal that says less.

5

Sanity-check the sign, not just the size

A b of the right magnitude and the wrong sign more than doubles the variance here. Since b* carries the sign of the covariance automatically, the way to get this wrong is to impose a sign by hand, and the check is to confirm that the variance at your b is below the variance at b = 0.

Coefficients, conditions and what the factor means

Score 0 / 0

The arrivals as a control, and the parabola either side of b*

Twenty-four replications of two hundred slots at p = 2/5, q = 1/2, seed 1. X is the run's time-average number in system and C is its arrival count, whose expectation is 200 × 2/5 = 80 exactly.

rep X C C − 80 X − b*(C − 80) 1 207/200 78 −2 1.2596 2 62/25 90 +10 1.3569 3 221/100 86 +6 1.5361 4 319/200 79 −1 1.7073 5 437/200 76 −4 2.6342 6 303/200 70 −10 2.6381 … eighteen more … Cov(X, C) 172147/27600 ≈ 6.23721 Var C 3832/69 ≈ 55.5362 Var X 33798959/22080000 ≈ 1.530750 b* = Cov / Var C = 172147/1532800 ≈ 0.1123 ρ² = 0.457615 1 − ρ² = 0.542385 both exact variance at b* 0.830256 the parabola, read at four values of b b = −b* 3.632232 worse than no control b = 0 1.530750 no control b = b* 0.830256 the minimum b = 2b* 1.530750 exactly no control again

The C − 80 column is the whole idea in one place. Replication 6 drew only seventy arrivals, ten below the known mean, and its raw X of 303/200 = 1.515 is low partly for that reason; the correction adds b* × 10, about 1.1231, back and lands at 2.6381. The estimator is not being nudged toward the answer — the correction has expectation zero — it is having a known source of run-to-run variation removed.

The symmetry of the last block is worth keeping. b = 0 and b = 2b* give the same variance to the last digit, because a parabola is symmetric about its vertex, so the penalty for overshooting by a factor of two is exactly the benefit foregone. The penalty for the wrong sign is not symmetric with anything: 3.632232 against 1.530750 is a control that has made the estimate more than twice as noisy.

For a faded rehearsal, switch the configuration to the busier queue, p = 1/2 and q = 3/5. The supplied first move is that E[C] becomes 200 × 1/2 = 100 exactly, so the whole C − E[C] column shifts. Predict whether ρ² will rise or fall — the arrivals now drive a queue that is closer to saturation — and say what you would need to see before believing your prediction rather than the one seed in front of you.

Common mistakes

1
Using a control whose mean was estimated from the same runThe correction is then correlated with the error it is meant to cancel, and the estimator is no longer unbiased. Nothing on the page reveals it: the variance figures all look fine, and the variance of a biased estimator is a perfectly well-defined number that says nothing about how far the estimate is from the truth.
2
Choosing b by hand, or imposing a sign on itb* = Cov/Var C is an arithmetic expression in quantities already computed, and it carries the correct sign automatically. Setting b = 1 because the control “should track” X, or flipping the sign because the correction “should be a subtraction”, is how a control ends up at 3.632232 against an uncontrolled 1.530750.
3
Treating correlation as the condition and the known mean as a detailIt is the other way round. The measured page has one control with ρ² of 0.458 and one with 0.075, and both are valid because both means are known exactly. A candidate with ρ² of 0.9 and an estimated mean is not a better control; it is not one.

Check your understanding

✓
Finish when the first question about a proposed control is whether its mean is known.

You should be able to state why the controlled estimator is unbiased at every b, complete the square to find b* and the value Var X (1 − ρ²) there, compute Cov, Var C, b* and ρ² as exact quantities from a set of replications, say what b = 0, b = 2b* and b = −b* each cost, and distinguish a control that is weak from one that is invalid.

Note: All three techniques so far leave the sampling distribution alone and rearrange what is computed from it. The last one changes the distribution being sampled from, which is the only way to reach an event that almost never happens — and it is the one technique on this course that can make things enormously worse. “Importance Sampling for Rare Events” measures both directions on the same event.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.