import OAI.Probability.GaussianRegression.Stream import OAI.Probability.GaussianRegression.Sphere namespace OAI /-! Spherical cap mass bounds along sequential routes. -/ open MeasureTheory ProbabilityTheory Set Filter open scoped ENNReal NNReal RealInnerProductSpace Topology open InnerProductSpace open scoped Pointwise noncomputable section universe u namespace NoiselessRegression section StreamCaps variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] variable {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] [Nonempty J] def capWeight (y : E) (ε : ℝ) : E → ℝ≥0∞ := (Metric.closedBall y ε).indicator (fun _ => 1) omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [Nontrivial E] in lemma measurable_capWeight (y : E) (ε : ℝ) : Measurable (capWeight y ε) := measurable_const.indicator Metric.isClosed_closedBall.measurableSet omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] in lemma capWeight_le_one (y s : E) (ε : ℝ) : capWeight y ε s ≤ 1 := by classical simp only [capWeight, Set.indicator_apply] split <;> simp lemma capWeight_mass (y : E) {ε : ℝ} (hε : 0 < ε) (a : ℕ) (ha : 2*a ≤ Module.finrank ℝ E - 1) : PolynomialMass ((ambientSphereLaw (E := E)).withDensity (capWeight y ε)) a (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) := by change PolynomialMass ((ambientSphereLaw (E := E)).withDensity ((Metric.closedBall y ε).indicator 1)) a _ rw [withDensity_indicator_one Metric.isClosed_closedBall.measurableSet] exact fun z r hr => terminal_cap_mass y z hε hr a ha lemma ambient_mass_bound {f : E → ℝ≥0∞} {a : ℕ} {C : ℝ≥0∞} (h : PolynomialMass ((ambientSphereLaw (E := E)).withDensity f) a C) : (∫⁻ s, f s ∂ambientSphereLaw) ≤ C := by rw [← setLIntegral_univ, ← withDensity_apply _ MeasurableSet.univ] apply (measure_mono_ae ?_).trans (by simpa using h 0 1 zero_lt_one) filter_upwards [(withDensity_absolutelyContinuous (ambientSphereLaw (E := E)) f).ae_le (ambientSphereLaw_ae_norm (E := E))] with s hs intro _ change dist s 0 ≤ 1 simp [dist_zero_right, hs] lemma continuation_cap_integral_bound {δ : ℕ → J → (E × ℝ) → J} (hδ : ∀ n j, Measurable (δ n j)) (y : ℕ → J → E) {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ Module.finrank ℝ E - 1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) (n k : ℕ) (j : J) : (∫⁻ s, continuation δ (fun n j => capWeight (y n j) ε) n k j s ∂ambientSphereLaw) ≤ (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) * streamFactor (E := E) (J := J) q ^ (k/q+1) := by apply ambient_mass_bound apply continuation_mass_bound _ hδ (fun n j => measurable_capWeight _ _) (fun n j s => capWeight_le_one _ _ _) (mul_ne_zero (by positivity) (by positivity)) (ENNReal.mul_ne_top ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top) (fun n j => capWeight_mass (y n j) hε a ha) (Module.finrank_pos (R := ℝ) (M := E)) (by omega) hq hqa lemma route_cap_bound {δ : ℕ → J → (E × ℝ) → J} (hδ : ∀ n j, Measurable (δ n j)) (y : J → E) {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ Module.finrank ℝ E - 1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) (k : ℕ) (j : J) : ((sphereLaw (E := E)).prod (Measure.pi (fun _ : Fin k => stdGaussian E))) {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} ≤ (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) * streamFactor (E := E) (J := J) q ^ (k/q+1) := by let w : ℕ → J → E → ℝ≥0∞ := fun _ j => capWeight (y j) ε have hV := measurable_continuation (w := w) hδ (fun _ j => measurable_capWeight (y j) ε) 0 k j have he (s : E) : continuation δ w 0 k j s = ∫⁻ A : Fin k → E, capWeight (y (streamRoute δ 0 k j (A,fun i => ⟪s,A i⟫))) ε s ∂Measure.pi (fun _ => stdGaussian E) := by simpa [w, blockValue, continuation] using continuation_unroll (w := w) hδ 0 k 0 j s let S : Set ((Metric.sphere (0 : E) 1) × (Fin k → E)) := {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} have hS : MeasurableSet S := by apply measurableSet_le _ measurable_const exact measurable_subtype_coe.comp measurable_fst |>.dist ((measurable_of_finite y).comp ((measurable_streamRoute hδ 0 k j).comp (by fun_prop))) change ((sphereLaw (E := E)).prod _) S ≤ _ rw [← one_mul (((sphereLaw (E := E)).prod _) S), ← lintegral_indicator_const hS 1, lintegral_prod _ (measurable_const.indicator hS).aemeasurable] have hf : ∀ s : Metric.sphere (0 : E) 1, (∫⁻ A, S.indicator (fun _ => (1 : ℝ≥0∞)) (s,A) ∂Measure.pi (fun _ => stdGaussian E)) = continuation δ w 0 k j s.val := by intro s rw [he] apply lintegral_congr intro A classical change (if dist s.val (y (streamRoute δ 0 k j (A,fun i => ⟪s.val,A i⟫))) ≤ ε then 1 else 0) = _ unfold capWeight rw [Set.indicator_apply] rfl simp_rw [hf] rw [← lintegral_map hV measurable_subtype_coe] exact continuation_cap_integral_bound hδ (fun _ => y) hε ha hq hqa 0 k j end StreamCaps end NoiselessRegression end end OAI