= Solution
I would first collapse the duration noises as in part (c), then use <self-normalized importance sampling> on the two shared parameters. Draw independent $(\mu_j,\sigma_j)\sim\rho$, give each the <importance weight> $w_j=L(\mu_j,\sigma_j)$, and return
$$
\boxed{\widehat P_N=\frac{\sum_{j=1}^Nw_j\pi(\mu_j,\sigma_j)^5}{\sum_{j=1}^Nw_j}.}
$$
This is <likelihood weighting>: the observations affect the weights rather than forcing repeated simulation of twenty latent inequalities. Integrating out both the constraints' auxiliary randomness and the future <Boolean> query is <Rao-Blackwellization>; at fixed parameters it removes randomness without changing the relevant <conditional expectations>.
The weights and weighted queries lie in $[0,1]$, and the evidence is positive. The <strong law of large numbers> therefore makes the numerator and denominator averages converge to their corresponding integrals, proving <almost sure convergence> of their ratio to part (d). The finite-$N$ ratio is generally biased; the assertion concerns consistency rather than a finite-sample <unbiased estimator>. Use <logarithms> of <importance weights> to avoid numerical underflow:
``
def weighted_answer(n, rng):
if n <= 0:
raise ValueError("n must be positive")
samples = []
for _ in range(n):
mu = rng.uniform(0.0, 60.0)
sigma = rng.uniform(1.0, 20.0)
samples.append((journey_loglik(mu, sigma),
math.exp(5.0 * normal_logcdf((mu - 30.0) / sigma))))
offset = max(logw for logw, h in samples)
if not math.isfinite(offset):
raise ArithmeticError("all weights underflowed")
scaled = [(math.exp(logw - offset), h) for logw, h in samples]
den = math.fsum(w for w, h in scaled)
answer = math.fsum(w * h for w, h in scaled) / den
ess = den * den / math.fsum(w * w for w, h in scaled)
return answer, ess
``
The returned <effective sample size of importance sampling> is a concentration diagnostic, not a proof of accuracy. Repeat runs and inspect the weights. If the prior is much broader than the posterior, improve the proposal with the corresponding <importance sampling> density correction, or use the <Metropolis–Hastings algorithm> targeting $\rho L$. Because this particular collapsed problem is only two-dimensional, deterministic <numerical integration> is also an excellent independent accuracy check; it was used for the figure and numerical illustration. Straight rejection of the original traces is correct but wastes most proposals here.
Back to article page