Bayes Nets: Sampling

Similar documents
CS 343: Artificial Intelligence

Bayes Net Representation. CS 188: Artificial Intelligence. Approximate Inference: Sampling. Variable Elimination. Sampling.

CS 188: Artificial Intelligence. Bayes Nets

Approximate Inference

Announcements. Inference. Mid-term. Inference by Enumeration. Reminder: Alarm Network. Introduction to Artificial Intelligence. V22.

Announcements. CS 188: Artificial Intelligence Fall Causality? Example: Traffic. Topology Limits Distributions. Example: Reverse Traffic

Bayes Nets III: Inference

qfundamental Assumption qbeyond the Bayes net Chain rule conditional independence assumptions,

Introduction to Artificial Intelligence (AI)

Intelligent Systems (AI-2)

Bayesian Networks BY: MOHAMAD ALSABBAGH

CS 188: Artificial Intelligence Spring Announcements

CS 188: Artificial Intelligence Spring Announcements

Bayes Nets: Independence

Informatics 2D Reasoning and Agents Semester 2,

Machine Learning for Data Science (CS4786) Lecture 24

CS 343: Artificial Intelligence

Stochastic Simulation

CS188 Outline. We re done with Part I: Search and Planning! Part II: Probabilistic Reasoning. Part III: Machine Learning

Bayes Networks. CS540 Bryan R Gibson University of Wisconsin-Madison. Slides adapted from those used by Prof. Jerry Zhu, CS540-1

Markov Networks.

Artificial Intelligence Bayes Nets: Independence

Sampling from Bayes Nets

CS 343: Artificial Intelligence

PROBABILISTIC REASONING SYSTEMS

CS 343: Artificial Intelligence

Sampling Rejection Sampling Importance Sampling Markov Chain Monte Carlo. Sampling Methods. Oliver Schulte - CMPT 419/726. Bishop PRML Ch.

Artificial Intelligence

CS 343: Artificial Intelligence

Hidden Markov Models. Vibhav Gogate The University of Texas at Dallas

CSE 473: Artificial Intelligence Probability Review à Markov Models. Outline

CSE 473: Artificial Intelligence

Machine Learning for Data Science (CS4786) Lecture 24

Reinforcement Learning Wrap-up

CSE 473: Ar+ficial Intelligence. Probability Recap. Markov Models - II. Condi+onal probability. Product rule. Chain rule.

CS 188: Artificial Intelligence

Bayesian Inference and MCMC

CS188 Outline. CS 188: Artificial Intelligence. Today. Inference in Ghostbusters. Probability. We re done with Part I: Search and Planning!

CSE 473: Ar+ficial Intelligence. Hidden Markov Models. Bayes Nets. Two random variable at each +me step Hidden state, X i Observa+on, E i

Our Status. We re done with Part I Search and Planning!

CSE 473: Artificial Intelligence

Sampling Rejection Sampling Importance Sampling Markov Chain Monte Carlo. Sampling Methods. Machine Learning. Torsten Möller.

CS 343: Artificial Intelligence

Bayesian Networks. Machine Learning, Fall Slides based on material from the Russell and Norvig AI Book, Ch. 14

Announcements. CS 188: Artificial Intelligence Fall Markov Models. Example: Markov Chain. Mini-Forward Algorithm. Example

Announcements. CS 188: Artificial Intelligence Spring Bayes Net Semantics. Probabilities in BNs. All Conditional Independences

CS 188: Artificial Intelligence Spring 2009

Stochastic inference in Bayesian networks, Markov chain Monte Carlo methods

CS 188: Artificial Intelligence. Our Status in CS188

CS 5522: Artificial Intelligence II

CSEP 573: Artificial Intelligence

CS 188: Artificial Intelligence Fall Recap: Inference Example

CS 188: Artificial Intelligence

MCMC and Gibbs Sampling. Kayhan Batmanghelich

Product rule. Chain rule

Sampling Methods. Bishop PRML Ch. 11. Alireza Ghane. Sampling Rejection Sampling Importance Sampling Markov Chain Monte Carlo

Probabilistic Models. Models describe how (a portion of) the world works

Markov Models and Hidden Markov Models

Sampling Algorithms for Probabilistic Graphical models

Probability. CS 3793/5233 Artificial Intelligence Probability 1

Announcements. CS 188: Artificial Intelligence Spring Probability recap. Outline. Bayes Nets: Big Picture. Graphical Model Notation

Probabilistic Graphical Models and Bayesian Networks. Artificial Intelligence Bert Huang Virginia Tech

Announcements. CS 188: Artificial Intelligence Fall VPI Example. VPI Properties. Reasoning over Time. Markov Models. Lecture 19: HMMs 11/4/2008

CSE 473: Ar+ficial Intelligence. Example. Par+cle Filters for HMMs. An HMM is defined by: Ini+al distribu+on: Transi+ons: Emissions:

27 : Distributed Monte Carlo Markov Chain. 1 Recap of MCMC and Naive Parallel Gibbs Sampling

CS 188: Artificial Intelligence Spring Announcements

