File size: 13,054 Bytes
4a56cd6 | 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 322 323 324 325 326 327 328 329 330 | import Mathlib
import OAI.Computability.MinUncut.Estimates.F2
import OAI.Computability.MinUncut.Analysis.Gradient
namespace OAI
noncomputable section
open scoped BigOperators
open MeasureTheory ProbabilityTheory Filter
open scoped Topology NNReal
open scoped BigOperators
open MeasureTheory ProbabilityTheory Polynomial Filter
open scoped BigOperators Topology
namespace MinUncut.GaussianHermite
variable {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ]
lemma noise_derivative (Ο s : β) (hs : s β 0) {Q : (ΞΉ β β) β β}
(hQ : Measurable Q) (hb : β x, |Q x| β€ 1) (x : ΞΉ β β) (i : ΞΉ) :
HasDerivAt (fun t => noise Ο s Q (Function.update x i t)) (gradient Ο s Q i x) (x i) := by
have hd := GaussianSmoothing.product_convolution_derivative hQ hb hs (Ο β’ x) i
have hm : HasDerivAt (fun t : β => Ο*t) Ο (x i) := by
simpa only [mul_one, id_eq] using (hasDerivAt_id (x i)).const_mul Ο
have hc := hd.comp (x i) hm
convert! hc using 1
Β· funext t
unfold noise
congr 1
funext g
congr 2
ext j
by_cases hj : j = i
Β· subst j; simp; rfl
Β· simp [Function.update_of_ne hj]
Β· dsimp [gradient, score]
ring
def convolution (Ο : β) (Q : (ΞΉ β β) β β) (x : ΞΉ β β) : β :=
β« g, Q (x + Ο β’ g) βΞ³pi ΞΉ
def convolutionGradient (Ο : β) (Q : (ΞΉ β β) β β) (i : ΞΉ) (x : ΞΉ β β) : β :=
Οβ»ΒΉ * β« g, g i * Q (x + Ο β’ g) βΞ³pi ΞΉ
lemma convolution_derivative {Ο : β} (hΟ : Ο β 0) {Q : (ΞΉ β β) β β}
(hQ : Measurable Q) (hb : β x, |Q x| β€ 1) (x : ΞΉ β β) (i : ΞΉ) :
HasDerivAt (fun t => convolution Ο Q (Function.update x i t))
(convolutionGradient Ο Q i x) (x i) :=
GaussianSmoothing.product_convolution_derivative hQ hb hΟ x i
omit [DecidableEq ΞΉ] in
lemma convolution_as_noise {Ο Ο : β} (hΟ : Ο β 0) (Q : (ΞΉ β β) β β) :
convolution Ο Q = noise Ο (Ο*Ο) (fun v => Q (Οβ»ΒΉ β’ v)) := by
funext x
unfold convolution noise
congr 1
funext g
congr 1
ext i
dsimp
field_simp
omit [DecidableEq ΞΉ] in
lemma convolutionGradient_as_noise {Ο Ο : β} (hΟ : Ο β 0) (hΟ : Ο β 0)
(Q : (ΞΉ β β) β β) (i : ΞΉ) :
convolutionGradient Ο Q i = gradient Ο (Ο*Ο) (fun v => Q (Οβ»ΒΉ β’ v)) i := by
funext x
unfold convolutionGradient gradient score
have hc : Ο/(Ο*Ο) = Οβ»ΒΉ := by field_simp
rw [hc]
congr 1
apply integral_congr_ae
filter_upwards [] with g
congr 2
ext j
dsimp
field_simp
lemma convolution_poincare {Ο Ο : β} (hΟ : Ο β 0) (hΟ : Ο β 0)
(h : Ο^2+(Ο*Ο)^2=1) {Q : (ΞΉ β β) β β} (hQ : Measurable Q)
(hb : β x, |Q x| β€ 1) (hmean : (β« x, convolution Ο Q x βΞ³pi ΞΉ) = 0) :
(β« x, (convolution Ο Q x)^2 βΞ³pi ΞΉ) β€
β i, β« x, (convolutionGradient Ο Q i x)^2 βΞ³pi ΞΉ := by
simp_rw [convolution_as_noise hΟ, convolutionGradient_as_noise hΟ hΟ] at *
exact poincare Ο (Ο*Ο) h (mul_ne_zero hΟ hΟ) (hQ.comp (by fun_prop))
(fun x => hb _) hmean
lemma convolution_gradient_tail {Ο Ο Ξ΅ : β} (hΟ : Ο β 0) (hΟ : Ο β 0)
(h : Ο^2+(Ο*Ο)^2=1) (hΞ΅ : 0 β€ Ξ΅) (d : β)
(hd : β k : β, d+2 β€ k β (k:β)*Ο^(2*k) β€ Ξ΅)
{Q : (ΞΉ β β) β β} (hQ : Measurable Q) (hb : β x, |Q x| β€ 1) :
(β i, β« x, (convolutionGradient Ο Q i x -
project d (convolutionGradient Ο Q i) x)^2 βΞ³pi ΞΉ) β€ Ξ΅ := by
simp_rw [convolutionGradient_as_noise hΟ hΟ]
exact gradient_tail_le Ο (Ο*Ο) h (mul_ne_zero hΟ hΟ) (hQ.comp (by fun_prop))
(fun x => hb _) d hΞ΅ hd
end MinUncut.GaussianHermite
namespace MinUncut.RowNoise
open BinaryFourier
local instance convolutionDualFintype {U : Type*} [AddCommGroup U] [Module Fβ U] [Fintype U] :
Fintype (Module.Dual Fβ U) := BinaryFourier.dualFintype
variable {R W : Type*} [Fintype R] [DecidableEq R] [Fintype W] [DecidableEq W]
[AddCommGroup W] [Module Fβ W]
lemma expect_prod {A : R β Type*} [β r, Fintype (A r)] (f : β r, A r β β) :
(πΌ x : β r, A r, β r, f r (x r)) = β r, πΌ a, f r a := by
simp only [Fintype.expect_eq_sum_div_card, Fintype.card_pi]
rw [β Fintype.prod_sum, Nat.cast_prod, Finset.prod_div_distrib]
def rowDensity (a : β) (b c : W) : β :=
(1-a)*(if c=b then (Fintype.card W : β) else 0) + a
omit [Module Fβ W] in
lemma rowDensity_mean (a : β) (b : W) : (πΌ c, rowDensity a b c) = 1 := by
rw [Fintype.expect_eq_sum_div_card]
simp only [rowDensity, Finset.sum_add_distrib, β Finset.mul_sum,
Finset.sum_ite_eq', Finset.mem_univ, ite_true, Finset.sum_const,
Finset.card_univ, nsmul_eq_mul]
have hn : (Fintype.card W : β) β 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero
field_simp
ring
omit [AddCommGroup W] [Module Fβ W] in
lemma rowDensity_symmetric (a : β) (b c : W) : rowDensity a b c = rowDensity a c b := by
simp [rowDensity, eq_comm]
omit [Module Fβ W] in
lemma rowDensity_nonneg {a : β} (ha : 0 β€ a) (ha1 : a β€ 1) (b c : W) :
0 β€ rowDensity a b c := by
unfold rowDensity
split_ifs <;> positivity
def density (a : β) (B C : R β W) : β := β r, rowDensity a (B r) (C r)
omit [Module Fβ W] in
lemma density_mean (a : β) (B : R β W) : (πΌ C, density a B C) = 1 := by
simp only [density, expect_prod, rowDensity_mean, Finset.prod_const_one]
omit [DecidableEq R] [AddCommGroup W] [Module Fβ W] in
lemma density_symmetric (a : β) (B C : R β W) : density a B C = density a C B := by
simp only [density, rowDensity_symmetric a]
omit [DecidableEq R] [Module Fβ W] in
lemma density_nonneg {a : β} (ha : 0 β€ a) (ha1 : a β€ 1) (B C : R β W) :
0 β€ density a B C := Finset.prod_nonneg (fun _ _ => rowDensity_nonneg ha ha1 _ _)
def frequency (Ξ± : Module.Dual Fβ (R β W)) (r : R) : Module.Dual Fβ W :=
Ξ±.comp (LinearMap.single Fβ (fun _ : R => W) r)
omit [Fintype W] [DecidableEq W] in
lemma dual_apply (Ξ± : Module.Dual Fβ (R β W)) (B : R β W) :
Ξ± B = β r, frequency Ξ± r (B r) := by
change Ξ± B = β r, Ξ± (Pi.single r (B r))
rw [β map_sum]
congr 1
ext r
simp
lemma sign_sum {S : Type*} (s : Finset S) (f : S β Fβ) :
sign (β i β s, f i) = β i β s, sign (f i) := by
classical
induction s using Finset.induction_on with
| empty => simp
| insert i s hi ih => simp [hi, sign_add, ih]
omit [Fintype W] [DecidableEq W] in
lemma character_product (Ξ± : Module.Dual Fβ (R β W)) (B : R β W) :
character Ξ± B = β r, character (frequency Ξ± r) (B r) := by
simp only [character, dual_apply, sign_sum]
def mask (Ξ± : Module.Dual Fβ (R β W)) : Finset R :=
Finset.univ.filter (fun r => frequency Ξ± r β 0)
def degree (Ξ± : Module.Dual Fβ (R β W)) : β := (mask Ξ±).card
lemma row_character_eigen (a : β) (b : W) (Ξ± : Module.Dual Fβ W) :
(πΌ c, rowDensity a b c * character Ξ± c) =
(if Ξ±=0 then 1 else 1-a)*character Ξ± b := by
unfold rowDensity
simp only [add_mul, Finset.expect_add_distrib, mul_assoc, β Finset.mul_expect]
have hh : (πΌ c, (if c=b then (Fintype.card W : β) else 0) * character Ξ± c) =
character Ξ± b := by
rw [Fintype.expect_eq_sum_div_card]
simp only [ite_mul, zero_mul, Finset.sum_ite_eq', Finset.mem_univ, ite_true]
exact mul_div_cancel_leftβ _ (Nat.cast_ne_zero.mpr Fintype.card_ne_zero)
rw [hh, character_mean]
split_ifs with hΞ±
Β· subst Ξ±; simp
Β· ring
def noise (a : β) (f : (R β W) β β) (B : R β W) : β :=
πΌ C, density a B C * f C
lemma noise_character (a : β) (Ξ± : Module.Dual Fβ (R β W)) (B : R β W) :
noise a (character Ξ±) B = (1-a)^degree Ξ±*character Ξ± B := by
simp only [noise, density, character_product]
simp_rw [β Finset.prod_mul_distrib]
rw [expect_prod (fun r c => rowDensity a (B r) c * character (frequency Ξ± r) c)]
simp only [row_character_eigen, Finset.prod_mul_distrib]
congr 1
simp only [Finset.prod_ite, Finset.prod_const_one, one_mul, Finset.prod_const]
rfl
lemma noise_expansion (a : β) (f : (R β W) β β) (B : R β W) :
noise a f B = β Ξ±, coefficient f Ξ± * (1-a)^degree Ξ± * character Ξ± B := by
unfold noise
simp_rw [β inversion f, Finset.mul_sum, Finset.expect_sum_comm]
apply Finset.sum_congr rfl
intro Ξ± _
have he : (πΌ C, density a B C * (coefficient f Ξ± * character Ξ± C)) =
coefficient f Ξ± * noise a (character Ξ±) B := by
unfold noise
rw [Finset.mul_expect]
apply Finset.expect_congr rfl
intro C _
ring
rw [he, noise_character]
ring
lemma correlation (a : β) (f : (R β W) β β) :
(πΌ B, f B * noise a f B) = β Ξ±, (1-a)^degree Ξ±*(coefficient f Ξ±)^2 := by
simp_rw [noise_expansion, Finset.mul_sum, Finset.expect_sum_comm]
apply Finset.sum_congr rfl
intro Ξ± _
calc
_ = ((1-a)^degree Ξ±*coefficient f Ξ±) * (πΌ B, f B * character Ξ± B) := by
rw [Finset.mul_expect]
apply Finset.expect_congr rfl
intro B _
ring
_ = _ := by rw [β coefficient]; ring
omit [Module Fβ W] in
lemma stationary (a : β) (f : (R β W) β β) : (πΌ B, noise a f B) = πΌ B, f B := by
unfold noise
rw [Finset.expect_comm]
apply Finset.expect_congr rfl
intro C _
simp_rw [density_symmetric a _ C, β Finset.expect_mul, density_mean, one_mul]
lemma dirichlet (a : β) (f : (R β W) β β) :
(πΌ B, πΌ C, density a B C * (f B - f C)^2) =
2 * β Ξ±, (1-(1-a)^degree Ξ±)*(coefficient f Ξ±)^2 := by
have he (B C : R β W) : density a B C*(f B-f C)^2 =
(f B)^2*density a B C + density a B C*(f C)^2 - 2*f B*(density a B C*f C) := by ring
simp_rw [he, Finset.expect_sub_distrib, Finset.expect_add_distrib,
β Finset.mul_expect, density_mean, mul_one]
have ht : (πΌ B, 2*f B*(πΌ C, density a B C*f C)) =
2*(πΌ B, f B*noise a f B) := by
simp only [noise, Finset.mul_expect, mul_assoc]
rw [ht]
change (πΌ B, f B^2)+(πΌ B, noise a (fun C => (f C)^2) B) -
2*(πΌ B, f B*noise a f B) = _
rw [stationary, correlation, β parseval]
simp_rw [sub_mul, one_mul, Finset.sum_sub_distrib]
ring
def project (D : β) (f : (R β W) β β) (B : R β W) : β :=
β Ξ± β Finset.univ.filter (fun Ξ± => degree Ξ± β€ D), coefficient f Ξ± * character Ξ± B
omit [DecidableEq W] in
lemma coefficient_project (D : β) (f : (R β W) β β) (Ξ² : Module.Dual Fβ (R β W)) :
coefficient (project D f) Ξ² = if degree Ξ² β€ D then coefficient f Ξ² else 0 := by
unfold coefficient project
simp_rw [Finset.sum_mul, Finset.expect_sum_comm, mul_assoc, β Finset.mul_expect,
character_orthogonality]
simp [Finset.mem_filter, coefficient]
omit [DecidableEq W] in
lemma coefficient_residual (D : β) (f : (R β W) β β) (Ξ² : Module.Dual Fβ (R β W)) :
coefficient (fun B => f B-project D f B) Ξ² =
if degree Ξ² β€ D then 0 else coefficient f Ξ² := by
have he : coefficient (fun B => f B-project D f B) Ξ² =
coefficient f Ξ² - coefficient (project D f) Ξ² := by
simp only [coefficient, sub_mul, Finset.expect_sub_distrib]
rw [he, coefficient_project]
split_ifs <;> ring
omit [DecidableEq W] in
lemma residual_energy (D : β) (f : (R β W) β β) :
(πΌ B, (f B-project D f B)^2) =
β Ξ±, if D < degree Ξ± then (coefficient f Ξ±)^2 else 0 := by
rw [β parseval]
apply Finset.sum_congr rfl
intro Ξ± _
rw [coefficient_residual]
split_ifs <;> simp_all
omega
lemma geometric_bernoulli {a : β} (_ha : 0 β€ a) (ha1 : a β€ 1) (k : β) :
(1-a)^k*(1+(k:β)*a) β€ 1 := by
induction k with
| zero => simp
| succ k ih =>
have hp : 0 β€ (1-a)^k := pow_nonneg (by linarith) _
have hh : (1-a)*(1+((k:β)+1)*a) β€ 1+(k:β)*a := by
nlinarith [mul_nonneg (by positivity : (0:β) β€ (k:β)+1) (sq_nonneg a)]
calc
_ = (1-a)^k*((1-a)*(1+((k:β)+1)*a)) := by rw [pow_succ]; push_cast; ring
_ β€ (1-a)^k*(1+(k:β)*a) := mul_le_mul_of_nonneg_left hh hp
_ β€ 1 := ih
lemma spectral_weight_ge_one {a : β} (ha : 0 β€ a) (ha1 : a β€ 1)
(k : β) (hk : 1 β€ (k:β)*a) : 1 β€ 2*(1-(1-a)^k) := by
have hp := pow_nonneg (by linarith : 0 β€ 1-a) k
have hb := geometric_bernoulli ha ha1 k
nlinarith [mul_nonneg hp (sub_nonneg.mpr hk)]
lemma row_tail_le {a : β} (ha : 0 β€ a) (ha1 : a β€ 1) (D : β)
(hD : β k : β, D < k β 1 β€ (k:β)*a) (f : (R β W) β β) :
(πΌ B, (f B-project D f B)^2) β€
πΌ B, πΌ C, density a B C*(f B-f C)^2 := by
rw [residual_energy, dirichlet, Finset.mul_sum]
apply Finset.sum_le_sum
intro Ξ± _
by_cases hd : D < degree Ξ±
Β· rw [ite_eq_left hd, β mul_assoc]
simpa using mul_le_mul_of_nonneg_right
(spectral_weight_ge_one ha ha1 (degree Ξ±) (hD _ hd))
(sq_nonneg (coefficient f Ξ±))
Β· rw [ite_eq_right hd]
have hp : (1-a)^degree Ξ± β€ 1 := pow_le_oneβ (by linarith) (by linarith)
positivity
end MinUncut.RowNoise
end
end OAI
|