import Mathlib import OAI.Probability.Perceptron.Variational.GaussianLinearVariance namespace OAI noncomputable section open MeasureTheory ProbabilityTheory Filter Set open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction namespace SphericalPerceptronFreeEnergy lemma enrichedTerminal_C1 (n M : ℕ) (f : ℝ →ᵇ ℝ) (g : Fin M → Fin (n+1) → ℝ) (p : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (htop : ℝ) : ∃ D : EnrichedMark (n+1) (n+1) p → StrongDual ℝ (EnrichedMark (n+1) (n+1) p), Continuous D ∧ ∀ x, HasFDerivAt (enrichedTerminal n M f g p u htop) (D x) x := by let W := normalizedPatternEnergy (n+1) M f g let V := fun x : NormalizedSpin (n+1) => innerSL ℝ (sourceEnrichedFeature (n+1) p u x) have hW : Continuous W := (normalizedPatternEnergy_continuous (n+1) M f).comp (continuous_const.prodMk continuous_id) have hV : Continuous V := (innerSL ℝ).continuous.comp (enrichedFeature_continuous _ _ _ _ _) have hWB : ∀ x, |W x| ≤ (M:ℝ)*‖f‖ := normalizedPatternEnergy_bound _ _ _ _ have hVB : ∀ x, ‖V x‖ ≤ enrichedFeatureBound (n+1) u := fun x => by change ‖innerSL ℝ (sourceEnrichedFeature (n+1) p u x)‖ ≤ _ rw [innerSL_apply_norm,sourceEnrichedFeature_norm] refine ⟨vectorLogDerivative (unitSphereLaw (n+1)) W V, vectorLogDerivative_continuous (unitSphereLaw (n+1)) hW.measurable hV.measurable (enrichedFeatureBound (n+1) u).coe_nonneg hWB hVB,?_⟩ intro x exact (vectorLogPartition_hasFDerivAt (unitSphereLaw (n+1)) hW.measurable hV.measurable (enrichedFeatureBound (n+1) u).coe_nonneg hWB hVB x).sub_const _ lemma enrichedCascadeLog_fixed_patterns_variance (n M k : ℕ) (f : ℝ →ᵇ ℝ) (g : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0