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.

A ratio can remove an unknown constant
  1. Unnormalised target
    p~(x)∝e−x4/4\widetilde p(x)\propto e^{-x^4/4}
  2. Normalise relative weights
    w~i∝p~(Xi)/q(Xi)\widetilde w_i\propto\widetilde p(X_i)/q(X_i)
  3. Self-normalised expectation
    μ^=∑iwiXi2∑iwi\widehat\mu=\frac{\sum_iw_iX_i^2}{\sum_iw_i}
Reference illustration. The unknown target normalising constant cancels. The finite-sample estimator remains a random ratio; an iid SE of raw X squared values would ignore that structure.

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.

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 ↗

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?

Back to the Python editor

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?

Choose an answer
Need a hint?
Hint 1

Compare E[A/B]E[A/B] with E[A]/E[B]E[A]/E[B].

Hint 2

Check support and overlap even when constants cancel.

Your notes