This Probability concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.
Probability
Monte Carlo Estimation and Importance Sampling
Monte Carlo turns expectations into sample averages; importance sampling changes where samples come from and uses p/q weights, so proposal choice controls variance.
Concept Structure
Monte Carlo Estimation and Importance Sampling
Start with the picture, metaphor, or geometric mechanism.
Make the objects explicit and connect them with notation.
Mirror the equations with runnable implementation details.
Manipulate the mechanism and watch the idea respond.
Learner Contract
What this page should let you do.
3 prerequisites listed; refresh them before leaning on the math or code.
Explain the mechanism, trace the main notation, and test one prediction in the live demo.
Read the intuition before the notation; the math should name a mechanism you already felt.
Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.
Claim/source review status
Substantive review recorded
1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Monte Carlo estimation starts with a simple promise:
can be estimated by drawing samples and averaging the values of .
That is already powerful. If is a model distribution and is a quantity we care about, sampling can replace an impossible sum or integral with a procedure we can run.
The catch is variance. A sample average is not just "more samples means better." It also asks whether the samples visit the parts of the space that matter for the expectation. If rare states carry large values of , ordinary samples can spend most of the budget watching unimportant states.
Importance sampling changes the question:
What if we sample from a different distribution , then correct the accounting?
Each sample gets an importance weight
If samples a point too often compared with , the weight shrinks it. If samples a point too rarely, the weight amplifies it. The identity is clean, but the experience can be brutal: a bad proposal can make one sample carry most of the estimate.
The learner move is to separate three ideas:
- the target distribution defines the expectation;
- the proposal defines where samples come from;
- the weighted contribution defines the estimator variance.
Good importance sampling makes those weighted contributions stable. Bad importance sampling creates heavy weights and low effective sample size.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let be a random variable with target probability mass or density , and let be an integrable function. The target quantity is
or an integral in the continuous case.
The direct Monte Carlo estimator draws and uses
When the samples are iid and the variance is finite,
Importance sampling chooses a proposal such that whenever can be nonzero. Then
where
The standard importance-sampling estimator is
It is unbiased under the support and integrability assumptions above. Its variance is
This equation is the whole design problem. A proposal can be algebraically valid and still terrible if has heavy tails.
For nonnegative , the ideal proposal is proportional to the target contribution:
Then is constant on contributing states, so the estimator has zero variance in the finite toy case. In real problems we usually cannot sample exactly from this proposal because its normalizer is the target expectation or something equally hard. But it tells us the direction: sample where the contribution lives, not merely where is large.
When is known only up to a normalizing constant, or when estimating posterior ratios, a self-normalized estimator is common:
Self-normalization is generally biased at finite , but it is consistent under standard assumptions and often useful in approximate inference.
A quick diagnostic is effective sample size:
ESS is high when weights are balanced and low when a few weights dominate. It is a warning light, not the full variance formula: if , all weights equal one and ESS is maximal, but itself may still vary a lot.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
import numpy as np
x = np.arange(-4, 5)
p = np.array([.02, .05, .10, .17, .22, .18, .13, .08, .05])
f = np.maximum(.15, 1 + .38 * x + .10 * x**2)
true_value = np.sum(p * f)
proposals = {
"target": p,
"matched": p * f / true_value,
"too_central": np.array([.003, .006, .02, .11, .48, .27, .08, .021, .01]),
}
proposals["too_central"] /= proposals["too_central"].sum()
u_trials = np.array([
[.03, .11, .19, .28, .36, .44, .52, .61, .70, .79, .88, .97],
[.06, .14, .22, .35, .46, .55, .64, .71, .83, .91, .95, .99],
[.01, .08, .18, .27, .39, .47, .59, .68, .75, .84, .93, .985],
])
def draw(q, u):
return np.searchsorted(np.cumsum(q), u)
for name, q in proposals.items():
estimates = []
for us in u_trials:
i = draw(q, us)
w = p[i] / q[i]
estimates.append(np.mean(f[i] * w))
print(name, "true", round(true_value, 3),
"estimates", np.round(estimates, 3).tolist())
The three proposals estimate the same target value. The difference is stability. The matched proposal is close to , so the weighted contributions become nearly constant. The too_central proposal undersamples the right tail; when a tail point appears, its weight is large enough to move the whole estimate.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
The lab below hides the exact value, the trial estimates, and the ESS ledger until you commit.
Pick which proposal you think gives the lowest repeated-trial variance. Then reveal the ledger and compare three quantities:
- the exact target value ;
- the trial-to-trial variance of the weighted estimator;
- the ESS of the first sample batch.
The trick is that sample from p has perfect weight ESS, but it is not the lowest-variance estimator here. ESS only watches the weights. The actual estimator variance watches the weighted payoff .
Live Concept Demo
Explore Monte Carlo Estimation and Importance Sampling
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Commit to what Monte Carlo Estimation and Importance Sampling should make visible before reading the result.
After The First Pass
Turn the concept into an inspected object.
Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.
Mechanism Storyboard
See the idea move before the page explains it
Monte Carlo turns expectations into sample averages; importance sampling changes where samples come from and uses p/q weights, so proposal choice controls variance.
Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Monte Carlo Estimation and Importance Sampling should make visible.
Visual Inquiry
Make the image answer a mathematical question
Monte Carlo turns expectations into sample averages; importance sampling changes where samples come from and uses p/q weights, so proposal choice controls variance.
Which visible object should carry the first intuition?
Pick the cue that should make Monte Carlo Estimation and Importance Sampling easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
Grounds Monte Carlo expectation estimation, the importance-sampling p/q identity, estimator variance, normalized importance sampling, and the proposal-shape warning.
Open sourceDeep-learning textbook anchor for Monte Carlo methods as expectation approximation in ML.
Open sourceSupports the variance-reduction framing, self-normalized importance sampling, and importance-sampling diagnostics.
Open sourceSupports the normalized-weight ESS diagnostic and its role in importance sampling and sequential Monte Carlo.
Open sourceCurriculum anchor for modern approximate inference topics that use Monte Carlo and importance sampling.
Open sourceClaim Review
Monte Carlo turns expectations into sample averages; importance sampling changes where samples come from and uses p/q weights, so proposal choice controls variance.
Claims without a substantive review badge still need exact source-support review.
cs228-sampling-notes, goodfellow-2016-deep-learning-monte-carlo, owen-2013-importance-sampling, martino-2017-ess, murphy-2023-probml-advanced
Use equations, runnable code, and demos to check whether the source support is operational.
The sources support Monte Carlo as expectation approximation, standard importance sampling as q-sampling plus p/q weights, proposal-dependent variance, normalized importance sampling for posterior/marginal-ratio style estimates, and ESS as a diagnostic for concentrated normalized weights.
Sources: CS228 Notes: Sampling Methods, Deep Learning, Chapter 17: Monte Carlo Methods, Monte Carlo Theory, Methods and Examples: Importance Sampling, Effective Sample Size for Importance Sampling based on discrepancy measures, Probabilistic Machine Learning: Advanced TopicsFinite discrete witness only; does not cover continuous measure-theoretic support pathologies, adaptive/sequential importance sampling, bridge sampling, annealed importance sampling, rare-event asymptotics, or a GPT Pro publication pass.A bounded review summary is present; still check caveats and exact reference scope.Checked CS228 sampling notes for Monte Carlo expectation estimation, the p/q reweighting identity, variance formula, normalized importance sampling, and the ideal proposal proportional to |f|p; checked Owen's Monte Carlo book table of contents and importance-sampling chapter anchor for diagnostics and self-normalized IS; checked Martino et al. for the common normalized-weight ESS diagnostic. GPT Pro publication critique remains pending.
Reviewer: codex-local-source-review; reviewed 2026-07-02Source support candidates
course-notes 2026CS228 Notes: Sampling MethodsGrounds Monte Carlo expectation estimation, the importance-sampling p/q identity, estimator variance, normalized importance sampling, and the proposal-shape warning.
book 2016Deep Learning, Chapter 17: Monte Carlo MethodsDeep-learning textbook anchor for Monte Carlo methods as expectation approximation in ML.
book 2013Monte Carlo Theory, Methods and Examples: Importance SamplingSupports the variance-reduction framing, self-normalized importance sampling, and importance-sampling diagnostics.
paper 2017Effective Sample Size for Importance Sampling based on discrepancy measuresSupports the normalized-weight ESS diagnostic and its role in importance sampling and sequential Monte Carlo.
Practice Loop
Try the idea before it explains itself
Monte Carlo turns expectations into sample averages; importance sampling changes where samples come from and uses p/q weights, so proposal choice controls variance.
Before touching the demo, predict one visible change that should happen in Monte Carlo Estimation and Importance Sampling.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
A concrete answer is on the canvas.
The answer names why the claim should hold.
It touches the page context or a neighboring idea.
Research Room
Attach the question to a claim, equation, code, or demo
Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.Open the draft below to save one note and next action in this browser.
Monte Carlo Estimation and Importance Sampling
What is the smallest example that makes Monte Carlo Estimation and Importance Sampling click without losing the math?
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays in this browser, attached to the selected learning item.
- References to inspect: attached references on this page.
- Definition, prerequisite, and contrast concept links
- The equation or runnable code that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Monte Carlo Estimation and Importance Sampling Selected item key: recorded for copy. Context: Probability Page anchor: recorded for copy. Open question: What is the smallest example that makes Monte Carlo Estimation and Importance Sampling click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.
concept/concept-notebook/probability/monte-carlo-importance-sampling
concept:probability/monte-carlo-importance-sampling