The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V21. Dynamics, ergodic theory and information theory

Mathlib.InformationTheory.KullbackLeibler.KLFun

26 declarations. Mathlib docs · Source

The real function fun x ↦ x * log x + 1 - x

We define klFun x = x * log x + 1 - x. That function is notable because the Kullback-Leibler divergence is an f-divergence for klFun. That is, the Kullback-Leibler divergence is an integral of klFun composed with a Radon-Nikodym derivative.

For probability measures, any function f that differs from klFun by an affine function of the form x ↦ a * (x - 1) would give the same value for the integral ∫ x, f (μ.rnDeriv ν x).toReal ∂ν. However, klFun is the particular choice among those that satisfies klFun 1 = 0 and deriv klFun 1 = 0, which ensures that desirable properties of the Kullback-Leibler divergence extend to other finite measures: it is nonnegative and zero iff the two measures are equal.

Main definitions

  • klFun: the function fun x : ℝ ↦ x * log x + 1 - x.

This is a continuous nonnegative, strictly convex function on $[0,∞)$, with minimum value 0 at 1.

Main statements

  • integrable_klFun_rnDeriv_iff: For two finite measures μ ≪ ν, the function x ↦ klFun (μ.rnDeriv ν x).toReal is integrable with respect to ν iff the log-likelihood ratio llr μ ν is integrable with respect to μ.
  • integral_klFun_rnDeriv: For two finite measures μ ≪ ν such that llr μ ν is integrable with respect to μ, ∫ x, klFun (μ.rnDeriv ν x).toReal ∂ν = ∫ x, llr μ ν x ∂μ + ν.real univ - μ.real univ.

def InformationTheory.klFun E3 #

ℝ → ℝ

The function x : ℝ ↦ x * log x + 1 - x. The Kullback-Leibler divergence is an f-divergence for this function.

theorem InformationTheory.klFun_apply E0 #

∀ (x : ℝ), InformationTheory.klFun x = x * Real.log x + 1 - x

theorem InformationTheory.klFun_zero E1 #

InformationTheory.klFun 0 = 1

theorem InformationTheory.klFun_one E1 #

InformationTheory.klFun 1 = 0

theorem InformationTheory.strictConvexOn_klFun E1 #

StrictConvexOn ℝ (Set.Ici 0) InformationTheory.klFun

klFun is strictly convex on $[0,∞)$.

theorem InformationTheory.convexOn_klFun E1 #

ConvexOn ℝ (Set.Ici 0) InformationTheory.klFun

klFun is convex on $[0,∞)$.

theorem InformationTheory.convexOn_Ioi_klFun E1 #

ConvexOn ℝ (Set.Ioi 0) InformationTheory.klFun

klFun is convex on $(0,∞)$. This is an often useful consequence of convexOn_klFun, which states convexity on $[0, ∞)$.

theorem InformationTheory.continuous_klFun E1 #

Continuous InformationTheory.klFun

klFun is continuous.

theorem InformationTheory.measurable_klFun E1 #

Measurable InformationTheory.klFun

klFun is measurable.

theorem InformationTheory.stronglyMeasurable_klFun E1 #

MeasureTheory.StronglyMeasurable InformationTheory.klFun

klFun is strongly measurable.

theorem InformationTheory.hasDerivAt_klFun E1 #

∀ {x : ℝ}, x ≠ 0 → HasDerivAt InformationTheory.klFun (Real.log x) x

The derivative of klFun at x ≠ 0 is log x.

theorem InformationTheory.not_differentiableAt_klFun_zero E1 #

¬DifferentiableAt ℝ InformationTheory.klFun 0

theorem InformationTheory.deriv_klFun E0 #

deriv InformationTheory.klFun = Real.log

The derivative of klFun is log x. This also holds at x = 0 although klFun is not differentiable there since the default value of deriv in that case is 0.

theorem InformationTheory.not_differentiableWithinAt_klFun_Ioi_zero E1 #

¬DifferentiableWithinAt ℝ InformationTheory.klFun (Set.Ioi 0) 0

theorem InformationTheory.not_differentiableWithinAt_klFun_Iio_zero E1 #

¬DifferentiableWithinAt ℝ InformationTheory.klFun (Set.Iio 0) 0

theorem InformationTheory.rightDeriv_klFun E0 #

∀ {x : ℝ}, derivWithin InformationTheory.klFun (Set.Ioi x) x = Real.log x

The right derivative of klFun is log x. This also holds at x = 0 although klFun is not differentiable there since the default value of derivWithin in that case is 0.

theorem InformationTheory.leftDeriv_klFun E0 #

∀ {x : ℝ}, derivWithin InformationTheory.klFun (Set.Iio x) x = Real.log x

The left derivative of klFun is log x. This also holds at x = 0 although klFun is not differentiable there since the default value of derivWithin in that case is 0.

theorem InformationTheory.rightDeriv_klFun_one E1 #

derivWithin InformationTheory.klFun (Set.Ioi 1) 1 = 0

theorem InformationTheory.leftDeriv_klFun_one E1 #

derivWithin InformationTheory.klFun (Set.Iio 1) 1 = 0

theorem InformationTheory.tendsto_rightDeriv_klFun_atTop E1 #

Filter.Tendsto (fun x ↦ derivWithin InformationTheory.klFun (Set.Ioi x) x) Filter.atTop Filter.atTop

theorem InformationTheory.isMinOn_klFun E1 #

IsMinOn InformationTheory.klFun (Set.Ici 0) 1

theorem InformationTheory.klFun_nonneg E1 #

∀ {x : ℝ}, 0 ≤ x → 0 ≤ InformationTheory.klFun x

The function klFun is nonnegative on [0,∞).

theorem InformationTheory.klFun_eq_zero_iff E0 #

∀ {x : ℝ}, 0 ≤ x → (InformationTheory.klFun x = 0 ↔ x = 1)

theorem InformationTheory.tendsto_klFun_atTop E1 #

Filter.Tendsto InformationTheory.klFun Filter.atTop Filter.atTop

theorem InformationTheory.integrable_klFun_rnDeriv_iff E3 #

∀ {α : Type u_1} {mα : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} [MeasureTheory.IsFiniteMeasure μ]
  [MeasureTheory.IsFiniteMeasure ν],
  μ.AbsolutelyContinuous ν →
    (MeasureTheory.Integrable (fun x ↦ InformationTheory.klFun (μ.rnDeriv ν x).toReal) ν ↔
      MeasureTheory.Integrable (MeasureTheory.llr μ ν) μ)

For two finite measures μ ≪ ν, the function x ↦ klFun (μ.rnDeriv ν x).toReal is integrable with respect to ν iff llr μ ν is integrable with respect to μ.

theorem InformationTheory.integral_klFun_rnDeriv E3 #

∀ {α : Type u_1} {mα : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} [MeasureTheory.IsFiniteMeasure μ]
  [MeasureTheory.IsFiniteMeasure ν],
  μ.AbsolutelyContinuous ν →
    MeasureTheory.Integrable (MeasureTheory.llr μ ν) μ →
      ∫ (x : α), InformationTheory.klFun (μ.rnDeriv ν x).toReal ∂ν =
        ∫ (x : α), MeasureTheory.llr μ ν x ∂μ + ν.real Set.univ - μ.real Set.univ