Maximum Mean Discrepancy (MMD) is a popular kernel-based metric used to measure the similarity or difference between probability distributions. Given two distributions P and Q, MMD measures the distance between them by computing the difference between the means of their element-wise kernel functions over a given feature space.
Let X and Y be two sets of samples drawn from distributions P and Q respectively. Let k be a positive semidefinite kernel function that takes two inputs and produces a scalar value. The MMD between the distributions P and Q is defined as follows:
$$\text{MMD}(P, Q) = \| \frac{1}{n} \sum_{x \in X} \phi(x) - \frac{1}{m} \sum_{y \in Y} \phi(y) \|^2,$$
where โฅโ โ โ โฅ denotes the Euclidean norm and ฯ represents a feature map that maps data points to some high-dimensional space where they can be separated easily. This is known as the kernel trick, which involves mapping data to a higher dimensional feature space without computing the coordinates of the data in that space explicitly.
Intuitively, MMD measures the difference between the expected kernel function values of the two distributions, which corresponds to the distance between their means in the feature space. If the MMD is small, it suggests that the distributions are similar, whereas a large MMD implies that the distributions are dissimilar.
MMD is commonly used in generative modeling tasks, where the objective is to learn a model that generates samples that are similar to a target distribution. In such cases, MMD can be used as a metric to train the generative model by minimizing the distance between the true target distribution and the distribution of generated samples. This can be achieved by minimizing the following objective function:
MMDk(Pdata,โPmodel)โ=โMMD(Pdata,โPmodel)
โ
โโ
2๐ผxโโผโPdata,โzโโผโp(z)[k(x,โG(z))]โ
+โ
๐ผz1,โz2โโผโp(z)[k(G(z1),โG(z2))],
where Pdata is the true distribution, Pmodel is the distribution of generated samples from the generator function G, and p(z) is the prior distribution over the latent space. The first term measures the distance between the data and model distributions, while the second and third terms encourage the generator to produce samples that are close to the data distribution and are diverse enough.
In summary, MMD is a powerful metric that can be used to compare distributions and is particularly useful in generative modeling tasks for measuring the similarity between the true target distribution and the distribution of generated samples.