Solution (source code)

= Solution

For normalized target density $p(m\mid d)$ and proposal $q$, the unbiased importance estimator $K^{-1}\sum_i m_i p(m_i\mid d)/q(m_i)$ has variance
$$
\frac1K\left[
\int\frac{m^2p(m\mid d)^2}{q(m)}\,dm
-\mathbb E[m\mid d]^2
\right].
$$
By <Cauchy-Schwarz inequality>,
$$
\int\frac{m^2p(m\mid d)^2}{q(m)}\,dm
\geq\left(\int|m|p(m\mid d)\,dm\right)^2,
$$
with equality exactly when
$$
q^*(m)=\frac{|m|p(m\mid d)}{\int|m|p(m\mid d)\,dm}.
$$
This is rarely useful because constructing and sampling from it already requires detailed knowledge of the posterior and its absolute first moment, the objects importance sampling was meant to avoid computing.