Statistical programming with categorical measure theory and LazyPPL

Statistical programming with categorical measure theory & LazyPPL

Swaraj Dash, Younesse Kaddar, Hugo Paquet, Sam Staton

Statistical programming with categorical measure theory and LazyPPL

Probabilistic Programming

Bayes’ law

p(x∣d)⏟posterior∝p(d∣x)⏟likelihood×p(x)⏟prior\underbrace{p(x \mid d)}_{\mathrm{posterior}} \propto \underbrace{p(d \mid x)}_{\mathrm{likelihood}} × \underbrace{p(x)}_{\mathrm{prior}}

  • sample: prior
  • observe: likelihood, conditioning on the observed datapoints dd
  • infer/normalize: posterior, inference from effects (observations dd) to causes (parameters xx)
Statistical programming with categorical measure theory and LazyPPL

Demo

linear :: Prob (Double -> Double)
linear = do
  a <- normal 0 3
  b <- normal 0 3
  let f = \x -> a * x + b
  return f

regress :: Double -> Prob (a -> Double) -> [(a, Double)] -> Meas (a -> Double)
regress σ prior dataset = do
    f <- sample prior
    mapM_ (\(x, y) -> score $ normalPdf (f x) σ y) dataset
    return f
Statistical programming with categorical measure theory and LazyPPL

Semantically

center

Inference:

  • pick a parameter pp by sampling a point from the area under the curve of the weight function ll
  • use this parameter pp to determine a result r(p)r(p).
Statistical programming with categorical measure theory and LazyPPL

Problems

  • Meas\cal Meas not cartesian closed:

    • no function space like Double -> Double
  • Not known if there is a strong monad of measures

    • the category of s-finite kernels is distributive symmetric monoidal
    • but is it a Kleisli category?
Statistical programming with categorical measure theory and LazyPPL

Inverse Transform Sampling

Noise outsourcing lemma: The law of every Borel-valued random variable can be obtained as a pushforward of the uniform measure [0,1][0,1].

Given a parameterized probability distribution k:A→P(B)k:A → {\cal P} (B), there is a function f:A×[0,1]→Bf: A × [0, 1] → B such that for all aa,

k(a)=Df(a,u)where u∼U([0,1])k(a) \overset{\cal D}{=} f(a, u) \quad \text{where } u \sim {\cal U}([0, 1])

k(a) = do { u ← uniform 0 1; return f (a, p)
Statistical programming with categorical measure theory and LazyPPL

Quasi-Borel Spaces

  • ΩΩ: fixed uncountable standard Borel space

    • LazyPPL: infinite rose trees, with splitting γ:Ω≅Ω×Ωγ:Ω ≅ Ω × Ω
  • quasi-Borel space XX: set MX⊆XΩM_X ⊆ X^{Ω} of random elements

  • QbsQbs: cartesian closed, commutative monad of measures

    • LazyPPL: Prob vs Meas ⟶ two Kleisli categories
    • Laziness in program evaluation: monoidal category Kl(Prob)\cal Kl(\texttt{Prob}) has a terminal unit
Statistical programming with categorical measure theory and LazyPPL

Proba and Measure Kernels

  • Prob: Probability kernels f:X×Ω→Yf:X × Ω → Y modulo equivalence

    • Composition: X×Ω→X×γX×Ω×Ω→f×ΩY×Ω→gZX × Ω \xrightarrow {X × γ} X × Ω × Ω \xrightarrow {f × Ω} Y × Ω \xrightarrow {g} Z
    • Monad on QbsQbs: X↦XΩX ↦ X^Ω
  • Meas: Measure kernels [0,∞]←lX×Ω→fY[0, \infty] \xleftarrow{l} X × Ω \xrightarrow{f} Y mod equiv

    • Composition: compose the proba kernels, multiply the weights
    • Monad on QbsQbs: X↦(X×R)ΩX ↦ (X × ℝ)^Ω
Statistical programming with categorical measure theory and LazyPPL

Correspondence

Proba Categorical Proba Prob Prog
Spaces Objects Types
Proba kernels Morphisms Programs
Fubini’s theorem Interchange law / Commutativity Reordering lines
Marginalisation Semi-cartesianness / Affineness Discarding / Laziness
Statistical programming with categorical measure theory and LazyPPL

Demo