math / data /lean /OAI /LinearAlgebra /MatrixMultiplication /JointExtraction /PairMixtureControls.lean
Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/PairMixtureControls.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.02 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/PairMixtureControls.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/PairMixtureControls.lean
-
curl -L -o PairMixtureControls.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/PairMixtureControls.lean
5.02 kB
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.CompatibilityControls | |
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.CompatibilityScaling | |
| namespace OAI | |
| /-! Joint tensor extraction, compatibility and entropy estimates. -/ | |
| noncomputable section | |
| namespace MatrixMultiplication.JointPairMixtureControls | |
| open JointCompatibilityControls JointCompatibilityScaling | |
| open scoped BigOperators | |
| attribute [local instance] Classical.propDecidable | |
| variable {C : Type*} [Fintype C] [DecidableEq C] | |
| {Shape A B : C β Type*} | |
| [β c, Fintype (Shape c)] [β c, DecidableEq (Shape c)] | |
| [β c, Fintype (A c)] [β c, DecidableEq (A c)] | |
| [β c, Fintype (B c)] [β c, DecidableEq (B c)] | |
| def pairMixture (base : β c, Shape c β β) | |
| (left : β c, Shape c β A c β β) (right : β c, Shape c β B c β β) | |
| (c : C) (ab : A c Γ B c) : β := | |
| (β u, (base c u : β) * left c u ab.1 * right c u ab.2) / baseSize base c | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (B c)] in | |
| theorem sum_first_fiber (c : C) (q : A c Γ B c β β) (a : A c) : | |
| (β ab : {ab : A c Γ B c // ab.1 = a}, q ab.val) = β b, q (a, b) := by | |
| let e : B c β {ab : A c Γ B c // ab.1 = a} := | |
| { toFun := fun b => β¨(a, b), rflβ© | |
| invFun := fun ab => ab.val.2 | |
| left_inv := fun _ => rfl | |
| right_inv := fun ab => by apply Subtype.ext; exact Prod.ext ab.property.symm rfl } | |
| exact (e.sum_comp (fun ab => q ab.val)).symm | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (A c)] in | |
| theorem sum_second_fiber (c : C) (q : A c Γ B c β β) (b : B c) : | |
| (β ab : {ab : A c Γ B c // ab.2 = b}, q ab.val) = β a, q (a, b) := by | |
| let e : A c β {ab : A c Γ B c // ab.2 = b} := | |
| { toFun := fun a => β¨(a, b), rflβ© | |
| invFun := fun ab => ab.val.1 | |
| left_inv := fun _ => rfl | |
| right_inv := fun ab => by apply Subtype.ext; exact Prod.ext rfl ab.property.symm } | |
| exact (e.sum_comp (fun ab => q ab.val)).symm | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (Shape c)] in | |
| theorem base_eq_zero_of_size_eq_zero (base : β c, Shape c β β) | |
| (c : C) (hz : baseSize base c = 0) (u : Shape c) : base c u = 0 := | |
| Nat.eq_zero_of_le_zero ((Finset.single_le_sum (fun _ _ => Nat.zero_le _) | |
| (Finset.mem_univ u)).trans_eq hz) | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (Shape c)] | |
| [β c, Fintype (A c)] [β c, DecidableEq (A c)] in | |
| theorem totalCenterCount_eq_zero_of_size_eq_zero (base : β c, Shape c β β) | |
| (law : β c, Shape c β A c β β) (c : C) (hz : baseSize base c = 0) (a : A c) : | |
| totalCenterCount base law c a = 0 := by | |
| simp only [totalCenterCount, base_eq_zero_of_size_eq_zero base c hz, | |
| Nat.cast_zero, zero_mul, Finset.sum_const_zero] | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (Shape c)] | |
| [β c, DecidableEq (B c)] in | |
| theorem pairMixture_left_balance (base : β c, Shape c β β) | |
| (left : β c, Shape c β A c β β) (right : β c, Shape c β B c β β) | |
| (hnormalized : β c u, 0 < base c u β β b, right c u b = 1) | |
| (c : C) (a : A c) : | |
| (baseSize base c : β) * | |
| (β ab : {ab : A c Γ B c // ab.1 = a}, pairMixture base left right c ab.val) = | |
| totalCenterCount base left c a := by | |
| rw [sum_first_fiber] | |
| simp only [pairMixture, β Finset.sum_div] | |
| have hnum : (β b : B c, β u : Shape c, | |
| (base c u : β) * left c u a * right c u b) = totalCenterCount base left c a := by | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro u _ | |
| by_cases hu : base c u = 0 | |
| Β· simp [hu] | |
| Β· rw [β Finset.mul_sum, hnormalized c u (Nat.pos_of_ne_zero hu), mul_one] | |
| rw [hnum] | |
| by_cases hz : baseSize base c = 0 | |
| Β· rw [totalCenterCount_eq_zero_of_size_eq_zero base left c hz a] | |
| simp | |
| Β· exact mul_div_cancelβ _ (Nat.cast_ne_zero.mpr hz) | |
| omit [Fintype C] [DecidableEq C] [β c, DecidableEq (Shape c)] | |
| [β c, DecidableEq (A c)] in | |
| theorem pairMixture_right_balance (base : β c, Shape c β β) | |
| (left : β c, Shape c β A c β β) (right : β c, Shape c β B c β β) | |
| (hnormalized : β c u, 0 < base c u β β a, left c u a = 1) | |
| (c : C) (b : B c) : | |
| (baseSize base c : β) * | |
| (β ab : {ab : A c Γ B c // ab.2 = b}, pairMixture base left right c ab.val) = | |
| totalCenterCount base right c b := by | |
| rw [sum_second_fiber] | |
| simp only [pairMixture, β Finset.sum_div] | |
| have hnum : (β a : A c, β u : Shape c, | |
| (base c u : β) * left c u a * right c u b) = totalCenterCount base right c b := by | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro u _ | |
| by_cases hu : base c u = 0 | |
| Β· simp [hu] | |
| Β· rw [β Finset.sum_mul, β Finset.mul_sum, | |
| hnormalized c u (Nat.pos_of_ne_zero hu), mul_one] | |
| rw [hnum] | |
| by_cases hz : baseSize base c = 0 | |
| Β· rw [totalCenterCount_eq_zero_of_size_eq_zero base right c hz b] | |
| simp | |
| Β· exact mul_div_cancelβ _ (Nat.cast_ne_zero.mpr hz) | |
| end MatrixMultiplication.JointPairMixtureControls | |
| end | |
| end OAI | |