File size: 12,689 Bytes
dd14c26 | 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 | import Mathlib
import OAI.Probability.LogConcave.Numerics.Basis
namespace OAI
section
section
noncomputable section
namespace LogConcaveSampling.RMSIntegral
open MeasureTheory
open scoped BigOperators
variable {I Ω E : Type*} [Fintype I] [MeasurableSpace Ω]
[NormedAddCommGroup E] [NormedSpace ℝ E] {μ : Measure Ω}
lemma weighted_sum_sq_varying (w : I → ℝ) (f : I → Ω → E) (B : I → ℝ)
(hm : ∀i,AEStronglyMeasurable (f i) μ)
(hi : ∀i,Integrable (fun y => ‖f i y‖^2) μ)
(hB : ∀i,(∫y,‖f i y‖^2 ∂μ)≤B i) :
Integrable (fun y => ‖∑i,w i • f i y‖^2) μ ∧
(∫y,‖∑i,w i • f i y‖^2 ∂μ)≤(∑i,|w i|)*(∑i,|w i| *B i) := by
have hw0 : 0≤∑i,|w i| := Finset.sum_nonneg (fun _ _ => abs_nonneg _)
have hs : Integrable (fun y => (∑i,|w i|)*(∑i,|w i| *‖f i y‖^2)) μ := by
apply Integrable.const_mul
exact integrable_finsetSum _ (fun i _ => (hi i).const_mul _)
have hmeas : AEStronglyMeasurable (fun y => ‖∑i,w i • f i y‖^2) μ := by
have h := (Finset.aestronglyMeasurable_sum Finset.univ
(fun i _ => (hm i).const_smul (w i))).norm.pow 2
convert h using 1
ext y
simp only [Finset.sum_apply,Pi.smul_apply,Pi.pow_apply]
have ho : Integrable (fun y => ‖∑i,w i • f i y‖^2) μ :=
hs.mono' hmeas (Filter.Eventually.of_forall (fun y => by
simpa only [Real.norm_eq_abs,abs_sq] using norm_weighted_sum_sq w (fun i => f i y)))
refine ⟨ho,(integral_mono ho hs (fun y => norm_weighted_sum_sq w (fun i => f i y))).trans ?_⟩
rw [integral_const_mul,integral_finsetSum]
· simp only [integral_const_mul]
exact mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun i _ =>
mul_le_mul_of_nonneg_left (hB i) (abs_nonneg _))) hw0
· exact fun i _ => (hi i).const_mul _
end LogConcaveSampling.RMSIntegral
end
noncomputable section
namespace LogConcaveSampling.RMSIntegral
open MeasureTheory Set
variable {α β E : Type*} [MeasurableSpace α] [MeasurableSpace β]
[NormedAddCommGroup E] [NormedSpace ℝ E]
{μ : Measure α} {ν : Measure β} [IsFiniteMeasure μ] [SFinite ν]
theorem weighted_time_seed {f : α × β → E} {w : α → ℝ}
(hf : AEStronglyMeasurable f (μ.prod ν)) (hw : AEStronglyMeasurable w μ)
{K B : ℝ} (hB0 : 0≤B) (hK : ∀ᵐ t ∂μ,|w t|≤K)
(hslice : ∀ᵐ t ∂μ,Integrable (fun z => ‖f (t,z)‖^2) ν)
(hB : ∀ᵐ t ∂μ,(∫z,‖f (t,z)‖^2 ∂ν)≤B) :
Integrable (fun z => ‖∫t,w t • f (t,z) ∂μ‖^2) ν ∧
(∫z,‖∫t,w t • f (t,z) ∂μ‖^2 ∂ν)≤(μ.real univ)^2*K^2*B := by
have he (t : α) (z : β) : ‖w t • f (t,z)‖^2=(w t)^2*‖f (t,z)‖^2 := by
rw [norm_smul,Real.norm_eq_abs,mul_pow,sq_abs]
have hs : ∀ᵐ t ∂μ,Integrable (fun z => ‖w t • f (t,z)‖^2) ν := by
filter_upwards [hslice] with t ht
simp only [he]
exact ht.const_mul _
have hb : ∀ᵐ t ∂μ,(∫z,‖w t • f (t,z)‖^2 ∂ν)≤K^2*B := by
filter_upwards [hK,hB] with t ht hb
simp only [he,integral_const_mul]
have ht2 : (w t)^2≤K^2 := by simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (w t)) ht 2
exact (mul_le_mul_of_nonneg_left hb (sq_nonneg _)).trans (mul_le_mul_of_nonneg_right ht2 hB0)
simpa only [mul_assoc] using time_seed_uniform (f:=fun p => w p.1 • f p)
(hw.comp_fst.smul hf) hs hb
end LogConcaveSampling.RMSIntegral
end
end
section
noncomputable section
namespace LogConcaveSampling.Quadrature
open MeasureTheory Set
open scoped BigOperators
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
omit [CompleteSpace E] in
lemma iteratedDerivWithin_chain (J : ℕ → ℝ → E) {s : Set ℝ} (hs : UniqueDiffOn ℝ s)
(hJ : ∀n t,t∈s → HasDerivWithinAt (J n) (J (n+1) t) s t) (n : ℕ) :
EqOn (iteratedDerivWithin n (J 0) s) (J n) s := by
induction n with
| zero => intro _ _; rfl
| succ n ih =>
intro t ht
rw [iteratedDerivWithin_succ,derivWithin_congr ih (ih ht)]
exact (hJ n t ht).derivWithin (hs t ht)
omit [CompleteSpace E] in
lemma contDiffOn_chain (J : ℕ → ℝ → E) {s : Set ℝ} (hs : UniqueDiffOn ℝ s)
(hJ : ∀n t,t∈s → HasDerivWithinAt (J n) (J (n+1) t) s t) :
ContDiffOn ℝ (⊤:ℕ∞) (J 0) s := by
rw [contDiffOn_infty]
intro n
rw [contDiffOn_nat_iff_continuousOn_differentiableOn_deriv hs]
constructor
· intro m _
apply (show ContinuousOn (J m) s from fun t ht => (hJ m t ht).continuousWithinAt).congr
intro t ht
exact iteratedDerivWithin_chain J hs hJ m ht
· intro m _
apply (show DifferentiableOn ℝ (J m) s from fun t ht => (hJ m t ht).differentiableWithinAt).congr
intro t ht
exact iteratedDerivWithin_chain J hs hJ m ht
def chainTaylor (J : ℕ → ℝ → E) (n : ℕ) (a x : ℝ) : E :=
∑k∈Finset.range (n+1),((k.factorial:ℝ)⁻¹*(x-a)^k) • J k a
omit [CompleteSpace E] in
lemma chainTaylor_eq {J : ℕ → ℝ → E} {s : Set ℝ} (hs : UniqueDiffOn ℝ s)
(hJ : ∀n t,t∈s → HasDerivWithinAt (J n) (J (n+1) t) s t)
(n : ℕ) {a : ℝ} (ha : a∈s) (x : ℝ) :
taylorWithinEval (J 0) n s a x=chainTaylor J n a x := by
rw [taylor_within_apply]
apply Finset.sum_congr rfl
intro k _
rw [iteratedDerivWithin_chain J hs hJ k ha]
lemma chainTaylor_remainder {J : ℕ → ℝ → E} {s : Set ℝ}
(hJ : ∀n t,t∈s → HasDerivWithinAt (J n) (J (n+1) t) s t)
{a x : ℝ} (hsub : uIcc a x⊆s) (n : ℕ) :
J 0 x-chainTaylor J n a x=
∫t in a..x,((x-t)^n/(n.factorial:ℝ)) • J (n+1) t := by
by_cases hax : a=x
· subst x
simp [chainTaylor, Finset.sum_range_succ']
have hs := uniqueDiffOn_uIcc hax
have hJ' (n : ℕ) (t : ℝ) (ht : t∈uIcc a x) :
HasDerivWithinAt (J n) (J (n+1) t) (uIcc a x) t := (hJ n t (hsub ht)).mono hsub
rw [←chainTaylor_eq hs hJ' n left_mem_uIcc x,
taylor_integral_remainder ((contDiffOn_chain J hs hJ').of_le (by exact_mod_cast (show (n+1:ℕ∞)≤⊤ from le_top)))]
apply intervalIntegral.integral_congr
intro t ht
dsimp only
rw [iteratedDerivWithin_chain J hs hJ' _ ht]
end LogConcaveSampling.Quadrature
end
end
section
noncomputable section
namespace LogConcaveSampling.Quadrature
open MeasureTheory Set
variable {β E : Type*} [MeasurableSpace β]
[NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
{ν : Measure β} [SFinite ν]
theorem chainTaylor_remainder_rms {J : ℕ → ℝ → β → E} {s : Set ℝ} {n : ℕ} {a x B : ℝ}
(hax : a≤x) (hB0 : 0≤B) (hsub : uIcc a x⊆s)
(hf : ∀z n t,t∈s → HasDerivWithinAt (fun t => J n t z) (J (n+1) t z) s t)
(hm : AEStronglyMeasurable (fun p : ℝ × β => J (n+1) p.1 p.2)
((volume.restrict (Ioc a x)).prod ν))
(hi : ∀t∈Ioc a x,Integrable (fun z => ‖J (n+1) t z‖^2) ν)
(hB : ∀t∈Ioc a x,(∫z,‖J (n+1) t z‖^2 ∂ν)≤B) :
Integrable (fun z => ‖J 0 x z-chainTaylor (fun k t => J k t z) n a x‖^2) ν ∧
(∫z,‖J 0 x z-chainTaylor (fun k t => J k t z) n a x‖^2 ∂ν)≤
((x-a)^(n+1)/(n.factorial:ℝ))^2*B := by
let μ : Measure ℝ := volume.restrict (Ioc a x)
let w : ℝ → ℝ := fun t => (x-t)^n/(n.factorial:ℝ)
have hw : AEStronglyMeasurable w μ := by
apply Continuous.aestronglyMeasurable
dsimp [w]; fun_prop
have hk : ∀ᵐ t ∂μ,|w t|≤(x-a)^n/(n.factorial:ℝ) := by
filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht
exact taylor_kernel_bound ht.1.le ht.2 n
have hs : ∀ᵐ t ∂μ,Integrable (fun z => ‖J (n+1) t z‖^2) ν := by
filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht
exact hi t ht
have hb : ∀ᵐ t ∂μ,(∫z,‖J (n+1) t z‖^2 ∂ν)≤B := by
filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht
exact hB t ht
have hv := RMSIntegral.weighted_time_seed hm hw hB0 hk hs hb
have he (z : β) : J 0 x z-chainTaylor (fun k t => J k t z) n a x=
∫t,w t • J (n+1) t z ∂μ := by
rw [chainTaylor_remainder (hf z) hsub,intervalIntegral.integral_of_le hax]
have hμ : μ.real univ=x-a := by
dsimp only [μ,Measure.real]
rw [Measure.restrict_apply_univ]
exact Real.volume_real_Ioc_of_le hax
simp_rw [he]
refine ⟨hv.1,hv.2.trans_eq ?_⟩
rw [hμ,pow_succ]
ring
end LogConcaveSampling.Quadrature
end
end
section
noncomputable section
namespace LogConcaveSampling.Quadrature
open MeasureTheory Set Polynomial
open scoped BigOperators
variable {I E : Type*} [Fintype I] [DecidableEq I]
[NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
omit [CompleteSpace E] in
lemma chainTaylor_scaled_eval (J : ℕ → ℝ → E) (n : ℕ) (a ℓ t : ℝ) :
chainTaylor J n a (a+ℓ*t)=
∑k : Fin (n+1),t^(k:ℕ) •
(((k.val.factorial:ℝ)⁻¹*ℓ^(k:ℕ)) • J k a) := by
unfold chainTaylor
rw [←Fin.sum_univ_eq_sum_range]
apply Finset.sum_congr rfl
intro k _
rw [show a+ℓ*t-a=ℓ*t by ring,mul_pow,smul_smul]
congr 1
ring
omit [CompleteSpace E] in
lemma reproduces_cell_chainTaylor (u : I → ℝ) (hu : Function.Injective u) (n : ℕ)
(hn : n+1≤Fintype.card I) (J : ℕ → ℝ → E) (a ℓ t : ℝ) :
interpolation u (fun i => chainTaylor J n a (a+ℓ*u i)) t=
chainTaylor J n a (a+ℓ*t) := by
simp_rw [chainTaylor_scaled_eval]
exact reproduces_vector u hu (n+1) hn _ t
omit [CompleteSpace E] in
lemma interpolation_sub_unused (u : I → ℝ) (f g : I → E) (t : ℝ) :
interpolation u (fun i => f i-g i) t=interpolation u f t-interpolation u g t := by
simp [interpolation,smul_sub,Finset.sum_sub_distrib]
omit [CompleteSpace E] in
lemma cell_chain_error_eq (u : I → ℝ) (hu : Function.Injective u) (n : ℕ)
(hn : n+1≤Fintype.card I) (J : ℕ → ℝ → E) (a ℓ t : ℝ) :
J 0 (a+ℓ*t)-interpolation u (fun i => J 0 (a+ℓ*u i)) t=
(J 0 (a+ℓ*t)-chainTaylor J n a (a+ℓ*t))-
interpolation u (fun i => J 0 (a+ℓ*u i)-chainTaylor J n a (a+ℓ*u i)) t := by
rw [interpolation_sub_unused,reproduces_cell_chainTaylor u hu n hn]
abel
end LogConcaveSampling.Quadrature
end
end
section
noncomputable section
namespace LogConcaveSampling.Quadrature
open MeasureTheory Set
open scoped BigOperators
variable {I Ω E : Type*} [Fintype I] [DecidableEq I] [MeasurableSpace Ω]
[NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {ν : Measure Ω}
omit [CompleteSpace E] in
theorem cell_chain_error_rms (u : I → ℝ) (hu : Function.Injective u) (n : ℕ)
(hn : n+1≤Fintype.card I) (J : ℕ → ℝ → Ω → E) (a ℓ t : ℝ) {B C : ℝ}
(hB : 0≤B) (hC : 1≤C) (hc : ∑i,|basis u i t|≤C)
(hm : ∀s∈insert t (Set.range u),AEStronglyMeasurable
(fun z => J 0 (a+ℓ*s) z-chainTaylor (fun k v => J k v z) n a (a+ℓ*s)) ν)
(hi : ∀s∈insert t (Set.range u),Integrable
(fun z => ‖J 0 (a+ℓ*s) z-chainTaylor (fun k v => J k v z) n a (a+ℓ*s)‖^2) ν)
(hR : ∀s∈insert t (Set.range u),(∫z,
‖J 0 (a+ℓ*s) z-chainTaylor (fun k v => J k v z) n a (a+ℓ*s)‖^2 ∂ν)≤B) :
Integrable (fun z => ‖J 0 (a+ℓ*t) z-interpolation u (fun i => J 0 (a+ℓ*u i) z) t‖^2) ν ∧
(∫z,‖J 0 (a+ℓ*t) z-interpolation u (fun i => J 0 (a+ℓ*u i) z) t‖^2 ∂ν)≤4*C^2*B := by
let R (s : ℝ) (z : Ω) := J 0 (a+ℓ*s) z-chainTaylor (fun k v => J k v z) n a (a+ℓ*s)
have hmt := hm t (mem_insert t _)
have hmn (i : I) := hm (u i) (mem_insert_of_mem t (mem_range_self i))
have hit := hi t (mem_insert t _)
have hin (i : I) := hi (u i) (mem_insert_of_mem t (mem_range_self i))
have hRn (i : I) := hR (u i) (mem_insert_of_mem t (mem_range_self i))
have hsum := RMSIntegral.weighted_sum_sq (fun i => basis u i t) (fun i => R (u i)) hmn hin hRn
have hms : AEStronglyMeasurable (fun z => interpolation u (fun i => R (u i) z) t) ν := by
have hs := Finset.aestronglyMeasurable_sum Finset.univ (fun i _ => (hmn i).const_smul (basis u i t))
convert hs using 1
ext z
simp only [interpolation,Finset.sum_apply,Pi.smul_apply,R]
have hsb : (∫z,‖interpolation u (fun i => R (u i) z) t‖^2 ∂ν)≤C^2*B := by
apply hsum.2.trans
exact mul_le_mul_of_nonneg_right (pow_le_pow_left₀
(Finset.sum_nonneg (fun _ _ => abs_nonneg _)) hc 2) hB
have hs := RMSIntegral.sub_sq_bound hmt hms hit hsum.1 (hR t (mem_insert t _)) hsb
have he (z : Ω) := cell_chain_error_eq u hu n hn (fun k v => J k v z) a ℓ t
simp_rw [he]
refine ⟨hs.1,hs.2.trans ?_⟩
have hc2 : 1≤C^2 := by nlinarith
nlinarith [mul_le_mul_of_nonneg_right hc2 hB]
end LogConcaveSampling.Quadrature
end
end
end
end OAI
|