File size: 8,900 Bytes
cdec422
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.EntropyMax

namespace OAI

/-! Joint tensor extraction, compatibility and entropy estimates. -/

noncomputable section

open scoped BigOperators Topology
open Filter MatrixMultiplication.Foundation
open MatrixMultiplication.JointEntropyMax

namespace MatrixMultiplication.JointGibbsApproximation

def marginalError {A B : Type*} [Fintype A] [Fintype B]
    (p q : FiniteLaw A) (f : A → B) (v : B → ℝ) : ℝ :=
  ∑ b, |(q.map f).mass b - (p.map f).mass b| * |v b|

theorem marginalError_nonneg {A B : Type*} [Fintype A] [Fintype B]
    (p q : FiniteLaw A) (f : A → B) (v : B → ℝ) :
    0 ≤ marginalError p q f v :=
  Finset.sum_nonneg fun _ _ => mul_nonneg (abs_nonneg _) (abs_nonneg _)

theorem entropy_le_crossEntropy_of_support {A : Type*} [Fintype A]
    (p q : FiniteLaw A) (hsupport : ∀ a, p.mass a = 0 → q.mass a = 0) :
    finiteEntropy q.mass ≤ ∑ a, -q.mass a * Real.log (p.mass a) := by
  have hterm (a : A) :
      entropyTerm (q.mass a) ≤ -q.mass a * Real.log (p.mass a) + p.mass a - q.mass a := by
    by_cases hp : p.mass a = 0
    · simp [hp, hsupport a hp]
    · exact entropyTerm_le_crossEntropyTerm
        (lt_of_le_of_ne (p.nonneg a) (Ne.symm hp)) (q.nonneg a)
  calc
    finiteEntropy q.mass ≤
        ∑ a, (-q.mass a * Real.log (p.mass a) + p.mass a - q.mass a) :=
      Finset.sum_le_sum fun a _ => hterm a
    _ = ∑ a, -q.mass a * Real.log (p.mass a) := by
      rw [Finset.sum_sub_distrib, Finset.sum_add_distrib, p.total, q.total]
      ring

private theorem potential_difference_le {A B : Type*} [Fintype A] [Fintype B]
    (p q : FiniteLaw A) (f : A → B) (v : B → ℝ) :
    (∑ a, p.mass a * v (f a)) - (∑ a, q.mass a * v (f a)) ≤
      marginalError p q f v := by
  rw [sum_mass_mul_coordinate p f v, sum_mass_mul_coordinate q f v,
    ← Finset.sum_sub_distrib]
  apply Finset.sum_le_sum
  intro b _
  calc
    (p.map f).mass b * v b - (q.map f).mass b * v b =
        ((p.map f).mass b - (q.map f).mass b) * v b := by ring
    _ ≤ |((p.map f).mass b - (q.map f).mass b) * v b| := le_abs_self _
    _ = |(q.map f).mass b - (p.map f).mass b| * |v b| := by
      rw [abs_mul, abs_sub_comm]

