Solution (source code)

= Solution

If equally informative independent draws have variance $s_m^2$, an ordinary mean of $K_{\mathrm{eff}}$ draws has variance $s_m^2/K_{\mathrm{eff}}$. The weighted mean has the corresponding variance $s_m^2\sum_iw_i^2$. Equating them gives the <effective sample size of importance sampling>
$$
K_{\mathrm{eff}}=\frac1{\sum_{i=1}^Kw_i^2}
=\frac{\left(\sum_i p(d\mid x_i)\right)^2}
{\sum_i p(d\mid x_i)^2}\leq K,
$$
where the inequality follows from <Cauchy-Schwarz inequality>.