# Why don't we also need to approximate $p(x \mid z)$ in the VAE?

In the VAE, we approximate the probability distribution $$p(z \mid x)$$, where $$z$$ is the latent vector and $$x$$ is our data. The reason is that $$p(z \mid x)$$ becomes impossible to calculate for continuous data because of $$p(x)$$, which require integration (not in closed form) to be solved.

But why don't we also need to approximate $$p(x \mid z)$$?

What I can guess here is that, in VAEs, we assume $$p(z)$$ (prior), so we are able to calculate $$p(x \mid z)$$, but for $$p(x)$$ we can't assume its distribution? Is it right?

What I can guess here is that, in VAEs, we assume $$p(z)$$ (prior), so we are able to calculate $$p(x \mid z)$$, but for $$p(x)$$ we can't assume its distribution? Is it right?

You could assume $$p(x)$$ is some distribution (e.g. the Gaussian $$\mathcal{N}(0, 1)$$), but that assumption might be completely wrong - you can also check that against your given data (i.e. if your data is unlikely under your assumed distribution, then maybe your assumption is unreasonable - see this or this).

The ultimate goal of a generative model, like the VAE, is to be able to generate data (so you want to use it for tasks like image denoising). So, you want to learn a probability distribution that approximates the distribution from which your given dataset was sampled that would allow you to sample more similar data. In practice, you want to learn a probability distribution of the form $$p(x, z)$$, where $$z$$ is some latent random variable, which we assume to be involved in the process of generating $$x$$ (a random variable that represents the type of data that you have), i.e. $$x$$ depends on $$z$$.

By definition, $$p(x, z)$$ can be written as $$p(x, z) = p(x \mid z)p(z)$$ or $$p(x, z) = p(z \mid x) p(x)$$. If you put together these equations, you obtain the Bayes rule/theorem $$p(z \mid x) = \frac{p(x \mid z)p(z)}{p(x)}$$, where $$p(z \mid x)$$ is the posterior, $$p(x \mid z)$$ the likelihood, $$p(z)$$ the prior, and $$p(x)$$ the marginal (likelihood) or evidence.

In the VAE, we use the variational distribution, $$q_\phi$$, to approximate $$p_\theta(z \mid x)$$, but we also learn $$p_\theta(x \mid z)$$ - in fact, that's the decoder - and we learn it jointly with the variational distribution by maximizing the ELBO. We maximize the ELBO because it's a lower bound on $$p(x)$$, so, by maximizing it, we're also maximizing the marginal likelihood (aka evidence) $$p(x)$$, i.e. we're trying to find the parameters $$\theta$$ and $$\phi$$, such that $$x$$ is more likely to have been sample from $$p(x)$$, which is unknown. See the VAE paper (in particular, algorithm 1) for more details.

Once the VAE is trained, you have $$q_\tilde{\phi}(z \mid x)$$ and $$p_\tilde{\theta}(x \mid z)$$. If $$p_\theta(z \mid x)$$ is the posterior, then $$q_\tilde{\phi}(z \mid x)$$ is an approximation of the posterior. Now, you can generate data with the VAE as follows

1. Let $$q_\tilde{\phi}(z \mid x)$$ be the new prior (as opposed to the user-defined $$p(z)$$, which was used to train the VAE) - in Bayes statistics, the posterior then becomes the prior (it's our new belief of how $$z$$ behaves given our data $$x$$)
2. Sample $$z^i$$ from $$q_\tilde{\phi}(z \mid x)$$
3. Sample $$x^i$$ from $$p_\tilde{\theta}(x \mid z^i)$$

So, together, $$\color{blue}{p_\tilde{\theta}(x \mid z^i)}$$ and $$\color{red}{q_\tilde{\phi}(z \mid x)}$$ approximate $$p(x, z) = \color{blue}{p(x \mid z)} \color{red}{p(z)}$$.

It might be possible to come up with a new objective function (different from the ELBO), where we use some kind of variational distribution to approximate $$p_\theta(x \mid z)$$, but, in the VAE, that's not the case.