File size: 6,382 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 | import OAI.Probability.GaussianPropeller.Quantile
namespace OAI
universe uE uΞΉ
open MeasureTheory ProbabilityTheory
open scoped ENNReal
open scoped RealInnerProductSpace
open scoped RealInnerProductSpace
open MeasureTheory ProbabilityTheory Set
open scoped ENNReal RealInnerProductSpace
open Filter
open scoped Topology
open MeasureTheory ProbabilityTheory Set Filter
open scoped Topology
open scoped RealInnerProductSpace
namespace GaussianPropeller.QuantilePDE
open GaussianPropeller.Quantile
variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace β E]
lemma quantile_fderiv {u : E β β} {g : E} {x : E}
(hu : u x β Ioo (0:β) 1) (hd : HasFDerivAt u (innerSL β g) x) :
HasFDerivAt (fun y => q (u y)) (innerSL β ((Ο (q (u x)))β»ΒΉ β’ g)) x := by
have hh := (hasDerivAt_q hu).comp_hasFDerivAt x hd
convert hh using 1 <;> (first | rfl | (ext y; simp))
lemma quantile_gradient_line_derivative {u : E β β} {g : E β E}
{K : E β E βL[β] E} (hu : β x, u x β Ioo (0:β) 1)
(hdu : β x, HasFDerivAt u (innerSL β (g x)) x)
(hdg : β x, HasFDerivAt g (K x) x) (x e : E) :
HasDerivAt (fun s : β => βͺ(Ο (q (u (x+sβ’e))))β»ΒΉ β’ g (x+sβ’e), eβ«)
((Ο (q (u x)))β»ΒΉ*βͺK x e,eβ« +
q (u x)*(Ο (q (u x)))β»ΒΉ^2*βͺg x,eβ«^2) 0 := by
have hdx : HasDerivAt (fun s : β => x+sβ’e) e 0 := by
simpa using ((hasDerivAt_id (0:β)).smul_const e).const_add x
have hdv : HasDerivAt (fun s : β => q (u (x+sβ’e)))
((Ο (q (u x)))β»ΒΉ*βͺg x,eβ«) 0 := by
simpa [Function.comp_def] using (quantile_fderiv (hu (x+0β’e)) (hdu (x+0β’e))).comp_hasDerivAt 0 hdx
have hdΟ := (hasDerivAt_Ο (q (u (x+0β’e)))).comp 0 hdv
have hdi := hdΟ.inv (ne_of_gt (Ο_pos _))
have hdg' : HasDerivAt (fun s : β => g (x+sβ’e)) (K x e) 0 := by
simpa only [Function.comp_def, zero_smul, add_zero] using (hdg (x+0β’e)).comp_hasDerivAt 0 hdx
have hi : HasDerivAt (fun s : β => βͺg (x+sβ’e), eβ«) βͺK x e,eβ« 0 := by
simpa using hdg'.inner β (hasDerivAt_const (0:β) e)
have hh := hdi.mul hi
convert hh using 1 <;> try rfl
Β· funext s; simp only [real_inner_smul_left, Function.comp_def, Pi.mul_apply, Pi.inv_apply]
Β· simp only [Function.comp_def, zero_smul, add_zero, Pi.inv_apply]
field_simp [ne_of_gt (Ο_pos (q (u x)))]
ring
lemma trace_quantile_hessian {ΞΉ : Type uΞΉ} [Fintype ΞΉ]
(e : OrthonormalBasis ΞΉ β E) (v a : β) (g : E) (K : E βL[β] E) :
(β i : ΞΉ, (a*βͺK (e i),e iβ« + v*a^2*βͺg,e iβ«^2)) - v*βa β’ gβ^2 =
a*(β i : ΞΉ, βͺK (e i),e iβ«) := by
rw [Finset.sum_add_distrib, β Finset.mul_sum, β Finset.mul_sum,
e.sum_sq_inner_left, norm_smul, Real.norm_eq_abs, mul_pow, sq_abs]
ring
end GaussianPropeller.QuantilePDE
namespace GaussianPropeller.SmoothCDF
open GaussianPropeller.Quantile
variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace β E]
lemma abs_mul_Ο_le (a : β) : |a| *Ο a β€ Ο 0 := by
have hsq : |a| β€ 1+a^2/2 := by nlinarith [sq_nonneg (|a|-1), sq_abs a]
have he : |a| β€ Real.exp (a^2/2) := hsq.trans (by nlinarith [Real.add_one_le_exp (a^2/2)])
have hh := mul_le_mul_of_nonneg_right he (Real.exp_pos (-a^2/2)).le
rw [β Real.exp_add] at hh
have heq : a^2/2 + -a^2/2 = 0 := by ring
rw [heq, Real.exp_zero] at hh
unfold Ο
simp only [zero_pow (by norm_num : 2 β 0), neg_zero, zero_div, Real.exp_zero, mul_one]
nlinarith [mul_le_mul_of_nonneg_left hh (by positivity : 0 β€ (Real.sqrt (2*Real.pi))β»ΒΉ)]
noncomputable def grad (f : E β β) (g : E β E) (x : E) : E := Ο (f x) β’ g x
noncomputable def hess (f : E β β) (g : E β E) (K : E β E βL[β] E) (x : E) : E βL[β] E :=
Ο (f x) β’ K x - (f x*Ο (f x)) β’ ((innerSL β (g x)).smulRight (g x))
lemma fderiv {f : E β β} {g : E β E}
(hf : β x, HasFDerivAt f (innerSL β (g x)) x) (x : E) :
HasFDerivAt (fun y => Ξ¦ (f y)) (innerSL β (grad f g x)) x := by
have h := (hasDerivAt_Ξ¦ (f x)).comp_hasFDerivAt x (hf x)
convert h using 1 <;> (first | rfl | (ext e; simp [grad]))
lemma grad_fderiv {f : E β β} {g : E β E} {K : E β E βL[β] E}
(hf : β x, HasFDerivAt f (innerSL β (g x)) x)
(hg : β x, HasFDerivAt g (K x) x) (x : E) :
HasFDerivAt (grad f g) (hess f g K x) x := by
have h := ((hasDerivAt_Ο (f x)).comp_hasFDerivAt x (hf x)).smul (hg x)
convert h using 1 <;> try rfl
ext e
simp only [hess, sub_apply, add_apply,
smul_apply, ContinuousLinearMap.smulRight_apply, innerSL_apply_apply, smul_eq_mul, Function.comp_def]
module
lemma continuous_hess {f : E β β} {g : E β E} {K : E β E βL[β] E}
(hf : Continuous f) (hg : Continuous g) (hK : Continuous K) : Continuous (hess f g K) := by
have hΟ := continuous_Ο.comp hf
unfold hess
fun_prop
omit [NormedAddCommGroup E] [InnerProductSpace β E] in
lemma cdf_bound [NormedAddCommGroup E] [InnerProductSpace β E]
(f : E β β) (x : E) : βΞ¦ (f x)β β€ 1 := by
rw [Real.norm_eq_abs, abs_of_pos (Ξ¦_pos _)]; exact (Ξ¦_lt_one _).le
lemma grad_bound {f : E β β} {g : E β E} {L : β}
(hL : β x, βg xβ β€ L) (x : E) : βgrad f g xβ β€ Ο 0*L := by
rw [grad, norm_smul, Real.norm_eq_abs, abs_of_pos (Ο_pos _)]
exact mul_le_mul (Ο_le_zero _) (hL x) (norm_nonneg _) (Ο_pos _).le
lemma hess_bound {f : E β β} {g : E β E} {K : E β E βL[β] E} {L D : β}
(hL0 : 0 β€ L) (hL : β x, βg xβ β€ L) (hD : β x, βK xβ β€ D) (x : E) :
βhess f g K xβ β€ Ο 0*(D+L^2) := by
have hD0 : 0 β€ D := (norm_nonneg (K x)).trans (hD x)
calc
βhess f g K xβ β€ βΟ (f x) β’ K xβ +
β(f x*Ο (f x)) β’ ((innerSL β (g x)).smulRight (g x))β := norm_sub_le _ _
_ = Ο (f x)*βK xβ + (|f x| *Ο (f x))*βg xβ^2 := by
rw [norm_smul, norm_smul, Real.norm_eq_abs, Real.norm_eq_abs,
abs_of_pos (Ο_pos _), abs_mul, abs_of_pos (Ο_pos _),
ContinuousLinearMap.norm_smulRight_apply, innerSL_apply_norm]
ring
_ β€ Ο 0*D + Ο 0*L^2 := add_le_add
(mul_le_mul (Ο_le_zero _) (hD x) (norm_nonneg _) (Ο_pos _).le)
(mul_le_mul (abs_mul_Ο_le _) ((sq_le_sqβ (norm_nonneg _) hL0).2 (hL x))
(sq_nonneg _) (Ο_pos _).le)
_ = _ := by ring
end GaussianPropeller.SmoothCDF
end OAI
|