What's the difference between p(Z, X=x) and p(Z|X=x)? I'm trying to understand variational inference, and I've found resources that mention $p(Z, X=x)$, where $Z$ is a latent random variable and $X$ is the observed random variable. (Here is one such example)
Is there a difference between $p(Z, X=x)$ and $p(Z|X=x)$? Let's consider a simple example: $X$ is a random variable of MNIST handwritten digit images, and $Z$ is the random variable for the actual digit class (i.e. if x is a picture of a hand drawn 7, z is 7)
 A: With conditioning, you reduce the space of possible outcomes, which can change the probabilities.
Imagine there are precisely two images $x_1$ and $x_2$ with the following probabilities:




Z=
0
1
2
3
4
5
6
7
8
9




X=x1
0
0.05
0
0
0
0
0
0.45
0
0


X=x2
0
0
0
0
0
0.25
0.25
0
0
0




The probabilities over the complete table add up to one, as they should. In this case, I have chosen both images to be of equal probability, i.e. the row sums are both $0.5$, so $p(X = x_1) = p(X = x_2) = 0.5$.
Now, the table says $p(Z=7, X = x_1) = 0.45$. But if we condition on $X = x_1$, i.e. we consider $p(Z|X = x_1)$, we exclude all possibilities from the second row. But the sum of all the probabilities must still be equal to one, so we have to normalize the first row, which is done by dividing each cell in the first row by the probability of the first row, i.e. by $0.5$. That gives:




Z=
0
1
2
3
4
5
6
7
8
9




X=x1
0
0.1
0
0
0
0
0
0.9
0
0




So, this table says that $p(Z=7|X=x_1) = 0.9$. In formulas, that normalization is just the definition of conditional probabilities:
$$
p(Z=7|X = x_1) = \frac{p(Z=7, X=x_1)}{p(X=x_1)} = \frac{0.45}{0.5} = 0.9.
$$
A: 
(i.e. if x is a picture of a hand drawn 7, z is 7)

If $X$ is a picture of a hand drawn 7, then $Z$ is almost surely equal to $7$. That is,
$$P(Z=7|X = \text{image of a $7$}) \approx 1$$
A computer will see this region $X = \text{image of a $7$}$ as the red encircled area below
Adapted from: The Memory for Latent Representations: An Account of Working Memory that Builds on Visual Knowledge for Efficient and Detailed Visual Representations

If you have such an image then the probability for a 7 will be close to one. However... Obviously you will not have
$$P(Z=7 \text{ and }X = \text{image of a $7$}) \approx 1$$
That would mean that you are almost certainly are gonna have an image $X$ and a value $Z$ that is equal to 7. But what about all the other digits?
A: Joint probability $p(Z,X)$ is: what is the probability that someone has blue eyes $Z$ and red hair $X$.
Conditional probability $p(Z|X)$ is: what is the probability that someone with red hair $X$ has blue eyes $Z$.
With discrete data, in the first case to calculate the probability you would consider all the possible combinations of eye color and hair color, in the second case, you care only about people with red hair. This is what the definition says
$$
p(Z|X) = \frac{p(Z, X)}{p(X)}
$$
because you only “count” the cases where $X$ happens, you need to normalize (divide by) the probability of observing $X$. From the whole “pie” you cut off only the piece of size equal to $p(X)$ fraction of the $X$ side, so the piece is $p(X)$ smaller than the whole “pie”.
