Download data/lean/OAI/Combinatorics/PerfectMatching/MatchingCovariance.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/PerfectMatching/MatchingCovariance.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/PerfectMatching/MatchingCovariance.lean
-
curl -L -o MatchingCovariance.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/PerfectMatching/MatchingCovariance.lean
11.7 kB
| import OAI.Combinatorics.PerfectMatching.Continuity | |
| import OAI.Combinatorics.PerfectMatching.Covariance | |
| namespace OAI | |
| /-! | |
| Normalized matching covariance: face rank, exact trace, and second variation. | |
| -/ | |
| noncomputable section | |
| open scoped BigOperators Topology | |
| open Filter | |
| namespace MatchingEntropy | |
| open Matrix | |
| variable {V E : Type*} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] | |
| /-- Normalized matching directions on exactly the positive edge support. -/ | |
| def matchingNormalized (G : LooplessGraph V E) (x : E β β) : | |
| G.Matching β {e // 0 < x e} β β := | |
| normalizedCentered (fun M e => G.indicator M e.val) (fun e => x e.val) | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem matchingNormalized_average (G : LooplessGraph V E) {x y : E β β} | |
| {q : G.Matching β β} (hq : q β G.feasibleLaws y) (e : {e // 0 < x e}) : | |
| (β M, q M*matchingNormalized G x M e)=(y e.val-x e.val)/Real.sqrt (x e.val) := by | |
| simp only [matchingNormalized,normalizedCentered,β mul_div_assoc,mul_sub, | |
| β Finset.sum_div,Finset.sum_sub_distrib,β Finset.sum_mul,hq.1.2,one_mul] | |
| rw [show (β M, q M*G.indicator M e.val)=y e.val from congrFun hq.2 e.val] | |
| omit [Fintype V] [DecidableEq V] in | |
| /-- A feasible two-sided direction has a positive-side law supported on the | |
| entropy optimizer at its midpoint. -/ | |
| theorem midpoint_law_support (G : LooplessGraph V E) {x v : E β β} {a : β} | |
| {p q r : G.Matching β β} (hp : p β G.feasibleLaws x) | |
| (hopt : entropy p=maxMatchingEntropy G x) | |
| (hq : q β G.feasibleLaws (x+a β’ v)) | |
| (hr : r β G.feasibleLaws (x+(-a) β’ v)) : | |
| β M, 0 < q M β 0 < p M := by | |
| let w : G.Matching β β := (1/2:β) β’ q+(1/2:β) β’ r | |
| have hw : w β G.feasibleLaws x := by | |
| refine β¨convex_probabilitySimplex _ hq.1 hr.1 (by norm_num) (by norm_num) (by norm_num),?_β© | |
| change G.meanLinear ((1/2:β) β’ q+(1/2:β) β’ r) = _ | |
| rw [map_add,map_smul,map_smul] | |
| change (1/2:β) β’ G.mean q+(1/2:β) β’ G.mean r = _ | |
| rw [hq.2,hr.2] | |
| ext e | |
| simp only [Pi.add_apply,Pi.smul_apply,smul_eq_mul] | |
| ring | |
| intro M hM | |
| apply matching_optimizer_support G hp hw hopt | |
| change 0 < (1/2:β)*q M+(1/2:β)*r M | |
| have hh := hr.1.1 M | |
| linarith | |
| /-- Every active-face direction belongs to the optimizer's normalized covariance | |
| span. No face support or dimension assertion is being supplied as a hypothesis. -/ | |
| theorem normalized_face_mem (G : LooplessGraph V E) {x : E β β} | |
| (heven : Even (Fintype.card V)) {p : G.Matching β β} | |
| (hp : p β G.feasibleLaws x) (hopt : entropy p=maxMatchingEntropy G x) | |
| {u : {e // 0 < x e} β β} (hu : u β G.faceSpace x) : | |
| (fun e => u e/Real.sqrt (x e.val)) β weightedDirectionSpace p (matchingNormalized G x) := by | |
| have hx : x β G.polytope := (G.mem_polytope_iff x).mpr β¨p,hpβ© | |
| have hev := G.faceSpace_eventually_line (G.polytope_subset_constraintPolytope hx) hu | |
| have hneg : βαΆ t : β in π 0, x+(-t) β’ LooplessGraph.positiveExtension x u β G.constraintPolytope := by | |
| have hc : Tendsto (fun t : β => -t) (π 0) (π 0) := by simpa using continuous_neg.tendsto (0:β) | |
| exact hc.eventually hev | |
| have hh : βαΆ t : β in π[>] 0, | |
| (x+t β’ LooplessGraph.positiveExtension x u β G.constraintPolytope β§ | |
| x+(-t) β’ LooplessGraph.positiveExtension x u β G.constraintPolytope) β§ 0 < t := | |
| ((hev.and hneg).filter_mono nhdsWithin_le_nhds).and eventually_mem_nhdsWithin | |
| obtain β¨a,β¨ha,hnaβ©,ha0β© := hh.exists | |
| rw [β G.polytope_eq_constraints heven] at ha hna | |
| obtain β¨q,hqβ© := (G.mem_polytope_iff _).mp ha | |
| obtain β¨r,hrβ© := (G.mem_polytope_iff _).mp hna | |
| have hsupp := midpoint_law_support G hp hopt hq hr | |
| have hsum : (β M, q M β’ matchingNormalized G x M) β | |
| weightedDirectionSpace p (matchingNormalized G x) := by | |
| apply Submodule.sum_mem | |
| intro M _ | |
| by_cases hM : 0 < p M | |
| Β· exact Submodule.smul_mem _ _ (Submodule.subset_span β¨β¨M,hMβ©,rflβ©) | |
| Β· have hq0 : q M=0 := le_antisymm (le_of_not_gt fun hqM => hM (hsupp M hqM)) (hq.1.1 M) | |
| simp only [hq0,zero_smul] | |
| exact Submodule.zero_mem _ | |
| have hin := Submodule.smul_mem _ aβ»ΒΉ hsum | |
| have he : aβ»ΒΉ β’ (β M, q M β’ matchingNormalized G x M) = | |
| (fun e => u e/Real.sqrt (x e.val)) := by | |
| ext e | |
| simp only [Pi.smul_apply,Finset.sum_apply,smul_eq_mul] | |
| rw [matchingNormalized_average G hq] | |
| simp only [Pi.add_apply,Pi.smul_apply,smul_eq_mul,LooplessGraph.positiveExtension_pos] | |
| field_simp | |
| ring | |
| rwa [he] at hin | |
| def normalizeLinear (x : E β β) : | |
| ({e // 0 < x e} β β) ββ[β] ({e // 0 < x e} β β) where | |
| toFun := fun u e => u e/Real.sqrt (x e.val) | |
| map_add' := by intro u v; ext e; exact add_div _ _ _ | |
| map_smul' := by intro a u; ext e; exact mul_div_assoc _ _ _ | |
| /-- Face codimension gives a lower bound for the rank of the genuine covariance. -/ | |
| theorem matching_covariance_rank (G : LooplessGraph V E) {x : E β β} | |
| (heven : Even (Fintype.card V)) {p : G.Matching β β} | |
| (hp : p β G.feasibleLaws x) (hopt : entropy p=maxMatchingEntropy G x) : | |
| Fintype.card {e // 0 < x e} β€ 2*Fintype.card V+ | |
| (covariance p (matchingNormalized G x)).rank := by | |
| let W := weightedDirectionSpace p (matchingNormalized G x) | |
| let L : G.faceSpace x ββ[β] W := | |
| ((normalizeLinear x).comp (G.faceSpace x).subtype).codRestrict W | |
| (fun u => normalized_face_mem G heven hp hopt u.property) | |
| have hi : Function.Injective L := by | |
| intro u v huv | |
| apply Subtype.ext | |
| funext e | |
| have hh := congrFun (congrArg Subtype.val huv) e | |
| change u.val e/Real.sqrt (x e.val)=v.val e/Real.sqrt (x e.val) at hh | |
| exact (div_left_inj' (ne_of_gt (Real.sqrt_pos.mpr e.property))).mp hh | |
| have hdim := LinearMap.finrank_le_finrank_of_injective hi | |
| have hq := (G.faceSpace x).finrank_quotient_add_finrank | |
| have hc := G.faceCodimension_bound heven ((G.mem_polytope_iff x).mpr β¨p,hpβ©) | |
| rw [covariance_rank hp.1.1] | |
| have hq' : G.faceCodimension x+Module.finrank β (G.faceSpace x)=Fintype.card {e // 0 < x e} := by | |
| simpa only [LooplessGraph.faceCodimension,Module.finrank_pi,Module.finrank_self,Finset.sum_const, | |
| Finset.card_univ,smul_eq_mul,mul_one] using hq | |
| change Module.finrank β (G.faceSpace x) β€ Module.finrank β W at hdim | |
| dsimp only [W] at hdim | |
| omega | |
| omit [DecidableEq E] in | |
| theorem sum_positive_support (x f : E β β) (hf : β e, Β¬ 0 < x e β f e=0) : | |
| (β e, f e) = β e : {e // 0 < x e}, f e.val := by | |
| classical | |
| have hz : (β e : {e // Β¬ 0 < x e}, f e.val)=0 := | |
| Finset.sum_eq_zero fun e _ => hf e.val e.property | |
| have hh := Fintype.sum_subtype_add_sum_subtype (fun e => 0 < x e) f | |
| rw [hz,add_zero] at hh | |
| exact hh.symm | |
| def matchingScoreWeights (x : E β β) (u : {e // 0 < x e} β β) : E β β := | |
| LooplessGraph.positiveExtension x (fun e => u e/Real.sqrt (x e.val)) | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem matchingNormalized_score (G : LooplessGraph V E) (x : E β β) | |
| (u : {e // 0 < x e} β β) (M : G.Matching) : | |
| linearScore G (matchingScoreWeights x u) (β e, matchingScoreWeights x u e*x e) M = | |
| matchingNormalized G x M β¬α΅₯ u := by | |
| classical | |
| unfold linearScore | |
| rw [β Finset.sum_sub_distrib] | |
| rw [sum_positive_support x _ (fun e he => by simp [matchingScoreWeights,LooplessGraph.positiveExtension,he])] | |
| rw [dotProduct] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| simp only [matchingScoreWeights,LooplessGraph.positiveExtension_pos,matchingNormalized,normalizedCentered] | |
| ring | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem matchingNormalized_mulVec (G : LooplessGraph V E) {x : E β β} | |
| {p : G.Matching β β} (hp : p β G.feasibleLaws x) | |
| (u : {e // 0 < x e} β β) (e : {e // 0 < x e}) : | |
| (covariance p (matchingNormalized G x) *α΅₯ u) e = | |
| G.mean (fun M => p M * linearScore G (matchingScoreWeights x u) | |
| (β e, matchingScoreWeights x u e*x e) M) e.val / Real.sqrt (x e.val) := by | |
| let a := linearScore G (matchingScoreWeights x u) (β e, matchingScoreWeights x u e*x e) | |
| have hcenter : β M, p M*a M=0 := by | |
| dsimp only [a] | |
| rw [linearScore_expectation,hp.2,hp.1.2,mul_one,sub_self] | |
| calc | |
| _ = β M, (p M*a M*G.indicator M e.val-x e.val*(p M*a M))/Real.sqrt (x e.val) := by | |
| rw [covariance_mulVec hp.1.1] | |
| apply Finset.sum_congr rfl | |
| intro M _ | |
| rw [β matchingNormalized_score G x u M] | |
| change p M*((G.indicator M e.val-x e.val)/Real.sqrt (x e.val))*a M = _ | |
| ring | |
| _ = _ := by | |
| rw [β Finset.sum_div,Finset.sum_sub_distrib,β Finset.mul_sum,hcenter,mul_zero,sub_zero] | |
| rfl | |
| /-- The normalized covariance has the exact trace s-m. -/ | |
| theorem matching_covariance_trace (G : LooplessGraph V E) {x : E β β} | |
| {p : G.Matching β β} (hp : p β G.feasibleLaws x) {m : β} | |
| (hV : Fintype.card V=2*m) : | |
| (covariance p (matchingNormalized G x)).trace = Fintype.card {e // 0 < x e}-(m:β) := by | |
| have hx : x β G.polytope := (G.mem_polytope_iff x).mpr β¨p,hpβ© | |
| have hsum : (β e : {e // 0 < x e}, x e.val)=(m:β) := by | |
| rw [β G.marginal_sum hV hx] | |
| exact (sum_positive_support x x (fun e he => le_antisymm (le_of_not_gt he) (G.coordinate_mem_Icc hx e).1)).symm | |
| unfold matchingNormalized | |
| rw [normalized_covariance_trace hp.1 _ ?_ _ ?_ (fun e => e.property),hsum] | |
| Β· intro M e | |
| simp only [LooplessGraph.indicator] | |
| split <;> norm_num | |
| Β· intro e | |
| exact congrFun hp.2 e.val | |
| omit [Fintype V] [DecidableEq V] in | |
| /-- Convert the genuine second variation into the covariance spectral inequality. -/ | |
| theorem matching_covariance_second_variation (G : LooplessGraph V E) {x : E β β} | |
| {p : G.Matching β β} (hp : p β G.feasibleLaws x) | |
| (hopt : entropy p=maxMatchingEntropy G x) {m : β} (hm : 0 < m) | |
| (hmax : β y β G.polytope, entropyDefect G m y β€ entropyDefect G m x) | |
| (u : {e // 0 < x e} β β) : | |
| (8*Real.exp (-entropy x/m)-1)* | |
| ((covariance p (matchingNormalized G x) *α΅₯ u) β¬α΅₯ | |
| (covariance p (matchingNormalized G x) *α΅₯ u)) + | |
| u β¬α΅₯ (covariance p (matchingNormalized G x) *α΅₯ u) β€ 0 := by | |
| let w := matchingScoreWeights x u | |
| let c := β e, w e*x e | |
| let a := linearScore G w c | |
| have hcenter : β M, p M*a M=0 := by | |
| dsimp only [a,c] | |
| rw [linearScore_expectation,hp.2,hp.1.2,mul_one,sub_self] | |
| have hh := matching_defect_second_variation G hp hopt hm.ne' hmax w c hcenter | |
| have hnorm : (β e, (G.mean (fun M => p M*a M) e)^2/x e) = | |
| (covariance p (matchingNormalized G x) *α΅₯ u) β¬α΅₯ | |
| (covariance p (matchingNormalized G x) *α΅₯ u) := by | |
| have hx : x β G.polytope := (G.mem_polytope_iff x).mpr β¨p,hpβ© | |
| rw [sum_positive_support x _ (fun e he => by | |
| have hz : x e=0 := le_antisymm (le_of_not_gt he) (G.coordinate_mem_Icc hx e).1 | |
| simp [hz])] | |
| rw [dotProduct] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| rw [matchingNormalized_mulVec G hp,β sq,div_pow,Real.sq_sqrt e.property.le] | |
| have hquad : (β M, p M*(a M)^2) = u β¬α΅₯ (covariance p (matchingNormalized G x) *α΅₯ u) := by | |
| rw [covariance_quadratic hp.1.1] | |
| apply Finset.sum_congr rfl | |
| intro M _ | |
| rw [β matchingNormalized_score G x u M] | |
| change (8*Real.exp (-entropy x/m)-1)*(β e, (G.mean (fun M => p M*a M) e)^2/x e)+ | |
| (8*Real.exp (-entropy x/m)/m)*(entropyLineD x (G.mean (fun M => p M*a M)) 0)^2+ | |
| (β M, p M*(a M)^2) β€ 0 at hh | |
| rw [hnorm,hquad] at hh | |
| have hpterm : 0 β€ (8*Real.exp (-entropy x/m)/m)* | |
| (entropyLineD x (G.mean (fun M => p M*a M)) 0)^2 := by positivity | |
| linarith | |
| end MatchingEntropy | |
| end | |
| end OAI | |