Skip to content
AIAI Wranglers

10 Wasserstein GAN

Why Wasserstein?

In Chapter 9 we saw that the original GAN minimises the Jensen–Shannon divergence between the data distribution pdata and the generator distribution pθ. While elegant, this choice leads to two persistent difficulties:

  1. Vanishing gradients. When the discriminator is too powerful, the generator receives almost no gradient signal because the JSD saturates at log2 for distributions with disjoint support (see Example Example 14).

  2. Training instability. The minimax game oscillates rather than converges, and small architectural or hyperparameter changes can cause complete training failure (recall Section Mode Collapse and Failure Modes).

Both problems share a common root: the JSD, the KL divergence, and the total-variation distance are all insensitive to the geometry of the underlying space. When two distributions live on low-dimensional manifolds that do not overlap, which is the typical case in image generation, these divergences are either constant or infinite, providing no useful gradient.

Key Idea.

The Wasserstein distance “knows about geometry.” Because it measures the cost of transporting mass rather than comparing densities point-wise, it varies smoothly even when the supports of the two distributions are disjoint. This gives the generator a meaningful gradient everywhere.

Example 1 (Parallel Lines in 2D).

Let P be the uniform distribution on the line segment {(x,0):x[0,1]} and let Qt be the uniform distribution on the shifted segment {(x,t):x[0,1]}. For every t>0, P and Qt have disjoint support, so: 𝖣KL(PQt)=+,𝖣JS(PQt)=log2,𝖣TV(P,Qt)=1,W1(P,Qt)=t. Only W1 tells the generator “move the line down by t” and provides a gradient of constant magnitude tW1=1. The other divergences say “you're completely wrong” with zero gradient.

Left: transporting mass from P to Qt costs t. Right: only W1 provides a non-zero, continuous gradient; JSD and TV are flat constants for t>0.

Historical Note.

The idea of using the Wasserstein distance for training generative models was proposed by Arjovsky et al. [1] in their influential 2017 paper. The name “Earth Mover's Distance” was popularised in computer science by Rubner et al. [2], who used it for image retrieval. The mathematical foundations go back to Gaspard Monge (1781) and Leonid Kantorovich (1942), whose work on optimal transport won him the Nobel Prize in Economics.

Recap: The Wasserstein-1 Distance

We introduced the Wasserstein distance in the divergences chapter (Definition Definition 8). Here we recall the key facts needed for WGAN.

Definition 1 (Wasserstein-1 Distance).

