File size: 16,460 Bytes
e5a97c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
import OAI.Combinatorics.MatchingEntropy.FractionalReduction

namespace OAI

noncomputable section

open scoped BigOperators Topology
open Filter

universe uV uE uI uJ uA uB uC uW uF uD uι

namespace MatchingEntropyBounds.Refined

variable {V : Type uV} {E : Type uE} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E]

def underlyingSimple (G : LooplessGraph V E) : SimpleGraph V where
  Adj v w := ∃ e, (G.left e = v ∧ G.right e = w) ∨ (G.left e = w ∧ G.right e = v)
  symm := ⟨by
    rintro v w ⟨e, h | h⟩
    · exact ⟨e, Or.inr h⟩
    · exact ⟨e, Or.inl h⟩⟩
  loopless := ⟨by
    rintro v ⟨e, h | h⟩ <;> exact G.loopless e (h.1.trans h.2.symm)⟩

abbrev Component (G : LooplessGraph V E) := (underlyingSimple G).ConnectedComponent
noncomputable instance componentFintype (G : LooplessGraph V E) : Fintype (Component G) := Fintype.ofFinite _
noncomputable instance componentDecidableEq (G : LooplessGraph V E) : DecidableEq (Component G) := Classical.decEq _

def componentOf (G : LooplessGraph V E) (v : V) : Component G :=
  (underlyingSimple G).connectedComponentMk v

omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in
theorem component_edge_eq (G : LooplessGraph V E) (e : E) :
    componentOf G (G.left e) = componentOf G (G.right e) :=
  SimpleGraph.ConnectedComponent.connectedComponentMk_eq_of_adj ⟨e, Or.inl ⟨rfl,rfl⟩⟩

