Download data/lean/OAI/LinearAlgebra/MatrixFields/Construction/JointGibbsApproximation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.93 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Construction/JointGibbsApproximation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixFields/Construction/JointGibbsApproximation.lean
-
curl -L -o JointGibbsApproximation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixFields/Construction/JointGibbsApproximation.lean
8.93 kB
| import Mathlib | |
| import OAI.LinearAlgebra.MatrixFields.Entropy.ZeroLeafRateFormula | |
| namespace OAI | |
| namespace MatrixAllFields | |
| open scoped BigOperators Topology Polynomial | |
| 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 le_rfl (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 MatrixAllFields | |
| end OAI | |