Markov Networks. l Like Bayes Nets. l Graph model that describes joint probability distribution using tables (AKA potentials)

Hidden Markov Models. Hal Daumé III. Computer Science University of Maryland CS 421: Introduction to Artificial Intelligence 19 Apr 2012

Markov Models. CS 188: Artificial Intelligence Fall Example. Mini-Forward Algorithm. Stationary Distributions.

COMS 4771 Probabilistic Reasoning via Graphical Models. Nakul Verma

Our Status in CSE 5522

The Particle Filter. PD Dr. Rudolph Triebel Computer Vision Group. Machine Learning for Computer Vision

1 Probabilities. 1.1 Basics 1 PROBABILITIES

Stochastic Simulation

CSE 473: Ar+ficial Intelligence

Computer Vision Group Prof. Daniel Cremers. 14. Sampling Methods

Markov Networks. l Like Bayes Nets. l Graphical model that describes joint probability distribution using tables (AKA potentials)

CSE 473: Artificial Intelligence Autumn Topics

ˆ The exam is closed book, closed calculator, and closed notes except your one-page crib sheet.

The Ising model and Markov chain Monte Carlo

Reminder of some Markov Chain properties:

1 Probabilities. 1.1 Basics 1 PROBABILITIES

Inference in Bayesian Networks

Answers and expectations

Probabilistic Machine Learning

CS 5522: Artificial Intelligence II

CS 343: Artificial Intelligence

Computer Vision Group Prof. Daniel Cremers. 11. Sampling Methods

Markov chain Monte Carlo Lecture 9

CS 5522: Artificial Intelligence II

Outline. CSE 573: Artificial Intelligence Autumn Agent. Partial Observability. Markov Decision Process (MDP) 10/31/2012

CS 730/730W/830: Intro AI

Artificial Intelligence Bayesian Networks

April 20th, Advanced Topics in Machine Learning California Institute of Technology. Markov Chain Monte Carlo for Machine Learning

Results: MCMC Dancers, q=10, n=500

Outline. CSE 573: Artificial Intelligence Autumn Bayes Nets: Big Picture. Bayes Net Semantics. Hidden Markov Models. Example Bayes Net: Car

CS 188: Artificial Intelligence Fall 2008

CSEP 573: Artificial Intelligence

Bayesian networks. Independence. Bayesian networks. Markov conditions Inference. by enumeration rejection sampling Gibbs sampler

Bayesian networks: approximate inference

Transcription:

