math / data /lean /OAI /Probability /Perceptron /Model.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
3.8 kB
import Mathlib
namespace OAI
noncomputable section
open MeasureTheory ProbabilityTheory Filter Set
open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction
namespace SphericalPerceptronFreeEnergy
abbrev Time := unitInterval
abbrev BrownianPath := C(ℝβ‰₯0, ℝ)
instance : MeasurableSpace BrownianPath := borel BrownianPath
instance : BorelSpace BrownianPath := ⟨rfl⟩
abbrev Spin (N : β„•) := EuclideanSpace ℝ (Fin N)
def patternCount (Ξ± : ℝ) (N : β„•) : β„• := ⌊α * (N : ℝ)βŒ‹β‚Š
abbrev Patterns (Ξ± : ℝ) (N : β„•) := Fin (patternCount Ξ± N) β†’ Fin N β†’ ℝ
def patternLaw (Ξ± : ℝ) (N : β„•) : Measure (Patterns Ξ± N) :=
Measure.pi fun _ => Measure.pi fun _ => gaussianReal 0 1
def unitSphereLaw (N : β„•) : Measure (Metric.sphere (0 : Spin N) 1) :=
let s := (volume : Measure (Spin N)).toSphere
(s Set.univ)⁻¹ β€’ s
def sphereLaw (N : β„•) : Measure (Spin N) :=
(unitSphereLaw N).map fun x => Real.sqrt (N : ℝ) β€’ x.val
def patternField {Ξ± : ℝ} {N : β„•} (g : Patterns Ξ± N)
(a : Fin (patternCount Ξ± N)) (x : Spin N) : ℝ :=
(βˆ‘ i : Fin N, g a i * x i) / Real.sqrt (N : ℝ)
def hamiltonian (Ξ± : ℝ) (Ο† : ℝ →ᡇ ℝ) (N : β„•) (g : Patterns Ξ± N)
(x : Spin N) : ℝ :=
βˆ‘ a : Fin (patternCount Ξ± N), Ο† (patternField g a x)
def pressure (Ξ± Ξ² : ℝ) (Ο† : ℝ →ᡇ ℝ) (N : β„•) (g : Patterns Ξ± N) : ℝ :=
Real.log (∫ x, Real.exp (Ξ² * hamiltonian Ξ± Ο† N g x) βˆ‚sphereLaw N) / (N : ℝ)
def expectedPressure (Ξ± Ξ² : ℝ) (Ο† : ℝ →ᡇ ℝ) (N : β„•) : ℝ :=
∫ g, pressure Ξ± Ξ² Ο† N g βˆ‚patternLaw Ξ± N
structure Trial where
toFun : Time β†’ ℝ
monotone : Monotone toFun
measurable : Measurable toFun
nonneg : βˆ€ t, 0 ≀ toFun t
le_one : βˆ€ t, toFun t ≀ 1
instance : CoeFun Trial (fun _ => Time β†’ ℝ) := ⟨Trial.toFun⟩
def timeLaw : Measure Time := Measure.comap Subtype.val volume
def tailIntegral (m : Trial) (t : Time) : ℝ :=
∫ s in Set.Ici t, m s βˆ‚timeLaw
def entropy (m : Trial) : ℝβ‰₯0∞ :=
(∫⁻ t, (ENNReal.ofReal (tailIntegral m t))⁻¹ -
(ENNReal.ofReal (1 - (t : ℝ)))⁻¹ βˆ‚timeLaw) / 2
def brownianEval (t : ℝβ‰₯0) (Ο‰ : BrownianPath) : ℝ := Ο‰ t
@[instance_reducible] def nullSigma (P : Measure BrownianPath) : MeasurableSpace BrownianPath :=
MeasurableSpace.generateFrom {s | P s = 0}
@[instance_reducible] def usualBrownianSigma (P : Measure BrownianPath) (t : Time) :
MeasurableSpace BrownianPath :=
β¨… s : {s : ℝβ‰₯0 // (t : ℝ) < s},
(⨆ r : {r : ℝβ‰₯0 // r ≀ s.val},
MeasurableSpace.comap (brownianEval r.val) (borel ℝ)) βŠ” nullSigma P
def Progressive (P : Measure BrownianPath) (v : Time β†’ BrownianPath β†’ ℝ) : Prop :=
βˆ€ t : Time,
@Measurable (Set.Iic t Γ— BrownianPath) ℝ
(MeasurableSpace.prod inferInstance (usualBrownianSigma P t)) (borel ℝ)
(fun p => v p.1.val p.2)
def controlCost (P : Measure BrownianPath) (m : Trial)
(v : Time β†’ BrownianPath β†’ ℝ) : ℝβ‰₯0∞ :=
∫⁻ Ο‰, ∫⁻ t, ENNReal.ofReal (m t * v t Ο‰ ^ 2) βˆ‚timeLaw βˆ‚P
def controlPayoff (P : Measure BrownianPath) (f : ℝ →ᡇ ℝ) (m : Trial)
(v : Time β†’ BrownianPath β†’ ℝ) : ℝ :=
(∫ Ο‰, f (brownianEval 1 Ο‰ + ∫ t, m t * v t Ο‰ βˆ‚timeLaw) βˆ‚P) -
(controlCost P m v).toReal / 2
def controlValue (P : Measure BrownianPath) (f : ℝ →ᡇ ℝ) (m : Trial) : ℝ :=
sSup {a | βˆƒ v : Time β†’ BrownianPath β†’ ℝ,
Progressive P v ∧ controlCost P m v < ∞ ∧ a = controlPayoff P f m v}
def variationalValue (P : Measure BrownianPath) (Ξ± Ξ² : ℝ) (Ο† : ℝ →ᡇ ℝ) : EReal :=
β¨… m : Trial, ((Ξ± * controlValue P (Ξ² β€’ Ο†) m : ℝ) : EReal) + (entropy m).toEReal
end SphericalPerceptronFreeEnergy
end
end OAI