File size: 3,870 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
import Mathlib
import OAI.Probability.SKGap.Localization.ScalarSmallNoiseTests

namespace OAI

section
noncomputable section
open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter
open scoped NNReal ENNReal Topology
noncomputable section
open Real Set
noncomputable section
open MeasureTheory ProbabilityTheory Real Set Filter
open scoped Topology NNReal ENNReal BoundedContinuousFunction
open MeasureTheory ProbabilityTheory Filter Set Topology Real
open scoped NNReal ENNReal BoundedContinuousFunction
noncomputable section
open Set Filter Topology
noncomputable section
open MeasureTheory ProbabilityTheory Filter Set Topology Real
open scoped NNReal ENNReal BoundedContinuousFunction
noncomputable section
open MeasureTheory ProbabilityTheory Filter Set Topology Real
open scoped NNReal ENNReal BoundedContinuousFunction
noncomputable section
open MeasureTheory ProbabilityTheory Filter Set Topology Real
open scoped NNReal ENNReal
namespace SKGap
lemma normalLogDensity_centered (d s x : ℝ) :
    normalLogDensity d s x = -log (sqrt (2*Real.pi*s))-(x-d)^2/(2*s) := by
  unfold normalLogDensity normalLogConst
  ring

lemma gaussian_pointwise_envelope {ι : Type*} [Fintype ι] (y : ι → ℝ)
    {d s j D smin smax ψ : ℝ} (hsmin : 0 < smin) (hsl : smin ≤ s) (hsu : s ≤ smax)
    (hd : d^2 ≤ D^2)
    (hψ : (Fintype.card ι:ℝ)*ψ ≤ 3/(8*s)*(∑ i, (y i-d)^2)+3*(Fintype.card ι:ℝ)*j/2) :
    exp ((Fintype.card ι:ℝ)*ψ)*productNormal d s y ≤
      exp ((Fintype.card ι:ℝ)*(|log (sqrt (2*Real.pi*smin))|+3*j/2+D^2/(8*smin))-
        (1/(16*smax))*∑ i, (y i)^2) := by
  have hs : 0 < s := hsmin.trans_le hsl
  have hmax : 0 < smax := hs.trans_le hsu
  have hn : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _
  have hQ : 0 ≤ ∑ i, (y i)^2 := Finset.sum_nonneg (fun i _ => sq_nonneg _)
  have hc := sum_centered_sq_lower y d
  have hnd := mul_le_mul_of_nonneg_left hd hn
  have h1 : -(∑ i, (y i-d)^2)/(8*s) ≤
      -(∑ i, (y i)^2)/(16*s)+(Fintype.card ι:ℝ)*D^2/(8*s) := by
    have he : -(∑ i, (y i)^2)/(16*s)+(Fintype.card ι:ℝ)*D^2/(8*s) =
        (-(∑ i, (y i)^2)/2+(Fintype.card ι:ℝ)*D^2)/(8*s) := by ring
    rw [he]
    apply div_le_div_of_nonneg_right _ (by positivity : 0 ≤ 8*s)
    linarith
  have h2 : -(∑ i, (y i)^2)/(16*s) ≤ -(∑ i, (y i)^2)/(16*smax) := by
    rw [neg_div, neg_div, neg_le_neg_iff]
    gcongr
  have h3 : (Fintype.card ι:ℝ)*D^2/(8*s) ≤ (Fintype.card ι:ℝ)*D^2/(8*smin) := by
    gcongr
  have hp : 0 < sqrt (2*Real.pi*smin) := sqrt_pos.mpr (by positivity)
  have hlog : log (sqrt (2*Real.pi*smin)) ≤ log (sqrt (2*Real.pi*s)) :=
    log_le_log hp (sqrt_le_sqrt (by nlinarith [Real.pi_pos]))
  have hlog' : -log (sqrt (2*Real.pi*s)) ≤ |log (sqrt (2*Real.pi*smin))| :=
    (neg_le_neg hlog).trans (neg_le_abs _)
  have hnlog := mul_le_mul_of_nonneg_left hlog' hn
  have he : (∑ i, normalLogDensity d s (y i)) =
      -(Fintype.card ι:ℝ)*log (sqrt (2*Real.pi*s))-(∑ i, (y i-d)^2)/(2*s) := by
    simp only [normalLogDensity_centered, Finset.sum_sub_distrib, Finset.sum_const,
      Finset.card_univ, nsmul_eq_mul, Finset.sum_div]
    ring
  rw [productNormal_eq_exp _ hs, ← exp_add, he]
  apply exp_le_exp.mpr
  calc
    _ ≤ 3/(8*s)*(∑ i, (y i-d)^2)+3*(Fintype.card ι:ℝ)*j/2+
        (-(Fintype.card ι:ℝ)*log (sqrt (2*Real.pi*s))-(∑ i, (y i-d)^2)/(2*s)) :=
      by linarith only [hψ]
    _ = (Fintype.card ι:ℝ)*(-log (sqrt (2*Real.pi*s)))+3*(Fintype.card ι:ℝ)*j/2+
        (-(∑ i, (y i-d)^2)/(8*s)) := by ring
    _ ≤ (Fintype.card ι:ℝ)*|log (sqrt (2*Real.pi*smin))|+3*(Fintype.card ι:ℝ)*j/2+
        (-(∑ i, (y i)^2)/(16*smax)+(Fintype.card ι:ℝ)*D^2/(8*smin)) :=
      add_le_add (by linarith only [hnlog]) (h1.trans (add_le_add h2 h3))
    _ = _ := by ring

end SKGap

end
end
end
end
end
end
end
end

end OAI