Advanced sampling and rare eventsLesson 68 of 76 · 10 min
An unknown normalising constant
Construct a self-normalised importance estimate and recognise finite-sample ratio bias.
Sometimes a target density is known only up to a positive multiplicative constant. Dividing weighted function sums by weighted mass sums cancels that constant. This is self-normalised importance sampling.
Bias means repeated-run average error at a fixed sample size. Consistency means approaching the target as sample size grows under suitable assumptions. A ratio can be consistent but biased at finite n, because E[A/B] generally differs from E[A]/E[B]. Support, integrable contributions and a nonzero finite denominator expectation are needed for the ratio's convergence; error bars need further variance conditions.
The target has unnormalised density exp(−x⁴/4). Its second moment means E[X²], the average squared value under the target. Symmetry and a supplied exact gamma-function calculation provide checks; gamma is a special function used only for this optional analytic reference. A normal proposal covers the domain. Estimate E[X²] using the normalised weighted ratio, retaining its finite-sample limitations.
- Unnormalised target
- Normalise relative weights
- Self-normalised expectation
Does cancelling an unknown constant also eliminate every finite-sample bias?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
Self-normalised E[X²] estimate: 0.670689 Analytical target E[X²]: 0.675978 Weighted symmetry check E[X]: -0.00422 Weight ESS diagnostic: 18446.48
Read the first result
The analytical check is valuable because a stable-looking ratio can still be inaccurate. Ordinary iid SE of the raw X squared values would ignore the weights and ratio.
Try an edit
Replace x = rng.normal(size=20000) with x = rng.normal(size=100) and run. Then set the size to 1000. Select Run Python again. Compare Self-normalised E[X²] estimate with Analytical target E[X²] at each size. At size 1000, change default_rng(2067) to default_rng(68) and rerun. Why would you need more independent repetitions before making a claim about bias?
Scope. This uses a tractable one-dimensional target. General self-normalised error estimation and multi-modal overlap require further checks.
Try a fresh case
Which statement fits a self-normalised importance estimator?
Need a hint?
Hint 1
Compare with .
Hint 2
Check support and overlap even when constants cancel.