Download data/lean/OAI/Probability/Perceptron/Variational/CoupledDual.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Perceptron/Variational/CoupledDual.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Perceptron/Variational/CoupledDual.lean
-
curl -L -o CoupledDual.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Perceptron/Variational/CoupledDual.lean
7.7 kB
| import Mathlib | |
| import OAI.Probability.Perceptron.Variational.StationaryExistence | |
| namespace OAI | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory Filter Set | |
| open scoped ENNReal NNReal Topology BigOperators | |
| namespace SphericalPerceptronFreeEnergy | |
| lemma Trial.ext_fun {m n : Trial} (h : β t, m t=n t) : m=n := by | |
| cases m | |
| cases n | |
| congr 1 | |
| exact funext h | |
| lemma weightedStepTrial_coupling_fst {I J : Type*} [Fintype I] [Fintype J] | |
| (c : IΓJ β β) (w : I β β) (q : I β Time) | |
| (hc : β a, 0 β€ c a) (hc1 : β a, c a=1) | |
| (hw : β i, 0 β€ w i) (hw1 : β i, w i=1) | |
| (hrow : β i, β j, c (i,j)=w i) : | |
| weightedStepTrial c (fun a => q a.1) hc hc1=weightedStepTrial w q hw hw1 := by | |
| apply Trial.ext_fun | |
| intro t | |
| change (β a : IΓJ, if q a.1 β€ t then c a else 0)=β i, if q i β€ t then w i else 0 | |
| rw [Fintype.sum_prod_type] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| by_cases hi : q i β€ t <;> simp [hi,hrow] | |
| lemma weightedStepTrial_coupling_snd {I J : Type*} [Fintype I] [Fintype J] | |
| (c : IΓJ β β) (v : J β β) (p : J β Time) | |
| (hc : β a, 0 β€ c a) (hc1 : β a, c a=1) | |
| (hv : β i, 0 β€ v i) (hv1 : β i, v i=1) | |
| (hcol : β j, β i, c (i,j)=v j) : | |
| weightedStepTrial c (fun a => p a.2) hc hc1=weightedStepTrial v p hv hv1 := by | |
| apply Trial.ext_fun | |
| intro t | |
| change (β a : IΓJ, if p a.2 β€ t then c a else 0)=β j, if p j β€ t then v j else 0 | |
| rw [Fintype.sum_prod_type,Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro j _ | |
| by_cases hj : p j β€ t <;> simp [hj,hcol] | |
| lemma coupling_sum_fst {I J : Type*} [Fintype I] [Fintype J] | |
| (c : IΓJ β β) (w f : I β β) (hrow : β i, β j, c (i,j)=w i) : | |
| (β a, c a*f a.1)=β i, w i*f i := by | |
| rw [Fintype.sum_prod_type] | |
| simp_rw [β Finset.sum_mul,hrow] | |
| lemma coupling_sum_snd {I J : Type*} [Fintype I] [Fintype J] | |
| (c : IΓJ β β) (v f : J β β) (hcol : β j, β i, c (i,j)=v j) : | |
| (β a, c a*f a.2)=β j, v j*f j := by | |
| rw [Fintype.sum_prod_type,Finset.sum_comm] | |
| simp_rw [β Finset.sum_mul,hcol] | |
| lemma weightedStepTail_coupling_fst {I J : Type*} [Fintype I] [Fintype J] | |
| (c : IΓJ β β) (w q : I β β) (hrow : β i, β j, c (i,j)=w i) : | |
| weightedStepTail c (fun a => q a.1)=weightedStepTail w q := by | |
| funext t | |
| exact coupling_sum_fst c w (fun i => 1-max (q i) t) hrow | |
| lemma weightedStepA_coupling_fst {I J : Type*} [Fintype I] [Fintype J] | |
| (c : IΓJ β β) (w q : I β β) (hrow : β i, β j, c (i,j)=w i) : | |
| weightedStepA c (fun a => q a.1)=weightedStepA w q := by | |
| unfold weightedStepA | |
| rw [weightedStepTail_coupling_fst c w q hrow] | |
| lemma entropy_coupled_stationary_comparison {I J : Type*} [Fintype I] [Fintype J] | |
| (c : IΓJ β β) (w h : I β β) (v g : J β β) (q : I β Time) (p : J β Time) | |
| (hc : β a, 0 β€ c a) (hw : β i, 0 β€ w i) (hw1 : β i, w i=1) | |
| (hv : β j, 0 β€ v j) (hv1 : β j, v j=1) | |
| (hrow : β i, β j, c (i,j)=w i) (hcol : β j, β i, c (i,j)=v j) | |
| (B : β) (hB0 : 0 β€ B) (hB1 : B < 1) | |
| (hq : β i, (q i:β) β€ B) (hp : β j, (p j:β) β€ B) | |
| (hstat : β i, 2*h i=weightedStepA w (fun i => (q i:β)) (q i)) : | |
| (entropy (weightedStepTrial w q hw hw1)).toReal-β i, w i*h i*(q i:β) β€ | |
| (entropy (weightedStepTrial v p hv hv1)).toReal-β j, v j*g j*(p j:β)+ | |
| β a, c a*|h a.1-g a.2| := by | |
| have hc1 : β a, c a=1 := by rw [Fintype.sum_prod_type]; simp_rw [hrow]; exact hw1 | |
| have hs := entropy_weightedStep_support c (fun a => p a.2) (fun a => q a.1) | |
| hc hc1 B hB0 hB1 (fun a => hp a.2) (fun a => hq a.1) | |
| rw [weightedStepTrial_coupling_fst c w q hc hc1 hw hw1 hrow, | |
| weightedStepTrial_coupling_snd c v p hc hc1 hv hv1 hcol, | |
| weightedStepA_coupling_fst c w (fun i => (q i:β)) hrow] at hs | |
| have he : (β a, c a*((p a.2:β)-(q a.1:β))*weightedStepA w (fun i => (q i:β)) (q a.1))/2 = | |
| (β a, c a*h a.1*(p a.2:β))-(β i, w i*h i*(q i:β)) := by | |
| simp only [mul_assoc] | |
| rw [β coupling_sum_fst c w (fun i => h i*(q i:β)) hrow] | |
| simp only [β mul_assoc] | |
| rw [Finset.sum_div,β Finset.sum_sub_distrib] | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| rw [β hstat a.1] | |
| ring | |
| rw [he] at hs | |
| have hb : (β j, v j*g j*(p j:β))-(β a, c a*h a.1*(p a.2:β)) β€ | |
| β a, c a*|h a.1-g a.2| := by | |
| simp only [mul_assoc] | |
| rw [β coupling_sum_snd c v (fun j => g j*(p j:β)) hcol] | |
| simp only [β mul_assoc] | |
| rw [β Finset.sum_sub_distrib] | |
| apply Finset.sum_le_sum | |
| intro a _ | |
| have hβ : (g a.2-h a.1)*(p a.2:β) β€ |h a.1-g a.2| := calc | |
| _ β€ |g a.2-h a.1| *(p a.2:β) := mul_le_mul_of_nonneg_right (le_abs_self _) (p a.2).2.1 | |
| _ β€ |g a.2-h a.1| *1 := mul_le_mul_of_nonneg_left (p a.2).2.2 (abs_nonneg _) | |
| _ = _ := by rw [mul_one,abs_sub_comm] | |
| have H := mul_le_mul_of_nonneg_left hβ (hc a) | |
| nlinarith [H] | |
| linarith | |
| lemma finiteSphericalDual_eq_stationary {k : β} (w h : Fin (k+1) β β) | |
| (q : Fin (k+1) β Time) (hw : β i, 0 β€ w i) (hw1 : β i, w i=1) | |
| (hq : Monotone q) (hq1 : (q (Fin.last k):β) < 1) | |
| (hs : β i, 2*h i=weightedStepA w (fun j => (q j:β)) (q i)) : | |
| sInf (finiteSphericalDualValues w h hw hw1)=finiteSphericalDualObjective w h hw hw1 q := by | |
| apply IsLeast.csInf_eq | |
| refine β¨β¨q,β¨hq,hq1β©,rflβ©,?_β© | |
| rintro a β¨p,β¨hp,hp1β©,rflβ© | |
| exact stationary_finite_entropy_minimizes w h q p hw hw1 hq hp hq1 hp1 hs | |
| theorem finiteSphericalDual_abs_sub_le {k : β} (w h g : Fin (k+1) β β) | |
| (hw : β i, 0 < w i) (hw1 : β i, w i=1) | |
| (hh : Monotone h) (hh0 : 0 β€ h 0) (hg : Monotone g) (hg0 : 0 β€ g 0) : | |
| |sInf (finiteSphericalDualValues w h (fun i => (hw i).le) hw1)- | |
| sInf (finiteSphericalDualValues w g (fun i => (hw i).le) hw1)| β€ | |
| β i, w i*|h i-g i| := by | |
| classical | |
| obtain β¨q,hq,hq1,hsqβ© := exists_finite_stationary_quantile w h hw hw1 hh hh0 | |
| obtain β¨p,hp,hp1,hspβ© := exists_finite_stationary_quantile w g hw hw1 hg hg0 | |
| rw [finiteSphericalDual_eq_stationary w h q (fun i => (hw i).le) hw1 hq hq1 hsq, | |
| finiteSphericalDual_eq_stationary w g p (fun i => (hw i).le) hw1 hp hp1 hsp] | |
| let c : Fin (k+1)ΓFin (k+1) β β := fun a => if a.1=a.2 then w a.1 else 0 | |
| have hc : β a, 0 β€ c a := by intro a; dsimp [c]; split_ifs; exact (hw a.1).le; rfl | |
| have hr : β i, β j, c (i,j)=w i := by intro i; simp [c] | |
| have he : β j, β i, c (i,j)=w j := by intro j; simp [c] | |
| let B := max (q (Fin.last k):β) (p (Fin.last k):β) | |
| have hB0 : 0 β€ B := (q (Fin.last k)).2.1.trans (le_max_left _ _) | |
| have hB1 : B < 1 := max_lt hq1 hp1 | |
| have hQ (i : Fin (k+1)) : (q i:β) β€ B := | |
| (show (q i:β) β€ (q (Fin.last k):β) from hq (Fin.le_last i)).trans (le_max_left _ _) | |
| have hP (i : Fin (k+1)) : (p i:β) β€ B := | |
| (show (p i:β) β€ (p (Fin.last k):β) from hp (Fin.le_last i)).trans (le_max_right _ _) | |
| have H := entropy_coupled_stationary_comparison c w h w g q p hc | |
| (fun i => (hw i).le) hw1 (fun i => (hw i).le) hw1 hr he B hB0 hB1 hQ hP hsq | |
| have H' := entropy_coupled_stationary_comparison c w g w h p q hc | |
| (fun i => (hw i).le) hw1 (fun i => (hw i).le) hw1 hr he B hB0 hB1 hP hQ hsp | |
| have hsum : (β a, c a*|h a.1-g a.2|)=β i, w i*|h i-g i| := by | |
| simp only [Fintype.sum_prod_type,c,ite_mul,zero_mul] | |
| simp | |
| have hsum' : (β a, c a*|g a.1-h a.2|)=β i, w i*|h i-g i| := by | |
| simp only [Fintype.sum_prod_type,c,ite_mul,zero_mul] | |
| simp [abs_sub_comm] | |
| rw [hsum] at H | |
| rw [hsum'] at H' | |
| unfold finiteSphericalDualObjective | |
| exact abs_le.mpr β¨by linarith,by linarithβ© | |
| end SphericalPerceptronFreeEnergy | |
| end | |
| end OAI | |