math / data /lean /OAI /Probability /SKGap /Localization /AttractionBasinIUnion.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
9.09 kB
import Mathlib
import OAI.Probability.SKGap.Localization.TapPotential
namespace OAI
section
noncomputable section
open scoped BigOperators
open Real Matrix Set Filter Function
open scoped Topology
namespace SKGap
section Basins
variable {X : Type*} [TopologicalSpace X] (T : X β†’ X)
lemma attractionBasin_eq_iUnion {p : X} {U : Set X} (hU : IsOpen U) (hp : p ∈ U)
(hatt : U βŠ† attractionBasin T p) :
attractionBasin T p = ⋃ k : β„•, (T^[k]) ⁻¹' U := by
ext x
constructor
Β· intro hx
have h := hx.eventually (hU.mem_nhds hp)
obtain ⟨k, hk⟩ := h.exists
exact mem_iUnion.mpr ⟨k, hk⟩
Β· intro hx
obtain ⟨k, hk⟩ := mem_iUnion.mp hx
exact (mem_attractionBasin_iterate_iff T p x k).mp (hatt hk)
lemma isOpen_attractionBasin (hT : Continuous T) {p : X} {U : Set X}
(hU : IsOpen U) (hp : p ∈ U) (hatt : U βŠ† attractionBasin T p) :
IsOpen (attractionBasin T p) := by
rw [attractionBasin_eq_iUnion T hU hp hatt]
exact isOpen_iUnion (fun k => hU.preimage (hT.iterate k))
lemma disjoint_attractionBasins [T2Space X] {p q : X} (hpq : p β‰  q) :
Disjoint (attractionBasin T p) (attractionBasin T q) := by
rw [disjoint_left]
intro x hx hy
exact hpq (tendsto_nhds_unique hx hy)
end Basins
theorem lyapunov_unique_fixed_point {X : Type*} [TopologicalSpace X] [CompactSpace X]
[ConnectedSpace X] [T2Space X]
(T : X β†’ X) (hT : Continuous T) (Ο† : X β†’ ℝ) (hΟ† : Continuous Ο†)
(hstrict : βˆ€ x, T x β‰  x β†’ Ο† (T x) < Ο† x)
(hattract : βˆ€ p, T p = p β†’ βˆƒ U : Set X, IsOpen U ∧ p ∈ U ∧
U βŠ† attractionBasin T p) : βˆƒ! p, T p = p := by
have hopen (p) (hp : T p = p) : IsOpen (attractionBasin T p) := by
obtain ⟨U, hU, hpU, hatt⟩ := hattract p hp
exact isOpen_attractionBasin T hT hU hpU hatt
have hcover (x : X) : βˆƒ p, T p = p ∧ x ∈ attractionBasin T p := by
let U := ⋃ p : {p // T p = p}, attractionBasin T p.val
have hU : IsOpen U := isOpen_iUnion (fun p => hopen p.val p.property)
have hfixed (p) (hp : T p = p) : p ∈ U :=
mem_iUnion.mpr ⟨⟨p, hp⟩, fixed_mem_attractionBasin T hp⟩
obtain ⟨k, hk⟩ := lyapunov_eventually_hits T hT Ο† hΟ† hstrict hU hfixed x
obtain ⟨p, hp⟩ := mem_iUnion.mp hk
exact ⟨p.val, p.property, (mem_attractionBasin_iterate_iff T p.val x k).mp hp⟩
obtain ⟨p, hp⟩ := lyapunov_fixed_point T Ο† hΟ† hstrict
refine ⟨p, hp, fun q hq => ?_⟩
by_contra hqp
let V := ⋃ q : {q // T q = q ∧ q β‰  p}, attractionBasin T q.val
have hV : IsOpen V := isOpen_iUnion (fun q => hopen q.val q.property.1)
have hdisj : Disjoint (attractionBasin T p) V := by
rw [disjoint_iUnion_right]
intro q
exact disjoint_attractionBasins T q.property.2.symm
have hcov : (univ : Set X) βŠ† attractionBasin T p βˆͺ V := by
intro x _
obtain ⟨r, hr, hx⟩ := hcover x
by_cases he : r = p
Β· subst r
exact Or.inl hx
· exact Or.inr (mem_iUnion.mpr ⟨⟨r, hr, he⟩, hx⟩)
have hconn := IsPreconnected.subset_or_subset (hopen p hp) hV hdisj hcov
isPreconnected_univ
rcases hconn with hconn | hconn
Β· have hqp' := tendsto_nhds_unique (hconn (mem_univ q))
(fixed_mem_attractionBasin T hq)
exact hqp hqp'.symm
Β· exact disjoint_left.mp hdisj (fixed_mem_attractionBasin T hp) (hconn (mem_univ p))
theorem local_contraction_attracts {X : Type*} [MetricSpace X]
{T : X β†’ X} {p : X} (hp : T p = p) {K : NNReal} (hK : K < 1)
{U : Set X} (hU : U ∈ 𝓝 p) (hlip : LipschitzOnWith K T U) :
βˆƒ V : Set X, IsOpen V ∧ p ∈ V ∧ V βŠ† attractionBasin T p := by
obtain ⟨Ρ, hΡ, hball⟩ := Metric.mem_nhds_iff.mp hU
have hpU : p ∈ U := hball (Metric.mem_ball_self hΡ)
have hmaps : MapsTo T (Metric.ball p Ξ΅) (Metric.ball p Ξ΅) := by
intro x hx
have h := hlip.dist_le_mul x (hball hx) p hpU
rw [hp] at h
exact h.trans_lt ((mul_le_of_le_one_left (dist_nonneg : 0 ≀ dist x p)
(show (K:ℝ) ≀ 1 by exact_mod_cast hK.le)).trans_lt hx)
refine ⟨Metric.ball p Ρ, Metric.isOpen_ball, Metric.mem_ball_self hΡ, ?_⟩
intro x hx
have hbd (n : β„•) : dist (T^[n] x) p ≀ (K:ℝ)^n * dist x p := by
induction n with
| zero => simp
| succ n ih =>
rw [iterate_succ_apply']
have h := hlip.dist_le_mul (T^[n] x) (hball (hmaps.iterate n hx)) p hpU
rw [hp] at h
exact h.trans (by simpa only [pow_succ', mul_assoc] using
mul_le_mul_of_nonneg_left ih K.coe_nonneg)
have ht := (tendsto_pow_atTop_nhds_zero_of_lt_one K.coe_nonneg
(show (K:ℝ) < 1 by exact_mod_cast hK)).mul_const (dist x p)
rw [zero_mul] at ht
exact Metric.tendsto_atTop.mpr (fun Ξ΄ hΞ΄ => by
obtain ⟨N, hN⟩ := eventually_atTop.mp (ht.eventually (gt_mem_nhds hδ))
exact ⟨N, fun n hn => (hbd n).trans_lt (hN n hn)⟩)
theorem strict_derivative_attracts {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
{T : E β†’ E} {p : E} {D : E β†’L[ℝ] E}
(hp : T p = p) (hD : HasStrictFDerivAt T D p) (hnorm : β€–Dβ€– < 1) :
βˆƒ U : Set E, IsOpen U ∧ p ∈ U ∧ U βŠ† attractionBasin T p := by
have hn : β€–Dβ€–β‚Š < 1 := by exact_mod_cast hnorm
obtain ⟨K, hDK, hK⟩ := exists_between hn
obtain ⟨U, hU, hlip⟩ := hD.exists_lipschitzOnWith_of_nnnorm_lt K hDK
exact local_contraction_attracts hp hK hU hlip
end SKGap
noncomputable section
open Set Function Real
open scoped Topology NNReal
namespace SKGap
section GradientDescent
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
theorem lipschitz_gradient_remainder {Ο† : E β†’ ℝ} {G : E β†’ E} {s : Set E}
(hs : Convex ℝ s) (hgrad : βˆ€ x ∈ s, HasFDerivAt Ο† (innerSL ℝ (G x)) x)
{L : ℝβ‰₯0} (hG : LipschitzOnWith L G s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
|Ο† y - Ο† x - inner ℝ (G x) (y-x)| ≀ (L:ℝ)*β€–y-xβ€–^2 := by
let d := y-x
let β„“ : ℝ →ᡃ[ℝ] E := AffineMap.lineMap x y
let f := fun t : ℝ => Ο† (β„“ t) - t * inner ℝ (G x) d
let f' := fun t : ℝ => inner ℝ (G (β„“ t) - G x) d
have hβ„“ (t : ℝ) : β„“ t = x + t β€’ d := by
simp only [β„“, d, AffineMap.lineMap_apply_module]
module
have hmem (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : β„“ t ∈ s :=
hs.mapsTo_lineMap hx hy ht
have hf (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) :
HasDerivWithinAt f (f' t) (Icc (0:ℝ) 1) t := by
have hd := ((hgrad (β„“ t) (hmem t ht)).comp_hasDerivAt t
AffineMap.hasDerivAt_lineMap).sub
((hasDerivAt_id t).mul_const (inner ℝ (G x) d))
convert! (hd.hasDerivWithinAt (s := Icc (0:ℝ) 1)) using 1
simp only [f', innerSL_apply_apply, inner_sub_left, d, one_mul]
have hb (t : ℝ) (ht : t ∈ Ico (0:ℝ) 1) :
β€–f' tβ€– ≀ (L:ℝ)*β€–dβ€–^2 := by
have hdiff : β€–β„“ t-xβ€– ≀ β€–dβ€– := by
rw [hβ„“, add_sub_cancel_left, norm_smul, Real.norm_eq_abs, abs_of_nonneg ht.1]
exact mul_le_of_le_one_left (norm_nonneg _) ht.2.le
have h := (hG.norm_sub_le (hmem t ⟨ht.1, ht.2.le⟩) hx).trans
(mul_le_mul_of_nonneg_left hdiff L.coe_nonneg)
calc
β€–f' tβ€– ≀ β€–G (β„“ t)-G xβ€–*β€–dβ€– := norm_inner_le_norm _ _
_ ≀ ((L:ℝ)*β€–dβ€–)*β€–dβ€– := mul_le_mul_of_nonneg_right h (norm_nonneg d)
_ = _ := by ring
have h := norm_image_sub_le_of_norm_deriv_le_segment_01' hf hb
simpa only [f, β„“, AffineMap.lineMap_apply_zero, AffineMap.lineMap_apply_one,
zero_mul, sub_zero, one_mul, Real.norm_eq_abs, d, sub_right_comm] using h
theorem gradient_step_strict_descent {Ο† : E β†’ ℝ} {G : E β†’ E} {s : Set E}
(hs : Convex ℝ s) (hgrad : βˆ€ x ∈ s, HasFDerivAt Ο† (innerSL ℝ (G x)) x)
{L : ℝβ‰₯0} (hG : LipschitzOnWith L G s) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅)
(hsmall : (L:ℝ)*Ξ΅ < 1) {x : E} (hx : x ∈ s) (hstep : x-Ξ΅ β€’ G x ∈ s)
(hGx : G x β‰  0) : Ο† (x-Ξ΅ β€’ G x) < Ο† x := by
have h := (le_abs_self _).trans (lipschitz_gradient_remainder hs hgrad hG hx hstep)
have he : x-Ξ΅ β€’ G x-x = -Ξ΅ β€’ G x := by module
rw [he, inner_smul_right, real_inner_self_eq_norm_sq,
norm_smul, Real.norm_eq_abs, abs_of_neg (neg_neg_of_pos hΞ΅)] at h
have hn : 0 < β€–G xβ€–^2 := sq_pos_of_pos (norm_pos_iff.mpr hGx)
have hc : 0 < Ξ΅*(1-(L:ℝ)*Ξ΅)*β€–G xβ€–^2 := by positivity
nlinarith only [h, hc]
theorem gradient_step_derivative_sq_bound {D : E β†’L[ℝ] E} {c M Ξ΅ : ℝ}
(_hc : 0 ≀ c) (_hM : 0 ≀ M) (hΞ΅ : 0 ≀ Ξ΅)
(hcoercive : βˆ€ v, c*β€–vβ€–^2 ≀ inner ℝ v (D v)) (hbound : β€–Dβ€– ≀ M)
(v : E) :
β€–v-Ξ΅ β€’ D vβ€–^2 ≀ (1-2*Ξ΅*c+Ξ΅^2*M^2)*β€–vβ€–^2 := by
have hD : β€–D vβ€– ≀ M*β€–vβ€– := D.le_of_opNorm_le hbound v
have hD2 : β€–D vβ€–^2 ≀ M^2*β€–vβ€–^2 := by
nlinarith [norm_nonneg (D v), mul_nonneg _hM (norm_nonneg v)]
have h := mul_le_mul_of_nonneg_left (hcoercive v) (show 0 ≀ 2*Ξ΅ by positivity)
have h' := mul_le_mul_of_nonneg_left hD2 (sq_nonneg Ξ΅)
rw [norm_sub_sq_real, inner_smul_right, norm_smul, Real.norm_eq_abs,
abs_of_nonneg hΞ΅]
nlinarith only [h, h']
end GradientDescent
end SKGap
end
end
end
end OAI