Let's say $X$ is a rv, $p(x)$ is its pmf. I want to importance-sample $\mu := \mathbb E[f(X)]$, for some bounded function $0<f<1$, using another distribution $q(x)$. Then what I should do is summing $$\hat\mu := \frac{1}{n} \sum_{k=1}^n \frac{f(Y_k)p(Y_k)}{q(Y_k)}$$ where $Y_k$ are generated using $q$.
According to this lecture note, there is an optimal $q$, denoted by $q'$, that minimizes the variance of $\hat\mu$: $$q'(x)\propto f(x)p(x)$$ If I sample using $q'$, then all summands in the definition of $\hat\mu$ becomes constant. So yeah, it does give me a variance-zero experience. Really appreciate.
What I don't seem to understand is that, if I now want to importance-sample $g := 1 - f$ instead, then suddenly $q'$ is not the best distribution, as $q'$ is no longer $\sim gp = (1 - f)p$.
Yet another example is that, if I want to sample $h := 100 + f$, then $hp$ is just $100(p \pm \epsilon)$, so the optimal $q$ is very close to $p$. Or maybe it's telling me that I shouldn't bother.
How is it possible that the optimal choice of $q$ depends on an affine transformation I applied to $f$? Does that mean that I should optimize over the affine transformations that can be applied to $f$?