math / data /lean /OAI /Probability /Perceptron /Sphere /SphereLimit.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
14.9 kB
import Mathlib
import OAI.Probability.Perceptron.Variational.ShellBridge
namespace OAI
noncomputable section
open MeasureTheory ProbabilityTheory Filter Set
open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction
namespace SphericalPerceptronFreeEnergy
def normalizedCoordinateSphereLog (n k : β„•) (Οƒ : β„• β†’ ℝ)
(p : (Fin (n+1) β†’ ℝ) Γ— DecoratedCascade (Fin (n+1) β†’ ℝ) k) : ℝ :=
coordinateAngularLog n k Οƒ (Real.sqrt (n+1:β„•)) ((fun i _ => p.1 i),p.2) / ((n+1:β„•):ℝ)
def expectedCoordinateSphereLog (n k : β„•) (Οƒ : β„• β†’ ℝ) (z : Fin k β†’ ℝ) (r : ℝβ‰₯0) : ℝ :=
∫ p, normalizedCoordinateSphereLog n k Οƒ p βˆ‚coordinateCascadeLaw (n+1) k z r
lemma normalizedCoordinateSphereLog_measurable (n k : β„•) (Οƒ : β„• β†’ ℝ) :
Measurable (normalizedCoordinateSphereLog n k Οƒ) := by
have hm := (coordinateAngularLog_measurable n k Οƒ (Real.sqrt (n+1:β„•))).comp
(show Measurable (fun p : (Fin (n+1) β†’ ℝ) Γ— DecoratedCascade (Fin (n+1) β†’ ℝ) k =>
((fun (i : Fin (n+1)) (_ : β„•) => p.1 i),p.2)) from by fun_prop)
exact hm.div_const _
lemma normalizedCoordinateSphereLog_integrable (n k : β„•) (Οƒ : β„• β†’ ℝ) {b : ℝ}
(z : Fin k β†’ ℝ) (hz : StrictMono z) (hz0 : βˆ€ i, 0 < z i) (hz1 : βˆ€ i, z i < 1)
(hp : 0 < quadraticCascadePrecision Οƒ b k z) (r : ℝβ‰₯0) :
Integrable (normalizedCoordinateSphereLog n k Οƒ) (coordinateCascadeLaw (n+1) k z r) :=
(coordinateAngularLog_integrable n k Οƒ (Real.sqrt (n+1:β„•)) z hz hz0 hz1 hp r).div_const _
lemma normalizedCoordinateSphereLog_nonneg (n k : β„•) (Οƒ : β„• β†’ ℝ) {b : ℝ}
(z : Fin k β†’ ℝ) (hz : StrictMono z) (hz0 : βˆ€ i, 0 < z i) (hz1 : βˆ€ i, z i < 1)
(hp : 0 < quadraticCascadePrecision Οƒ b k z) (r : ℝβ‰₯0) :
0 ≀ᡐ[coordinateCascadeLaw (n+1) k z r] normalizedCoordinateSphereLog n k Οƒ := by
have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le Οƒ b k z (fun i => (hz0 i).le))
filter_upwards [canonicalCoordinateBase_pos (n+1) k Οƒ z hz hz0 hz1 r,
canonicalCoordinateTotal_pos (n+1) k Οƒ b z hz hz0 hz1 hp r] with p h0 hc
exact div_nonneg (coordinateAngularLog_regular n k Οƒ _ hb _ h0 hc).2.1 (by positivity)
lemma expectedCoordinateSphereLog_upper (n k : β„•) (Οƒ : β„• β†’ ℝ) {b Ξ΅ : ℝ}
(z : Fin k β†’ ℝ) (hz : StrictMono z) (hz0 : βˆ€ i, 0 < z i) (hz1 : βˆ€ i, z i < 1)
(hp : 0 < quadraticCascadePrecision Οƒ b k z) (r : ℝβ‰₯0)
(hΞ΅ : 0 ≀ Ξ΅) (hΞ΅1 : Ξ΅ ≀ 1)
(hm : 0 < (canonicalRadialMass n b).real (normSquareBand n Ξ΅)) :
expectedCoordinateSphereLog n k Οƒ z r ≀
(1+Ξ΅)*canonicalGaussianFreeValue Οƒ k z r b-
Real.log ((canonicalRadialMass n b).real (normSquareBand n Ξ΅))/((n+1:β„•):ℝ)+
Ξ΅*(Real.log b/2+2*b) := by
let ΞΌ := coordinateCascadeLaw (n+1) k z r
let C := fun p : (Fin (n+1) β†’ ℝ) Γ— DecoratedCascade (Fin (n+1) β†’ ℝ) k =>
canonicalCoordinateLog (n+1) k Οƒ b ((fun i _ => p.1 i),p.2)
let M := Real.log ((canonicalRadialMass n b).real (normSquareBand n Ξ΅))
let d : ℝ := n+1
have hd : 0 < d := by dsimp [d]; positivity
have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le Οƒ b k z (fun i => (hz0 i).le))
have hi : Integrable C ΞΌ := (canonical_coordinate_joint_mean (n+1) Οƒ b k z hz hz0 hz1 hp r).1
have he : (∫ p, C p βˆ‚ΞΌ) = d*canonicalGaussianFreeValue Οƒ k z r b := by
simpa [d,C,ΞΌ,coordinateCascadeLaw] using (canonical_coordinate_joint_mean (n+1) Οƒ b k z hz hz0 hz1 hp r).2
have hni := normalizedCoordinateSphereLog_integrable n k Οƒ z hz hz0 hz1 hp r
have hbi : Integrable (fun p => (1+Ξ΅)*C p/d-M/d+Ξ΅*(Real.log b/2+2*b)) ΞΌ :=
(((hi.const_mul (1+Ξ΅)).div_const d).sub (integrable_const _)).add (integrable_const _)
have hlo : βˆ€α΅ p βˆ‚ΞΌ, normalizedCoordinateSphereLog n k Οƒ p ≀
(1+Ξ΅)*C p/d-M/d+Ξ΅*(Real.log b/2+2*b) := by
filter_upwards [canonicalCoordinateBase_pos (n+1) k Οƒ z hz hz0 hz1 r,
canonicalCoordinateTotal_pos (n+1) k Οƒ b z hz hz0 hz1 hp r] with p h0 hc
have hraw := canonicalCoordinate_unitSphere_upper n k Οƒ hb hΞ΅ hΞ΅1 _ h0 hc hm
have hh := div_le_div_of_nonneg_right hraw hd.le
have heq : ((1+Ξ΅)*C p-M+Ξ΅*((n+1:β„•):ℝ)*(Real.log b/2+2*b))/d =
(1+Ξ΅)*C p/d-M/d+Ξ΅*(Real.log b/2+2*b) := by
dsimp only [d]
push_cast
field_simp
change coordinateAngularLog n k Οƒ (Real.sqrt (n+1:β„•)) ((fun i _ => p.1 i),p.2)/d ≀
((1+Ξ΅)*C p-M+Ξ΅*((n+1:β„•):ℝ)*(Real.log b/2+2*b))/d at hh
rw [heq] at hh
simpa only [normalizedCoordinateSphereLog,d,Nat.cast_add,Nat.cast_one] using hh
have hh := integral_mono_ae hni hbi hlo
have hcalc : (∫ p, (1+Ξ΅)*C p/d-M/d+Ξ΅*(Real.log b/2+2*b) βˆ‚ΞΌ) =
(1+Ξ΅)*canonicalGaussianFreeValue Οƒ k z r b-M/d+Ξ΅*(Real.log b/2+2*b) := by
rw [integral_add (f := fun p => (1+Ξ΅)*C p/d-M/d)
(g := fun _ => Ξ΅*(Real.log b/2+2*b))
(((hi.const_mul (1+Ξ΅)).div_const d).sub (integrable_const (M/d)))
(integrable_const (Ξ΅*(Real.log b/2+2*b))),
integral_sub (f := fun p => (1+Ξ΅)*C p/d) (g := fun _ => M/d)
((hi.const_mul (1+Ξ΅)).div_const d) (integrable_const (M/d)),
integral_div,integral_const_mul,he]
simp only [integral_const,probReal_univ,one_smul]
field_simp
rw [hcalc] at hh
simpa [expectedCoordinateSphereLog,M,d] using hh
lemma expectedCoordinateSphereLog_upper_eventually (k : β„•) (Οƒ : β„• β†’ ℝ) {b Ξ΅ : ℝ}
(z : Fin k β†’ ℝ) (hz : StrictMono z) (hz0 : βˆ€ i, 0 < z i) (hz1 : βˆ€ i, z i < 1)
(hp : 0 < quadraticCascadePrecision Οƒ b k z) (r : ℝβ‰₯0) (hΞ΅ : 0 < Ξ΅) (hΞ΅1 : Ξ΅ < 1) :
βˆ€αΆ  n : β„• in atTop, expectedCoordinateSphereLog n k Οƒ z r ≀
canonicalGaussianFreeValue Οƒ k z r b+(b-1)/2+
Ξ΅*(canonicalGaussianFreeValue Οƒ k z r b+Real.log b/2+2*b+|1-b|/2)+
Real.log 2/((n+1:β„•):ℝ) := by
have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le Οƒ b k z (fun i => (hz0 i).le))
filter_upwards [canonicalRadial_band_eventually_half hΞ΅ hΞ΅1] with n hn
have hm := (canonicalRadial_band_mass_bounds n hb hn).1
have hmp : 0 < (canonicalRadialMass n b).real (normSquareBand n Ξ΅) :=
(by positivity : 0 < Real.exp (((n+1:β„•):ℝ)*((1-b)/2-|1-b| * Ξ΅/2))/2).trans_le hm
have hu := expectedCoordinateSphereLog_upper n k Οƒ z hz hz0 hz1 hp r hΞ΅.le hΞ΅1.le hmp
have hl := (canonicalRadial_band_log_bounds n hb hn).1
linarith
lemma normalizedCoordinateSphereLog_lower_probability (k : β„•) (Οƒ : β„• β†’ ℝ)
(z : Fin k β†’ ℝ) (hz : StrictMono z) (hz0 : βˆ€ i, 0 < z i) (hz1 : βˆ€ i, z i < 1)
(r : ℝβ‰₯0) (b : ℝ) (hp : 0 < quadraticCascadePrecision Οƒ b k z)
(hstat : -1/(2*b)+quadraticCascadeReciprocalSlope Οƒ b k z-
(r:ℝ)/(2*(quadraticCascadePrecision Οƒ b k z)^2) = -1/2)
{Ξ΅ a : ℝ} (hΞ΅ : 0 < Ξ΅) (hΞ΅1 : Ξ΅ < 1)
(ha : a < canonicalGaussianFreeValue Οƒ k z r b+(b-1)/2-
Ξ΅*(canonicalGaussianFreeValue Οƒ k z r b+Real.log b/2+2*b+|1-b|/2)) :
Tendsto (fun n : β„• => (coordinateCascadeLaw (n+1) k z r).real
{p | a ≀ normalizedCoordinateSphereLog n k Οƒ p}) atTop (𝓝 1) := by
let C := canonicalGaussianFreeValue Οƒ k z r b
let K := Real.log b/2+2*b
let L := C+(b-1)/2-Ξ΅*(C+K+|1-b|/2)
let Ξ΄ := L-a
have hΞ΄ : 0 < Ξ΄ := by
apply sub_pos.mpr
simpa [L,C,K,add_assoc] using ha
let ΞΌ := fun n => coordinateCascadeLaw (n+1) k z r
let F := fun n (p : (Fin (n+1) β†’ ℝ) Γ— DecoratedCascade (Fin (n+1) β†’ ℝ) k) =>
canonicalCoordinateLog (n+1) k Οƒ b ((fun i _ => p.1 i),p.2)
let B := fun n => {p : (Fin (n+1) β†’ ℝ) Γ— DecoratedCascade (Fin (n+1) β†’ ℝ) k |
(canonicalCoordinateBandTotalE n k Οƒ b Ξ΅ ((fun i _ => p.1 i),p.2)).toReal <
decoratedTerminalTotal (canonicalCoordinateStep (n+1) Οƒ)
(canonicalCoordinatePotential (n+1) b) k ((fun i _ => p.1 i),p.2)/2}
let D := fun n => {p : (Fin (n+1) β†’ ℝ) Γ— DecoratedCascade (Fin (n+1) β†’ ℝ) k |
(Ξ΄/2)*((n+1:β„•):ℝ) ≀ |F n p-((n+1:β„•):ℝ)*C|}
have hB : Tendsto (fun n => ΞΌ n (B n)) atTop (𝓝 0) :=
canonicalCoordinate_bad_half_band_tendsto_zero k Οƒ z hz hz0 hz1 r b hp hstat hΞ΅
have hD : Tendsto (fun n => ΞΌ n (D n)) atTop (𝓝 0) :=
(canonical_coordinate_converges Οƒ b k z hz hz0 hz1 hp r (half_pos hΞ΄)).comp
(tendsto_add_atTop_nat 1)
have hsum := hB.add hD
simp only [add_zero] at hsum
have ht : Tendsto (fun n : β„• => Real.log 2/((n+1:β„•):ℝ)) atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1))
have hev : βˆ€αΆ  n : β„• in atTop, Real.log 2/((n+1:β„•):ℝ) < Ξ΄/2 :=
ht.eventually (gt_mem_nhds (half_pos hΞ΄))
have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le Οƒ b k z (fun i => (hz0 i).le))
have hbad : Tendsto (fun n => ΞΌ n {p | normalizedCoordinateSphereLog n k Οƒ p < a}) atTop (𝓝 0) := by
apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hsum
(Eventually.of_forall (fun _ => bot_le))
filter_upwards [hev,canonicalRadial_band_eventually_half hΞ΅ hΞ΅1] with n hn hhalf
apply le_trans (measure_mono_ae (t := B n βˆͺ D n) ?_) (measure_union_le _ _)
filter_upwards [canonicalCoordinateBase_pos (n+1) k Οƒ z hz hz0 hz1 r,
canonicalCoordinateTotal_pos (n+1) k Οƒ b z hz hz0 hz1 hp r] with p h0 hc
intro hbad
by_cases hpB : p ∈ B n
Β· exact Or.inl hpB
Β· right
by_contra hpD
have hm := (canonicalRadial_band_mass_bounds n hb hhalf).1
have hmp : 0 < (canonicalRadialMass n b).real (normSquareBand n Ξ΅) :=
(by positivity : 0 < Real.exp (((n+1:β„•):ℝ)*((1-b)/2-|1-b| * Ξ΅/2))/2).trans_le hm
have hu := (canonicalRadial_band_log_bounds n hb hhalf).2
have hraw := canonicalCoordinate_unitSphere_lower n k Οƒ hb hΞ΅.le hΞ΅1.le _ h0 hc hmp
(le_of_not_gt hpB)
have hd : 0 < ((n+1:β„•):ℝ) := by positivity
have hlow := (div_le_div_of_nonneg_right hraw hd.le)
have herr : |F n p-((n+1:β„•):ℝ)*C| < (Ξ΄/2)*((n+1:β„•):ℝ) := not_le.mp hpD
have herr' : C-Ξ΄/2 < F n p/((n+1:β„•):ℝ) := by
apply (lt_div_iffβ‚€ hd).mpr
have hh := (abs_lt.mp herr).1
nlinarith
have he : ((1-Ξ΅)*F n p-Real.log 2-
Real.log ((canonicalRadialMass n b).real (normSquareBand n Ξ΅))-
Ξ΅*((n+1:β„•):ℝ)*K)/((n+1:β„•):ℝ) =
(1-Ξ΅)*(F n p/((n+1:β„•):ℝ))-Real.log 2/((n+1:β„•):ℝ)-
Real.log ((canonicalRadialMass n b).real (normSquareBand n Ξ΅))/((n+1:β„•):ℝ)-Ξ΅*K := by
field_simp
change ((1-Ξ΅)*F n p-Real.log 2-
Real.log ((canonicalRadialMass n b).real (normSquareBand n Ξ΅))-
Ξ΅*((n+1:β„•):ℝ)*K)/((n+1:β„•):ℝ) ≀ normalizedCoordinateSphereLog n k Οƒ p at hlow
rw [he] at hlow
have hmule := mul_lt_mul_of_pos_left herr' (sub_pos.mpr hΞ΅1)
have haeq : a = L-Ξ΄ := by dsimp [Ξ΄]; ring
change normalizedCoordinateSphereLog n k Οƒ p < a at hbad
dsimp only [L] at haeq
nlinarith [mul_nonneg hΞ΅.le hΞ΄.le]
have hreal : Tendsto (fun n => (ΞΌ n).real {p | normalizedCoordinateSphereLog n k Οƒ p < a}) atTop (𝓝 0) := by
exact (ENNReal.tendsto_toReal (by simp : (0:ℝβ‰₯0∞) β‰  ⊀)).comp hbad
have hone : Tendsto (fun n => 1-(ΞΌ n).real {p | normalizedCoordinateSphereLog n k Οƒ p < a}) atTop (𝓝 1) := by
simpa using (tendsto_const_nhds (x := (1:ℝ))).sub hreal
convert hone using 1
ext n
have hmeas : MeasurableSet {p | normalizedCoordinateSphereLog n k Οƒ p < a} :=
measurableSet_lt (normalizedCoordinateSphereLog_measurable n k Οƒ) measurable_const
rw [← probReal_compl_eq_one_sub hmeas]
congr 1
ext p
simp only [mem_compl_iff,mem_ofPred_eq,not_lt]
lemma expectedCoordinateSphereLog_lower_eventually (k : β„•) (Οƒ : β„• β†’ ℝ)
(z : Fin k β†’ ℝ) (hz : StrictMono z) (hz0 : βˆ€ i, 0 < z i) (hz1 : βˆ€ i, z i < 1)
(r : ℝβ‰₯0) (b : ℝ) (hp : 0 < quadraticCascadePrecision Οƒ b k z)
(hstat : -1/(2*b)+quadraticCascadeReciprocalSlope Οƒ b k z-
(r:ℝ)/(2*(quadraticCascadePrecision Οƒ b k z)^2) = -1/2)
{Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) (hΞ΅1 : Ξ΅ < 1) :
βˆ€ a : ℝ, a < canonicalGaussianFreeValue Οƒ k z r b+(b-1)/2-
Ξ΅*(canonicalGaussianFreeValue Οƒ k z r b+Real.log b/2+2*b+|1-b|/2) β†’
βˆ€αΆ  n : β„• in atTop, a < expectedCoordinateSphereLog n k Οƒ z r := by
apply expected_eventually_gt_of_probability_lower
(fun n => coordinateCascadeLaw (n+1) k z r) (fun n => normalizedCoordinateSphereLog n k Οƒ)
(fun n => normalizedCoordinateSphereLog_integrable n k Οƒ z hz hz0 hz1 hp r)
(fun n => normalizedCoordinateSphereLog_nonneg n k Οƒ z hz hz0 hz1 hp r)
exact fun a ha => normalizedCoordinateSphereLog_lower_probability k Οƒ z hz hz0 hz1 r b hp hstat hΞ΅ hΞ΅1 ha
theorem expectedCoordinateSphereLog_tendsto (k : β„•) (Οƒ : β„• β†’ ℝ)
(z : Fin k β†’ ℝ) (hz : StrictMono z) (hz0 : βˆ€ i, 0 < z i) (hz1 : βˆ€ i, z i < 1)
(r : ℝβ‰₯0) (b : ℝ) (hp : 0 < quadraticCascadePrecision Οƒ b k z)
(hstat : -1/(2*b)+quadraticCascadeReciprocalSlope Οƒ b k z-
(r:ℝ)/(2*(quadraticCascadePrecision Οƒ b k z)^2) = -1/2) :
Tendsto (fun n : β„• => expectedCoordinateSphereLog n k Οƒ z r) atTop
(𝓝 (canonicalGaussianFreeValue Οƒ k z r b+(b-1)/2)) := by
let T := canonicalGaussianFreeValue Οƒ k z r b+(b-1)/2
let A := canonicalGaussianFreeValue Οƒ k z r b+Real.log b/2+2*b+|1-b|/2
let e := fun j : β„• => 1/((j+1:β„•):ℝ)
have he : Tendsto e atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1))
have he0 : βˆ€ j, 0 < e j := by intro j; dsimp [e]; positivity
have he1 : βˆ€αΆ  j in atTop, e j < 1 := he.eventually (gt_mem_nhds zero_lt_one)
have hl : Tendsto (fun j => T-e j*A) atTop (𝓝 T) := by
simpa using tendsto_const_nhds.sub (he.mul_const A)
have hu : Tendsto (fun j => T+e j*A) atTop (𝓝 T) := by
simpa using tendsto_const_nhds.add (he.mul_const A)
apply tendsto_order.mpr
constructor
Β· intro a ha
obtain ⟨j,hj1,hja⟩ := (he1.and (hl.eventually (lt_mem_nhds ha))).exists
exact expectedCoordinateSphereLog_lower_eventually k Οƒ z hz hz0 hz1 r b hp hstat (he0 j) hj1 a hja
Β· intro a ha
obtain ⟨j,hj1,hja⟩ := (he1.and (hu.eventually (gt_mem_nhds ha))).exists
have ht : Tendsto (fun n : β„• => T+e j*A+Real.log 2/((n+1:β„•):ℝ)) atTop (𝓝 (T+e j*A)) := by
have hh : Tendsto (fun n : β„• => Real.log 2/((n+1:β„•):ℝ)) atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1))
simpa using tendsto_const_nhds.add hh
filter_upwards [expectedCoordinateSphereLog_upper_eventually k Οƒ z hz hz0 hz1 hp r (he0 j) hj1,
ht.eventually (gt_mem_nhds hja)] with n hn hn'
exact hn.trans_lt hn'
end SphericalPerceptronFreeEnergy
end
end OAI