Bayes Nets: Sampling [These slides were created by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at http://ai.berkeley.edu.]

Approximate Inference: Sampling 2

Sampling Sampling is a lot like repeated simulation Predicting the weather, basketball games, Basic idea Draw N samples from a sampling distribution S Compute an approximate posterior probability Show this converges to the true probability P Why sample? Learning: get samples from a distribution you don t know Inference: getting a sample is faster than computing the right answer (e.g. with variable elimination) 3

Sampling Sampling from given distribution Step 1: Get sample u from uniform distribution over [0, 1) E.g. random() in python Step 2: Convert this sample u into an outcome for the given distribution by having each outcome associated with a sub-interval of [0,1) with sub-interval size equal to probability of the outcome Example C P(C) red 0.6 green 0.1 blue 0.3 If random() returns u = 0.83, then our sample is C = blue E.g, after sampling 8 times: 4

Sampling in Bayes Nets Prior Sampling Rejection Sampling Likelihood Weighting Gibbs Sampling 5

Prior Sampling 6

Prior Sampling +c 0.5 -c 0.5 Cloudy +c +s 0.1 -s 0.9 -c +s 0.5 -s 0.5 Sprinkler Rain +c +r 0.8 -r 0.2 -c +r 0.2 -r 0.8 +s +r +w 0.99 -w 0.01 -r +w 0.90 -w 0.10 -s +r +w 0.90 -w 0.10 -r +w 0.01 -w 0.99 WetGrass Samples: +c, -s, +r, +w -c, +s, -r, +w 7

Prior Sampling For i=1, 2,, n Sample x i from P(X i Parents(X i )) Return (x 1, x 2,, x n ) 8

Prior Sampling This process generates samples with probability: i.e. the BN s joint probability Let the number of samples of an event be Then I.e., the sampling procedure is consistent 9

Example We ll get a bunch of samples from the BN: +c, -s, +r, +w +c, +s, +r, +w S -c, +s, +r, -w +c, -s, +r, +w -c, -s, -r, +w If we want to know P(W) We have counts <+w:4, -w:1> Normalize to get P(W) = <+w:0.8, -w:0.2> This will get closer to the true distribution with more samples Can estimate anything else, too What about P(C +w)? P(C +r, +w)? P(C -r, -w)? Fast: can use fewer samples if less time (what s the drawback?) C W 10 R

Rejection Sampling 11

Rejection Sampling Let s say we want P(C) No point keeping all samples around Just tally counts of C as we go Let s say we want P(C +s) Same thing: tally C outcomes, but ignore (reject) samples which don t have S=+s This is called rejection sampling It is also consistent for conditional probabilities (i.e., correct in the limit) S C W R +c, -s, +r, +w +c, +s, +r, +w -c, +s, +r, -w +c, -s, +r, +w -c, -s, -r, +w 12

Rejection Sampling IN: evidence instantiation For i=1, 2,, n Sample x i from P(X i Parents(X i )) If x i not consistent with evidence Reject: Return, and no sample is generated in this cycle Return (x 1, x 2,, x n ) 13

Likelihood Weighting 14

Likelihood Weighting Problem with rejection sampling: If evidence is unlikely, rejects lots of samples Evidence not exploited as you sample Consider P(Shape blue) Shape Color pyramid, green pyramid, red sphere, blue cube, red sphere, green Idea: fix evidence variables and sample the rest Problem: sample distribution not consistent! Solution: weight by probability of evidence Shape given parents Color pyramid, blue pyramid, blue sphere, blue cube, blue sphere, blue 15

Likelihood Weighting +c 0.5 -c 0.5 +c +s 0.1 -s 0.9 -c +s 0.5 -s 0.5 Sprinkler Cloudy Rain +c +r 0.8 -r 0.2 -c +r 0.2 -r 0.8 +s +r +w 0.99 -w 0.01 -r +w 0.90 -w 0.10 -s +r +w 0.90 -w 0.10 -r +w 0.01 -w 0.99 WetGrass Samples: +c, +s, +r, +w 16

Likelihood Weighting IN: evidence instantiation w = 1.0 for i=1, 2,, n if X i is an evidence variable else X i = observation x i for X i Set w = w * P(x i Parents(X i )) Sample x i from P(X i Parents(X i )) return (x 1, x 2,, x n ), w 17

Likelihood Weighting Sampling distribution if z sampled and e fixed evidence Cloudy C Now, samples have weights S R W Together, weighted sampling distribution is consistent 18

Likelihood Weighting Likelihood weighting is good We have taken evidence into account as we generate the sample E.g. here, W s value will get picked based on the evidence values of S, R More of our samples will reflect the state of the world suggested by the evidence Likelihood weighting doesn t solve all our problems Evidence influences the choice of downstream variables, but not upstream ones (C isn t more likely to get a value matching the evidence) We would like to consider evidence when we sample every variable Gibbs sampling 19

Gibbs Sampling 20

Gibbs Sampling Procedure: keep track of a full instantiation x 1, x 2,, x n. Start with an arbitrary instantiation consistent with the evidence. Sample one variable at a time, conditioned on all the rest, but keep evidence fixed. Keep repeating this for a long time. Property: in the limit of repeating this infinitely many times the resulting sample is coming from the correct distribution Rationale: both upstream and downstream variables condition on evidence. In contrast: likelihood weighting only conditions on upstream evidence, and hence weights obtained in likelihood weighting can sometimes be very small. Sum of weights over all samples is indicative of how many effective samples were obtained, so want high weight. 21

Gibbs Sampling Example: P( S +r) Step 1: Fix evidence R = +r C S +r Step 2: Initialize other variables Randomly C S +r W W Steps 3: Repeat Choose a non-evidence variable X Resample X from P( X all other variables) C C C C C C S +r S +r S +r S +r S +r S +r W W W W W W 22

Efficient Resampling of One Variable Sample from P(S +c, +r, -w) C S +r W Many things cancel out only CPTs with S remain! More generally: only CPTs that have resampled variable need to be considered, and 24 joined together

Bayes Net Sampling Summary Prior Sampling P Rejection Sampling P( Q e ) Likelihood Weighting P( Q e) Gibbs Sampling P( Q e ) 25

Further Reading on Gibbs Sampling* Gibbs sampling produces sample from the query distribution P( Q e ) in limit of re-sampling infinitely often Gibbs sampling is a special case of more general methods called Markov chain Monte Carlo (MCMC) methods Metropolis-Hastings is one of the more famous MCMC methods (in fact, Gibbs sampling is a special case of Metropolis-Hastings) You may read about Monte Carlo methods they re just sampling 26

How About Particle Filtering? X 1 X 2 = likelihood weighting E 2 Elapse Weight Resample Particles: (3,3) (2,3) (3,3) (3,2) (3,3) (3,2) (1,2) (3,3) (3,3) (2,3) Particles: (3,2) (2,3) (3,2) (3,1) (3,3) (3,2) (1,3) (2,3) (3,2) (2,2) Particles: (3,2) w=.9 (2,3) w=.2 (3,2) w=.9 (3,1) w=.4 (3,3) w=.4 (3,2) w=.9 (1,3) w=.1 (2,3) w=.2 (3,2) w=.9 (2,2) w=.4 27 (New) Particles: (3,2) (2,2) (3,2) (2,3) (3,3) (3,2) (1,3) (2,3) (3,2) (3,2)

Particle Filtering Particle filtering operates on ensemble of samples Performs likelihood weighting for each individual sample to elapse time and incorporate evidence Resamples from the weighted ensemble of samples to focus computation for the next time step where most of the probability mass is estimated to be 28