Here is my understanding of importance sampling. If we have two distributions $p(x)$ and $q(x)$, where we have a way of sampling from $p(x)$ but not from $q(x)$, but we want to compute the expectation wrt $q(x)$, then we use importance sampling.
The formula goes as follows:
$$ E_q[x] = E_p\Big[x\frac{q(x)}{p(x)}\Big] $$
The only limitation is that we need a way to compute the ratio. Now, here is what I don't understand. Without knowing the density function $q(x)$, how can we compute the ratio $\frac{q(x)}{p(x)}$?
Because if we know $q(x)$, then we can compute the expectation directly.
I am sure I am missing something here, but I am not sure what. Can someone help me understand this?
Thank you.