File size: 15,547 Bytes
7d9f027 | 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | import Mathlib
import OAI.Probability.SKGap.Localization.IntegrableLinearCombinationSq
import OAI.Probability.SKGap.Localization.ProdEventSectionLaw
namespace OAI
section
open scoped BigOperators
open scoped BigOperators
open scoped BigOperators
open scoped BigOperators
open scoped BigOperators
open scoped BigOperators NNReal
open MeasureTheory ProbabilityTheory
open MeasureTheory ProbabilityTheory Filter
open scoped BigOperators NNReal
open MeasureTheory ProbabilityTheory
open scoped BigOperators NNReal ENNReal
open MeasureTheory ProbabilityTheory Filter
open scoped BigOperators NNReal ENNReal
open MeasureTheory ProbabilityTheory
open scoped BigOperators Matrix Matrix.Norms.Elementwise
open scoped BigOperators
open MeasureTheory ProbabilityTheory
open scoped BigOperators Matrix Matrix.Norms.Elementwise
open scoped BigOperators
open scoped BigOperators NNReal ENNReal
open MeasureTheory Metric Set
open scoped BigOperators NNReal ENNReal
open MeasureTheory ProbabilityTheory Filter Set
open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator
open MeasureTheory ProbabilityTheory Filter Set
open scoped BigOperators Matrix.Norms.L2Operator
open MeasureTheory ProbabilityTheory Filter Set
open scoped BigOperators Matrix Matrix.Norms.Elementwise
open MeasureTheory ProbabilityTheory Filter Set
open MeasureTheory ProbabilityTheory Filter
open scoped BigOperators ENNReal NNReal
open MeasureTheory ProbabilityTheory Filter
open scoped BigOperators NNReal ENNReal Matrix
open MeasureTheory ProbabilityTheory Filter
open scoped BigOperators ENNReal NNReal
open MeasureTheory ProbabilityTheory Filter
open scoped BigOperators NNReal ENNReal
open scoped BigOperators
open MeasureTheory ProbabilityTheory
open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal
open scoped BigOperators
open Filter Topology
open MeasureTheory ProbabilityTheory Filter
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter
open Matrix
open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise
open MeasureTheory ProbabilityTheory Filter
open scoped BigOperators NNReal ENNReal Topology
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter
open scoped BigOperators NNReal ENNReal Topology
open MeasureTheory ProbabilityTheory Filter
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter
open scoped ENNReal Topology
open MeasureTheory ProbabilityTheory Filter
open scoped ENNReal NNReal Topology BigOperators
open MeasureTheory ProbabilityTheory Filter
open scoped ENNReal NNReal Topology BigOperators
open MeasureTheory ProbabilityTheory Filter
open scoped ENNReal NNReal Topology BigOperators
open MeasureTheory ProbabilityTheory Filter
open scoped ENNReal NNReal Topology BigOperators
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise
namespace SKGapCutoff.Regression
local instance {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) :=
inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ))
noncomputable def completedMatrix {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ)
(g : (Fin n × Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ :=
revealedCompletion U Y + residualProjection U*goe g*residualProjection U
lemma completedMatrix_symmetric {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ)
(hY : Uᵀ*Y=Yᵀ*U) (g : (Fin n × Fin n) → ℝ) :
(completedMatrix U Y g)ᵀ=completedMatrix U Y g := by
simp only [completedMatrix,Matrix.transpose_add,Matrix.transpose_mul,
revealedCompletion_symmetric U Y hY,residualProjection_symmetric,goe_symmetric,
Matrix.mul_assoc]
lemma completedMatrix_answer {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ)
(hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) (g : (Fin n × Fin n) → ℝ) :
completedMatrix U Y g*U=Y := by
rw [completedMatrix,Matrix.add_mul,revealedCompletion_answer U Y hU hY,
Matrix.mul_assoc,residualProjection_mul U hU,Matrix.mul_zero,add_zero]
lemma mul_extendFrame {n r : ℕ} (A : Matrix (Fin n) (Fin n) ℝ)
(U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) :
A*extendFrame U q=extendFrame (A*U) (A *ᵥ q) := by
funext i a
obtain rfl | ⟨a,rfl⟩ := Fin.eq_zero_or_eq_succ a
· rfl
· rfl
lemma extendedProjection_mul_old {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ)
(q : Fin n → ℝ) (hU : Uᵀ*U=1) (ho : Uᵀ *ᵥ q=0) :
residualProjection (extendFrame U q)*residualProjection U=
residualProjection (extendFrame U q) := by
have hqU : (queryColumn q)ᵀ*U=0 := by
ext a b
fin_cases a
have hh := congrFun ho b
simpa only [Matrix.mul_apply,Matrix.transpose_apply,queryColumn,Matrix.mulVec,
dotProduct,Matrix.zero_apply,Pi.zero_apply,mul_comm] using hh
have hqP : (queryColumn q)ᵀ*residualProjection U=(queryColumn q)ᵀ := by
rw [residualProjection,Matrix.mul_sub,Matrix.mul_one,
← Matrix.mul_assoc,hqU,Matrix.zero_mul,sub_zero]
rw [extendFrame_projection,queryComplement,Matrix.sub_mul,
residualProjection_idem U hU,Matrix.mul_assoc,hqP]
lemma old_mul_extendedProjection {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ)
(q : Fin n → ℝ) (hU : Uᵀ*U=1) (ho : Uᵀ *ᵥ q=0) :
residualProjection U*residualProjection (extendFrame U q)=
residualProjection (extendFrame U q) := by
have hh := congrArg Matrix.transpose (extendedProjection_mul_old U q hU ho)
simpa only [Matrix.transpose_mul,residualProjection_symmetric] using hh
lemma completedMatrix_new_residual {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ)
(q : Fin n → ℝ) (hU : Uᵀ*U=1) (ho : Uᵀ *ᵥ q=0)
(g : (Fin n × Fin n) → ℝ) :
residualProjection (extendFrame U q)*completedMatrix U Y g*
residualProjection (extendFrame U q)=
residualProjection (extendFrame U q)*goe g*residualProjection (extendFrame U q) := by
let P := residualProjection U
let Q := residualProjection (extendFrame U q)
have hQP : Q*P=Q := extendedProjection_mul_old U q hU ho
have hPQ : P*Q=Q := old_mul_extendedProjection U q hU ho
have hR : Q*revealedCompletion U Y*Q=0 := by
calc
_ = Q*(P*revealedCompletion U Y*P)*Q := by
simp only [← Matrix.mul_assoc,hQP]
rw [Matrix.mul_assoc (Q*revealedCompletion U Y) P Q,hPQ]
_ = 0 := by rw [revealedCompletion_residual U Y hU,Matrix.mul_zero,Matrix.zero_mul]
change Q*(revealedCompletion U Y+P*goe g*P)*Q=Q*goe g*Q
rw [Matrix.mul_add,Matrix.add_mul,hR,zero_add]
simp only [← Matrix.mul_assoc,hQP]
rw [Matrix.mul_assoc (Q*goe g) P Q,hPQ]
theorem completedMatrix_update {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ)
(q : Fin n → ℝ) (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) (ho : Uᵀ *ᵥ q=0)
(g : (Fin n × Fin n) → ℝ) :
completedMatrix U Y g =
revealedCompletion (extendFrame U q) (extendFrame Y (completedMatrix U Y g *ᵥ q))+
residualProjection (extendFrame U q)*goe g*residualProjection (extendFrame U q) := by
have hh := regression_decomposition (completedMatrix U Y g) (extendFrame U q)
(completedMatrix_symmetric U Y hY g)
simpa only [mul_extendFrame,completedMatrix_answer U Y hU hY,
revealedCompletion,completedMatrix_new_residual U Y q hU ho] using hh
lemma completedMatrix_new_compatibility {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ)
(q : Fin n → ℝ) (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) (g : (Fin n × Fin n) → ℝ) :
(extendFrame U q)ᵀ*extendFrame Y (completedMatrix U Y g *ᵥ q)=
(extendFrame Y (completedMatrix U Y g *ᵥ q))ᵀ*extendFrame U q := by
have he : completedMatrix U Y g*extendFrame U q=
extendFrame Y (completedMatrix U Y g *ᵥ q) := by
rw [mul_extendFrame,completedMatrix_answer U Y hU hY g]
rw [← he,Matrix.transpose_mul,completedMatrix_symmetric U Y hY g,Matrix.mul_assoc]
lemma completedMatrix_input_decomposition {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ)
(hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) (v : Fin n → ℝ)
(g : (Fin n × Fin n) → ℝ) :
completedMatrix U Y g *ᵥ v = Y *ᵥ (Uᵀ *ᵥ v)+
completedMatrix U Y g *ᵥ (residualProjection U *ᵥ v) := by
simp only [residualProjection,Matrix.sub_mulVec,Matrix.one_mulVec,
Matrix.mulVec_sub,Matrix.mulVec_mulVec]
rw [← Matrix.mul_assoc,completedMatrix_answer U Y hU hY g]
abel
@[fun_prop] lemma measurable_revealedCompletion {n r : ℕ} :
Measurable (fun z : Matrix (Fin n) (Fin r) ℝ × Matrix (Fin n) (Fin r) ℝ =>
revealedCompletion z.1 z.2) := by
apply Measurable.of_eval
intro i
apply Measurable.of_eval
intro j
simp only [revealedCompletion,Matrix.add_apply,Matrix.sub_apply,
Matrix.mul_apply,Matrix.transpose_apply]
fun_prop
@[fun_prop] lemma measurable_extendFrame {n r : ℕ} :
Measurable (fun z : Matrix (Fin n) (Fin r) ℝ × (Fin n → ℝ) => extendFrame z.1 z.2) := by
apply Measurable.of_eval
intro i
apply Measurable.of_eval
intro a
obtain rfl | ⟨a,rfl⟩ := Fin.eq_zero_or_eq_succ a
· exact (measurable_pi_apply i).comp measurable_snd
· exact (measurable_pi_apply a).comp ((measurable_pi_apply i).comp measurable_fst)
theorem completedMatrix_regeneration {n r : ℕ} (hn : 0 < n) {H : Type*}
[MeasurableSpace H] (ρ : Measure H) [SFinite ρ]
(U Y : H → Matrix (Fin n) (Fin r) ℝ) (q : H → Fin n → ℝ)
(hUm : Measurable U) (hYm : Measurable Y) (hqm : Measurable q)
(hU : ∀ h, (U h)ᵀ*U h=1) (hY : ∀ h, (U h)ᵀ*Y h=(Y h)ᵀ*U h)
(hq : ∀ h, ∑ i, q h i^2=1) (ho : ∀ h, (U h)ᵀ *ᵥ q h=0) :
let p := fun h => U h *ᵥ ((Y h)ᵀ *ᵥ q h)
(ρ.prod (standardArrayLaw (Fin n × Fin n))).map
(fun z => ((z.1,completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1),
completedMatrix (U z.1) (Y z.1) z.2)) =
((answerHistoryLaw ρ (fun h => residualProjection (U h)) q).prod
(standardArrayLaw (Fin n × Fin n))).map
(fun z => ((z.1.1,p z.1.1+z.1.2),
completedMatrix (extendFrame (U z.1.1) (q z.1.1))
(extendFrame (Y z.1.1) (p z.1.1+z.1.2)) z.2)) := by
dsimp only
let P := fun h => residualProjection (U h)
let p := fun h => U h *ᵥ ((Y h)ᵀ *ᵥ q h)
have hU' : Measurable (fun h => fun i j => U h i j) := hUm
have hY' : Measurable (fun h => fun i j => Y h i j) := hYm
have hPm : Measurable P := by
apply Measurable.of_eval
intro i
apply Measurable.of_eval
intro j
simp only [P,residualProjection,Matrix.sub_apply,Matrix.mul_apply,Matrix.transpose_apply]
fun_prop
have hpm : Measurable p := by
apply Measurable.of_eval
intro i
simp only [p,Matrix.mulVec,dotProduct,Matrix.transpose_apply]
fun_prop
have hPq h : P h *ᵥ q h=q h := by
dsimp [P,residualProjection]
rw [Matrix.sub_mulVec,Matrix.one_mulVec,← Matrix.mulVec_mulVec,ho,
Matrix.mulVec_zero,sub_zero]
have hPqc h : P h*queryColumn (q h)=queryColumn (q h) := by
ext i a
fin_cases a
exact congrFun (hPq h) i
have hj := adaptive_query_regeneration hn ρ P q hPm hqm
(fun h => residualProjection_symmetric (U h))
(fun h => residualProjection_idem (U h) (hU h)) hq hPqc
let out : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) →
(H × (Fin n → ℝ)) × Matrix (Fin n) (Fin n) ℝ := fun z =>
((z.1.1,p z.1.1+z.1.2),
revealedCompletion (extendFrame (U z.1.1) (q z.1.1))
(extendFrame (Y z.1.1) (p z.1.1+z.1.2))+Matrix.of (fun i j => z.2 (i,j)))
have hout : Measurable out := by
have ha : Measurable (fun z : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) =>
p z.1.1+z.1.2) := (hpm.comp measurable_fst.fst).add measurable_fst.snd
have hu' : Measurable (fun z : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) =>
extendFrame (U z.1.1) (q z.1.1)) := measurable_extendFrame.comp
((hUm.comp measurable_fst.fst).prodMk (hqm.comp measurable_fst.fst))
have hy' : Measurable (fun z : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) =>
extendFrame (Y z.1.1) (p z.1.1+z.1.2)) := measurable_extendFrame.comp ((hYm.comp measurable_fst.fst).prodMk ha)
have hc := measurable_revealedCompletion.comp (hu'.prodMk hy')
apply (measurable_fst.fst.prodMk ha).prodMk
apply Measurable.of_eval
intro i
apply Measurable.of_eval
intro j
exact (((measurable_pi_apply j).comp (measurable_pi_apply i)).comp hc).add
((measurable_pi_apply (i,j)).comp measurable_snd)
have hmL : Measurable (fun z : H × ((Fin n × Fin n) → ℝ) =>
((z.1, queryAnswer (P z.1) (q z.1) z.2),queryResidual (P z.1) (q z.1) z.2)) :=
(measurable_fst.prodMk (measurable_queryAnswer_comp _ _ _
(hPm.comp measurable_fst) (hqm.comp measurable_fst) measurable_snd)).prodMk
(measurable_queryResidual_comp _ _ _ (hPm.comp measurable_fst)
(hqm.comp measurable_fst) measurable_snd)
have hmR : Measurable (fun z : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) =>
(z.1,queryResidual (P z.1.1) (q z.1.1) z.2)) :=
measurable_fst.prodMk (measurable_queryResidual_comp _ _ _
(hPm.comp measurable_fst.fst) (hqm.comp measurable_fst.fst) measurable_snd)
have he := congrArg (Measure.map out) hj
rw [Measure.map_map hout hmL,Measure.map_map hout hmR] at he
have hof (A : Matrix (Fin n) (Fin n) ℝ) : Matrix.of (fun i j => A i j)=A := rfl
have hpoint (z : H × ((Fin n × Fin n) → ℝ)) : out ((z.1,queryAnswer (P z.1) (q z.1) z.2),
queryResidual (P z.1) (q z.1) z.2) =
((z.1,completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1),
completedMatrix (U z.1) (Y z.1) z.2) := by
have ha := completed_query_answer (U z.1) (Y z.1) (q z.1) z.2 (ho z.1) (hPq z.1)
change completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1=p z.1+queryAnswer (P z.1) (q z.1) z.2 at ha
dsimp only [out]
rw [← ha]
congr 1
simpa only [extendFrame_projection,P,queryResidual,hof] using
(completedMatrix_update (U z.1) (Y z.1) (q z.1) (hU z.1) (hY z.1) (ho z.1) z.2).symm
simp_rw [Function.comp_def,hpoint] at he
simpa only [out,completedMatrix,queryResidual,← extendFrame_projection,P,p,hof] using he
end SKGapCutoff.Regression
open MeasureTheory ProbabilityTheory Filter Matrix
open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise
end
end OAI
|