Download data/lean/OAI/Combinatorics/MatchingEntropy/Components.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 16.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingEntropy/Components.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/MatchingEntropy/Components.lean
-
curl -L -o Components.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/MatchingEntropy/Components.lean
16.5 kB
| 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 | |