Wasserstein distance

We’ve seen that the GAN loss can be interpreted in terms of distances between probability distributions. In the original formulation, the gradient of this distance becomes zero when the generated samples are too easy to distinguish from the real examples. Thus, we aim to choose a distance metric with better properties.

The Wasserstein or earth mover’s distance (for discrete distributions) is the quantity of work required to transport the probability mass from one distribution to create the other. Here, “work” is defined as the mass multiplied by the distance moved. This makes the Wasserstein distance well-defined even when the distributions are disjoint and decreases smoothly as they become closer to one another.

Discrete (Earth mover’s distance)

Consider distributions and defined over bins. Assume there is a cost associated with moving one unit of mass from bin in the first distribution to bin in the second. This cost might be the absolute difference between the indices. The amounts that are moved form the transport plan and are stored in the matrix .

The Wasserstein distance is defined as:

subject to the constraints that:

  • – initial distribution of Pr(x)
  • – initial distribution of q(x)
  • – non-negative masses

In other words, the Wasserstein distance is the solution to a constrained minimization problem that maps the masses of one distribution to the other. This is inconvenient, as we must solve this minimization problem over the elements every time we want to compute the distance. Fortunately, this is a standard problem that is easily solved for small systems of equations. It’s a linear programming problem in its primal form:

where contains the vectorized elements that determine the amount of mass moved, contains the distance, contains the initial distribution constraints, and ensures the masses moved are non-negative.

As for all linear programming problems, there is an equivalent dual problem with the same solution. Here, we maximize with respect to a variable that is applied to the initial distributions, subject to constraints that depend on the distances . The solution to this dual problem is:

subject to the constraint that:

In other words, we optimize over a new set of variables where adjacent values cannot change by more than one.

Continuous

Translating the above results back to the continuous multi-dimensional domain, the equivalent of the primal form is:

subject to similar constraints on the transport plan representing the mass moved from position to .

The equivalent of the dual form is:

subject to the constraint the the Lipschitz constant of the function is less than one (the absolute gradient of the function is less than one)..

Wasserstein GAN loss

In the context of neural networks, we maximize over the space of functions by optimizing the parameters in a neural network , and we approximate these integrals using generated samples and real examples :

where we must constrain the neural network discriminator to have an absolute gradient norm of less than one at every position:

One way to achieve this is to clip the discriminator weights to a small range (e.g., ). An alternative is the gradient penalty Wasserstein GAN (WGAN-GP), which adds a regularization term that increases as the gradient norm deviates from unity.

dl
Why does using a Wasserstein distance loss function make GAN training more stable?
?
Compared to the Jensen-Shannon divergence used in the original GAN loss function, Wasserstein distance is well-defined even when the real/synthetic distributions are disjoint and decreases smoothly as they become closer to one another.

+++