embedded probabilistic programming
play

Embedded probabilistic programming Oleg Kiselyov Chung-chieh Shan - PowerPoint PPT Presentation

Embedded probabilistic programming Oleg Kiselyov Chung-chieh Shan FNMOC Rutgers University oleg@pobox.com ccshan@cs.rutgers.edu 17 July 2009 Probabilistic inference Model (what) Inference (how) Prt


  1. Embedded probabilistic programming Oleg Kiselyov Chung-chieh Shan FNMOC Rutgers University oleg@pobox.com ccshan@cs.rutgers.edu 17 July 2009

  2. Probabilistic inference Model (what) Inference (how) Pr✭❘❡❛❧✐t②✮ ✾ ❂ Pr✭❖❜s ❥ ❘❡❛❧✐t②✮ ❀ Pr✭❘❡❛❧✐t② ❥ ❖❜s ❂ ♦❜s✮ ♦❜s Pr✭❖❜s ❂ ♦❜s ❥ ❘❡❛❧✐t②✮ Pr✭❘❡❛❧✐t②✮ Pr✭❖❜s ❂ ♦❜s✮ 2/14

  3. Declarative probabilistic inference Model (what) Inference (how) Pr✭❘❡❛❧✐t②✮ ✾ ❂ Pr✭❖❜s ❥ ❘❡❛❧✐t②✮ ❀ Pr✭❘❡❛❧✐t② ❥ ❖❜s ❂ ♦❜s✮ ♦❜s Pr✭❖❜s ❂ ♦❜s ❥ ❘❡❛❧✐t②✮ Pr✭❘❡❛❧✐t②✮ Pr✭❖❜s ❂ ♦❜s✮ 2/14

  4. Declarative probabilistic inference Model (what) Inference (how) invoke Toolkit distributions, (BNT, PFP) conditionalization, . . . Language random choice, interpret (BLOG, IBAL, observation, . . . Church) 2/14

  5. Declarative probabilistic inference Model (what) Inference (how) + use existing libraries, Toolkit + easy to add custom types, debugger (BNT, PFP) inference Language + random variables are + compile models for (BLOG, IBAL, ordinary variables faster inference Church) 2/14

  6. Declarative probabilistic inference Model (what) Inference (how) + use existing libraries, Toolkit + easy to add custom types, debugger (BNT, PFP) inference Language + random variables are + compile models for (BLOG, IBAL, ordinary variables faster inference Church) Today: invoke interpret Best of both Express models and inference as interacting programs in the same general-purpose language. 2/14

  7. Declarative probabilistic inference Model (what) Inference (how) + use existing libraries, Toolkit + easy to add custom types, debugger (BNT, PFP) inference Language + random variables are + compile models for (BLOG, IBAL, ordinary variables faster inference Church) Today: Payoff: expressive model Payoff: fast inference Best of both + models of inference : + deterministic parts of bounded-rational models run at full speed theory of mind + importance sampling Express models and inference as interacting programs in the same general-purpose language. 2/14

  8. Outline ◮ Expressivity Nested inference Implementation Reifying a model into a search tree Importance sampling with look-ahead Performance 3/14

  9. Pr✭❙t❛t❡ ✺ ❥ ❖❜s ✹ ❂ ✮ Hidden Markov model 0.7 0.4 0.4 0.4 0.4 0.4 0.4 0.7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0 1 2 3 4 5 6 7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 4/14

  10. Pr✭❙t❛t❡ ✺ ❥ ❖❜s ✹ ❂ ✮ Hidden Markov model 0.7 0.4 0.4 0.4 0.4 0.4 0.4 0.7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0 1 2 3 4 5 6 7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 1 6/7 1/7 5/7 2/7 4/7 3/7 3/7 4/7 2/7 5/7 1/7 6/7 1 L L R L R L R L R L R L R R 4/14

  11. Hidden Markov model 0.7 0.4 0.4 0.4 0.4 0.4 0.4 0.7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0 1 2 3 4 5 6 7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 1 6/7 1/7 5/7 2/7 4/7 3/7 3/7 4/7 2/7 5/7 1/7 6/7 1 L L R L R L R L R L R L R R 1/8 Pr✭❙t❛t❡ ✺ ❥ ❖❜s ✹ ❂ L ✮ L 4/14

  12. Hidden Markov model 0.7 0.4 0.4 0.4 0.4 0.4 0.4 0.7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0 1 2 3 4 5 6 7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 1 6/7 1/7 5/7 2/7 4/7 3/7 3/7 4/7 2/7 5/7 1/7 6/7 1 L L R L R L R L R L R L R R 2 1/8 0.3 3 0.4 Pr✭❙t❛t❡ ✺ ❥ ❖❜s ✹ ❂ L ✮ 3 0.3 4 L 3/7 0.3 3 4/14

  13. Hidden Markov model type state = int type obs = L | R let nstates = 8 0.7 0.4 0.4 0.4 0.4 0.4 0.4 0.7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0 1 2 3 4 5 6 7 0.3 0.3 0.3 0.3 0.3 0.3 0.3 1 6/7 1/7 5/7 2/7 4/7 3/7 3/7 4/7 2/7 5/7 1/7 6/7 1 L L R L R L R L R L R L R R 1/8 Pr✭❙t❛t❡ ✺ ❥ ❖❜s ✹ ❂ L ✮ L 4/14

  14. Hidden Markov model type state = int type obs = L | R let nstates = 8 let transition_prob = [| [(0.7,0); (0.3,1)]; ... |] let evolve : state -> state = fun st -> dist (transition_prob.(st)) let observe : state -> obs = fun st -> let p = float st /. float (nstates - 1) in dist [(1.-.p, L); (p, R)] let rec run = fun n obs -> let st = if n = 1 then uniform nstates else evolve (run (n - 1) obs) in obs st n; st run 5 (fun st n -> if n = 4 && observe st <> L then fail ()) Models are ordinary code (in OCaml) using a library function dist . 4/14

  15. Hidden Markov model type state = int type obs = L | R let nstates = 8 let transition_prob = [| [(0.7,0); (0.3,1)]; ... |] let evolve : state -> state = fun st -> dist (transition_prob.(st)) let observe : state -> obs = fun st -> let p = float st /. float (nstates - 1) in dist [(1.-.p, L); (p, R)] let rec run = fun n obs -> let st = if n = 1 then uniform nstates else evolve (run (n - 1) obs) in obs st n; st run 5 (fun st n -> if n = 4 && observe st <> L then fail ()) Models are ordinary code (in OCaml) using a library function dist . 4/14

  16. Hidden Markov model type state = int type obs = L | R let nstates = 8 let transition_prob = [| [(0.7,0); (0.3,1)]; ... |] let evolve : state -> state = fun st -> dist (transition_prob.(st)) let observe : state -> obs = fun st -> let p = float st /. float (nstates - 1) in dist [(1.-.p, L); (p, R)] let rec run = fun n obs -> let st = if n = 1 then uniform nstates else evolve (run (n - 1) obs) in obs st n; st run 5 (fun st n -> if n = 4 && observe st <> L then fail ()) Models are ordinary code (in OCaml) using a library function dist . 4/14

  17. Hidden Markov model type state = int type obs = L | R let nstates = 8 let transition_prob = [| [(0.7,0); (0.3,1)]; ... |] let evolve : state -> state = fun st -> dist (transition_prob.(st)) let observe : state -> obs = fun st -> let p = float st /. float (nstates - 1) in dist [(1.-.p, L); (p, R)] let rec run = fun n obs -> let st = if n = 1 then uniform nstates else evolve (run (n - 1) obs) in obs st n; st normalize (exact_reify (fun () -> run 5 (fun st n -> if n = 4 && observe st <> L then fail ()))) Models are ordinary code (in OCaml) using a library function dist . Inference applies to a thunk and returns a distribution. 4/14

  18. Hidden Markov model type state = int type obs = L | R let nstates = 8 let transition_prob = [| [(0.7,0); (0.3,1)]; ... |] let evolve : state -> state = fun st -> dist (transition_prob.(st)) let observe : state -> obs = fun st -> let p = float st /. float (nstates - 1) in dist [(1.-.p, L); (p, R)] let rec run = fun n obs -> let st = if n = 1 then uniform nstates else evolve (run (n - 1) obs) in obs st n; st normalize (exact_reify (fun () -> run 5 (fun st n -> if n = 4 && observe st <> L then fail ()))) Models are ordinary code (in OCaml) using a library function dist . Inference applies to a thunk and returns a distribution. Deterministic parts of models run at full speed. 4/14

  19. Models as programs in a general-purpose language Reuse existing infrastructure! ◮ Rich libraries: lists, arrays, database access, I/O, . . . ◮ Type inference ◮ Functions as first-class values ◮ Compiler ◮ Debugger ◮ Memoization Express Dirichlet processes , etc. (Goodman et al. 2008) Speed up inference using lazy evaluation bucket elimination sampling w/memoization (Pfeffer 2007) 5/14

  20. Hidden Markov model type state = int type obs = L | R let nstates = 8 let transition_prob = [| [(0.7,0); (0.3,1)]; ... |] let evolve : state -> state = fun st -> dist (transition_prob.(st)) let observe : state -> obs = fun st -> let p = float st /. float (nstates - 1) in dist [(1.-.p, L); (p, R)] let rec run = fun n obs -> let st = if n = 1 then uniform nstates else evolve (run (n - 1) obs) in obs st n; st normalize (exact_reify (fun () -> run 5 (fun st n -> if n = 4 && observe st <> L then fail ()))) 6/14

  21. Hidden Markov model type state = int type obs = L | R let nstates = 8 let transition_prob = [| [(0.7,0); (0.3,1)]; ... |] let evolve : state -> state = fun st -> dist (transition_prob.(st)) let observe : state -> obs = fun st -> let p = float st /. float (nstates - 1) in dist [(1.-.p, L); (p, R)] let rec run = fun n obs -> let st = if n = 1 then uniform nstates else evolve (run (n - 1) obs) in obs st n; st normalize (exact_reify (fun () -> run 5 (fun st n -> if n = 4 && observe st <> L then fail ()))) 6/14

  22. Hidden Markov model type state = int type obs = L | R let nstates = 8 let transition_prob = [| [(0.7,0); (0.3,1)]; ... |] let evolve : state -> state = fun st -> dist (transition_prob.(st)) let observe : state -> obs = fun st -> let p = float st /. float (nstates - 1) in dist [(1.-.p, L); (p, R)] let rec run = fun n obs -> let st = if n = 1 then uniform nstates else evolve (dist (exact_reify (fun () -> run (n - 1) obs))) in obs st n; st normalize (exact_reify (fun () -> run 5 (fun st n -> if n = 4 && observe st <> L then fail ()))) 6/14

  23. ♣ ♣ ✵ ✿ ✸ ♣ Self application: nested inference Choose a coin that is either fair or completely biased for true . let biased = flip 0.5 in let coin = fun () -> flip 0.5 || biased in 7/14

Recommend


More recommend