# Sampling z in VAE

How many times do we sample from $Q(z|x)$ in a Variational Autoencoder?

Let’s say that the autoencoder input $x$ is a single image 28x28 pixels - and $Z$ is is a one dimensional distribution. Then, to reconstruct the output $X'$ - I read (I could be wrong) that we can sample $10 000$ times.

Why do we sample so many? And what do we do to reduce it to 28x28?

EDIT

I am still confused how we can sample $10000$ times from $Q(z|x)$. For example let us consider the example above and assume that $Q(z|x)$ ~ $N(0,1)$. We have a 28x28 pixel image as the VAE input denoted $X$ with $28$ nodes each corresponding to one pixel.

Also, just for simplicity lets calculate the expectation of the likelihood part of ELBO instead of the whole thing.

Since, the posterior is Gaussian and we sample only once

$$E_{z\sim Q}[\log p(x|z)] = \frac{1}{28} \sum_{1}^{28} (x_i-x'_i)^2$$

Note that $Z_1$ in this case is a single value, and we are summing the error for each node

If we were to sample twice instead - would the expectation be

$$E_{z\sim Q}[\log p(x|z)] = \frac{1}{2*28} \sum_{1}^{2*28} (x_i-\overline{x}_i)^2$$