Solution (source code)

= Solution

Write $f=f_0/C_f$ and $g=g_0/C_g$, where $f_0,g_0$ are known nonnegative kernels. If both constants are known, the ordinary weight is $(C_g/C_f)f_0/g_0$. If their ratio is unknown, use <self-normalized importance sampling>:
$$
\boxed{\widehat\mu_{\mathrm{SN}}
=\frac{\sum_i\theta(x_i)f_0(x_i)/g_0(x_i)}{\sum_i f_0(x_i)/g_0(x_i)}.}
$$
Indeed, under the normalized proposal law,
$$
\mathbb E_g\!\left[\frac{f_0(X)}{g_0(X)}\theta(X)\right]
=\frac{C_f}{C_g}\mu,
\qquad
\mathbb E_g\!\left[\frac{f_0(X)}{g_0(X)}\right]=\frac{C_f}{C_g}.
$$
The <strong law of large numbers> makes their empirical ratio converge to $\mu$, provided the numerator is absolutely <integrable> and $0<C_f,C_g<\infty$. Multiplicative constants cancel, whether the unknown one belongs to the target, proposal, or both. Unlike the estimator in part (i), this ratio is generally biased at finite sample size. Exact sampling from $g$ is still presumed; knowing only an unnormalized proposal does not itself supply a sampler.