Given two probability distributions P and Q on a metric space (𝒳,d), the Wasserstein-1 distance (Earth Mover's distance) is (W1)W1(P,Q)=infπΠ(P,Q)𝔼(𝒙,𝒚)π[d(𝒙,𝒚)], where Π(P,Q) is the set of all joint distributions (couplings) with marginals P and Q.

Remark 1 (Intuition: Piles of Sand).

Think of P as a pile of sand and Q as a hole of the same total volume. A coupling π specifies how much sand to move from each location 𝒙 to each location 𝒚, and d(𝒙,𝒚) is the cost of moving one unit of sand. The Wasserstein distance is the cheapest way to fill the hole.

The Wasserstein distance has a property that makes it uniquely suited for generative modelling:

Proposition 1 (Wasserstein Metrises Weak Convergence).

On a compact metric space 𝒳, a sequence of distributions Pn converges weakly to P (i.e. 𝔼Pn[f]𝔼P[f] for every bounded continuous f) if and only if W1(Pn,P)0.

This means that minimising W1 is equivalent to making the generator distribution converge to the data distribution in the weakest reasonable sense. In contrast, KL and JS divergence can be infinite or discontinuous even along sequences that converge weakly.

Kantorovich–Rubinstein Duality

The primal form requires optimising over the infinite-dimensional space of couplings, computationally intractable in general. The Kantorovich–Rubinstein (KR) duality provides an equivalent formulation that replaces the coupling with a single function, making it amenable to neural-network approximation.

Theorem 1 (Kantorovich–Rubinstein Duality).

For probability distributions P and Q on a compact metric space (𝒳,), (KR)W1(P,Q)=supfL1[𝔼𝒙P[f(𝒙)]𝔼𝒚Q[f(𝒚)]], where the supremum is over all 1-Lipschitz functions f:𝒳 (see Definition Definition 20).

Insight.

The dual form says: among all functions that cannot change faster than the metric d, find the one that maximally separates the two distributions. This “witness function” is exactly what the WGAN critic learns.

Proof of KR Duality

The proof proceeds in three steps: (1) construct the Lagrangian dual, (2) show the lower bound supfW1, (3) show the upper bound W1supf using the infimal convolution.

Proof.

Step 1: Lagrangian dual. The primal problem is W1(P,Q)=infπΠ(P,Q)𝒳×𝒳𝒙𝒚π(𝒙,𝒚)d𝒙d𝒚, subject to the marginal constraints π(𝒙,𝒚)d𝒚=P(𝒙),π(𝒙,𝒚)d𝒙=Q(𝒚). Introducing Lagrange multipliers f and g (see Definition def:lagrange), the Lagrangian is (Lagrangian)L(π,f,g)=𝒳×𝒳𝒙𝒚π(𝒙,𝒚)d𝒙d𝒚+𝒳(P(𝒙)π(𝒙,𝒚)d𝒚)f(𝒙)d𝒙+𝒳(Q(𝒚)π(𝒙,𝒚)d𝒙)g(𝒚)d𝒚. Collecting terms: (Collected)L(π,f,g)=𝔼P[f(𝒙)]+𝔼Q[g(𝒚)]+𝒳×𝒳(𝒙𝒚f(𝒙)g(𝒚))π(𝒙,𝒚)d𝒙d𝒚. The objective 𝒙𝒚 is convex, and the constraints are affine, so Slater's condition holds trivially (Definition Definition 17, Theorem Theorem 15). By strong duality (Theorem Theorem 16): (Strongdual)W1(P,Q)=infπsupf,gL(π,f,g)=supf,ginfπL(π,f,g).

For the inner infimum over π: if 𝒙𝒚<f(𝒙)+g(𝒚) for some (𝒙,𝒚), we could concentrate mass there and send L. Therefore the supremum is restricted to pairs satisfying f(𝒙)+g(𝒚)𝒙𝒚 for all 𝒙,𝒚, and the infimum over π yields: (DUAL)W1(P,Q)=supf,gf(𝒙)+g(𝒚)𝒙𝒚[𝔼P[f(𝒙)]+𝔼Q[g(𝒚)]].

Step 2: Lower bound. Let h be any 1-Lipschitz function. For any coupling π with marginals P and Q: (LB1)𝔼P[h(𝒙)]𝔼Q[h(𝒚)]=𝒳h(𝒙)P(𝒙)d𝒙𝒳h(𝒚)Q(𝒚)d𝒚=𝒳×𝒳(h(𝒙)h(𝒚))π(𝒙,𝒚)d𝒙d𝒚𝒳×𝒳𝒙𝒚π(𝒙,𝒚)d𝒙d𝒚, where uses the marginal constraints, and uses the 1-Lipschitz property |h(𝒙)h(𝒚)|𝒙𝒚. Since is independent of π, the inequality holds for the infimum over π: (Lowerbound)suphL1[𝔼P[h(𝒙)]𝔼Q[h(𝒚)]]W1(P,Q).

Step 3: Upper bound via infimal convolution. Given any feasible (f,g) with f(𝒙)+g(𝒚)𝒙𝒚, define the infimal convolution: (Infconv)k(𝒙)=inf𝒖[𝒙𝒖g(𝒖)].

Claim: k is 1-Lipschitz. Indeed, for any 𝒙,𝒚: k(𝒙)𝒙𝒖g(𝒖)𝒙𝒚+𝒚𝒖g(𝒖) for all 𝒖, so k(𝒙)𝒙𝒚+k(𝒚), i.e. k(𝒙)k(𝒚)𝒙𝒚. By symmetry, |k(𝒙)k(𝒚)|𝒙𝒚.

Now we show f(𝒗)k(𝒗) and k(𝒗)g(𝒗) for all 𝒗. From the feasibility constraint: f(𝒗)inf𝒖[𝒗𝒖g(𝒖)]=k(𝒗). Setting 𝒖=𝒗 in : k(𝒗)𝒗𝒗g(𝒗)=g(𝒗). Therefore: (FGK)𝔼P[f(𝒙)]+𝔼Q[g(𝒚)]𝔼P[k(𝒙)]𝔼Q[k(𝒚)]. Since k is 1-Lipschitz, combining with : W1(P,Q)=supf,gf+g[𝔼P[f]+𝔼Q[g]]suphL1[𝔼P[h]𝔼Q[h]]W1(P,Q). Both inequalities are equalities, completing the proof.

Remark 2 (Reading the Dual).

The KR dual says: “Find the function f whose Lipschitz constant is at most 1 that maximises the difference in expected values under P and Q.” Intuitively, f “tilts” the space so that mass under P rolls uphill and mass under Q rolls downhill, and the Lipschitz constraint limits how steep the tilt can be.

The WGAN Objective

The Kantorovich–Rubinstein duality directly suggests a GAN-like training procedure. Replace the supremum over all 1-Lipschitz functions with a neural network fw (called the critic), and replace Q with the generator distribution pθ.

Definition 2 (WGAN Value Function).

The WGAN objective is the saddle-point problem (Value)minθmaxw𝒲𝔼𝒙pdata[fw(𝒙)]𝔼𝒛pz[fw(Gθ(𝒛))]V(w,θ), where 𝒲 is a set of parameters such that {fw}w𝒲 are all K-Lipschitz for some K>0.

Example 2 (Comparing GAN and WGAN Objectives).

Side by side, the two objectives reveal their structural difference:

1.6

Original GANWGAN
Critic outputDϕ(𝒙)(0,1) via sigmoidfw(𝒙) (no activation)
Critic loss𝔼[logD]𝔼[log(1D)]𝔼[fw(𝒙fake)]𝔼[fw(𝒙real)]
Generator loss𝔼[logD(𝒙^)]𝔼[fw(𝒙^)]
DivergenceJensen–ShannonWasserstein-1
ConstraintNone (discriminator is a classifier)Lipschitz on fw

Caution.

The WGAN critic has no sigmoid output layer. Its output is an unbounded real number (a “score”), not a probability. Using a sigmoid would destroy the Wasserstein interpretation and revert to something closer to the original GAN.

Insight.

The WGAN loss V(w,θ) is an estimate of the Wasserstein distance. Unlike the GAN discriminator loss, which provides no information about sample quality once the discriminator is perfect, the WGAN critic loss correlates directly with generation quality. You can literally watch the loss curve go down and know that images are improving, a luxury that original GANs never offered.

Enforcing the Lipschitz Constraint

The entire WGAN framework hinges on constraining the critic to be Lipschitz. This seemingly simple requirement turns out to be the central practical challenge, and several ingenious solutions have been proposed.

Weight Clipping

The original WGAN paper [1] enforces the Lipschitz constraint by clipping all critic weights to a compact range [c,c] after each gradient update.

Definition 3 (Weight Clipping).

After each parameter update ww+αwV, set (CLIP)wclip(w,c,c)=defmax(c,min(w,c)), applied element-wise, where c>0 is a hyperparameter (typically c=0.01).

Remark 3 (Why Clipping Enforces Lipschitz).

A neural network with bounded weights has bounded operator norms for each layer. If each weight matrix satisfies Wic, then the Lipschitz constant of each affine layer is bounded, and the overall Lipschitz constant is bounded by the product of per-layer constants (Exercise Exercise 1).

Unfortunately, weight clipping has serious drawbacks:

Caution.

Weight clipping is a blunt instrument:

  • Capacity underuse. If c is too small, the critic can only represent very simple functions, wasting the network's capacity. In practice, clipped critics tend to learn functions that are nearly linear.

  • Exploding/vanishing gradients. If c is too large, the Lipschitz constant becomes very large and the Wasserstein estimate is poor; if c is too small, gradients can vanish through many layers.

  • Sensitivity to c. Performance depends critically on the clipping range, and the optimal c varies across datasets and architectures.

Gradient Penalty (WGAN-GP)

Gulrajani et al. [3] proposed a much more effective approach: instead of hard-clipping the weights, penalise the critic's gradient norm to encourage the 1-Lipschitz constraint directly.

The key theoretical motivation comes from the following result about the optimal critic:

Proposition 2 (Gradient Norm of the Optimal Critic).

Let P and Q be distributions on a compact metric space, f the optimal 1-Lipschitz critic, and π an optimal coupling. If f is differentiable, then for 𝒙t=(1t)𝒙+t𝒚 with t[0,1]: (Optgrad)(𝒙,𝒚)π[f(𝒙t)=1]=1. That is, the optimal critic has gradient norm exactly 1 almost everywhere along straight lines between coupled points.

Proof.

Since 𝒳 is compact, an optimal 1-Lipschitz critic f and optimal coupling π exist. For (x,y)π, optimality gives: f(y)f(x)=yxwith probability 1. Define ψ(t)=f(xt)f(x) for xt=(1t)x+ty. Since f is 1-Lipschitz: |ψ(t)ψ(t)|=|f(xt)f(xt)|xtxt=|tt|xy, so ψ is xy-Lipschitz with ψ(0)=0 and ψ(1)=xy. Writing: ψ(1)=(ψ(1)ψ(t))(1t)xy+(ψ(t)ψ(0))txyxy=ψ(1), both inequalities must be equalities, so ψ(t)=txy, i.e. f(xt)=f(x)+txy.

Let v=yxyx. The directional derivative: fv(xt)=limh0f(xt+h/yx)f(xt)h=limh0hh=1. Since f is 1-Lipschitz, f(xt)1. By the Pythagorean decomposition (Exercise Exercise 6): 1f(xt)2=(fv)2+f(xt)vfv2=1+f(xt)v21. The squeeze gives f(xt)=v=yxtyxt, so f(xt)=1.

This proposition tells us that the optimal critic has gradient norm exactly 1 along the optimal transport paths. This motivates penalising deviations from unit gradient norm:

Definition 4 (WGAN-GP Objective).

The WGAN-GP critic loss is (GP)LGP=𝔼𝒛pz[fw(Gθ(𝒛))]𝔼𝒙pdata[fw(𝒙)]Wasserstein estimate+λ𝔼𝒙^px^[(𝒙^fw(𝒙^)21)2]gradient penalty, where 𝒙^=ϵ𝒙real+(1ϵ)𝒙fake with ϵU[0,1], and λ>0 is the penalty coefficient (typically λ=10).

Example 3 (Understanding the Gradient Penalty).

The gradient penalty is evaluated at interpolated points 𝒙^ between real and fake samples. Why interpolations?

  1. Proposition Proposition 2 shows the optimal critic has unit gradient norm along straight lines between optimally coupled points (x,y).

  2. We approximate the optimal coupling by pairing each real sample with a generated sample and interpolating between them.

  3. The penalty (f21)2 is a two-sided penalty: it pushes the gradient norm towards 1, not just below 1. This is important because the optimal critic satisfies f=1, not merely f1.

Remark 4 (One-Sided vs. Two-Sided Penalty).

One might consider the one-sided penalty max(0,f21)2, which only penalises violations of the Lipschitz constraint. However, the two-sided penalty (f21)2 works better in practice: it constrains the critic to the optimal function class (gradient norm exactly 1) rather than the broader class of all 1-Lipschitz functions, reducing the effective search space.

Spectral Normalisation

Miyato et al. [4] proposed a third approach that is both computationally efficient and effective: normalise each weight matrix by its spectral norm (largest singular value).

Definition 5 (Spectral Normalisation).

For a weight matrix W, define the spectrally normalised weight: (SN)W=Wσ(W),σ(W)=max𝒉:𝒉2=1W𝒉2=σmax(W), where σmax(W) is the largest singular value of W.

Proposition 3 (Lipschitz Constant Under Spectral Normalisation).

A feed-forward network f=hLh1 where each layer h(𝒙)=a(W𝒙+𝒃) uses a 1-Lipschitz activation a (e.g. ReLU, leaky ReLU) has Lipschitz constant at most 1: (LIP)fL=1Lσ(W)=1.

Proof.

Each spectrally normalised layer satisfies W2=1 by construction, so h is 1-Lipschitz (since a is 1-Lipschitz and h(𝒙)h(𝒚)W(𝒙𝒚)𝒙𝒚). The composition of 1-Lipschitz functions is 1-Lipschitz.

In practice, computing σ(W) exactly at every iteration is expensive. Instead, one uses the power iteration method:

Algorithm 1 (Spectral Norm Estimation via Power Iteration).

  1. Initialise 𝒖 randomly with 𝒖2=1.

  2. At each training step, perform one update: 𝒗W𝒖W𝒖2,𝒖W𝒗W𝒗2.

  3. Estimate σ(W)𝒖W𝒗.

  4. Set W=W/σ(W).

One power-iteration step per training step suffices because W changes slowly, so the estimate tracks σ(W) accurately.

Remark 5 (Comparing Lipschitz Enforcement Methods).

1.3

Weight ClippingGradient PenaltySpectral Norm
Proposed by[1][3][4]
Constraint typeHard (project)Soft (penalty)Hard (normalise)
Per-step costNegligibleExpensive (Jacobian)Cheap (1 power iter.)
Critic capacityLow (underfits)FullFull
Batch normalisationCompatibleIncompatibleCompatible
Hyperparametersc (sensitive)λ (robust at 10)None

WGAN Algorithms

We now present the two main WGAN training algorithms.

WGAN with Weight Clipping

Algorithm 2 (WGAN Training (Weight Clipping)).

Hyperparameters: learning rate α=0.00005, clipping parameter c=0.01, batch size m=64, critic iterations ncritic=5.

  1. Initialise critic parameters w0, generator parameters θ0
  2. while θ has not converged
  3. for t=1,,ncritic
  4. Sample {𝒙(i)}i=1mpdata
  5. Sample {𝒛(i)}i=1mpz
  6. gww[1mi=1mfw(𝒙(i))1mi=1mfw(Gθ(𝒛(i)))]
  7. ww+αRMSProp(w,gw)
  8. wclip(w,c,c)
  9. Sample {𝒛(i)}i=1mpz
  10. gθθ1mi=1mfw(Gθ(𝒛(i)))
  11. θθαRMSProp(θ,gθ)

Remark 6 (Why ncritic=5?).

Unlike the original GAN where the discriminator trains for k=1 step per generator step, WGAN requires more critic updates. The Wasserstein estimate is only meaningful when the critic is close to optimal. In practice, ncritic=5 provides a good trade-off between estimation quality and training speed.

WGAN-GP Algorithm

Algorithm 3 (WGAN-GP Training (Gradient Penalty)).

Hyperparameters: learning rate α=0.0001, gradient penalty coefficient λ=10, batch size m=64, critic iterations ncritic=5. Use Adam with β1=0, β2=0.9.

  1. Initialise critic parameters w0, generator parameters θ0
  2. while θ has not converged
  3. for t=1,,ncritic
  4. Sample {𝒙(i)}i=1mpdata, {𝒛(i)}i=1mpz, {ϵ(i)}i=1mU[0,1]
  5. 𝒙^(i)ϵ(i)𝒙(i)+(1ϵ(i))Gθ(𝒛(i)) Interpolate
  6. L(i)fw(Gθ(𝒛(i)))fw(𝒙(i))+λ(𝒙^fw(𝒙^(i))21)2
  7. wwαAdam(w,w1miL(i))
  8. Sample {𝒛(i)}i=1mpz
  9. θθαAdam(θ,θ1mifw(Gθ(𝒛(i))))

Caution.

WGAN-GP is incompatible with batch normalisation in the critic. Batch normalisation introduces dependencies between samples in a mini-batch, which means the critic's gradient at 𝒙^ depends on other samples in the batch. This violates the assumption that the gradient penalty is evaluated independently for each interpolated point. Use layer normalisation or instance normalisation instead.

Training Dynamics and the Meaningful Loss

One of the most celebrated practical advantages of WGAN is its meaningful loss curve.

Key Idea.

In a standard GAN, the discriminator loss converges to log2 regardless of sample quality, so the loss provides no information about training progress. In WGAN, the critic loss V(w,θ) is an estimate of W1(pdata,pθ), which decreases monotonically as the generator improves. For the first time, you can monitor a single scalar to assess generation quality.

Example 4 (Monitoring the WGAN Loss).

During WGAN training on a face generation task:

  • Epoch 1: Critic loss 50. Generated images are random noise.

  • Epoch 50: Critic loss 10. Generated images show blurry face-like shapes.

  • Epoch 200: Critic loss 2. Generated images are sharp, recognisable faces.

  • Epoch 500: Critic loss 0.5. Generated images are nearly photorealistic.

The correlation between the critic loss and visual quality is remarkably strong, a property that original GANs lack entirely.

The WGAN critic loss (solid green) decreases monotonically and correlates with generation quality. The standard GAN discriminator loss (dashed red) oscillates around log2 and provides no information about training progress.

The convergence properties of WGAN are also theoretically grounded:

Theorem 2 (Convergence of WGAN).

Let pθ be a distribution parameterised by θ such that gθ(𝒛) is continuous in θ. If the critic is trained to optimality at each step, then the generator gradient θW1(pdata,pθ)=𝔼𝒛pz[θf(Gθ(𝒛))] exists and is continuous, providing a stable signal for gradient descent.

This is in stark contrast to the original GAN, where the generator gradient can be zero (saturated discriminator) or infinite (near decision boundaries).

Practical Advantages and Limitations

Remark 7 (Advantages of WGAN).

  1. Meaningful loss. The critic loss tracks the Wasserstein distance and correlates with sample quality.

  2. Stability. Training is more stable across architectures and hyperparameters.

  3. Mode coverage. The Wasserstein distance penalises all uncovered modes, reducing (though not eliminating) mode collapse.

  4. No careful balancing needed. In standard GANs, the discriminator and generator must be balanced; in WGAN, the critic should simply be trained to near-optimality.

Remark 8 (Limitations of WGAN).

  1. Slower per iteration. Training the critic for ncritic=5 steps per generator step means 5× more critic evaluations.

  2. Gradient penalty cost. WGAN-GP requires computing gradients of gradients (double backpropagation), which is expensive in memory and compute.

  3. Not always superior. On well-tuned benchmarks, standard GANs with spectral normalisation and hinge loss can match or exceed WGAN-GP.

  4. Critic architecture matters. The quality of the Wasserstein estimate depends heavily on the critic's expressiveness.

Example 5 (WGAN on MNIST).

Consider training a WGAN-GP on MNIST (28×28 grayscale digits):

  • Generator: Fully connected, 100256512784, ReLU activations, tanh output.

  • Critic: Fully connected, 7845122561, LeakyReLU, no batch normalisation, no sigmoid.

  • Training: Adam with α=104, β1=0, β2=0.9, λ=10, ncritic=5.

After 50,000 iterations, the generator produces sharp, diverse digits, and the critic loss curve is a smooth, monotonically decreasing function, confirming that the Wasserstein framework delivers on its promise of a meaningful training signal.

From WGAN to Modern Practice

The WGAN papers fundamentally changed how the community thinks about GAN training. Their key insight, that the choice of divergence matters enormously and that divergences from optimal transport are uniquely suited to generative modelling, has had lasting influence well beyond GANs.

Remark 9 (The Legacy of WGAN).

  • Spectral normalisation is now standard in almost all GAN architectures, even those not explicitly trained with the Wasserstein loss.

  • Optimal transport has become a central tool in machine learning, from domain adaptation to single-cell biology.

  • The critic loss as a quality metric inspired the FID score (Definition Definition 7), which is itself a Wasserstein-2 distance in feature space (Remark Remark 7).

  • Diffusion models implicitly use optimal-transport ideas through their score-matching objectives and probability flow ODEs.

Historical Note.

The WGAN paper [1] by Arjovsky, Chintala, and Bottou appeared in January 2017 and quickly became one of the most cited GAN papers. The follow-up WGAN-GP paper [3] by Gulrajani et al. appeared just three months later, in March 2017. Spectral normalisation by Miyato et al. [4] followed in 2018. Together, these three papers form the “Lipschitz trilogy” that solved WGAN's central practical challenge.

Exercises

Exercise 1 (Lipschitz Continuity of Compositions).

Let f:nm be L1-Lipschitz and g:mp be L2-Lipschitz. Show that gf is L1L2-Lipschitz. Conclude that a neural network with layers, each with Lipschitz constant Li, has overall Lipschitz constant at most i=1Li.

Exercise 2 (Weight Clipping Does Not Enforce 1-Lipschitz).

Consider a single-layer linear critic fw(𝒙)=𝒘𝒙 with 𝒘[c,c]d.

  1. (a)

    Show that the Lipschitz constant of fw is 𝒘2.

  2. (b)

    Show that weight clipping enforces 𝒘2cd, not 𝒘21.

  3. (c)

    Explain how this gap affects the Wasserstein estimate.

Exercise 3 (Gradient Penalty Derivation).

Starting from Proposition Proposition 2, explain why:

  1. (a)

    The gradient penalty is evaluated at interpolated points rather than at real or fake points alone.

  2. (b)

    The two-sided penalty (f21)2 is preferred over the one-sided penalty max(0,f21)2.

  3. (c)

    The penalty coefficient λ should be large enough to enforce the constraint but not so large that it dominates the Wasserstein objective.

Exercise 4 (WGAN vs. Original GAN on Point Masses).

Let pdata=δ0 and pθ=δθ on .

  1. (a)

    Compute W1(pθ,pdata).

  2. (b)

    Compute 𝖣JS(pθpdata).

  3. (c)

    Compute the gradients θW1 and θ𝖣JS for θ0.

  4. (d)

    Explain why this illustrates the advantage of WGAN for training generative models.

Exercise 5 (Wasserstein Distance in One Dimension).

For distributions P,Q on with CDFs FP,FQ:

  1. (a)

    Show that W1(P,Q)=|FP(x)FQ(x)|dx. Hint: the optimal transport maps quantiles to quantiles.

  2. (b)

    Compute W1(𝒩(0,1),𝒩(μ,1)) and show it equals |μ|.

  3. (c)

    Compute W1(𝒩(0,σ12),𝒩(0,σ22)).

Exercise 6 (Pythagorean Decomposition).

Let 𝒗 be a unit vector in d and 𝒙 an arbitrary vector.

  1. (a)

    Show that 𝒗 and 𝒙(𝒙𝒗)𝒗 are orthogonal.

  2. (b)

    Prove 𝒙2=(𝒙𝒗)2+𝒙(𝒙𝒗)𝒗2.

  3. (c)

    Use this decomposition to verify the squeeze argument in the proof of Proposition Proposition 2.

Exercise 7 (Infimal Convolution Properties).

Let k(𝒙)=inf𝒖[𝒙𝒖g(𝒖)] as in the KR duality proof.

  1. (a)

    Show that if f(𝒙)+g(𝒚)𝒙𝒚 for all 𝒙,𝒚, then f(𝒙)k(𝒙).

  2. (b)

    Show k(𝒚)g(𝒚) for all 𝒚.

  3. (c)

    Combine (a) and (b) to prove .

Exercise 8 (Spectral Norm Computation).

For the matrix W=(2103):

  1. (a)

    Compute the singular values of W.

  2. (b)

    Compute W=W/σ(W).

  3. (c)

    Verify that W2=1.

  4. (d)

    Perform two steps of power iteration starting from 𝒖0=(1,0) and compare with the exact answer.

Exercise 9 (ReLU Networks and Lipschitz Constants).

  1. (a)

    Show that ReLU is 1-Lipschitz.

  2. (b)

    Show that LeakyReLU with slope α is max(1,|α|)-Lipschitz.

  3. (c)

    For a two-layer network f(𝒙)=W2ReLU(W1𝒙), show that fLσmax(W2)σmax(W1).

  4. (d)

    Is this bound tight? Give an example.

Exercise 10 (Comparing WGAN, WGAN-GP, and SN-GAN).

Consider training a convolutional GAN on CIFAR-10.

  1. (a)

    Describe the critic architecture for each of WGAN (weight clipping), WGAN-GP, and SN-GAN. Which normalisation layers can each use?

  2. (b)

    If the critic has 5 convolutional layers each with 3×3 kernels, estimate the computational overhead of the gradient penalty versus spectral normalisation.

  3. (c)

    Why does WGAN-GP require Adam with β1=0 while standard GAN training uses β1=0.5?

Exercise 11 (The Critic as a Density Ratio Estimator).

In the original GAN, the optimal discriminator computes the density ratio pdata/(pdata+pθ) (Proposition Proposition 1). What does the optimal WGAN critic compute? Show that it is related to the Kantorovich potential and not a density ratio.

Exercise 12 (Wasserstein-2 and FID).

The Fréchet Inception Distance (FID, Definition Definition 7) is FID=𝝁r𝝁g2+trace(Σr+Σg2(Σr1/2ΣgΣr1/2)1/2).

  1. (a)

    Show that this equals W22(𝒩(𝝁r,Σr),𝒩(𝝁g,Σg)).

  2. (b)

    Explain why using W2 in Inception feature space rather than pixel space is advantageous.

Exercise 13 (WGAN for Discrete Data).

Suppose P and Q are distributions over a finite set 𝒳={1,2,,n} with metric d(i,j)=|ij|.

  1. (a)

    Write W1(P,Q) as a linear program.

  2. (b)

    Show that the KR dual specialises to W1=max|f(i)f(j)||ij|if(i)(P(i)Q(i)).

  3. (c)

    For P=(0.5,0.5,0) and Q=(0,0.5,0.5), compute W1 and find the optimal f.

Exercise 14 (Implementing WGAN-GP in PyTorch).

Write PyTorch pseudocode for:

  1. (a)

    The gradient penalty computation, using torch.autograd.grad to compute 𝒙^fw(𝒙^).

  2. (b)

    A training loop that alternates between critic and generator updates.

  3. (c)

    Explain why create_graph=True must be passed to torch.autograd.grad for the gradient penalty.

References

  1. Wasserstein GAN

    Martin Arjovsky, Soumith Chintala, Leon Bottou

    arXiv:1701.07875 · 2017

    BibTeX
    @article{arjovsky2017wasserstein,
        title = {Wasserstein GAN},
        author = {Arjovsky, Martin and Chintala, Soumith and Bottou, L\'eon},
        journal = {arXiv:1701.07875},
        year = {2017}
    }

    Journal article

  2. The Earth Mover's Distance as a Metric for Image Retrieval

    Yossi Rubner, Carlo Tomasi, Leonidas J. Guibas

    International Journal of Computer Vision, vol. 40, no. 2, pp. 99-121 · 2000

    BibTeX
    @article{rubner2000earth,
        title = {The Earth Mover's Distance as a Metric for Image Retrieval},
        author = {Rubner, Yossi and Tomasi, Carlo and Guibas, Leonidas J.},
        journal = {International Journal of Computer Vision},
        volume = {40},
        number = {2},
        pages = {99--121},
        year = {2000},
        publisher = {Springer}
    }

    Journal article

  3. Improved training of Wasserstein GANs

    Ishaan Gulrajani, Faruk Ahmed, Martin Arjovsky, Vincent Dumoulin, Aaron C Courville

    Advances in neural information processing systems, pp. 5767-5777 · 2017

    BibTeX
    @inproceedings{gulrajani2017improved,
      title={Improved training of Wasserstein GANs},
      author={Gulrajani, Ishaan and Ahmed, Faruk and Arjovsky, Martin and Dumoulin, Vincent and Courville, Aaron C},
      booktitle={Advances in neural information processing systems},
      pages={5767--5777},
      year={2017}
    }

    Conference paper

  4. Spectral normalization for generative adversarial networks

    Takeru Miyato, Toshiki Kataoka, Masanori Koyama, Yuichi Yoshida

    Proceedings of the International Conference on Learning Representations · 2018

    BibTeX
    @inproceedings{miyato2018spectral,
      title={Spectral normalization for generative adversarial networks},
      author={Miyato, Takeru and Kataoka, Toshiki and Koyama, Masanori and Yoshida, Yuichi},
      booktitle={Proceedings of the International Conference on Learning Representations},
      year={2018},
      url={https://openreview.net/forum?id=B1QRgziT-}
    }

    Conference paper