File size: 6,730 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 | import Mathlib
import OAI.Probability.GaussianInformation.Kernel.GaussianReference
namespace OAI
open MeasureTheory ProbabilityTheory Metric Set
open scoped ENNReal
open MeasureTheory ProbabilityTheory Set
open scoped ENNReal
namespace ReferenceGaussian
open MeasureTheory ProbabilityTheory Set Metric
open scoped ENNReal
open GaussianTools
lemma continuous_integrable_on_support {d : β} (Ξ½ : Measure (Vec d)) [IsFiniteMeasure Ξ½]
{f : Vec d β β} (hf : Continuous f) (s : Vec d) (R : β)
(hs : βα΅ u βΞ½, u β closedBall s R) : Integrable f Ξ½ := by
have h := hf.continuousOn.integrableOn_compact (ΞΌ := Ξ½) (isCompact_closedBall s R)
rwa [IntegrableOn,Measure.restrict_eq_self_of_ae_mem hs] at h
lemma integrable_log_atDensity {p d : β} (Ξ½ : Measure (Vec d)) [IsFiniteMeasure Ξ½]
{r : β} (hr : 0 < r) (X : Mat p d) (y : Fin p β β)
(s : Vec d) (R : β) (hs : βα΅ u βΞ½,u β closedBall s R) :
Integrable (fun u => Real.log (atDensity r X y u)) Ξ½ := by
apply continuous_integrable_on_support Ξ½ _ s R hs
have hc : Continuous (fun u => atDensity r X y u) := by
unfold atDensity labelDensity gaussianPDFReal applyRows
fun_prop
exact hc.log (fun u => (atDensity_pos hr X y u).ne')
lemma log_integral_ge {Ξ± : Type*} [MeasurableSpace Ξ±]
(ΞΌ : Measure Ξ±) [IsProbabilityMeasure ΞΌ] (v : Ξ± β β)
(hv : βα΅ x βΞΌ,0 < v x) (hvi : Integrable v ΞΌ)
(hvlog : Integrable (fun x => Real.log (v x)) ΞΌ)
{a : β} (ha : 0 < a) (hva : (β« x,v x βΞΌ) β€ a) :
(β« x,Real.log (v x) βΞΌ) β€ Real.log a := by
have hpoint : βα΅ x βΞΌ,Real.log (v x) β€ v x/a-1+Real.log a := by
filter_upwards [hv] with x hx
have h := Real.log_le_sub_one_of_pos (div_pos hx ha)
rw [Real.log_div hx.ne' ha.ne'] at h
linarith
have h := integral_mono_ae hvlog (((hvi.div_const a).sub (integrable_const 1)).add (integrable_const (Real.log a))) hpoint
have he : (β« x,v x/a-1+Real.log a βΞΌ) = (β« x,v x βΞΌ)/a-1+Real.log a := by
rw [integral_add (f := fun x => v x/a-1) (g := fun _ => Real.log a)
((hvi.div_const a).sub (integrable_const 1)) (integrable_const _),
integral_sub (f := fun x => v x/a) (g := fun _ => (1:β)) (hvi.div_const a) (integrable_const 1),
integral_div]
simp
change (β« x,Real.log (v x) βΞΌ) β€ (β« x,v x/a-1+Real.log a βΞΌ) at h
rw [he] at h
have hb : (β« x,v x βΞΌ)/a β€ 1 := (div_le_one ha).mpr hva
linarith
lemma local_log_lower {p d L : β} (hL : 0 < L) (Ξ½ Ο : Measure (Vec d))
[IsProbabilityMeasure Ξ½] [IsProbabilityMeasure Ο] {m : β} (hm : 0 < m)
(hdom : ENNReal.ofReal m β’ Ο β€ Ξ½)
(r : Fin L β β) (hr : β j,0 < r j) (X : Mat p d) (y : Fin p β β)
(s : Vec d) (R : β) (hs : βα΅ u βΟ,u β closedBall s R) (j : Fin L) :
Real.log m-Real.log L+(β« u,Real.log (atDensity (r j) X y u) βΟ) β€
Real.log (mixture Ξ½ r X y) := by
have hpos := integral_atDensity_pos Ο (hr j) X y
have hpoint : m*(β« u,atDensity (r j) X y u βΟ)/(L:β) β€ mixture Ξ½ r X y := by
have h := integral_mono_measure hdom
(Filter.Eventually.of_forall (fun u => (atDensity_pos (hr j) X y u).le))
(integrable_atDensity Ξ½ (hr j) X y)
rw [integral_smul_measure,ENNReal.toReal_ofReal hm.le,smul_eq_mul] at h
exact (div_le_div_of_nonneg_right h (by positivity)).trans (mixture_lower Ξ½ r hr X y j)
have hj := log_integral_ge Ο (atDensity (r j) X y)
(Filter.Eventually.of_forall (fun u => atDensity_pos (hr j) X y u))
(integrable_atDensity Ο (hr j) X y) (integrable_log_atDensity Ο (hr j) X y s R hs) hpos le_rfl
have hlog := Real.log_le_log (by positivity : 0 < m*(β« u,atDensity (r j) X y u βΟ)/(L:β)) hpoint
rw [Real.log_div (mul_ne_zero hm.ne' hpos.ne') (by positivity),Real.log_mul hm.ne' hpos.ne'] at hlog
linarith
noncomputable def energy {p d : β} (X : Mat p d) (v : Vec d) (e : Fin p β β) : β :=
β i,(applyRows X v i+e i)^2
noncomputable def matEnergy {p d : β} (X : Mat p d) : β := β i,β j,(X i j)^2
lemma energy_nonneg {p d : β} (X : Mat p d) (v : Vec d) (e : Fin p β β) :
0 β€ energy X v e := Finset.sum_nonneg (fun i _ => sq_nonneg (applyRows X v i+e i))
lemma matEnergy_nonneg {p d : β} (X : Mat p d) : 0 β€ matEnergy X :=
Finset.sum_nonneg (fun i _ => Finset.sum_nonneg (fun j _ => sq_nonneg (X i j)))
lemma energy_le {p d : β} (X : Mat p d) (v : Vec d) (e : Fin p β β) :
energy X v e β€ 2*matEnergy X*βvβ^2+2*β i,(e i)^2 := by
have hh (i : Fin p) : (applyRows X v i)^2 β€ (β j,(X i j)^2)*βvβ^2 := by
have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (X i) (fun j => v j)
dsimp [applyRows]
rw [EuclideanSpace.norm_sq_eq]
simpa using h
calc
_ β€ β i,(2*((β j,(X i j)^2)*βvβ^2)+2*(e i)^2) := by
apply Finset.sum_le_sum
intro i _
nlinarith [hh i,sq_nonneg (applyRows X v i-e i)]
_ = _ := by simp only [Finset.sum_add_distrib,β Finset.mul_sum,β Finset.sum_mul]; dsimp [matEnergy]; ring
lemma integrable_matEnergy {p d : β} :
Integrable (@matEnergy p d) (Measure.pi (fun _ : Fin p => scalarRow d)) := by
have : IsProbabilityMeasure (scalarRow d) := by unfold scalarRow; infer_instance
apply integrable_finsetSum
intro i _
apply integrable_finsetSum
intro j _
exact (((memLp_id_gaussianReal (2:NNReal)).comp_measurePreserving
(measurePreserving_eval (fun _ : Fin d => gaussianReal 0 1) j)).comp_measurePreserving
(measurePreserving_eval (fun _ : Fin p => scalarRow d) i)).integrable_sq
lemma integrable_energy_rows {p d : β} (v : Vec d) (e : Fin p β β) :
Integrable (fun X : Mat p d => energy X v e) (Measure.pi (fun _ : Fin p => scalarRow d)) := by
have : IsProbabilityMeasure (scalarRow d) := by unfold scalarRow; infer_instance
apply integrable_finsetSum
intro i _
exact (((row_memLp v).comp_measurePreserving
(measurePreserving_eval (fun _ : Fin p => scalarRow d) i)).add (memLp_const (e i))).integrable_sq
lemma energy_rows_le {p d : β} (v : Vec d) (e : Fin p β β) :
(β« X : Mat p d,energy X v e βMeasure.pi (fun _ : Fin p => scalarRow d)) β€
2*(p:β)*βvβ^2+2*β i,(e i)^2 := rows_shift_energy v e
lemma log_atDensity_shift {p d : β} {r : β} (hr : 0 < r) (X : Mat p d)
(s u : Vec d) (e : Fin p β β) :
Real.log (atDensity r X (applyRows X s+e) u) =
-(p:β)*Real.log r-(p:β)/2*Real.log (2*Real.pi)-energy X (s-u) e/(2*r^2) := by
rw [atDensity,log_labelDensity hr]
congr 2
unfold energy
apply Finset.sum_congr rfl
intro i _
rw [applyRows_sub]
simp only [Pi.add_apply,Pi.sub_apply]
ring
end ReferenceGaussian
end OAI
|