Documentation

FLT_Proofs.PureMath.KLDivergence

KL Divergence and Finite PMFs #

Pure mathematical infrastructure for probability mass functions over finite types, KL divergence, cross-entropy, and expected values. No learning-theory types.

Main definitions #

References #

structure FinitePMF (H : Type u_1) [Fintype H] :
Type u_1

A probability mass function over a finite type. Named FinitePMF to avoid conflict with Mathlib's PMF.

  • prob : H
  • prob_nonneg (h : H) : 0 self.prob h
  • prob_sum_one : h : H, self.prob h = 1
Instances For
    noncomputable def klDivFinitePMF {H : Type u_1} [Fintype H] (Q P : FinitePMF H) :

    KL divergence between two FinitePMFs over a finite type. KL(Q‖P) = ∑_h Q(h) · log(Q(h)/P(h)). Convention: 0 · log(0/p) = 0.

    Equations
    Instances For
      noncomputable def crossEntropyFinitePMF {H : Type u_1} [Fintype H] (Q P : FinitePMF H) :

      Cross-entropy: ∑_h Q(h) · log(1/P(h)). Equals KL(Q‖P) + H(Q) where H(Q) is Shannon entropy.

      Equations
      Instances For
        noncomputable def expectFinitePMF {H : Type u_1} [Fintype H] (Q : FinitePMF H) (f : H) :

        Expected value of a real-valued function under a FinitePMF.

        Equations
        Instances For
          class HasPositivePrior {H : Type u_1} [Fintype H] (P : FinitePMF H) :

          Typeclass asserting that a FinitePMF has strictly positive weights.

          • pos (h : H) : 0 < P.prob h
          Instances