cfahlgren1's picture
download
raw
5.15 kB
import Mathlib
namespace OAI
namespace UniqueGames.Foundations.Information
open scoped BigOperators
variable {α : Type*} [Fintype α]
def IsProbability (p : α → ℝ) : Prop :=
(∀ a, 0 ≤ p a) ∧ ∑ a, p a = 1
def SupportedBy (p q : α → ℝ) : Prop := ∀ a, p a ≠ 0 → q a ≠ 0
noncomputable def relativeEntropy (p q : α → ℝ) : ℝ :=
∑ a, p a * Real.log (p a / q a)
noncomputable def totalVariation (p q : α → ℝ) : ℝ :=
(∑ a, |p a - q a|) / 2
noncomputable def posterior (p w : α → ℝ) (z : ℝ) : α → ℝ :=
fun a => p a * w a / z
theorem posterior_isProbability (p w : α → ℝ) (hp : IsProbability p)
(hw : ∀ a, 0 ≤ w a) {z : ℝ} (hz : 0 < z)
(hmass : ∑ a, p a * w a = z) : IsProbability (posterior p w z) := by
constructor
· intro a
exact div_nonneg (mul_nonneg (hp.1 a) (hw a)) hz.le
· simp only [posterior, div_eq_mul_inv, ← Finset.sum_mul, hmass,
mul_inv_cancel₀ hz.ne']
omit [Fintype α] in
theorem posterior_supportedBy (p w : α → ℝ) (z : ℝ) :
SupportedBy (posterior p w z) p := by
intro a ha hp
exact ha (by simp [posterior, hp])
theorem mul_log_div_ge_sub {x y : ℝ} (hx : 0 < x) (hy : 0 < y) :
x - y ≤ x * Real.log (x / y) := by
have h := Real.one_sub_inv_le_log_of_pos (div_pos hx hy)
have hm := mul_le_mul_of_nonneg_left h hx.le
have he : x * (1 - (x / y)⁻¹) = x - y := by
field_simp [hx.ne', hy.ne']
rwa [he] at hm
theorem relativeEntropy_nonneg (p q : α → ℝ) (hp : IsProbability p)
(hq : IsProbability q) (hs : SupportedBy p q) : 0 ≤ relativeEntropy p q := by
have hpoint : ∀ a, p a - q a ≤ p a * Real.log (p a / q a) := by
intro a
by_cases hpa : p a = 0
· simp only [hpa, zero_sub, zero_div, zero_mul]
exact neg_nonpos.mpr (hq.1 a)
· exact mul_log_div_ge_sub (lt_of_le_of_ne (hp.1 a) (Ne.symm hpa))
(lt_of_le_of_ne (hq.1 a) (Ne.symm (hs a hpa)))
have hsum := Finset.sum_le_sum (fun a (_ : a ∈ (Finset.univ : Finset α)) => hpoint a)
simpa [relativeEntropy, Finset.sum_sub_distrib, hp.2, hq.2] using hsum
theorem posterior_relativeEntropy_le (p w : α → ℝ) (hp : IsProbability p)
(hw : ∀ a, 0 ≤ w a) (hw_one : ∀ a, w a ≤ 1) {z : ℝ} (hz : 0 < z)
(hmass : ∑ a, p a * w a = z) :
relativeEntropy (posterior p w z) p ≤ Real.log (1 / z) := by
have hpost := posterior_isProbability p w hp hw hz hmass
have hpoint : ∀ a, posterior p w z a * Real.log (posterior p w z a / p a) ≤
posterior p w z a * Real.log (1 / z) := by
intro a
by_cases hpa : posterior p w z a = 0
· simp [hpa]
have hpne := posterior_supportedBy p w z a hpa
have hppos : 0 < p a := lt_of_le_of_ne (hp.1 a) (Ne.symm hpne)
have hpostpos : 0 < posterior p w z a :=
lt_of_le_of_ne (hpost.1 a) (Ne.symm hpa)
have hr : posterior p w z a / p a = w a / z := by
dsimp [posterior]
field_simp [hpne, hz.ne']
apply mul_le_mul_of_nonneg_left _ (hpost.1 a)
apply Real.log_le_log (div_pos hpostpos hppos)
rw [hr]
exact div_le_div_of_nonneg_right (hw_one a) hz.le
have hsum := Finset.sum_le_sum (fun a (_ : a ∈ (Finset.univ : Finset α)) => hpoint a)
simpa only [relativeEntropy, ← Finset.sum_mul, hpost.2, one_mul] using hsum
theorem totalVariation_nonneg (p q : α → ℝ) : 0 ≤ totalVariation p q := by
exact div_nonneg (Finset.sum_nonneg (fun a _ => abs_nonneg (p a - q a))) (by norm_num)
theorem totalVariation_symm (p q : α → ℝ) : totalVariation p q = totalVariation q p := by
simp only [totalVariation, abs_sub_comm]
theorem totalVariation_le_one (p q : α → ℝ) (hp : IsProbability p)
(hq : IsProbability q) : totalVariation p q ≤ 1 := by
have hpoint : ∀ a, |p a - q a| ≤ p a + q a := by
intro a
rw [abs_le]
constructor <;> linarith [hp.1 a, hq.1 a]
have hsum := Finset.sum_le_sum (fun a (_ : a ∈ (Finset.univ : Finset α)) => hpoint a)
simp only [Finset.sum_add_distrib, hp.2, hq.2] at hsum
dsimp [totalVariation]
linarith
theorem le_binaryLog_of_le_log {r x : ℝ} (hr : 0 ≤ r) (h : r ≤ Real.log x) :
r ≤ Real.log x / Real.log 2 := by
have htwo : 0 < Real.log 2 := Real.log_pos (by norm_num)
have htwo_one : Real.log 2 ≤ 1 := by
have ht := Real.log_le_sub_one_of_pos (show (0 : ℝ) < 2 by norm_num)
norm_num at ht ⊢
exact ht
apply (le_div_iff₀ htwo).2
exact (mul_le_mul_of_nonneg_left htwo_one hr).trans (by simpa using h)
theorem weighted_sum_sq_le (w x : α → ℝ) (hw : IsProbability w) :
(∑ a, w a * x a)^2 ≤ ∑ a, w a * (x a)^2 := by
have hcs := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset α)
(fun a => Real.sqrt (w a)) (fun a => Real.sqrt (w a) * x a)
have hfirst : ∀ a, Real.sqrt (w a) * (Real.sqrt (w a) * x a) = w a * x a := by
intro a
rw [← mul_assoc, Real.mul_self_sqrt (hw.1 a)]
have hsecond : ∀ a, (Real.sqrt (w a) * x a)^2 = w a * (x a)^2 := by
intro a
rw [mul_pow, Real.sq_sqrt (hw.1 a)]
simpa only [hfirst, hsecond, Real.sq_sqrt (hw.1 _), hw.2, one_mul] using hcs
end UniqueGames.Foundations.Information
end OAI

Xet Storage Details

Size:
5.15 kB
·
Xet hash:
5af36e129f84310743e84ac0ce3d256322fd131c865c4f0ea4f3f99e46409513

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.