File size: 10,785 Bytes
cdec422 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | import Mathlib
import OAI.LinearAlgebra.MatrixFields.Construction.JointCompatibilityIncidence
namespace OAI
namespace MatrixAllFields
open scoped BigOperators Topology Polynomial
section
noncomputable section
open MatrixMultiplication.Foundation
open MatrixMultiplication.JointTypeCounts MatrixMultiplication.JointCompatibilityIncidence
open scoped BigOperators
namespace MatrixMultiplication.JointCompatibilityEntropyBound
attribute [local instance] Classical.propDecidable
section ClassCounts
variable {C : Type*} [Fintype C] [DecidableEq C]
variable (Pos A : C → Type*)
[∀ c, Fintype (Pos c)] [∀ c, DecidableEq (Pos c)]
[∀ c, Fintype (A c)] [∀ c, DecidableEq (A c)]
def classEntropy (counts : ∀ c, A c → ℕ) : ℝ :=
∑ c, (Fintype.card (Pos c) : ℝ) *
finiteEntropy (fun a => (counts c a : ℝ) / Fintype.card (Pos c))
def classTypeError : ℝ :=
∑ c, ((Fintype.card (A c) : ℝ) + 1) *
(1 + Real.log (Fintype.card (Pos c) + 1 : ℕ))
omit [Fintype C] [DecidableEq C] [∀ c, DecidableEq (Pos c)] in
theorem fixedClassWords_size (counts : ∀ c, A c → ℕ)
(w : FixedClassWords Pos A counts) (c : C) :
Fintype.card (Pos c) = ∑ a, counts c a := by
calc
Fintype.card (Pos c) = ∑ a, wordPopulation (w c).val a :=
(wordPopulation_sum (w c).val).symm
_ = ∑ a, counts c a := Finset.sum_congr rfl fun a _ => (w c).property a
theorem abs_log_card_sub_classEntropy_le (counts : ∀ c, A c → ℕ)
(w : FixedClassWords Pos A counts) :
|Real.log (Fintype.card (FixedClassWords Pos A counts) : ℝ) -
classEntropy Pos A counts| ≤ classTypeError Pos A := by
have hsize := fixedClassWords_size Pos A counts w
simpa only [classEntropy, classTypeError, ← hsize] using
abs_log_fixedClassWords_card_sub_entropy_le Pos A counts hsize
theorem fixedClassWords_card_le_exp (counts : ∀ c, A c → ℕ)
(w : FixedClassWords Pos A counts) :
(Fintype.card (FixedClassWords Pos A counts) : ℝ) ≤
Real.exp (classEntropy Pos A counts + classTypeError Pos A) := by
have hpos : 0 < (Fintype.card (FixedClassWords Pos A counts) : ℝ) := by
exact_mod_cast (Fintype.card_pos_iff.mpr ⟨w⟩)
have h := (abs_le.mp (abs_log_card_sub_classEntropy_le Pos A counts w)).2
calc
(Fintype.card (FixedClassWords Pos A counts) : ℝ) =
Real.exp (Real.log (Fintype.card (FixedClassWords Pos A counts) : ℝ)) :=
(Real.exp_log hpos).symm
_ ≤ Real.exp (classEntropy Pos A counts + classTypeError Pos A) :=
Real.exp_le_exp.mpr (by linarith)
theorem exp_le_fixedClassWords_card (counts : ∀ c, A c → ℕ)
(w : FixedClassWords Pos A counts) :
Real.exp (classEntropy Pos A counts - classTypeError Pos A) ≤
(Fintype.card (FixedClassWords Pos A counts) : ℝ) := by
have hpos : 0 < (Fintype.card (FixedClassWords Pos A counts) : ℝ) := by
exact_mod_cast (Fintype.card_pos_iff.mpr ⟨w⟩)
have h := (abs_le.mp (abs_log_card_sub_classEntropy_le Pos A counts w)).1
calc
Real.exp (classEntropy Pos A counts - classTypeError Pos A) ≤
Real.exp (Real.log (Fintype.card (FixedClassWords Pos A counts) : ℝ)) :=
Real.exp_le_exp.mpr (by linarith)
_ = (Fintype.card (FixedClassWords Pos A counts) : ℝ) := Real.exp_log hpos
end ClassCounts
section GroupCounts
def wordTypeError (I A : Type*) [Fintype I] [Fintype A] : ℝ :=
((Fintype.card A : ℝ) + 1) * (1 + Real.log (Fintype.card I + 1 : ℕ)) +
(Fintype.card A : ℝ) * Real.log (Fintype.card I + 1 : ℕ)
theorem wordEntropyBound_eq_exp (I A : Type*) [Fintype I] [Fintype A] (H : ℝ) :
wordEntropyBound I A H =
Real.exp ((Fintype.card I : ℝ) * H + wordTypeError I A) := by
unfold wordEntropyBound wordTypeError
rw [show (Fintype.card I : ℝ) * H +
(((Fintype.card A : ℝ) + 1) * (1 + Real.log (Fintype.card I + 1 : ℕ)) +
(Fintype.card A : ℝ) * Real.log (Fintype.card I + 1 : ℕ)) =
(Fintype.card A : ℝ) * Real.log (Fintype.card I + 1 : ℕ) +
((Fintype.card I : ℝ) * H + ((Fintype.card A : ℝ) + 1) *
(1 + Real.log (Fintype.card I + 1 : ℕ))) by ring]
conv_rhs => rw [Real.exp_add, Real.exp_nat_mul, Real.exp_log (by positivity)]
simp only [Nat.cast_add, Nat.cast_one]
variable {C : Type*} [Fintype C] [DecidableEq C]
variable (Pos Shape A : C → Type*)
[∀ c, Fintype (Pos c)] [∀ c, DecidableEq (Pos c)]
[∀ c, Fintype (Shape c)] [∀ c, DecidableEq (Shape c)]
[∀ c, Fintype (A c)] [∀ c, DecidableEq (A c)]
variable (counts : ∀ c, Shape c → ℕ)
(designated : ∀ c, Shape c → Prop)
(H : (Σ c, Option (Shape c)) → ℝ)
(w : FixedClassWords Pos Shape counts)
def groupedEntropy : ℝ :=
∑ g : Σ c, Option (Shape c),
(Fintype.card (GroupPos (w g.1).val (designated g.1) g.2) : ℝ) * H g
def groupedTypeError : ℝ :=
∑ g : Σ c, Option (Shape c),
wordTypeError (GroupPos (w g.1).val (designated g.1) g.2) (A g.1)
omit [DecidableEq C] [∀ c, DecidableEq (Pos c)] [∀ c, DecidableEq (A c)] in
theorem prod_wordEntropyBound_eq_exp :
(∏ g : Σ c, Option (Shape c), wordEntropyBound
(GroupPos (w g.1).val (designated g.1) g.2) (A g.1) (H g)) =
Real.exp (groupedEntropy Pos Shape counts designated H w +
groupedTypeError Pos Shape A counts designated w) := by
simp only [wordEntropyBound_eq_exp, groupedEntropy, groupedTypeError,
← Real.exp_sum, Finset.sum_add_distrib]
end GroupCounts
section Compatibility
variable {C : Type*} [Fintype C] [DecidableEq C]
variable (Pos Shape Pair Left Right : C → Type*)
[∀ c, Fintype (Pos c)] [∀ c, DecidableEq (Pos c)]
[∀ c, Fintype (Shape c)] [∀ c, DecidableEq (Shape c)]
[∀ c, Fintype (Pair c)] [∀ c, DecidableEq (Pair c)]
[∀ c, Fintype (Left c)] [∀ c, DecidableEq (Left c)]
[∀ c, Fintype (Right c)] [∀ c, DecidableEq (Right c)]
variable (shapeCounts : ∀ c, Shape c → ℕ) (pairCounts : ∀ c, Pair c → ℕ)
(leftPart : ∀ c, Pair c → Left c) (rightPart : ∀ c, Pair c → Right c)
(designatedLeft designatedRight : ∀ c, Shape c → Prop)
(leftLaw : ∀ c, Shape c → Left c → ℝ)
(rightLaw : ∀ c, Shape c → Right c → ℝ) (χ : ℝ)
def compatibilityExponent (HL HR : (Σ c, Option (Shape c)) → ℝ)
(w : FixedClassWords Pos Shape shapeCounts) : ℝ :=
classEntropy Pos Shape shapeCounts - classEntropy Pos Pair pairCounts +
groupedEntropy Pos Shape shapeCounts designatedLeft HL w +
groupedEntropy Pos Shape shapeCounts designatedRight HR w +
classTypeError Pos Shape + classTypeError Pos Pair +
groupedTypeError Pos Shape Left shapeCounts designatedLeft w +
groupedTypeError Pos Shape Right shapeCounts designatedRight w
theorem compatibleCandidateCount_le_exp
(w : FixedClassWords Pos Shape shapeCounts)
(z : FixedClassWords Pos Pair pairCounts)
(hpair : ∀ c, Function.Injective (fun s : Pair c => (leftPart c s, rightPart c s)))
(HL HR : (Σ c, Option (Shape c)) → ℝ)
(controlLeft : SideEntropyControl Pos Shape Pair Left shapeCounts pairCounts
leftPart designatedLeft leftLaw χ HL w)
(controlRight : SideEntropyControl Pos Shape Pair Right shapeCounts pairCounts
rightPart designatedRight rightLaw χ HR w) :
(compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts
leftPart rightPart designatedLeft designatedRight leftLaw rightLaw χ z : ℝ) ≤
Real.exp (compatibilityExponent Pos Shape Pair Left Right shapeCounts pairCounts
designatedLeft designatedRight HL HR w) := by
have h := compatibleCandidateCount_le_of_controls Pos Shape Pair Left Right
shapeCounts pairCounts leftPart rightPart designatedLeft designatedRight
leftLaw rightLaw χ w z hpair HL HR controlLeft controlRight
rw [prod_wordEntropyBound_eq_exp, prod_wordEntropyBound_eq_exp] at h
let E := groupedEntropy Pos Shape shapeCounts designatedLeft HL w +
groupedTypeError Pos Shape Left shapeCounts designatedLeft w +
(groupedEntropy Pos Shape shapeCounts designatedRight HR w +
groupedTypeError Pos Shape Right shapeCounts designatedRight w)
rw [← Real.exp_add] at h
have hnum : (Fintype.card (FixedClassWords Pos Shape shapeCounts) : ℝ) * Real.exp E ≤
Real.exp (classEntropy Pos Shape shapeCounts + classTypeError Pos Shape + E) := by
conv_rhs => rw [Real.exp_add]
exact mul_le_mul_of_nonneg_right
(fixedClassWords_card_le_exp Pos Shape shapeCounts w) (Real.exp_pos E).le
calc
(compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts
leftPart rightPart designatedLeft designatedRight leftLaw rightLaw χ z : ℝ) ≤
(Fintype.card (FixedClassWords Pos Shape shapeCounts) : ℝ) * Real.exp E /
Fintype.card (FixedClassWords Pos Pair pairCounts) := h
_ ≤ Real.exp (classEntropy Pos Shape shapeCounts + classTypeError Pos Shape + E) /
Real.exp (classEntropy Pos Pair pairCounts - classTypeError Pos Pair) :=
div_le_div₀ (Real.exp_pos _).le hnum (Real.exp_pos _)
(exp_le_fixedClassWords_card Pos Pair pairCounts z)
_ = Real.exp (compatibilityExponent Pos Shape Pair Left Right shapeCounts pairCounts
designatedLeft designatedRight HL HR w) := by
rw [← Real.exp_sub]
congr 1
dsimp [E, compatibilityExponent]
ring
theorem log_compatibleCandidateCount_le
(w : FixedClassWords Pos Shape shapeCounts)
(z : FixedClassWords Pos Pair pairCounts)
(hpair : ∀ c, Function.Injective (fun s : Pair c => (leftPart c s, rightPart c s)))
(HL HR : (Σ c, Option (Shape c)) → ℝ)
(controlLeft : SideEntropyControl Pos Shape Pair Left shapeCounts pairCounts
leftPart designatedLeft leftLaw χ HL w)
(controlRight : SideEntropyControl Pos Shape Pair Right shapeCounts pairCounts
rightPart designatedRight rightLaw χ HR w)
(hpos : 0 < compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts
leftPart rightPart designatedLeft designatedRight leftLaw rightLaw χ z) :
Real.log (compatibleCandidateCount Pos Shape Pair Left Right shapeCounts pairCounts
leftPart rightPart designatedLeft designatedRight leftLaw rightLaw χ z : ℝ) ≤
compatibilityExponent Pos Shape Pair Left Right shapeCounts pairCounts
designatedLeft designatedRight HL HR w := by
have h := Real.log_le_log (Nat.cast_pos.mpr hpos)
(compatibleCandidateCount_le_exp Pos Shape Pair Left Right shapeCounts pairCounts
leftPart rightPart designatedLeft designatedRight leftLaw rightLaw χ
w z hpair HL HR controlLeft controlRight)
simpa only [Real.log_exp] using h
end Compatibility
end MatrixMultiplication.JointCompatibilityEntropyBound
end
end
end MatrixAllFields
end OAI
|