theorem entropy_le_of_marginal_errors_of_support
    {A X Y Z : Type*} [Fintype A] [Fintype X] [Fintype Y] [Fintype Z]
    (p q : FiniteLaw A) (fX : A → X) (fY : A → Y) (fZ : A → Z)
    (u : X → ℝ) (v : Y → ℝ) (w : Z → ℝ) (c : ℝ)
    (hsupport : ∀ a, p.mass a = 0 → q.mass a = 0)
    (hlog : ∀ a, 0 < p.mass a →
      Real.log (p.mass a) = u (fX a) + v (fY a) + w (fZ a) - c) :
    finiteEntropy q.mass ≤ finiteEntropy p.mass +
      marginalError p q fX u + marginalError p q fY v + marginalError p q fZ w := by
  have hexpand (r : FiniteLaw A) (hr : ∀ a, p.mass a = 0 → r.mass a = 0) :
      (∑ a, r.mass a * Real.log (p.mass a)) =
        (∑ a, r.mass a * u (fX a)) + (∑ a, r.mass a * v (fY a)) +
          (∑ a, r.mass a * w (fZ a)) - c := by
    have hterm (a : A) : r.mass a * Real.log (p.mass a) =
        r.mass a * (u (fX a) + v (fY a) + w (fZ a) - c) := by
      by_cases hp : p.mass a = 0
      · simp [hr a hp]
      · rw [hlog a (lt_of_le_of_ne (p.nonneg a) (Ne.symm hp))]
    simp_rw [hterm, mul_sub, mul_add]
    rw [Finset.sum_sub_distrib, Finset.sum_add_distrib, Finset.sum_add_distrib,
      ← Finset.sum_mul, r.total, one_mul]
  have hcross : (∑ a, -q.mass a * Real.log (p.mass a)) =
      finiteEntropy p.mass +
        ((∑ a, p.mass a * u (fX a)) - (∑ a, q.mass a * u (fX a))) +
        ((∑ a, p.mass a * v (fY a)) - (∑ a, q.mass a * v (fY a))) +
        ((∑ a, p.mass a * w (fZ a)) - (∑ a, q.mass a * w (fZ a))) := by
    have hp : finiteEntropy p.mass = -(∑ a, p.mass a * Real.log (p.mass a)) := by
      simp only [finiteEntropy, entropyTerm, neg_mul, Finset.sum_neg_distrib]
    simp only [neg_mul, Finset.sum_neg_distrib]
    rw [hp, hexpand p (fun _ h => h), hexpand q hsupport]
    ring
  calc
    finiteEntropy q.mass ≤ ∑ a, -q.mass a * Real.log (p.mass a) :=
      entropy_le_crossEntropy_of_support p q hsupport
    _ = _ := hcross
    _ ≤ _ := add_le_add
      (add_le_add (add_le_add_right (potential_difference_le p q fX u) _)
        (potential_difference_le p q fY v)) (potential_difference_le p q fZ w)

