cfahlgren1/math / lean /OAI /Probability /SKValue /Gaussian /GaussianSquareVariance.lean
cfahlgren1's picture
download
raw
12.9 kB
import Mathlib
import OAI.Probability.SKValue.GroundState.PredictableNormalizer
namespace OAI
section
open MeasureTheory ProbabilityTheory Set
open scoped ENNReal NNReal BigOperators
open MeasureTheory ProbabilityTheory Filter Set
open scoped BigOperators Topology
namespace SKValue
open MeasureTheory ProbabilityTheory Set Filter
open scoped BigOperators Topology
variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω}
lemma gaussian_square_memLp_two {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) μ) :
MemLp (fun ω ↦ (Z ω)^2) 2 μ := by
have h := (gaussian_memLp hZ 4 (by norm_num)).norm_rpow_div 2
norm_num [Real.norm_eq_abs, Real.rpow_two, sq_abs] at h
have he : (4 : ℝ≥0∞)/2=2 := by
change ((4 : ℝ≥0) : ℝ≥0∞)/((2 : ℝ≥0) : ℝ≥0∞)=((2 : ℝ≥0) : ℝ≥0∞)
rw [← ENNReal.coe_div] <;> norm_num
rwa [he] at h
lemma gaussian_centered_square_memLp_two [IsProbabilityMeasure μ]
{Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) μ) :
MemLp (fun ω ↦ (Z ω)^2-1) 2 μ :=
(gaussian_square_memLp_two hZ).sub (memLp_const 1)
lemma gaussian_centered_square_mean [IsProbabilityMeasure μ]
{Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) μ) :
(∫ ω, (Z ω)^2-1 ∂μ)=0 := by
rw [integral_sub (gaussian_memLp hZ 2 (by norm_num)).integrable_sq (integrable_const 1),
gaussian_second_moment hZ]
simp
noncomputable def gaussianSquareVariance : ℝ :=
∫ z : ℝ, (z^2-1)^2 ∂gaussianReal 0 1
lemma gaussianSquareVariance_nonneg : 0≤gaussianSquareVariance :=
integral_nonneg fun _ ↦ sq_nonneg _
lemma gaussian_centered_square_variance {Z : Ω → ℝ}
(hZ : HasLaw Z (gaussianReal 0 1) μ) :
(∫ ω, ((Z ω)^2-1)^2 ∂μ)=gaussianSquareVariance := by
exact hZ.integral_comp (f := fun z : ℝ ↦ (z^2-1)^2) (by fun_prop)
lemma predictableCenteredSquare_memLp {N j : ℕ}
{H : (Fin (N+1) → ℝ) → ℝ} {K : ℝ}
(hm : Measurable H) (hbound : ∀ z, |H z|≤K) :
MemLp (fun z ↦ H z*((coordinate N j z)^2-1)) 2 (gaussianProduct (Fin (N+1))) := by
have hQ := (gaussian_centered_square_memLp_two (coordinate_hasLaw N j))
have hH : MemLp H ∞ (gaussianProduct (Fin (N+1))) :=
MemLp.of_bound hm.aestronglyMeasurable K (Filter.Eventually.of_forall (by simpa only [Real.norm_eq_abs] using hbound))
exact hH.mul hQ
lemma predictableCenteredSquare_variance {N j : ℕ} (hj : j<N+1)
{H : (Fin (N+1) → ℝ) → ℝ} {K : ℝ}
(hK : 0≤K) (hm : Measurable H) (hp : DependsBefore j H) (hbound : ∀ z, |H z|≤K) :
(∫ z, (H z*((coordinate N j z)^2-1))^2 ∂gaussianProduct (Fin (N+1))) ≤
K^2*gaussianSquareVariance := by
have hind := (hp.independent hj hm).comp (measurable_id.pow_const 2)
((measurable_id.pow_const 2 |>.sub (measurable_const (a := (1 : ℝ)))).pow_const 2)
have hi := hind.integral_mul_eq_mul_integral (hm.pow_const 2).aestronglyMeasurable
(((measurable_coordinate N j).pow_const 2 |>.sub (measurable_const (a := (1 : ℝ)))).pow_const 2).aestronglyMeasurable
simp only [Pi.mul_apply, Pi.sub_apply, Function.comp_def, id_eq] at hi
simp_rw [mul_pow]
rw [hi, gaussian_centered_square_variance (coordinate_hasLaw N j)]
have hH : MemLp H 2 (gaussianProduct (Fin (N+1))) := MemLp.of_bound hm.aestronglyMeasurable K
(Filter.Eventually.of_forall (by simpa only [Real.norm_eq_abs] using hbound))
have hb : (∫ z, (H z)^2 ∂gaussianProduct (Fin (N+1))) ≤ K^2 := by
have hi' := integral_mono hH.integrable_sq (integrable_const (K^2))
(fun z ↦ by simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hK).2 (hbound z))
simpa using hi'
exact mul_le_mul_of_nonneg_right hb gaussianSquareVariance_nonneg
lemma centeredSquare_dependsBefore {N j : ℕ} (hj : j<N+1)
{H : (Fin (N+1) → ℝ) → ℝ} (hp : DependsBefore j H) :
DependsBefore (j+1) (fun z ↦ H z*((coordinate N j z)^2-1)) := by
intro z z' h
dsimp only
rw [hp.mono (Nat.le_succ j) z z' h]
have hz : coordinate N j z=coordinate N j z' := by
rw [coordinate_eq_apply hj, coordinate_eq_apply hj]
exact h ⟨j,hj⟩ (Nat.lt_succ_self j)
rw [hz]
lemma predictableCenteredSquares_orthogonal {N i j : ℕ} (hij : i<j) (hj : j<N+1)
{H K : (Fin (N+1) → ℝ) → ℝ}
(hHm : Measurable H) (hKm : Measurable K)
(hHp : DependsBefore i H) (hKp : DependsBefore j K) :
(∫ z, (H z*((coordinate N i z)^2-1))*(K z*((coordinate N j z)^2-1))
∂gaussianProduct (Fin (N+1)))=0 := by
have hprev := (centeredSquare_dependsBefore (hij.trans hj) hHp).mono (by omega : i+1≤j)
have hpm : Measurable (fun z ↦ H z*((coordinate N i z)^2-1)) :=
hHm.mul (((measurable_coordinate N i).pow_const 2).sub (measurable_const (a := (1 : ℝ))))
have hind := ((hprev.mul hKp).independent hj (hpm.mul hKm)).comp measurable_id
((measurable_id.pow_const 2).sub (measurable_const (a := (1 : ℝ))))
have ht := hind.integral_mul_eq_mul_integral (hpm.mul hKm).aestronglyMeasurable
(((measurable_coordinate N j).pow_const 2).sub (measurable_const (a := (1 : ℝ)))).aestronglyMeasurable
simp only [Pi.mul_apply, Pi.sub_apply, Function.comp_def, id_eq] at ht
simp_rw [mul_assoc] at ht ⊢
rw [ht, gaussian_centered_square_mean (coordinate_hasLaw N j), mul_zero]
lemma orthogonal_sum_square {ι : Type*} [Fintype ι] [DecidableEq ι]
{R : ι → Ω → ℝ} (hR : ∀ i, MemLp (R i) 2 μ)
(horth : ∀ i j, i≠j → (∫ ω, R i ω*R j ω ∂μ)=0) :
(∫ ω, (∑ i, R i ω)^2 ∂μ)=∑ i, ∫ ω, (R i ω)^2 ∂μ := by
have hsum : MemLp (fun ω ↦ ∑ i, R i ω) 2 μ := memLp_finsetSum _ (fun i _ ↦ hR i)
have hi j : (∫ ω, (∑ i, R i ω)*R j ω ∂μ) = ∫ ω, (R j ω)^2 ∂μ := by
simp_rw [Finset.sum_mul]
rw [integral_finsetSum Finset.univ (fun i _ ↦
show Integrable (fun ω ↦ R i ω*R j ω) μ from (hR i).integrable_mul (hR j))]
rw [Finset.sum_eq_single j]
· simp [pow_two]
· intro i _ hij
exact horth i j hij
· simp
simp_rw [pow_two, Finset.sum_mul]
rw [integral_finsetSum Finset.univ (fun i _ ↦
show Integrable (fun ω ↦ R i ω*(∑ j, R j ω)) μ from (hR i).integrable_mul hsum)]
apply Finset.sum_congr rfl
intro i _
rw [show (fun ω ↦ R i ω*(∑ j, R j ω))=(fun ω ↦ (∑ j, R j ω)*R i ω)
from funext (fun _ ↦ mul_comm _ _), hi]
simp [pow_two]
lemma predictableCenteredSquare_sum_bound {N : ℕ} {δ K : ℝ}
{H : Fin N → (Fin (N+1) → ℝ) → ℝ} (hK : 0≤K)
(hm : ∀ i, Measurable (H i)) (hp : ∀ i : Fin N, DependsBefore (i : ℕ) (H i))
(hb : ∀ i z, |H i z|≤K) :
(∫ z, ((δ/2)*(∑ i : Fin N, H i z*((coordinate N i z)^2-1)))^2
∂gaussianProduct (Fin (N+1))) ≤ (δ/2)^2*(N : ℝ)*K^2*gaussianSquareVariance := by
have hmem (i : Fin N) := predictableCenteredSquare_memLp (j := (i : ℕ)) (hm i) (hb i)
have hort : ∀ i j : Fin N, i≠j →
(∫ z, (H i z*((coordinate N i z)^2-1))*(H j z*((coordinate N j z)^2-1))
∂gaussianProduct (Fin (N+1)))=0 := by
intro i j hij
rcases lt_or_gt_of_ne hij with h | h
· exact predictableCenteredSquares_orthogonal (by exact_mod_cast h) (by omega)
(hm i) (hm j) (hp i) (hp j)
· rw [show (fun z ↦ (H i z*((coordinate N i z)^2-1))*(H j z*((coordinate N j z)^2-1))) =
(fun z ↦ (H j z*((coordinate N j z)^2-1))*(H i z*((coordinate N i z)^2-1)))
from funext (fun _ ↦ mul_comm _ _)]
exact predictableCenteredSquares_orthogonal (by exact_mod_cast h) (by omega)
(hm j) (hm i) (hp j) (hp i)
simp_rw [mul_pow]
rw [integral_const_mul, orthogonal_sum_square hmem hort]
calc
_ ≤ (δ/2)^2*(∑ _i : Fin N, K^2*gaussianSquareVariance) := by
gcongr with i
exact predictableCenteredSquare_variance (by omega) hK (hm i) (hp i) (hb i)
_ = _ := by simp; ring
noncomputable def cubicEnvelope (G K C : ℝ) (z : ℝ) : ℝ :=
K*(|z|+G)^3+C*(1+|z|+G)+K*G*(|z|+G/2)
lemma cubicEnvelope_nonneg {G K C : ℝ} (hG : 0≤G) (hK : 0≤K) (hC : 0≤C) (z : ℝ) :
0≤cubicEnvelope G K C z := by unfold cubicEnvelope; positivity
lemma measurable_cubicEnvelope (G K C : ℝ) : Measurable (cubicEnvelope G K C) := by
unfold cubicEnvelope
fun_prop
lemma abs_add_cube_memLp {Z : Ω → ℝ} (hz6 : MemLp (fun ω ↦ |Z ω|) 6 μ)
{G : ℝ} (hG : 0≤G) [IsProbabilityMeasure μ] :
MemLp (fun ω ↦ (|Z ω|+G)^3) 2 μ := by
have hbase : MemLp (fun ω ↦ |Z ω|+G) 6 μ := hz6.add (memLp_const G)
have hpow := hbase.norm_rpow_div 3
have he : (6 : ℝ≥0∞)/3=2 := by
change ((6 : ℝ≥0) : ℝ≥0∞)/((3 : ℝ≥0) : ℝ≥0∞)=((2 : ℝ≥0) : ℝ≥0∞)
rw [← ENNReal.coe_div] <;> norm_num
have hh : ∀ ω, ‖|Z ω|+G‖=|Z ω|+G := fun ω ↦ Real.norm_of_nonneg (by positivity)
simpa only [hh, ENNReal.toReal_ofNat, Real.rpow_ofNat, he] using hpow
lemma cubicEnvelope_memLp_two [IsProbabilityMeasure μ] {Z : Ω → ℝ}
(hZ : HasLaw Z (gaussianReal 0 1) μ) {G : ℝ} (hG : 0≤G) (K C : ℝ) :
MemLp (fun ω ↦ cubicEnvelope G K C (Z ω)) 2 μ := by
have hz6 : MemLp (fun ω ↦ |Z ω|) 6 μ := by
simpa only [Real.norm_eq_abs] using (gaussian_memLp hZ 6 (by norm_num)).norm
have hp := abs_add_cube_memLp hz6 hG
have hz2 : MemLp (fun ω ↦ |Z ω|) 2 μ := hz6.mono_exponent (by norm_num)
have hlin : MemLp (fun ω ↦ 1+|Z ω|+G) 2 μ := ((memLp_const (1 : ℝ)).add hz2).add (memLp_const G)
have hlast : MemLp (fun ω ↦ |Z ω|+G/2) 2 μ := hz2.add (memLp_const (G/2))
change MemLp (fun ω ↦ K*(|Z ω|+G)^3+C*(1+|Z ω|+G)+K*G*(|Z ω|+G/2)) 2 μ
exact ((hp.const_mul K).add (hlin.const_mul C)).add (hlast.const_mul (K*G))
noncomputable def cubicEnvelopeMoment (G K C : ℝ) : ℝ :=
∫ z : ℝ, (cubicEnvelope G K C z)^2 ∂gaussianReal 0 1
lemma cubicEnvelopeMoment_nonneg (G K C : ℝ) : 0≤cubicEnvelopeMoment G K C :=
integral_nonneg fun _ ↦ sq_nonneg _
lemma cubicEnvelope_moment_eq {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) μ) (G K C : ℝ) :
(∫ ω, (cubicEnvelope G K C (Z ω))^2 ∂μ)=cubicEnvelopeMoment G K C :=
hZ.integral_comp (f := fun z ↦ (cubicEnvelope G K C z)^2)
((measurable_cubicEnvelope G K C).pow_const 2).aestronglyMeasurable
lemma finite_sum_square_le {ι : Type*} [Fintype ι] (f : ι → ℝ) :
(∑ i, f i)^2≤(Fintype.card ι : ℝ)*(∑ i, (f i)^2) := by
have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ : ι ↦ (1 : ℝ)) f
simpa using h
lemma finite_envelope_L2_bound [IsProbabilityMeasure μ] {ι : Type*} [Fintype ι]
{P : ι → Ω → ℝ} {R : Ω → ℝ} {α β M : ℝ}
(hα : 0≤α) (hβ : 0≤β) (hPm : ∀ i, MemLp (P i) 2 μ)
(hPpos : ∀ i ω, 0≤P i ω) (hPval : ∀ i, (∫ ω, (P i ω)^2 ∂μ)≤M)
(hRm : AEStronglyMeasurable R μ)
(hR : ∀ ω, |R ω|≤α*(∑ i, P i ω)+β) :
(∫ ω, (R ω)^2 ∂μ) ≤ 2*α^2*(Fintype.card ι : ℝ)^2*M+2*β^2 := by
have hsum : MemLp (fun ω ↦ ∑ i, P i ω) 2 μ := memLp_finsetSum _ (fun i _ ↦ hPm i)
have henv : MemLp (fun ω ↦ α*(∑ i, P i ω)+β) 2 μ := (hsum.const_mul α).add (memLp_const β)
have hsumpos (ω : Ω) : 0≤∑ i, P i ω := Finset.sum_nonneg (fun i _ ↦ hPpos i ω)
have henvpos (ω : Ω) : 0≤α*(∑ i, P i ω)+β := add_nonneg (mul_nonneg hα (hsumpos ω)) hβ
have hRmem : MemLp R 2 μ := henv.mono hRm (Filter.Eventually.of_forall (fun ω ↦ by
rw [Real.norm_eq_abs, Real.norm_of_nonneg (henvpos ω)]
exact hR ω))
have hbound : ∀ ω, (R ω)^2 ≤ 2*α^2*(Fintype.card ι : ℝ)*(∑ i, (P i ω)^2)+2*β^2 := by
intro ω
have he : 0≤α*(∑ i, P i ω)+β := henvpos ω
have hsq := (sq_le_sq₀ (abs_nonneg _) he).2 (hR ω)
rw [sq_abs] at hsq
have hfin := finite_sum_square_le (fun i ↦ P i ω)
have hmul := mul_le_mul_of_nonneg_left hfin (show 0≤2*α^2 by positivity)
nlinarith [sq_nonneg (α*(∑ i, P i ω)-β)]
have hfirst : Integrable (fun ω ↦ 2*α^2*(Fintype.card ι : ℝ)*(∑ i, (P i ω)^2)) μ :=
(integrable_finsetSum Finset.univ (fun i _ ↦ (hPm i).integrable_sq)).const_mul _
have heint : Integrable (fun ω ↦ 2*α^2*(Fintype.card ι : ℝ)*(∑ i, (P i ω)^2)+2*β^2) μ :=
hfirst.add (integrable_const _)
calc
_ ≤ ∫ ω, 2*α^2*(Fintype.card ι : ℝ)*(∑ i, (P i ω)^2)+2*β^2 ∂μ :=
integral_mono hRmem.integrable_sq heint hbound
_ = 2*α^2*(Fintype.card ι : ℝ)*(∑ i, ∫ ω, (P i ω)^2 ∂μ)+2*β^2 := by
rw [integral_add hfirst (integrable_const _)]
rw [integral_const_mul, integral_finsetSum Finset.univ (fun i _ ↦ (hPm i).integrable_sq)]
simp
_ ≤ 2*α^2*(Fintype.card ι : ℝ)*(∑ _i : ι, M)+2*β^2 := by gcongr with i; exact hPval i
_ = _ := by simp; ring
end SKValue
open MeasureTheory ProbabilityTheory Set Filter
open scoped Topology BigOperators
end
end OAI

Xet Storage Details

Size:
12.9 kB
·
Xet hash:
772b21a23c171330c3e57be5dc2175790104307a17da02cfa0ece54548515fa3

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.