A Type Theory for Probability Density Functions Sooraj Bhat Ashish Agarwal ⋆ Richard Vuduc Alexander Gray Georgia Institute of Technology ⋆ New York University POPL 2012 – January 27, 2012 Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 1 / 27
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
A Type Theory for ProbabilityDensity Functions
Sooraj Bhat Ashish Agarwal⋆
Richard Vuduc Alexander Gray
Georgia Institute of Technology⋆New York University
POPL 2012 – January 27, 2012
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 1 / 27
An example probabilistic program
var z ∼ flip (1/2) invar x1 ∼ uniform 1 2 invar x2 ∼ uniform 3 5 inreturn (if z then x1 else x2)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 2 / 27
Using a probabilistic program
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 3 / 27
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 4 / 27
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 5 / 27
P(A) = 3/4
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 5 / 27
P(A) = 3/4
how can we compute this?
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 5 / 27
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 6 / 27
P(A) =
∫A
f (x) dx
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 7 / 27
This is the probability density function (pdf).
P(A) =
∫A
f (x) dx
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 7 / 27
What we want
in:
var z ∼ flip (1/2) invar x1 ∼ uniform 1 2 invar x2 ∼ uniform 3 5 inreturn (if z then x1 else x2)
out:f(x) = 〈1 ≤ x ≤ 2〉 ∗ (1/2)
+ 〈3 ≤ x ≤ 5〉 ∗ (1/4)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 8 / 27
A pdf may not exist!
var z ∼ flip (1/2) invar x1 ∼ uniform 1 2 invar x2 ∼ return 4 inreturn (if z then x1 else x2)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 9 / 27
A pdf may not exist!
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 10 / 27
Contributions
First formal syntactic work on pdfs.
type system (“P has a pdf”)
compiler for calculating pdfs
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 11 / 27
Abstract syntax
base types τ ::= bool | Z | R | τ1 × τ2
expressions ε ::= x | l | op ε1...εn
| if ε1 then ε2 else ε3
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 12 / 27
Abstract syntax
base types τ ::= bool | Z | R | τ1 × τ2
expressions ε ::= x | l | op ε1...εn
| if ε1 then ε2 else ε3
types t ::= τ | dist τ
distributions e ::= random
| return ε
| var x ∼ e1 in e2
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 12 / 27
Abstract syntax
base types τ ::= bool | Z | R | τ1 × τ2
expressions ε ::= x | l | op ε1...εn
| if ε1 then ε2 else ε3
types t ::= τ | dist τ
distributions e ::= random
| return ε
| var x ∼ e1 in e2
programs p ::= pdf e
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 12 / 27
The power of return+bind
The probability monad [Giry ’82]
semantics [Ramsey & Pfeffer POPL’03]
verification [Audebaud & Paulin-Mohring MPC’06]
sampling [Park, Pfenning, Thrun POPL’05]
EDSLs [Erwig & Kollmansberger JFP’05, Kiselyov &
Shan ’09]
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 13 / 27
The power of return+bind+random
flip ε :=var u ∼ random inreturn (u ≤ ε)
uniform ε1 ε2 :=var u ∼ random inreturn ((ε2 − ε1) ∗ u + ε1)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 14 / 27
Type system: the obvious strategy
var x ∼ random in return (2 ∗ x)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 15 / 27
Type system: the obvious strategy
var x ∼ random in return (2 ∗ x)
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 15 / 27
Type system: the obvious strategy
var x ∼ random in return (2 ∗ x)
random
λx � return (2 ∗ x)
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 15 / 27
Type system: the obvious strategy
var x ∼ random in return (2 ∗ x)
random“Well formed distribution?”
λx � return (2 ∗ x)“Has a pdf, for all x?”
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 15 / 27
Type system: the obvious strategy
var x ∼ random in return (2 ∗ x)
random“Well formed distribution?” YES
λx � return (2 ∗ x)“Has a pdf, for all x?”
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 15 / 27
Type system: the obvious strategy
var x ∼ random in return (2 ∗ x)
random“Well formed distribution?” YES
λx � return (2 ∗ x)“Has a pdf, for all x?” NO
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 15 / 27
Type system: the obvious strategy
var x ∼ random in return (2 ∗ x)
random“Well formed distribution?” YES
λx � return (2 ∗ x)“Has a pdf, for all x?” NO
“Has a pdf?” NO too conservative
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 15 / 27
Type system: refined strategy
var x ∼ random in return (2 ∗ x)
random“Well formed distribution?” YES
λx � return (2 ∗ x)
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 16 / 27