POPL 2012 Presentation

48
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

Transcript of POPL 2012 Presentation

Page 1: 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

Page 2: POPL 2012 Presentation

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

Page 3: POPL 2012 Presentation

Using a probabilistic program

Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 3 / 27

Page 4: POPL 2012 Presentation

Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 4 / 27

Page 5: POPL 2012 Presentation

Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 5 / 27

Page 6: POPL 2012 Presentation

P(A) = 3/4

Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 5 / 27

Page 7: POPL 2012 Presentation

P(A) = 3/4

how can we compute this?

Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 5 / 27

Page 8: POPL 2012 Presentation

Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 6 / 27

Page 9: POPL 2012 Presentation

P(A) =

∫A

f (x) dx

Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 7 / 27

Page 10: POPL 2012 Presentation

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

Page 11: POPL 2012 Presentation

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

Page 12: POPL 2012 Presentation

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

Page 13: POPL 2012 Presentation

A pdf may not exist!

Bhat et al. (Georgia Tech, NYU) A Type Theory for pdfs POPL 2012 10 / 27

Page 14: POPL 2012 Presentation

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

Page 15: POPL 2012 Presentation

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

Page 16: POPL 2012 Presentation

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

Page 17: POPL 2012 Presentation

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

Page 18: POPL 2012 Presentation

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

Page 19: POPL 2012 Presentation

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

Page 20: POPL 2012 Presentation

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

Page 21: POPL 2012 Presentation

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

Page 22: POPL 2012 Presentation

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

Page 23: POPL 2012 Presentation

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

Page 24: POPL 2012 Presentation

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

Page 25: POPL 2012 Presentation

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

Page 26: POPL 2012 Presentation

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

Page 27: POPL 2012 Presentation

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

Page 28: POPL 2012 Presentation

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

Page 29: POPL 2012 Presentation

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

Page 30: POPL 2012 Presentation

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

Page 31: POPL 2012 Presentation

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

Page 32: POPL 2012 Presentation

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

Page 33: POPL 2012 Presentation

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

Page 34: POPL 2012 Presentation

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

Page 35: POPL 2012 Presentation

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

Page 36: POPL 2012 Presentation

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

Page 37: POPL 2012 Presentation

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

Page 38: POPL 2012 Presentation

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

Page 39: POPL 2012 Presentation

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

Page 40: POPL 2012 Presentation

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

Page 41: POPL 2012 Presentation

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

Page 42: POPL 2012 Presentation

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

Page 43: POPL 2012 Presentation

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

Page 44: POPL 2012 Presentation

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

Page 45: POPL 2012 Presentation

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

Page 46: POPL 2012 Presentation

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

Page 47: POPL 2012 Presentation

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

Page 48: POPL 2012 Presentation

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