KL Divergence and its variants

1. KL Divergence and its variants

KL(𝑃‖𝑄)=𝔼π‘₯βˆΌπ‘ƒ[log𝑃(π‘₯)𝑄(π‘₯)]

Forward (inclusive) KL: KL(𝑃‖𝑄) where 𝑃 is the true distribution and 𝑄 is the approximating distribution.

  • Mode covering: Since we sample from 𝑃 and penalize when 𝑄(π‘₯) is small, 𝑄 tends to cover all modes of 𝑃 (even if it means being over-dispersed). If 𝑃(π‘₯)>0 but 𝑄(π‘₯)β‰ˆ0, the penalty is large.
  • Typical use: Maximize likelihood, VAE (ensures decoder explains all data)

Reverse (exclusive) KL: KL(𝑄‖𝑃)

  • Mode seeking: Since we sample from 𝑄 and penalize when 𝑃(π‘₯) is small, 𝑄 tends to concentrate on a single mode of 𝑃 (under-dispersed but sharper). If 𝑄(π‘₯)>0 but 𝑃(π‘₯)β‰ˆ0, the penalty is large.
  • Reduces exposure bias 1
  • Typical use: Variational inference, policy optimization in RL

1.1. Jensen-Shannon Divergence

JSD ( 𝑃 β€– 𝑄 ) = 1 2 ( KL ( 𝑃 β€– 𝑀 ) + KL ( 𝑄 β€– 𝑀 ) ) , 𝑀 = 1 2 ( 𝑃 + 𝑄 )

JSD measures divergence relative to the mixture distribution 𝑀, which makes it:

  • Symmetric: JSD(𝑃‖𝑄)=JSD(𝑄‖𝑃) (unlike KL)
  • Bounded: 0≀JSD(𝑃‖𝑄)≀1 (log 2 when distributions have disjoint support)
  • Nearly a metric: JSD(𝑃‖𝑄) satisfies triangle inequality
  • Balances between mode-covering and mode-seeking behavior of KL variants

1.2. Wasserstein Distance

The distribution of 𝑇(π‘₯) is called the push-forward of 𝑃, denoted by 𝑇#𝑃(𝐴)=𝑃({π‘₯:𝑇(π‘₯)∈𝐴})=𝑃(π‘‡βˆ’1(𝐴))

The Monge version of the optimal transport distance is infπ‘‡βˆ«β€–π‘₯βˆ’π‘‡(π‘₯)‖𝑝𝑑𝑃(π‘₯) where the infimum is over all 𝑇 such that 𝑇#𝑃=𝑄. Intuitively, this measures how far you have to move the mass of 𝑃 to turn it into 𝑄. A minimizer π‘‡βˆ—, if one exists, is called the optimal transport map.

Let Ξ (𝑃,𝑄) denote all joint distributions πœ‹ for (𝑋,π‘Œ) that have marginals 𝑃 and 𝑄. In other words, 𝑇𝑋#πœ‹=𝑃 and π‘‡π‘Œ#πœ‹=𝑄 where 𝑇𝑋(π‘₯,𝑦)=π‘₯ and π‘‡π‘Œ(π‘₯,𝑦)=𝑦. Then the Wasserstein distance is

π‘Š 𝑝 ( 𝑃 , 𝑄 ) = ( inf 𝛾 ∈ Ξ  ( 𝑃 , 𝑄 ) ∫ β€– π‘₯ βˆ’ 𝑦 β€– 𝑝 𝑑 𝛾 ( π‘₯ , 𝑦 ) ) 1 𝑝 = ( inf 𝛾 ∈ Ξ  ( 𝑃 , 𝑄 ) 𝔼 π‘₯ , 𝑦 ∼ 𝛾 [ β€– π‘₯ βˆ’ 𝑦 β€– 𝑝 ] ) 1 𝑝

where 𝑝β‰₯1. When 𝑝=1, this is also called the Earth Mover’s Distance.

It can be shown from Kantorovich Rubinstein Duality that

π‘Š 𝑝 𝑝 ( 𝑃 , 𝑄 ) = βˆ‘ πœ“ , πœ™ ∫ πœ“ ( 𝑦 ) 𝑑 𝑄 ( 𝑦 ) βˆ’ ∫ πœ™ ( π‘₯ ) 𝑑 𝑃 ( π‘₯ )

where πœ“(𝑦)βˆ’πœ™(π‘₯)≀‖π‘₯βˆ’π‘¦β€–π‘. When 𝑝=1, we have

π‘Š 1 ( 𝑃 , 𝑄 ) = sup β€– 𝑇 β€– 𝐿 ≀ 1 𝔼 π‘₯ ∼ 𝑃 [ 𝑇 ( π‘₯ ) ] βˆ’ 𝔼 𝑦 ∼ 𝑄 [ 𝑇 ( 𝑦 ) ]

where ‖𝑇‖𝐿≀1 means |𝑇(π‘₯)βˆ’π‘‡(𝑦)|≀‖π‘₯βˆ’π‘¦β€–.

When to use Wasserstein Distance instead of KL:

  • Non-overlapping distributions: KL divergence becomes infinite (or undefined) when distributions have non-overlapping support, while WD remains finite and meaningful. This is critical in high-dimensional spaces where distributions rarely overlap perfectly.
  • Meaningful gradients: Even when distributions barely overlap, WD provides useful gradients for optimization. This is why Wasserstein GAN (WGAN)) works better than vanilla GAN - it can still learn when the generator distribution is far from the real data distribution.
  • True metric: WD is a proper distance metric (satisfies triangle inequality), making it more suitable for geometric interpretations and certain theoretical analyses.
  • Weak topology: WD convergence is weaker than KL convergence, meaning π‘Š(𝑃𝑛,𝑃)β†’0 implies convergence in distribution, which is often more natural for generative modeling.

1.3. Fisher Divergence

𝐹 ( 𝑃 β€– 𝑄 ) = 1 2 𝔼 π‘₯ ∼ 𝑃 [ β€– βˆ‡ π‘₯ log 𝑃 ( π‘₯ ) βˆ’ βˆ‡ π‘₯ log 𝑄 ( π‘₯ ) β€– 2 2 ]

Unlike KL divergence which compares probability values, Fisher divergence compares the score functions (gradients of log probabilities). This makes it particularly useful when:

  • Dealing with unnormalized distributions (only need score functions, not normalization constants)
  • Training score-based generative models
  • The score function is more well-behaved than the density itself

1.4. Applications

  • Variational Inference: Reverse KL (mode-seeking behavior prevents over-dispersed approximations)
  • GAN: JSD (symmetric, bounded measure between real and generated distributions)
  • WGAN: Wasserstein Distance (stable training with meaningful gradients)
  • VAE: Forward KL (mode-covering ensures all data modes are explained)
  • RL (e.g., PPO, TRPO): Reverse KL (prevents policy from assigning probability to bad actions)
  • Score-based models (diffusion): Fisher Divergence (training without normalized densities)
  1. 1see Scheduled Sampling for Sequence Prediction with Recurrent Neural Networks