Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

38
Practical Probabilistic Programming with Figaro Avi Pfeffer Charles River Analytics MLConf May 20, 2016

Transcript of Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Page 1: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Practical Probabilistic Programming with Figaro

Avi Pfeffer

Charles River Analytics

MLConf May 20, 2016

Page 2: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Why Probabilistic Programming? Figaro Examples and Applications Where We’re Going

Overview

Page 3: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

We want to Predict the future Infer past causes of current observations Learn from experience

With much less effort and expertise than before

What Are We Trying To Do?

Page 4: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Probabilistic Reasoning Lets You Do All These Things

Page 5: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Probabilistic Reasoning: Predicting the Future

Page 6: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Probabilistic Reasoning: Inferring Factors that Caused Observations

Page 7: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Probabilistic Reasoning: Using the Past to Predict the Future

Page 8: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Probabilistic Reasoning: Learning from the Past

Page 9: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

You need to Implement the representation

Implement the probabilistic inference algorithm

Implement the learning algorithm

Interact with data

Integrate with an application

But Probabilistic Reasoning Is Hard!

Page 10: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Drastically reduce the work to create probabilistic reasoning applications

Goal of Probabilistic Programming

Page 11: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

1. Expressive programming language for representing models2. General-purpose inference and learning algorithms apply to

models written in the language

All you have to do is represent the model in code and you automatically get the application

How Probabilistic Programming Achieves This

Page 12: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

It’s easy to incorporate rich domain knowledge into probabilistic programs

Probabilistic programming can work well even when you don’t have a lot of data

Probabilistic programming models are explainable and understandable

Probabilistic programming can predict outputs belonging to complex data types of variable size, like social networks

Probabilistic Programming Compared to Deep Learning

Page 13: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Why Probabilistic Programming? Figaro Examples and Applications Where We’re Going

Overview

Page 14: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Figaro goalsA probabilistic programming system that is: Easy to interact with data

Easy to integrate with applications

General and expressive representation to capture common programming patterns

An extensible library of inference algorithms

Page 15: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Figaro provides data structures to represent probabilistic programs

Scala programs construct the Figaro models

Inference algorithms implemented in Scala operate on these models

Figaro as a Scala Library

Page 16: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Easy interaction with data and integration with applications

Can embed general-purpose code in probabilistic programs

Can construct models programmatically

Figaro inherits functional and object-oriented features of Scala

Can use Scala functions to specify constraints

Scala supports extensible library of inference algorithms

Advantages of Scala Embedding

Page 17: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Hard to reason about models at source level, since arbitrary Scala code may be embedded in model

Syntax not as elegant as self-contained languages

Steeper learning curve You need to learn Scala and Figaro But we have found that beginners can easily learn to write models

quickly

We have found that the power and practicality of Figaro more than make up for these disadvantages

Disadvantages of Scala Embedding

Page 18: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Why Probabilistic Programming? Figaro Examples and Applications Where We’re Going

Overview

Page 19: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Figaro novices were able to quickly build up an integrated probabilistic reasoning application

Hydrological Terrain Modeling for Army Logistics

Page 20: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

We were able to perform a sophisticated analysis far better than our previous non-probabilistic method

Malware Lineage (DARPA Cyber Genome)

Parent Correct

Parent Precision

Parent Recall

Parent FMeasure

00.10.20.30.40.50.60.70.80.9

1New Algorithm

Old Algorithm With New Fea-tures

Phase I IV &V Result

Page 21: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Tracklet Merging (DARPA PPAML Challenge Problem)

0.3

0.2

0.5

0.3

0.2

0.5

0.7

0.2

0.1

0.7

0.2

0.1

=

We came up with a new algorithm that we would not have thought of without

probabilistic programming and expressed it in one slide

Page 22: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

class Tracklet( toCandidates: List[(Double, Tracklet)], fromCandidates: List[(Double, Tracklet)]){  val next = Select(toCandidates: _*)  val previous = Select(fromCandidates: _*)}

for (source <- sources) {  val nextPrevious = Chain(source.next, nextTracklet => nextTracklet.previous)  nextPrevious.observe(source)}

Tracklet Merging in Figaro

Page 23: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Why Probabilistic Programming? Figaro Examples and Applications Where We’re Going

Overview

Page 24: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

We’ve significantly reduced the effort required to build complex probabilistic reasoning applications

But it still requires a fair amount of machine learning expertise to make these applications work You need to know how to represent models You need to know how to choose and configure inference algorithms

Current State of the Art

Page 25: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

A probabilistic programming framework that domain experts with little or no machine learning knowledge can use

1. An English-like language for describing a domain2. A method for automatically filling in the gaps in a model3. Automated inference techniques that optimally choose and

configure algorithms for a particular problem

Our Goal

Page 26: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

1. Decompose an inference problem into many subproblems

2. Optimize the choice an appropriate solver for each subproblem

3. Combine the subproblem solutions into a solution of the whole problem

Automated Inference Strategy

Page 27: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Subproblems are represented as factor graphs

Factored algorithms are used to solve subproblems E.g., variable elimination, belief propagation, Gibbs sampling

We intelligently choose between the available algorithms on each subproblem

Structured Factored Inference (SFI)

Page 28: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Compiled Graphical Model of Figaro Program

aMUX

fbT fb

F

MUX

fcT fc

F

b c

x1bT x2b

T

y1bT y2b

T

x1bF x2b

F

y1bF y2b

F

x1cT x2c

T

y1cT y2c

T

x1cF x2c

F

y1cF y2c

F

Page 29: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Decompose Problem Automatically

aMUX

fbT fb

F

MUX

fcT fc

F

b c

x1bT x2b

T

y1bT y2b

T

x1bF x2b

F

y1bF y2b

F

x1cT x2c

T

y1cT y2c

T

x1cF x2c

F

y1cF y2c

F

Subproblems

Top level problem

Page 30: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Combine and Reuse Solutions

aMUX

fbT fb

F

MUX

fcT fc

F

b c

x1bT x2b

T

y1bT y2b

T

x1bF x2b

F

y1bF y2b

F

x1cT x2c

T

y1cT y2c

T

x1cF x2c

F

y1cF y2c

F

Subproblems

Top level problem

pT pF pT pF

Page 31: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Optimize Each Subproblem Individually

Results on a model structure used for medical diagnosis

Number of diseases

L 1 Err

or

Page 32: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

It’s easy to write probabilistic programs that define very large or even infinite factor graphs

32

Challenge

You can’t construct the factor graph

Page 33: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

We can solve problems with infinitely many variables Partially expand the problem

Quantify the effect of the unexpanded part of the program on the query Produces lower and upper bounds on answer to the query

As you expand more of the problem, the bounds get tighter

Lazy Inference

Page 34: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Grammar with Sentences of Unbounded Length

34

Page 35: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Grammar with Infinite Sentences

35

Page 36: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

Probabilistic reasoning helps you predict, infer, and learn

Probabilistic programming makes this much easier!

Figaro is a mature, practical probabilistic programming system with many applications

We’re striving to make probabilistic programming even easier!

Conclusion

Page 37: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

This material is based upon work supported by the United States Air Force under Contract No. FA8750-14-C-0011.

Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the United States Air Force.

Acknowledgement

Page 38: Avi Pfeffer, Principal Scientist, Charles River Analytics at MLconf SEA - 5/20/16

More Information• Figaro is open source

Contributions welcome! Releases can be downloaded from

www.cra.com/figaro Figaro source is on GitHub at

www.github.com/p2t2 Version 4.0 was released in March

• If you have any questions, feel free to contact me at [email protected]

39% discount code on Manning books: ctwmlconfsea