func onal probabilis c programming cufp 2013
play

Func%onal Probabilis%c Programming CUFP 2013 Avi Pfeffer - PowerPoint PPT Presentation

Func%onal Probabilis%c Programming CUFP 2013 Avi Pfeffer Charles River Analy2cs apfeffer@cra.com Outline What is probabilistic programming? History Our Figaro language


  1. Func%onal ¡Probabilis%c ¡Programming ¡ CUFP ¡2013 ¡ Avi ¡Pfeffer ¡ Charles ¡River ¡Analy2cs ¡ apfeffer@cra.com ¡

  2. Outline Ÿ What is probabilistic programming? Ÿ History Ÿ Our Figaro language Ÿ Examples

  3. The Problem Ÿ Suppose you have some information Ÿ E.g., Brian ate pizza last night Ÿ You want to answer some questions based on this information Ÿ Is Brian a student? Ÿ Is Brian a programmer? Ÿ There is uncertainty in the answers 3

  4. Probabilistic Modeling Ÿ Create a joint probability distribution over the variables Ÿ P(Pizza, programmer, student) Ÿ Either directly or by learning it from data Ÿ Assert the evidence Ÿ Brian ate pizza Ÿ Use probabilistic inference to get the answer Ÿ P(student, programmer | pizza) 4

  5. Generative Models Ÿ Probabilistic models in which variables are generated in order Ÿ Later variables can depend on earlier variables Ÿ Large number of variants, e.g. Ÿ Bayesian networks Ÿ Hidden Markov models Ÿ Probabilistic context free grammars Ÿ Kalman filters Ÿ Probabilistic relational models 5

  6. Building Generative Models Developing a new model requires implementing Ÿ Representation Ÿ Inference algorithm Ÿ Learning algorithm Ÿ All three are significant challenges Ÿ Considered paper worthy Can ¡we ¡make ¡this ¡easier? ¡ 6

  7. Probabilistic Programming Systems Ÿ Expressive representation language Ÿ Capture wide variety of probabilistic models Ÿ Built-in inference and learning algorithms Ÿ Automatically apply to models written in the language 7

  8. Functional Probabilistic Programming Ÿ Ordinary functional language: an expression describes a computation that produces a value let student = true in let programmer = student in let pizza = student && programmer in (student, programmer, pizza) Ÿ Functional probabilistic programming language: an expression describes a random computation that produces a value let student = flip(0.7) in let programmer = if (student) flip(0.2) else flip(0.1) in let pizza = if (student && programmer) flip(0.9) else flip(0.3) in (student, programmer, pizza) 8

  9. Sampling Semantics let student = flip(0.7) in let programmer = if (student) flip(0.2) else flip(0.1) in let pizza = if (student && programmer) flip(0.9) else flip(0.3) in (student, programmer, pizza) Ÿ Imagine running this program many times Ÿ Each run generates a sample outcome Ÿ In each run, each outcome has some probability of being generated Ÿ The program defines a probability distribution over outcomes 9

  10. Power of Functional Probabilistic Programming Ÿ Turing complete language + probabilistic primitives Ÿ Naturally express wide range of probabilistic models Ÿ A number of general purpose algorithms have been developed Ÿ Structured variable elimination Ÿ Markov chain Monte Carlo Ÿ Importance sampling Ÿ Factor graph compilation 10

  11. Making Probabilistic Programming Practical Ÿ PPLs aim to “democratize” model building Ÿ One should not need extensive training in ML or AI to build and code a model Ÿ This means that a PPL should (broadly) satisfy two main goals: Ÿ Usability Ÿ Intuitive to use Ÿ Common design patterns easily expressed Ÿ Integration into other/existing applications Ÿ Extensible language Ÿ Extensible reasoning Ÿ Power Ÿ Ability to represent a wide variety of models, data, etc Ÿ Powerful and practical inference techniques 11

  12. History | KMP 97 Ÿ With Daphne Koller and David McAllester, we first formulated the idea of probabilistic programming Ÿ Lisp + flip Ÿ Convoluted inference algorithm Ÿ Later found to be buggy 12

  13. History | IBAL (2000-2007) Ÿ Representation Ÿ First practical probabilistic programming language Ÿ OCaml like syntax Ÿ Implemented in Ocaml Ÿ Inference Ÿ Exact inference using structured variable elimination Ÿ Later implemented intelligent importance sampling Ÿ Limitations Ÿ Hard to integrate with applications and data Ÿ No continuous variables 13

  14. History | Figaro (2009-Present) Ÿ Representation Ÿ Embedded DSL in Scala Ÿ Allows distributions over any data type Ÿ Highly expressive constraint system also allows it to express non- generative models Ÿ Inference Ÿ Extensible library of inference algorithms Ÿ Contains many of the most popular probabilistic inference algorithms, generalized to probabilistic programs Ÿ E.g., variable elimination, Metropolis-Hastings, particle filtering Ÿ New version to be released shortly Ÿ Parameter learning Ÿ Decision making Ÿ Improved algorithms 14

  15. Goals of the Figaro Language Ÿ Implement a PPL in a widely-used language Ÿ Scala is widely-used Ÿ Scala interoperability with Java also gives Figaro access to an even larger library Ÿ Provide a language to describe models with interacting components Ÿ Object-oriented Ÿ Provide a means to expressed directed and undirected models with general constraints Ÿ Functional Ÿ Extensibility and reuse of inference algorithms Ÿ Object-oriented, traits Ÿ Using Scala helps achieve all of these goals! 15

  16. Basic Figaro Concepts Ÿ Element[T] is class of probabilistic models over type T Ÿ Atomic elements Constant[T], Flip, Uniform, Geometric Ÿ Compound elements built out of other elements If(Flip(0.8), Constant(0.5), Uniform(0,1)) 16

  17. The Probability Monad Ÿ Constant[T] is the monadic unit Ÿ Chain[T,U] implements monadic bind Ÿ Use an Element[T] to generate T Ÿ Apply a function to the T to generate an Element[U] Ÿ Generate a U from the Element[U] Chain(Uniform(0,1), (d: Double) => Normal(d, 0.5)) Ÿ Apply[T,U] implements monadic fmap Apply(Uniform(0,1), (d: Double) => d * 2) Ÿ Most Figaro compound elements implemented using monad Ÿ E.g., If 17

  18. Conditions and Constraints Ÿ Any Element[T] can have conditions and constraints Ÿ Condition: function from T T to Boolean Ÿ Specifies a property that must be satisfied for a value to have positive probability Ÿ Constraint: function from T to Double Ÿ Weights probability of value Ÿ Two purposes Ÿ Asserting evidence Ÿ Specifying new kinds of models including undirected models 18

  19. Example 1: Probabilistic Processes on Graphs Ÿ Google’s PageRank is a model of a probabilistic process on a graph Ÿ Directed edge from page A to page B if A links to B Ÿ Consider a random walk starting at any point in the graph Ÿ What is the probability a node will be reached in n steps? 19

  20. Random Walk in Figaro Ÿ Start by defining some data structures for a webpage graph class Edge(from: Int, to: Int) class Node(ID: int, edges: Set[Edge]) class Graph(nodes: Set[Nodes]) { def get(id: Int) = // return Node with ID == id } // function that randomly builds a graph given some params def graphGenProcess(params*): Element[Graph] Ÿ Define some parameters of the random walk val numSteps: Element[Int] = Constant(10) val inputGraph: Element[Graph] = graphGenProcess(…) val startNode: Element[Int] = Uniform(inputGraph.nodes) 20

  21. Random Walk in Figaro // randomly move forward from a node def step(last: Int, g: Graph): Element[Int] = Uniform(g(last).edges.map(e => e.to)) val rWalk = Chain(inputGraph, numSteps, startNode, rFcn) def rFcn(g: Graph, remain: Int, n: Int): Element[List[Int]] = { if (remain == 1) Apply(step(n, g), (i: Int) => List(i)) else { val prev = rFcn(g, remain-1, n) val curr = step(Apply(prev, (l: List[Int]) => l.head), g) Apply(curr, prev, (i: Int, l: List[Int]) => I :: l) } } 21

  22. Example 2: Network Analysis Ÿ People smoke with probability 0.6 Ÿ Friends are 3 times as likely to have the same smoking habit than different Ÿ Alice is friends with Bob, Bob is friends with Clara Ÿ Alice smokes Ÿ What is the probability that Clara smokes? Want a general solution that works for any friends network

  23. Friends and Smokers | General Solution // A per person on smok mokes es wit ith h pr proba obabilit bility 0.6 0.6 clas lass Per erson on { val al smok mokes es = Flip lip(0.6) 0.6) } // Friends iends ar are e thr hree ee times imes as as lik likel ely to o ha have e the he same ame // smoking moking ha habit bit than han dif differ erent ent def def cons constraint aint(pair pair: : (Boolean, oolean, Boolean) oolean)) = if if (pair pair._1 ._1 == == pair pair._2 ._2) 3.0; 3.0; els else e 1.0 1.0 // Appl pply the he cons constraint aints to o all all pair pairs of of friends iends def def appl pplyCons onstraint aints(friends iends: : Lis List[Per erson] on]) { for or { (p1,p2 p1,p2) ) ← friends iends } { (p1.s p1.smok mokes es ^^ ^^ p2.s p2.smok mokes es). ).ad addC dCons onstraint aint(cons constraint aint) } } } }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend