Solution (source code)

= Solution

Write $f=\widetilde f/Z_f$ and $g=\widetilde g/Z_g$. If the constants needed to evaluate $f/g$ are unavailable, use the <self-normalized importance sampling> <estimator>
$$
\boxed{\widehat\mu_{\mathrm{SN}}=\frac{\sum_i\widetilde w_i\theta(X_i)}{\sum_i\widetilde w_i},\qquad\widetilde w_i=\frac{\widetilde f(X_i)}{\widetilde g(X_i)}.}
$$
The unknown common factor $Z_g/Z_f$ cancels. Under full target <probability support> and integrability, the numerator and denominator sample means converge to $\int\widetilde f\theta/Z_g$ and $\int\widetilde f/Z_g$, respectively, whose ratio is $\mu$. The same construction applies if only one normalization is unknown by taking the other <probability density function> already normalized. Sampling from $g$ itself is assumed available, even when its normalization is not explicitly known.

This ratio <estimator> is generally biased at finite $n$, unlike the ordinary normalized-weight <estimator>. Also, its <variance> is not the formula in the next part: that formula concerns the ordinary unbiased <estimator>. Full <probability support> for $f$ is needed here because the denominator estimates the entire target normalizing <integral>, not just the <probability support> of $f\theta$.