roseking's picture
Add lean source and binary files (part 47)
e5a97c6 verified
Raw History Blame Contribute Delete
7.73 kB
import OAI.Combinatorics.PerfectMatching.Simplex
namespace OAI
/-!
Finite pushforwards and couplings with a prescribed common marginal.
-/
noncomputable section
open scoped BigOperators Topology
open Filter
namespace MatchingEntropy
/-- Finite pushforward weights. -/
def fiberMass {A C : Type*} [Fintype A] [DecidableEq C]
(p : A → ℝ) (f : A → C) (c : C) : ℝ := ∑ a, if f a = c then p a else 0
theorem fiberMass_nonneg {A C : Type*} [Fintype A] [DecidableEq C]
{p : A → ℝ} (hp : ∀ a, 0 ≤ p a) (f : A → C) (c : C) :
0 ≤ fiberMass p f c := by
apply Finset.sum_nonneg
intro a _
split <;> simp_all
theorem le_fiberMass_self {A C : Type*} [Fintype A] [DecidableEq C]
{p : A → ℝ} (hp : ∀ a, 0 ≤ p a) (f : A → C) (a : A) :
p a ≤ fiberMass p f (f a) := by
have h := Finset.single_le_sum (s := Finset.univ) (a := a)
(f := fun b => if f b = f a then p b else 0)
(by intro b _; split <;> simp_all) (Finset.mem_univ a)
simpa only [fiberMass, ite_true] using h
/-- The explicit cut-choice coupling. Only equal choices receive mass. -/
def jointLaw {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
(p : A → ℝ) (q : B → ℝ) (f : A → C) (g : B → C) (z : A × B) : ℝ :=
if f z.1 = g z.2 then p z.1*q z.2 / fiberMass p f (f z.1) else 0
theorem jointLaw_nonneg {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hp : ∀ a, 0 ≤ p a) (hq : ∀ b, 0 ≤ q b)
(f : A → C) (g : B → C) (z : A × B) : 0 ≤ jointLaw p q f g z := by
unfold jointLaw
split
· exact div_nonneg (mul_nonneg (hp _) (hq _)) (fiberMass_nonneg hp f _)
· rfl
theorem jointLaw_first {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hp : ∀ a, 0 ≤ p a)
(f : A → C) (g : B → C) (hcompat : ∀ c, fiberMass p f c = fiberMass q g c)
(a : A) : (∑ b, jointLaw p q f g (a,b)) = p a := by
have heq : ∀ b, jointLaw p q f g (a,b) =
(p a / fiberMass p f (f a)) * (if g b=f a then q b else 0) := by
intro b
by_cases h : f a=g b
· simp only [jointLaw, h, ite_true]
ring
· simp [jointLaw, h, Ne.symm h]
simp_rw [heq]
rw [← Finset.mul_sum]
change p a / fiberMass p f (f a) * fiberMass q g (f a) = p a
rw [← hcompat]
by_cases hz : fiberMass p f (f a) = 0
· have ha : p a = 0 := le_antisymm (by simpa [hz] using le_fiberMass_self hp f a) (hp a)
simp [ha]
· exact div_mul_cancel₀ _ hz
theorem jointLaw_second {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hq : ∀ b, 0 ≤ q b)
(f : A → C) (g : B → C) (hcompat : ∀ c, fiberMass p f c = fiberMass q g c)
(b : B) : (∑ a, jointLaw p q f g (a,b)) = q b := by
have heq : ∀ a, jointLaw p q f g (a,b) =
(q b / fiberMass q g (g b)) * (if f a=g b then p a else 0) := by
intro a
by_cases h : f a=g b
· simp only [jointLaw, h, ite_true, ← hcompat]
ring
· simp [jointLaw, h]
simp_rw [heq]
rw [← Finset.mul_sum]
change q b / fiberMass q g (g b) * fiberMass p f (g b) = q b
rw [hcompat]
by_cases hz : fiberMass q g (g b) = 0
· have hb : q b = 0 := le_antisymm (by simpa [hz] using le_fiberMass_self hq g b) (hq b)
simp [hb]
· exact div_mul_cancel₀ _ hz
theorem jointLaw_mem_simplex {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hp : p ∈ probabilitySimplex A) (hq : q ∈ probabilitySimplex B)
(f : A → C) (g : B → C) (hcompat : ∀ c, fiberMass p f c = fiberMass q g c) :
jointLaw p q f g ∈ probabilitySimplex (A × B) := by
refine ⟨jointLaw_nonneg hp.1 hq.1 f g, ?_⟩
rw [Fintype.sum_prod_type]
simp_rw [jointLaw_first hp.1 f g hcompat]
exact hp.2
theorem sum_subtype_supported {A : Type*} [Fintype A] (P : A → Prop) [DecidablePred P]
(w : A → ℝ) (hsupp : ∀ a, ¬P a → w a = 0) :
(∑ a : {a // P a}, w a.val) = ∑ a, w a := by
have hh : (∑ a : {a // ¬P a}, w a.val) = 0 := by
apply Finset.sum_eq_zero
intro a _
exact hsupp a.val a.property
simpa only [hh, add_zero] using (Fintype.sum_subtype_add_sum_subtype P w)
/-- No mass is lost in retaining only compatible pairs. -/
theorem compatible_jointLaw_mem_simplex {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hp : p ∈ probabilitySimplex A) (hq : q ∈ probabilitySimplex B)
(f : A → C) (g : B → C) (hcompat : ∀ c, fiberMass p f c = fiberMass q g c) :
(fun z : {z : A × B // f z.1=g z.2} => jointLaw p q f g z.val) ∈
probabilitySimplex {z : A × B // f z.1=g z.2} := by
refine ⟨fun z => jointLaw_nonneg hp.1 hq.1 f g z.val, ?_⟩
rw [sum_subtype_supported (fun z : A × B => f z.1=g z.2) (jointLaw p q f g)
(by intro z hz; simp [jointLaw, hz])]
exact (jointLaw_mem_simplex hp hq f g hcompat).2
theorem fiberMass_sum {A C : Type*} [Fintype A] [Fintype C] [DecidableEq C]
(p : A → ℝ) (f : A → C) : ∑ c, fiberMass p f c = ∑ a, p a := by
unfold fiberMass
rw [Finset.sum_comm]
simp
theorem fiberMass_expect {A C : Type*} [Fintype A] [Fintype C] [DecidableEq C]
(p : A → ℝ) (f : A → C) (h : C → ℝ) :
∑ c, fiberMass p f c * h c = ∑ a, p a*h (f a) := by
unfold fiberMass
simp_rw [Finset.sum_mul]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro a _
simp only [ite_mul, zero_mul]
simp
theorem fiberMass_mem_simplex {A C : Type*} [Fintype A] [Fintype C] [DecidableEq C]
{p : A → ℝ} (hp : p ∈ probabilitySimplex A) (f : A → C) :
fiberMass p f ∈ probabilitySimplex C :=
⟨fiberMass_nonneg hp.1 f, (fiberMass_sum p f).trans hp.2⟩
theorem jointLaw_expect_first {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hp : ∀ a, 0 ≤ p a)
(f : A → C) (g : B → C) (hcompat : ∀ c, fiberMass p f c = fiberMass q g c)
(h : A → ℝ) : ∑ z : A × B, jointLaw p q f g z * h z.1 = ∑ a, p a*h a := by
rw [Fintype.sum_prod_type]
simp_rw [← Finset.sum_mul, jointLaw_first hp f g hcompat]
theorem jointLaw_expect_second {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hq : ∀ b, 0 ≤ q b)
(f : A → C) (g : B → C) (hcompat : ∀ c, fiberMass p f c = fiberMass q g c)
(h : B → ℝ) : ∑ z : A × B, jointLaw p q f g z * h z.2 = ∑ b, q b*h b := by
rw [Fintype.sum_prod_type, Finset.sum_comm]
simp_rw [← Finset.sum_mul, jointLaw_second hq f g hcompat]
theorem compatible_jointLaw_expect_first {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hp : ∀ a, 0 ≤ p a)
(f : A → C) (g : B → C) (hcompat : ∀ c, fiberMass p f c = fiberMass q g c)
(h : A → ℝ) :
∑ z : {z : A × B // f z.1=g z.2}, jointLaw p q f g z.val * h z.val.1 = ∑ a, p a*h a := by
rw [sum_subtype_supported (fun z : A × B => f z.1=g z.2)
(fun z => jointLaw p q f g z * h z.1)
(by intro z hz; simp [jointLaw, hz])]
exact jointLaw_expect_first hp f g hcompat h
theorem compatible_jointLaw_expect_second {A B C : Type*} [Fintype A] [Fintype B] [DecidableEq C]
{p : A → ℝ} {q : B → ℝ} (hq : ∀ b, 0 ≤ q b)
(f : A → C) (g : B → C) (hcompat : ∀ c, fiberMass p f c = fiberMass q g c)
(h : B → ℝ) :
∑ z : {z : A × B // f z.1=g z.2}, jointLaw p q f g z.val * h z.val.2 = ∑ b, q b*h b := by
rw [sum_subtype_supported (fun z : A × B => f z.1=g z.2)
(fun z => jointLaw p q f g z * h z.2)
(by intro z hz; simp [jointLaw, hz])]
exact jointLaw_expect_second hq f g hcompat h
end MatchingEntropy
end
end OAI