POPL 2012 Presentation
-
Upload
agarwal1975 -
Category
Education
-
view
4.647 -
download
0
Transcript of POPL 2012 Presentation
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
Type system: refined strategy
var x ∼ random in return (2 ∗ x)
random“Well formed distribution?” YES
λx � return (2 ∗ x)“∀N , [[random]]({x | [[return(2∗x)]](N) 6=
0}) = 0?”
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 16 / 27
Type system: refined strategy
var x ∼ random in return (2 ∗ x)
random“Well formed distribution?” YES
λx � return (2 ∗ x)“∀N , [[random]]({x | [[return(2∗x)]](N) 6=
0}) = 0?” YES
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 16 / 27
Type system: refined strategy
var x ∼ random in return (2 ∗ x)
random“Well formed distribution?” YES
λx � return (2 ∗ x)“∀N , [[random]]({x | [[return(2∗x)]](N) 6=
0}) = 0?” YES
“Has a pdf?” YES too hard to mechanize
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 16 / 27
Type system: our strategy
All non-trivial distributions:
e :=
var x1 ∼ e1 in. . .
var xn ∼ en inreturn ε
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 17 / 27
Type system: our strategy
All non-trivial distributions:
e :=
var x1 ∼ e1 in. . .
var xn ∼ en inreturn ε
Inspect
the joint distribution of e1, ..., enthe RV transform, λ(x1, ..., xn) � ε
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 17 / 27
Type system: our strategy
var x ∼ random in return (2 ∗ x)
random
λx � 2 ∗ x
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 18 / 27
Type system: our strategy
var x ∼ random in return (2 ∗ x)
random“Has a pdf?”
λx � 2 ∗ x“Non-nullifying?”
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 18 / 27
Type system: our strategy
var x ∼ random in return (2 ∗ x)
random“Has a pdf?” YES
λx � 2 ∗ x“Non-nullifying?”
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 18 / 27
Type system: our strategy
var x ∼ random in return (2 ∗ x)
random“Has a pdf?” YES
λx � 2 ∗ x“Non-nullifying?” YES
“Has a pdf?”
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 18 / 27
Type system: our strategy
var x ∼ random in return (2 ∗ x)
random“Has a pdf?” YES
λx � 2 ∗ x“Non-nullifying?” YES
“Has a pdf?” YES
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 18 / 27
Intuition for nullifying function
e ′ := var x ∼ e in return (h x)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 19 / 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 20 / 27
Compiling pdfs to a usable form
usable: λx � x + 5,∫ 50 x2 dx
not usable:∫g dP, dP/dL
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 21 / 27
Compiling pdfs to a usable form
usable: λx � x + 5,∫ 50 x2 dx
not usable:∫g dP, dP/dL
δ ::= ε | λx : τ � δ | δ1 δ2 |
∫δ
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 21 / 27
pdf (uniform 3 5)
var u ∼ random in return (2∗u+3)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 22 / 27
pdf (uniform 3 5)
var u ∼ random in return (2∗u+3)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 23 / 27
pdf (uniform 3 5)
var u ∼ random in return (2∗u+3)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 24 / 27
What we get
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/2) ∗ 〈1 ≤ x ≤ 2〉+ (1/2) ∗ 〈3 ≤ x ≤ 5〉 ∗ (1/2)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 25 / 27
What we get
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/2) ∗ 〈1 ≤ x ≤ 2〉+ (1/2) ∗ 〈3 ≤ x ≤ 5〉 ∗ (1/2)
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 25 / 27
More in the paper
full measure-theoretic details
pdfs in spaces besides R
multivariate distributions
more examples
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 26 / 27
Future work
Conditional probability.[Borgstram et al. ESOP’11]
Implementation in Coq.
Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 27 / 27