math / data /lean /OAI /Probability /GaussianInformation /Kernel /ReferenceBounds.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.73 kB
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