theorem entropy_le_of_marginal_errors
    {A X Y Z : Type*} [Fintype A] [Fintype X] [Fintype Y] [Fintype Z]
    (p q : FiniteLaw A) (fX : A → X) (fY : A → Y) (fZ : A → Z)
    (u : X → ℝ) (v : Y → ℝ) (w : Z → ℝ) (c : ℝ)
    (hp : ∀ a, 0 < p.mass a)
    (hlog : ∀ a, Real.log (p.mass a) = u (fX a) + v (fY a) + w (fZ a) - c) :
    finiteEntropy q.mass ≤ finiteEntropy p.mass +
      marginalError p q fX u + marginalError p q fY v + marginalError p q fZ w :=
  entropy_le_of_marginal_errors_of_support p q fX fY fZ u v w c
    (fun a h => ((hp a).ne' h).elim) (fun a _ => hlog a)

theorem tendsto_map_mass {I A B : Type*} [Fintype A] [Fintype B]
    {l : Filter I} {pN : I → FiniteLaw A} {p : FiniteLaw A}
    (h : ∀ a, Tendsto (fun n => (pN n).mass a) l (𝓝 (p.mass a)))
    (f : A → B) (b : B) :
    Tendsto (fun n => ((pN n).map f).mass b) l (𝓝 ((p.map f).mass b)) := by
  classical
  simp_rw [FiniteLaw.map_mass]
  apply tendsto_finsetSum
  intro a _
  by_cases hab : f a = b
  · simpa only [hab, ite_true] using h a
  · simp only [hab, ite_false]
    exact tendsto_const_nhds

theorem tendsto_marginalError {I A B : Type*} [Fintype A] [Fintype B]
    {l : Filter I} {pN : I → FiniteLaw A} {p : FiniteLaw A}
    (h : ∀ a, Tendsto (fun n => (pN n).mass a) l (𝓝 (p.mass a)))
    (f : A → B) (v : B → ℝ) :
    Tendsto (fun n => marginalError p (pN n) f v) l (𝓝 0) := by
  have hterm (b : B) :
      Tendsto (fun n => |((pN n).map f).mass b - (p.map f).mass b| * |v b|)
        l (𝓝 0) := by
    have hconst : Tendsto (fun _ : I => (p.map f).mass b) l
        (𝓝 ((p.map f).mass b)) := tendsto_const_nhds
    simpa only [sub_self, abs_zero, zero_mul] using
      ((tendsto_map_mass h f b).sub hconst).abs.mul_const |v b|
  simpa only [marginalError, Finset.sum_const_zero] using
    tendsto_finsetSum Finset.univ (fun b _ => hterm b)

theorem eventually_entropy_le_of_tendsto_of_support
    {I A X Y Z : Type*} [Fintype A] [Fintype X] [Fintype Y] [Fintype Z]
    {l : Filter I} (p : FiniteLaw A) (pN : I → FiniteLaw A)
    (fX : A → X) (fY : A → Y) (fZ : A → Z)
    (u : X → ℝ) (v : Y → ℝ) (w : Z → ℝ) (c : ℝ)
    (hlog : ∀ a, 0 < p.mass a →
      Real.log (p.mass a) = u (fX a) + v (fY a) + w (fZ a) - c)
    (hN : ∀ a, Tendsto (fun n => (pN n).mass a) l (𝓝 (p.mass a)))
    {η : ℝ} (hη : 0 < η) :
    ∀ᶠ n in l, ∀ q : FiniteLaw A,
      (∀ a, p.mass a = 0 → q.mass a = 0) →
      (q.map fX).mass = ((pN n).map fX).mass →
      (q.map fY).mass = ((pN n).map fY).mass →
      (q.map fZ).mass = ((pN n).map fZ).mass →
      finiteEntropy q.mass ≤ finiteEntropy p.mass + η := by
  have herror : Tendsto (fun n => marginalError p (pN n) fX u +
      marginalError p (pN n) fY v + marginalError p (pN n) fZ w) l (𝓝 0) := by
    simpa only [add_zero] using
      ((tendsto_marginalError hN fX u).add (tendsto_marginalError hN fY v)).add
        (tendsto_marginalError hN fZ w)
  have hsmall := herror.eventually (gt_mem_nhds hη)
  filter_upwards [hsmall] with n hn
  intro q hs hX hY hZ
  have hbound := entropy_le_of_marginal_errors_of_support p q fX fY fZ u v w c hs hlog
  have hx : marginalError p q fX u = marginalError p (pN n) fX u := by
    unfold marginalError
    rw [hX]
  have hy : marginalError p q fY v = marginalError p (pN n) fY v := by
    unfold marginalError
    rw [hY]
  have hz : marginalError p q fZ w = marginalError p (pN n) fZ w := by
    unfold marginalError
    rw [hZ]
  rw [hx, hy, hz] at hbound
  linarith

theorem eventually_entropy_le_of_tendsto
    {I A X Y Z : Type*} [Fintype A] [Fintype X] [Fintype Y] [Fintype Z]
    {l : Filter I} (p : FiniteLaw A) (pN : I → FiniteLaw A)
    (fX : A → X) (fY : A → Y) (fZ : A → Z)
    (u : X → ℝ) (v : Y → ℝ) (w : Z → ℝ) (c : ℝ)
    (hp : ∀ a, 0 < p.mass a)
    (hlog : ∀ a, Real.log (p.mass a) = u (fX a) + v (fY a) + w (fZ a) - c)
    (hN : ∀ a, Tendsto (fun n => (pN n).mass a) l (𝓝 (p.mass a)))
    {η : ℝ} (hη : 0 < η) :
    ∀ᶠ n in l, ∀ q : FiniteLaw A,
      (q.map fX).mass = ((pN n).map fX).mass →
      (q.map fY).mass = ((pN n).map fY).mass →
      (q.map fZ).mass = ((pN n).map fZ).mass →
      finiteEntropy q.mass ≤ finiteEntropy p.mass + η := by
  filter_upwards [eventually_entropy_le_of_tendsto_of_support p pN fX fY fZ u v w c
    (fun a _ => hlog a) hN hη] with n hn
  intro q hX hY hZ
  exact hn q (fun a h => ((hp a).ne' h).elim) hX hY hZ

end MatrixMultiplication.JointGibbsApproximation

end

end OAI