def componentGraph (G : LooplessGraph V E) (c : Component G) :
    LooplessGraph {v // componentOf G v = c} {e // componentOf G (G.left e) = c} where
  left e := ⟨G.left e.val,e.property⟩
  right e := ⟨G.right e.val,(component_edge_eq G e.val).symm.trans e.property⟩
  loopless e h := G.loopless e.val (congrArg Subtype.val h)

def componentMean (G : LooplessGraph V E) (x : E → ℝ) (c : Component G) :
    {e // componentOf G (G.left e) = c} → ℝ := fun e => x e.val

def componentOrder (G : LooplessGraph V E) (c : Component G) : ℕ :=
  Fintype.card {v // componentOf G v = c} / 2

section ProductLaws
variable {I : Type uI} [Fintype I] [DecidableEq I] {A : I → Type uA}
  [∀ i, Fintype (A i)] [∀ i, DecidableEq (A i)]

def piLaw (q : ∀ i, A i → ℝ) (a : ∀ i, A i) : ℝ := ∏ i, q i (a i)

omit [∀ i, DecidableEq (A i)] in
theorem piLaw_simplex {q : ∀ i, A i → ℝ} (hq : ∀ i, q i ∈ probabilitySimplex (A i)) :
    piLaw q ∈ probabilitySimplex (∀ i, A i) := by
  refine ⟨fun a => Finset.prod_nonneg (fun i _ => (hq i).1 (a i)), ?_⟩
  change (∑ a : ∀ i, A i, ∏ i, q i (a i)) = 1
  rw [← Fintype.prod_sum]
  simp_rw [(hq _).2]
  simp

omit [∀ i, DecidableEq (A i)] in
theorem piLaw_expect {q : ∀ i, A i → ℝ} (hq : ∀ i, q i ∈ probabilitySimplex (A i))
    (k : I) (f : A k → ℝ) :
    (∑ a : ∀ i, A i, piLaw q a * f (a k)) = ∑ b, q k b * f b := by
  let r : ∀ i, A i → ℝ := Function.update q k (fun b => q k b * f b)
  have heq (a : ∀ i, A i) : (∏ i, r i (a i)) = piLaw q a * f (a k) := by
    rw [Fintype.prod_eq_mul_prod_compl k (fun i => r i (a i)),
      piLaw, Fintype.prod_eq_mul_prod_compl k (fun i => q i (a i))]
    have hr : r k (a k) = q k (a k) * f (a k) := by simp [r]
    rw [hr]
    have hprod : (∏ i ∈ ({k}ᶜ : Finset I), r i (a i)) = ∏ i ∈ ({k}ᶜ : Finset I), q i (a i) := by
      apply Finset.prod_congr rfl
      intro i hi
      have hik : i ≠ k := by simpa using hi
      simp [r, hik]
    rw [hprod]
    ring
  rw [← show (∑ a : ∀ i, A i, ∏ i, r i (a i)) = _ from Finset.sum_congr rfl (fun a _ => heq a),
    ← Fintype.prod_sum, Fintype.prod_eq_mul_prod_compl k]
  have hr : (∑ b, r k b) = ∑ b, q k b * f b := by simp [r]
  rw [hr]
  have hprod : (∏ i ∈ ({k}ᶜ : Finset I), ∑ b, r i b) = 1 := by
    apply Finset.prod_eq_one
    intro i hi
    have hik : i ≠ k := by simpa using hi
    simpa [r, hik] using (hq i).2
  rw [hprod, mul_one]

theorem piLaw_marginal {q : ∀ i, A i → ℝ} (hq : ∀ i, q i ∈ probabilitySimplex (A i))
    (k : I) : fiberMass (piLaw q) (fun a => a k) = q k := by
  ext b
  have h := piLaw_expect hq k (fun x => if x=b then 1 else 0)
  simpa [fiberMass, mul_ite] using h

theorem piLaw_crossEntropy (p : (∀ i, A i) → ℝ) (q : ∀ i, A i → ℝ)
    (hsupp : ∀ a, p a ≠ 0 → ∀ i, q i (a i) ≠ 0) :
    -(∑ a, p a * Real.log (piLaw q a)) =
      ∑ i, -(∑ b, fiberMass p (fun a => a i) b * Real.log (q i b)) := by
  have heq (a : ∀ i, A i) : p a * Real.log (piLaw q a) = ∑ i, p a * Real.log (q i (a i)) := by
    by_cases ha : p a = 0
    · simp [ha]
    · rw [piLaw, Real.log_prod (fun i _ => hsupp a ha i), Finset.mul_sum]
  simp_rw [heq]
  rw [Finset.sum_comm, Finset.sum_neg_distrib]
  congr 1
  apply Finset.sum_congr rfl
  intro i _
  exact (fiberMass_expect p (fun a => a i) (fun b => Real.log (q i b))).symm

theorem entropy_piLaw {q : ∀ i, A i → ℝ} (hq : ∀ i, q i ∈ probabilitySimplex (A i)) :
    entropy (piLaw q) = ∑ i, entropy (q i) := by
  rw [entropy_eq, piLaw_crossEntropy]
  · simp_rw [piLaw_marginal hq, ← entropy_eq]
  · intro a ha i
    exact (Finset.prod_ne_zero_iff.mp ha) i (Finset.mem_univ i)

theorem entropy_le_marginal_sum {p : (∀ i, A i) → ℝ}
    (hp : p ∈ probabilitySimplex (∀ i, A i)) :
    entropy p ≤ ∑ i, entropy (fiberMass p (fun a => a i)) := by
  let q : ∀ i, A i → ℝ := fun i => fiberMass p (fun a => a i)
  have hq : ∀ i, q i ∈ probabilitySimplex (A i) := fun i => fiberMass_mem_simplex hp _
  have hs : ∀ a, p a ≠ 0 → ∀ i, q i (a i) ≠ 0 := by
    intro a ha i
    exact ne_of_gt ((lt_of_le_of_ne (hp.1 a) (Ne.symm ha)).trans_le (le_fiberMass_self hp.1 _ a))
  have h := entropy_le_crossEntropy (piLaw_simplex hq) hp (fun a ha => by
    by_contra hpa
    exact (Finset.prod_ne_zero_iff.mpr (fun i _ => hs a hpa i)) ha)
  rw [piLaw_crossEntropy p q hs] at h
  simpa only [q, ← entropy_eq] using h
end ProductLaws

omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in
theorem component_incident_iff (G : LooplessGraph V E) (c : Component G)
    (v : {v // componentOf G v = c}) (e : {e // componentOf G (G.left e) = c}) :
    (componentGraph G c).Incident v e ↔ G.Incident v.val e.val := by
  constructor
  · rintro (h | h)
    · exact Or.inl (congrArg Subtype.val h)
    · exact Or.inr (congrArg Subtype.val h)
  · rintro (h | h)
    · exact Or.inl (Subtype.ext h)
    · exact Or.inr (Subtype.ext h)

omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in
theorem component_eq_of_incident (G : LooplessGraph V E) {v : V} {e : E} (h : G.Incident v e) :
    componentOf G (G.left e) = componentOf G v := by
  rcases h with h | h
  · rw [h]
  · rw [component_edge_eq G e, h]

def componentRestrict (G : LooplessGraph V E) (c : Component G) (M : G.Matching) :
    (componentGraph G c).Matching := by
  classical
  refine ⟨M.val.subtype (fun e => componentOf G (G.left e) = c), ?_⟩
  intro v
  obtain ⟨e,he,hu⟩ := M.property v.val
  have hc : componentOf G (G.left e) = c := (component_eq_of_incident G he.2).trans v.property
  refine ⟨⟨e,hc⟩, ⟨by simpa using he.1,(component_incident_iff G c v _).mpr he.2⟩, ?_⟩
  intro f hf
  exact Subtype.ext (hu f.val ⟨by simpa using hf.1,(component_incident_iff G c v f).mp hf.2⟩)

omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in
@[simp] theorem mem_componentRestrict (G : LooplessGraph V E) (c : Component G) (M : G.Matching)
    (e : {e // componentOf G (G.left e) = c}) :
    e ∈ (componentRestrict G c M).val ↔ e.val ∈ M.val := by
  simp [componentRestrict]

omit [Fintype V] [Fintype E] [DecidableEq V] in
theorem componentRestrict_indicator (G : LooplessGraph V E) (c : Component G) (M : G.Matching)
    (e : {e // componentOf G (G.left e) = c}) :
    (componentGraph G c).indicator (componentRestrict G c M) e = G.indicator M e.val := by
  simp [LooplessGraph.indicator]

def componentGlue (G : LooplessGraph V E) (M : ∀ c : Component G, (componentGraph G c).Matching) :
    G.Matching := by
  classical
  let N := Finset.univ.filter (fun e => (⟨e,rfl⟩ : {f // componentOf G (G.left f) = componentOf G (G.left e)}) ∈ (M (componentOf G (G.left e))).val)
  have hmem (c : Component G) (e : {e // componentOf G (G.left e) = c}) : e.val ∈ N ↔ e ∈ (M c).val := by
    obtain ⟨e,he⟩ := e
    subst c
    simp [N]
  refine ⟨N, ?_⟩
  intro v
  obtain ⟨e,he,hu⟩ := (M (componentOf G v)).property ⟨v,rfl⟩
  refine ⟨e.val,⟨(hmem _ e).mpr he.1,(component_incident_iff G _ _ e).mp he.2⟩,?_⟩
  intro f hf
  have hfc := component_eq_of_incident G hf.2
  exact congrArg Subtype.val (hu ⟨f,hfc⟩ ⟨(hmem _ _).mp hf.1,(component_incident_iff G _ _ _).mpr hf.2⟩)

omit [Fintype V] [DecidableEq V] in
@[simp] theorem mem_componentGlue (G : LooplessGraph V E)
    (M : ∀ c : Component G, (componentGraph G c).Matching) (c : Component G)
    (e : {e // componentOf G (G.left e) = c}) :
    e.val ∈ (componentGlue G M).val ↔ e ∈ (M c).val := by
  obtain ⟨e,he⟩ := e
  subst c
  simp [componentGlue]

def componentMatchingEquiv (G : LooplessGraph V E) :
    G.Matching ≃ (∀ c : Component G, (componentGraph G c).Matching) where
  toFun := fun M c => componentRestrict G c M
  invFun := componentGlue G
  left_inv M := by
    apply Subtype.ext
    ext e
    exact (mem_componentGlue G _ _ ⟨e,rfl⟩).trans (mem_componentRestrict G _ M ⟨e,rfl⟩)
  right_inv M := by
    funext c
    apply Subtype.ext
    ext e
    rw [mem_componentRestrict, mem_componentGlue]

omit [Fintype V] in
omit [DecidableEq V] in
theorem component_mean_marginal (G : LooplessGraph V E) (c : Component G) (p : G.Matching → ℝ) :
    (componentGraph G c).mean (fiberMass p (componentRestrict G c)) = componentMean G (G.mean p) c := by
  ext e
  rw [LooplessGraph.mean, fiberMass_expect]
  simp_rw [componentRestrict_indicator]
  rfl

omit [Fintype V] in
omit [DecidableEq V] in
theorem component_feasible (G : LooplessGraph V E) (c : Component G)
    {x : E → ℝ} {p : G.Matching → ℝ} (hp : p ∈ G.feasibleLaws x) :
    fiberMass p (componentRestrict G c) ∈ (componentGraph G c).feasibleLaws (componentMean G x c) := by
  exact ⟨fiberMass_mem_simplex hp.1 _, by rw [component_mean_marginal, hp.2]⟩

section FiberComposition
variable {A : Type uA} {B : Type uB} {C : Type uC} [Fintype A] [Fintype B] [Fintype C] [DecidableEq B] [DecidableEq C]
omit [Fintype C] in
theorem fiberMass_comp (p : A → ℝ) (f : A → B) (g : B → C) :
    fiberMass (fiberMass p f) g = fiberMass p (g ∘ f) := by
  ext c
  have h := fiberMass_expect p f (fun b => if g b = c then 1 else 0)
  simpa [fiberMass, mul_ite] using h
end FiberComposition

omit [DecidableEq V] in
theorem component_joint_entropy_bound (G : LooplessGraph V E)
    {p : G.Matching → ℝ} (hp : p ∈ probabilitySimplex G.Matching) :
    entropy p ≤ ∑ c : Component G, entropy (fiberMass p (componentRestrict G c)) := by
  have h := entropy_le_marginal_sum (fiberMass_mem_simplex hp (componentMatchingEquiv G))
  rw [entropy_fiberMass_injective _ _ (componentMatchingEquiv G).injective] at h
  simpa only [fiberMass_comp, Function.comp_def, componentMatchingEquiv, Equiv.coe_fn_mk] using h

omit [DecidableEq V] in
theorem component_product_feasible (G : LooplessGraph V E) {x : E → ℝ}
    {q : ∀ c : Component G, (componentGraph G c).Matching → ℝ}
    (hq : ∀ c, q c ∈ (componentGraph G c).feasibleLaws (componentMean G x c)) :
    fiberMass (piLaw q) (componentMatchingEquiv G).symm ∈ G.feasibleLaws x := by
  refine ⟨fiberMass_mem_simplex (piLaw_simplex (fun c => (hq c).1)) _, ?_⟩
  ext e
  let c := componentOf G (G.left e)
  let f : {e // componentOf G (G.left e) = c} := ⟨e,rfl⟩
  rw [LooplessGraph.mean, fiberMass_expect]
  have hi (M : ∀ c : Component G, (componentGraph G c).Matching) :
      G.indicator ((componentMatchingEquiv G).symm M) e = (componentGraph G c).indicator (M c) f := by
    simp only [LooplessGraph.indicator]
    change (if f.val ∈ (componentGlue G M).val then (1:ℝ) else 0) = _
    simp only [mem_componentGlue]
  simp_rw [hi]
  rw [piLaw_expect (fun c => (hq c).1) c (fun M => (componentGraph G c).indicator M f)]
  exact congrFun (hq c).2 f

omit [DecidableEq V] in
theorem component_maxEntropy (G : LooplessGraph V E) {x : E → ℝ} (hx : x ∈ G.polytope) :
    maxMatchingEntropy G x = ∑ c : Component G, maxMatchingEntropy (componentGraph G c) (componentMean G x c) := by
  obtain ⟨p,hp,hopt⟩ := maxMatchingEntropy_attained G hx
  have hc (c : Component G) : componentMean G x c ∈ (componentGraph G c).polytope :=
    ((componentGraph G c).mem_polytope_iff _).mpr ⟨_,component_feasible G c hp⟩
  choose q hq hqo using fun c => maxMatchingEntropy_attained (componentGraph G c) (hc c)
  apply le_antisymm
  · rw [← hopt]
    exact (component_joint_entropy_bound G hp.1).trans (Finset.sum_le_sum (fun c _ =>
      entropy_le_maxMatchingEntropy _ (component_feasible G c hp)))
  · have hh := entropy_le_maxMatchingEntropy G (component_product_feasible G hq)
    rw [entropy_fiberMass_injective _ _ (componentMatchingEquiv G).symm.injective,
      entropy_piLaw (fun c => (hq c).1)] at hh
    simpa only [hqo] using hh

omit [DecidableEq V] [DecidableEq E] in
theorem component_entropy_terms (G : LooplessGraph V E) (x : E → ℝ) :
    entropy x = ∑ c : Component G, entropy (componentMean G x c) ∧
    complementEntropy x = ∑ c : Component G, complementEntropy (componentMean G x c) := by
  constructor
  · exact (Fintype.sum_fiberwise (fun e => componentOf G (G.left e)) (fun e => Real.negMulLog (x e))).symm
  · exact (Fintype.sum_fiberwise (fun e => componentOf G (G.left e)) (fun e => Real.negMulLog (1-x e))).symm

theorem component_additivity (G : LooplessGraph V E) {x : E → ℝ} (hx : x ∈ G.polytope) :
    (∀ c : Component G, 0 < componentOrder G c ∧
      Fintype.card {v // componentOf G v = c} = 2 * componentOrder G c ∧
      componentMean G x c ∈ (componentGraph G c).polytope) ∧
    maxMatchingEntropy G x = ∑ c : Component G, maxMatchingEntropy (componentGraph G c) (componentMean G x c) ∧
    entropy x = ∑ c : Component G, entropy (componentMean G x c) ∧
    complementEntropy x = ∑ c : Component G, complementEntropy (componentMean G x c) := by
  refine ⟨?_,component_maxEntropy G hx,component_entropy_terms G x⟩
  intro c
  obtain ⟨p,hp⟩ := (G.mem_polytope_iff x).mp hx
  have hr := (componentGraph G c).mean_mem_polytope (component_feasible G c hp).1
  rw [(component_feasible G c hp).2] at hr
  have hev := even_of_mem (componentGraph G c) hr
  obtain ⟨v,hv⟩ := c.exists_rep
  have hcpos : 0 < Fintype.card {v // componentOf G v = c} :=
    Fintype.card_pos_iff.mpr ⟨⟨v,hv⟩⟩
  refine ⟨?_,?_,hr⟩ <;> unfold componentOrder <;> obtain ⟨m,hm⟩ := hev <;> omega

theorem fractional_components (G : LooplessGraph V E) {x : E → ℝ} (hx : x ∈ G.polytope) :
    let R := fractionalGraph G x
    let z := fractionalMean x
    (∀ c : Component R, 0 < componentOrder R c ∧
      Fintype.card {v // componentOf R v = c} = 2 * componentOrder R c ∧
      componentMean R z c ∈ (componentGraph R c).polytope) ∧
    maxMatchingEntropy G x = ∑ c : Component R, maxMatchingEntropy (componentGraph R c) (componentMean R z c) ∧
    entropy x - (∑ c : Component R, (2 - 2 / (componentOrder R c : ℝ)) *
      complementEntropy (componentMean R z c)) ≤ maxMatchingEntropy G x ∧
    maxMatchingEntropy G x ≤ entropy x ∧
    (IsEmpty (Component R) → entropy x = 0 ∧ complementEntropy x = 0 ∧ maxMatchingEntropy G x = 0) := by
  dsimp only
  let R := fractionalGraph G x
  let z := fractionalMean x
  have hz := fractionalMean_mem G hx
  have ⟨ho,hH,hF,hB⟩ := component_additivity R hz
  have hHr : maxMatchingEntropy G x = maxMatchingEntropy R z := by
    simpa only [fractionalExtension_mean] using fractional_maxEntropy G hx hz
  have ⟨hFr,hBr⟩ := fractional_entropy_terms G hx
  refine ⟨ho,hHr.trans hH,?_,refined_upper G x hx,?_⟩
  · rw [hHr, hH, ← hFr, hF, ← Finset.sum_sub_distrib]
    exact Finset.sum_le_sum (fun c _ => refined_lower (componentGraph R c) (componentOrder R c)
      (ho c).1 (ho c).2.1 (componentMean R z c) (ho c).2.2)
  · intro hc
    have : IsEmpty (Component R) := hc
    constructor
    · rw [← hFr, hF]
      simp
    constructor
    · rw [← hBr, hB]
      simp
    · rw [hHr, hH]
      simp

end MatchingEntropyBounds.Refined

end

end OAI