SlideShare a Scribd company logo
1 of 25
Download to read offline
Think Bayes

Chapter 9 Two Dimensions
9.1 Paintball
•

Paintball is a sport in which competing teams try to shoot each
other with guns that fire paint-filled pellets that break on impact,
leaving a colorful mark on the target. It is usually played in an
arena decorated with barriers and other objects that can be used
as cover.
•

Suppose you are playing paintball in an indoor arena 30 feet wide
and 50 feet long. You are standing near one of the 30 foot walls,
and you suspect that one of your opponents has taken cover
nearby. Along the wall, you see several paint spatters, all the
same color, that you think your opponent fired recently.
•

•

The spatters are at 15, 16, 18, and 21 feet, measured from the
lower-left corner of the room. Based on these data, where do
you think your opponent is hiding?
Figure 9.1 shows a diagram of the arena. Using the lower-left
corner of the room as the origin, I denote the unknown location
of the shooter with coordinates α and β, or alpha and beta. The
location of a spatter is labeled x. The angle the opponent shoots
at is θ or theta.
9.2 The suite
•

•

To get started, we need a Suite that represents a set of
hypotheses about the location of the opponent. Each hypothesis is
a pair of coordinates: (alpha, beta).
Here is the definition of the Paintball suite:
•

The room is 30 feet wide and 50 feet long, so here’s the code that
creates the suite:

•

This prior distribution assumes that all locations in the room are
equally likely. Given a map of the room, we might choose a more
detailed prior, but we’ll start simple.
9.3 Trigonometry
•

•

Now we need a likelihood function, which means we have to
figure out the likelihood of hitting any spot along the wall, given
the location of the opponent.
As a simple model, imagine that the opponent is like a rotating
turret, equally likely to shoot in any direction. In that case, he is
most likely to hit the wall at location alpha, and less likely to hit
the wall far away from alpha.
•

With a little trigonometry, we can compute the probability of
hitting any spot along the wall. Imagine that the shooter fires a
shot at angle θ; the pellet would hit the wall at location x, where

•

Solving this equation for θ yields

•

Taking the derivative of the first equation with respect to θ yields

•

This derivative is what I’ll call the “strafing speed”, which is the
speed of the target location along the wall as θ increases. The
probability of hitting a given point on the wall is inversely related
to strafing speed.
•

If we know the coordinates of the shooter and a location along
the wall, we can compute strafing speed:

•

alpha and beta are the coordinates of the shooter; x is the
location of a spatter. The result is the derivative of x with respect
to theta.
•

Now we can compute a Pmf that represents the probability of
hitting any location on the wall.
MakeLocationPmf takes alpha and beta, the coordinates of the
shooter, and locations, a list of possible values of x.

•

MakeLocationPmf computes the probability of hitting each
location, which is inversely related to strafing speed. The result is
a Pmf of locations and their probabilities.
•

Figure 9.3 shows the Pmf of location with alpha = 10 and a range
of values for beta. For all values of beta the most likely spatter
location is x = 10; as beta increases, so does the spread of the Pmf.
9.4 Likelihood
•

Now all we need is a likelihood function. We can
use MakeLocationPmf to compute the likelihood of any value of x,
given the coordinates of the opponent.

•

Again, alpha and beta are the hypothetical coordinates of the
shooter, and x is the location of an observed spatter.
pmf contains the probability of each location, given the
coordinates of the shooter. From this Pmf, we select the
probability of the observed location.

•
•

And we’re done. To update the suite, we can use UpdateSet,
which is inherited from Suite.

•

The result is a distribution that maps each (alpha, beta) pair to a
posterior probability.
9.5 Joint distributions
•

When each value in a distribution is a tuple of variables, it is
called a joint distribution because it represents the distributions of
the variables together, that is “jointly”. A joint distribution
contains the distributions of the variables, as well information
about the relationships among them.
•
•

•

Given a joint distribution, we can compute the distributions of
each variable independently, which are called the marginal
distributions.
thinkbayes.Joint provides a method that computes marginal
distributions:

i is the index of the variable we want; in this
example i=0 indicates the distribution of alpha, and i=1 indicates
the distribution of beta
•

Here’s the code that extracts the marginal distributions:

•

Figure 9.2 shows the results (converted to CDFs). The median
value for alpha is 18, near the center of mass of the observed
spatters. For beta, the most likely values are close to the wall, but
beyond 10 feet the distribution is almost uniform, which indicates
that the data do not distinguish strongly between these possible
locations.
•

Given the posterior marginals, we can compute credible intervals
for each coordinate independently:

•

The 50% credible intervals are (14, 21) for alpha and (5,
31) for beta. So the data provide evidence that the shooter is in
the near side of the room. But it is not strong evidence. The 90%
credible intervals cover most of the room!
9.6 Conditional distributions
•
•

•
•

The marginal distributions contain information about the variables
independently, but they do not capture the dependence between
variables, if any.
One way to visualize dependence is by computing conditional
distributions.thinkbayes.Joint provides a method that does that:

Again, i is the index of the variable we want; j is the index of the
conditioning variable, and val is the conditional value.
The result is the distribution of the ith variable under the
condition that the jth variable is val.
•
•

For example, the following code computes the conditional
distributions of alpha for a range of values of beta:
•

Figure 9.4 shows the results, which we could fully describe as
“posterior conditional marginal distributions.” Whew!

•

If the variables were independent, the conditional distributions would
all be the same. Since they are all different, we can tell the variables
are dependent. For example, if we know (somehow) that beta = 10,
the conditional distribution of alpha is fairly narrow. For larger values
of beta, the distribution of alpha is wider.
9.7 Credible intervals
•

•

•

Another way to visualize the posterior joint distribution is to
compute credible intervals. When we looked at credible intervals
in Section 3.5, I skipped over a subtle point: for a given
distribution, there are many intervals with the same level of
credibility. For example, if you want a 50% credible interval, you
could choose any set of values whose probability adds up to 50%.
When the values are one-dimensional, it is most common to
choose the central credible interval; for example, the central 50%
credible interval contains all values between the 25th and 75th
percentiles.
In multiple dimensions it is less obvious what the right credible
interval should be. The best choice might depend on context, but
one common choice is the maximum likelihood credible interval,
which contains the most likely values that add up to 50% (or
some other percentage).
•

thinkbayes.Joint provides a method that computes maximum
likelihood credible intervals.
def MaxLikeInterval(self, percentage=90):

interval = []
total = 0
t = [(prob, val) for val, prob in self.Items()]
t.sort(reverse=True)
for prob, val in t:
interval.append(val)
total += prob
if total >= percentage / 100.0:
break
return interval

•

The first step is to make a list of the values in the suite, sorted in
descending order by probability. Next we traverse the list, adding
each value to the interval, until the total probability
exceeds percentage. The result is a list of values from the suite.
Notice that this set of values is not necessarily contiguous.
•

To visualize the intervals, I wrote a function that “colors” each
value according to how many intervals it appears in:

def MakeCrediblePlot(suite):
d = dict((pair, 0) for pair in suite.Values())
percentages = [75, 50, 25]
for p in percentages:
interval = suite.MaxLikeInterval(p)
for pair in interval:
d[pair] += 1
thinkplot.Contour(d, contour=False, pcolor=True)
pyplot.text(17, 4, '25', color='white')
pyplot.text(17, 15, '50', color='white')
pyplot.text(17, 30, '75')
thinkplot.Save('paintball5', xlabel='alpha', ylabel='beta', formats=FORMATS)

•

•

d is a dictionary that maps from each value in the suite to the
number of intervals it appears in. The loop computes intervals for
several percentages and modifies d.
•

•

Figure 9.5 shows the result. The 25% credible interval is the
darkest region near the bottom wall. For higher percentages, the
credible interval is bigger, of course, and skewed toward the right
side of the room.
9.8 Discussion
•

•

•

•

•

This chapter shows that the Bayesian framework from the previous
chapters can be extended to handle a two-dimensional parameter
space. The only difference is that each hypothesis is represented by a
tuple of parameters.
Given the joint distribution, you can compute marginal and
conditional distributions. With enough conditional distributions, you
could re-create the joint distribution, at least approximately. But
given the marginal distributions you cannot re-create the joint
distribution because you have lost information about the dependence
between variables.
If there are n possible values for each of two parameters, most
operations on the joint distribution take time proportional to n2. If
there are d parameters, run time is proportional to nd, which quickly
becomes impractical as the number of dimensions increases.
If you can process a million hypotheses in a reasonable amount of
time, you could handle two dimensions with 1000 values for each
parameter, or three dimensions with 100 values each, or six
dimensions with 10 values each.
If you need more dimensions, or more values per dimension, there
are optimizations you can try. I present an example in Chapter 15.

More Related Content

What's hot

Algorithm in computer science
Algorithm in computer scienceAlgorithm in computer science
Algorithm in computer scienceRiazul Islam
 
[DL輪読会]Generative Models of Visually Grounded Imagination
[DL輪読会]Generative Models of Visually Grounded Imagination[DL輪読会]Generative Models of Visually Grounded Imagination
[DL輪読会]Generative Models of Visually Grounded ImaginationDeep Learning JP
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1chidabdu
 
Fitting the log skew normal to
Fitting the log skew normal toFitting the log skew normal to
Fitting the log skew normal tocsandit
 
Introduction to Bootstrap and elements of Markov Chains
Introduction to Bootstrap and elements of Markov ChainsIntroduction to Bootstrap and elements of Markov Chains
Introduction to Bootstrap and elements of Markov ChainsUniversity of Salerno
 
Lecture 1 maximum likelihood
Lecture 1 maximum likelihoodLecture 1 maximum likelihood
Lecture 1 maximum likelihoodAnant Dashpute
 
Senior Research Final Draft3
Senior Research Final Draft3Senior Research Final Draft3
Senior Research Final Draft3Coleman Gorham
 
ラビットチャレンジ 深層学習Day1 day2レポート
ラビットチャレンジ 深層学習Day1 day2レポートラビットチャレンジ 深層学習Day1 day2レポート
ラビットチャレンジ 深層学習Day1 day2レポートKazuyukiMasada
 

What's hot (19)

Lower bound
Lower boundLower bound
Lower bound
 
Algorithm in computer science
Algorithm in computer scienceAlgorithm in computer science
Algorithm in computer science
 
[DL輪読会]Generative Models of Visually Grounded Imagination
[DL輪読会]Generative Models of Visually Grounded Imagination[DL輪読会]Generative Models of Visually Grounded Imagination
[DL輪読会]Generative Models of Visually Grounded Imagination
 
Implicit schemes for wave models
Implicit schemes for wave modelsImplicit schemes for wave models
Implicit schemes for wave models
 
Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
 
Baum3
Baum3Baum3
Baum3
 
Fitting the log skew normal to
Fitting the log skew normal toFitting the log skew normal to
Fitting the log skew normal to
 
Montecarlophd
MontecarlophdMontecarlophd
Montecarlophd
 
Introduction to Bootstrap and elements of Markov Chains
Introduction to Bootstrap and elements of Markov ChainsIntroduction to Bootstrap and elements of Markov Chains
Introduction to Bootstrap and elements of Markov Chains
 
Unit 2
Unit 2Unit 2
Unit 2
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Lecture 1 maximum likelihood
Lecture 1 maximum likelihoodLecture 1 maximum likelihood
Lecture 1 maximum likelihood
 
Machine Learning 1
Machine Learning 1Machine Learning 1
Machine Learning 1
 
Mechanical Engineering Assignment Help
Mechanical Engineering Assignment HelpMechanical Engineering Assignment Help
Mechanical Engineering Assignment Help
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
 
Senior Research Final Draft3
Senior Research Final Draft3Senior Research Final Draft3
Senior Research Final Draft3
 
ラビットチャレンジ 深層学習Day1 day2レポート
ラビットチャレンジ 深層学習Day1 day2レポートラビットチャレンジ 深層学習Day1 day2レポート
ラビットチャレンジ 深層学習Day1 day2レポート
 
Unit i
Unit iUnit i
Unit i
 

Viewers also liked

3 Generative models for discrete data
3 Generative models for discrete data3 Generative models for discrete data
3 Generative models for discrete dataJungkyu Lee
 
Eigenvalues of regular graphs
Eigenvalues of regular graphsEigenvalues of regular graphs
Eigenvalues of regular graphsJungkyu Lee
 
Murpy's Machine Learning 9. Generalize Linear Model
Murpy's Machine Learning 9. Generalize Linear ModelMurpy's Machine Learning 9. Generalize Linear Model
Murpy's Machine Learning 9. Generalize Linear ModelJungkyu Lee
 
머피의 머신러닝: Undirencted Graphical Model
머피의 머신러닝: Undirencted Graphical Model머피의 머신러닝: Undirencted Graphical Model
머피의 머신러닝: Undirencted Graphical ModelJungkyu Lee
 
ThinkBayes: chapter 13  simulation
ThinkBayes: chapter 13  simulationThinkBayes: chapter 13  simulation
ThinkBayes: chapter 13  simulationJungkyu Lee
 
파이널 판타지 3 루트 공략
파이널 판타지 3 루트 공략파이널 판타지 3 루트 공략
파이널 판타지 3 루트 공략Jungkyu Lee
 
머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear ModelJungkyu Lee
 
Murpy's Machine Learing: 10. Directed Graphical Model
Murpy's Machine Learing: 10. Directed Graphical ModelMurpy's Machine Learing: 10. Directed Graphical Model
Murpy's Machine Learing: 10. Directed Graphical ModelJungkyu Lee
 
TETRIS AI WITH REINFORCEMENT LEARNING
TETRIS AI WITH REINFORCEMENT LEARNINGTETRIS AI WITH REINFORCEMENT LEARNING
TETRIS AI WITH REINFORCEMENT LEARNINGJungkyu Lee
 
머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear ModelJungkyu Lee
 
7. Linear Regression
7. Linear Regression7. Linear Regression
7. Linear RegressionJungkyu Lee
 
머피의 머신러닝 13 Sparse Linear Model
머피의 머신러닝 13 Sparse Linear Model머피의 머신러닝 13 Sparse Linear Model
머피의 머신러닝 13 Sparse Linear ModelJungkyu Lee
 
4. Gaussian Model
4. Gaussian Model4. Gaussian Model
4. Gaussian ModelJungkyu Lee
 
앙상블 학습 기반의 추천시스템 개발
앙상블 학습 기반의 추천시스템 개발앙상블 학습 기반의 추천시스템 개발
앙상블 학습 기반의 추천시스템 개발Jungkyu Lee
 
머피's 머신러닝, Mixture model and EM algorithm
머피's 머신러닝, Mixture model and EM algorithm머피's 머신러닝, Mixture model and EM algorithm
머피's 머신러닝, Mixture model and EM algorithmJungkyu Lee
 
From A Neural Probalistic Language Model to Word2vec
From A Neural Probalistic Language Model to Word2vecFrom A Neural Probalistic Language Model to Word2vec
From A Neural Probalistic Language Model to Word2vecJungkyu Lee
 
Support Vector Machine Tutorial 한국어
Support Vector Machine Tutorial 한국어Support Vector Machine Tutorial 한국어
Support Vector Machine Tutorial 한국어Jungkyu Lee
 
8. Logistic Regression
8. Logistic Regression8. Logistic Regression
8. Logistic RegressionJungkyu Lee
 
머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian ProcessesJungkyu Lee
 
1. boolean 검색
1. boolean 검색1. boolean 검색
1. boolean 검색Jungkyu Lee
 

Viewers also liked (20)

3 Generative models for discrete data
3 Generative models for discrete data3 Generative models for discrete data
3 Generative models for discrete data
 
Eigenvalues of regular graphs
Eigenvalues of regular graphsEigenvalues of regular graphs
Eigenvalues of regular graphs
 
Murpy's Machine Learning 9. Generalize Linear Model
Murpy's Machine Learning 9. Generalize Linear ModelMurpy's Machine Learning 9. Generalize Linear Model
Murpy's Machine Learning 9. Generalize Linear Model
 
머피의 머신러닝: Undirencted Graphical Model
머피의 머신러닝: Undirencted Graphical Model머피의 머신러닝: Undirencted Graphical Model
머피의 머신러닝: Undirencted Graphical Model
 
ThinkBayes: chapter 13  simulation
ThinkBayes: chapter 13  simulationThinkBayes: chapter 13  simulation
ThinkBayes: chapter 13  simulation
 
파이널 판타지 3 루트 공략
파이널 판타지 3 루트 공략파이널 판타지 3 루트 공략
파이널 판타지 3 루트 공략
 
머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model
 
Murpy's Machine Learing: 10. Directed Graphical Model
Murpy's Machine Learing: 10. Directed Graphical ModelMurpy's Machine Learing: 10. Directed Graphical Model
Murpy's Machine Learing: 10. Directed Graphical Model
 
TETRIS AI WITH REINFORCEMENT LEARNING
TETRIS AI WITH REINFORCEMENT LEARNINGTETRIS AI WITH REINFORCEMENT LEARNING
TETRIS AI WITH REINFORCEMENT LEARNING
 
머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model머피's 머신러닝: Latent Linear Model
머피's 머신러닝: Latent Linear Model
 
7. Linear Regression
7. Linear Regression7. Linear Regression
7. Linear Regression
 
머피의 머신러닝 13 Sparse Linear Model
머피의 머신러닝 13 Sparse Linear Model머피의 머신러닝 13 Sparse Linear Model
머피의 머신러닝 13 Sparse Linear Model
 
4. Gaussian Model
4. Gaussian Model4. Gaussian Model
4. Gaussian Model
 
앙상블 학습 기반의 추천시스템 개발
앙상블 학습 기반의 추천시스템 개발앙상블 학습 기반의 추천시스템 개발
앙상블 학습 기반의 추천시스템 개발
 
머피's 머신러닝, Mixture model and EM algorithm
머피's 머신러닝, Mixture model and EM algorithm머피's 머신러닝, Mixture model and EM algorithm
머피's 머신러닝, Mixture model and EM algorithm
 
From A Neural Probalistic Language Model to Word2vec
From A Neural Probalistic Language Model to Word2vecFrom A Neural Probalistic Language Model to Word2vec
From A Neural Probalistic Language Model to Word2vec
 
Support Vector Machine Tutorial 한국어
Support Vector Machine Tutorial 한국어Support Vector Machine Tutorial 한국어
Support Vector Machine Tutorial 한국어
 
8. Logistic Regression
8. Logistic Regression8. Logistic Regression
8. Logistic Regression
 
머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes머피의 머신러닝 : Gaussian Processes
머피의 머신러닝 : Gaussian Processes
 
1. boolean 검색
1. boolean 검색1. boolean 검색
1. boolean 검색
 

Similar to ThinkBayes: Chapter 9 two_dimensions

Index cards characteristics and theorems
Index cards characteristics and theoremsIndex cards characteristics and theorems
Index cards characteristics and theoremstschmucker
 
SPATIAL POINT PATTERNS
SPATIAL POINT PATTERNSSPATIAL POINT PATTERNS
SPATIAL POINT PATTERNSLiemNguyenDuy
 
SAMPLING MEAN DEFINITION The term sampling mean is.docx
SAMPLING MEAN  DEFINITION  The term sampling mean is.docxSAMPLING MEAN  DEFINITION  The term sampling mean is.docx
SAMPLING MEAN DEFINITION The term sampling mean is.docxagnesdcarey33086
 
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docxSAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docxanhlodge
 
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docxSAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docxagnesdcarey33086
 
Lect w4 Lect w3 estimation
Lect w4 Lect w3 estimationLect w4 Lect w3 estimation
Lect w4 Lect w3 estimationRione Drevale
 
Essay On Linear Function
Essay On Linear FunctionEssay On Linear Function
Essay On Linear FunctionAngie Lee
 
Mathematical Background for Artificial Intelligence
Mathematical Background for Artificial IntelligenceMathematical Background for Artificial Intelligence
Mathematical Background for Artificial Intelligenceananth
 
Probility distribution
Probility distributionProbility distribution
Probility distributionVinya P
 
Theory of uncertainty of measurement.pdf
Theory of uncertainty of measurement.pdfTheory of uncertainty of measurement.pdf
Theory of uncertainty of measurement.pdfHnCngnh1
 
Information and network security 22 differential cryptanalysis
Information and network security 22 differential cryptanalysisInformation and network security 22 differential cryptanalysis
Information and network security 22 differential cryptanalysisVaibhav Khanna
 
Single Variable Calculus Assignment Help
Single Variable Calculus Assignment HelpSingle Variable Calculus Assignment Help
Single Variable Calculus Assignment HelpMath Homework Solver
 

Similar to ThinkBayes: Chapter 9 two_dimensions (20)

Index cards characteristics and theorems
Index cards characteristics and theoremsIndex cards characteristics and theorems
Index cards characteristics and theorems
 
125 3.3
125 3.3125 3.3
125 3.3
 
Two player games
Two player gamesTwo player games
Two player games
 
Excel Homework Help
Excel Homework HelpExcel Homework Help
Excel Homework Help
 
SPATIAL POINT PATTERNS
SPATIAL POINT PATTERNSSPATIAL POINT PATTERNS
SPATIAL POINT PATTERNS
 
SAMPLING MEAN DEFINITION The term sampling mean is.docx
SAMPLING MEAN  DEFINITION  The term sampling mean is.docxSAMPLING MEAN  DEFINITION  The term sampling mean is.docx
SAMPLING MEAN DEFINITION The term sampling mean is.docx
 
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docxSAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
 
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docxSAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
SAMPLING MEANDEFINITIONThe term sampling mean is a stati.docx
 
Lect w4 Lect w3 estimation
Lect w4 Lect w3 estimationLect w4 Lect w3 estimation
Lect w4 Lect w3 estimation
 
cupdf.com_control-chap7.ppt
cupdf.com_control-chap7.pptcupdf.com_control-chap7.ppt
cupdf.com_control-chap7.ppt
 
Probability Assignment Help
Probability Assignment HelpProbability Assignment Help
Probability Assignment Help
 
Essay On Linear Function
Essay On Linear FunctionEssay On Linear Function
Essay On Linear Function
 
Mathematical Background for Artificial Intelligence
Mathematical Background for Artificial IntelligenceMathematical Background for Artificial Intelligence
Mathematical Background for Artificial Intelligence
 
ASSIGMENT.PY.pptx
ASSIGMENT.PY.pptxASSIGMENT.PY.pptx
ASSIGMENT.PY.pptx
 
Probility distribution
Probility distributionProbility distribution
Probility distribution
 
Statistics Homework Help
Statistics Homework HelpStatistics Homework Help
Statistics Homework Help
 
Theory of uncertainty of measurement.pdf
Theory of uncertainty of measurement.pdfTheory of uncertainty of measurement.pdf
Theory of uncertainty of measurement.pdf
 
Information and network security 22 differential cryptanalysis
Information and network security 22 differential cryptanalysisInformation and network security 22 differential cryptanalysis
Information and network security 22 differential cryptanalysis
 
F-Distribution
F-DistributionF-Distribution
F-Distribution
 
Single Variable Calculus Assignment Help
Single Variable Calculus Assignment HelpSingle Variable Calculus Assignment Help
Single Variable Calculus Assignment Help
 

Recently uploaded

Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

ThinkBayes: Chapter 9 two_dimensions

  • 1. Think Bayes Chapter 9 Two Dimensions
  • 2. 9.1 Paintball • Paintball is a sport in which competing teams try to shoot each other with guns that fire paint-filled pellets that break on impact, leaving a colorful mark on the target. It is usually played in an arena decorated with barriers and other objects that can be used as cover.
  • 3. • Suppose you are playing paintball in an indoor arena 30 feet wide and 50 feet long. You are standing near one of the 30 foot walls, and you suspect that one of your opponents has taken cover nearby. Along the wall, you see several paint spatters, all the same color, that you think your opponent fired recently.
  • 4. • • The spatters are at 15, 16, 18, and 21 feet, measured from the lower-left corner of the room. Based on these data, where do you think your opponent is hiding? Figure 9.1 shows a diagram of the arena. Using the lower-left corner of the room as the origin, I denote the unknown location of the shooter with coordinates α and β, or alpha and beta. The location of a spatter is labeled x. The angle the opponent shoots at is θ or theta.
  • 5. 9.2 The suite • • To get started, we need a Suite that represents a set of hypotheses about the location of the opponent. Each hypothesis is a pair of coordinates: (alpha, beta). Here is the definition of the Paintball suite:
  • 6. • The room is 30 feet wide and 50 feet long, so here’s the code that creates the suite: • This prior distribution assumes that all locations in the room are equally likely. Given a map of the room, we might choose a more detailed prior, but we’ll start simple.
  • 7. 9.3 Trigonometry • • Now we need a likelihood function, which means we have to figure out the likelihood of hitting any spot along the wall, given the location of the opponent. As a simple model, imagine that the opponent is like a rotating turret, equally likely to shoot in any direction. In that case, he is most likely to hit the wall at location alpha, and less likely to hit the wall far away from alpha.
  • 8. • With a little trigonometry, we can compute the probability of hitting any spot along the wall. Imagine that the shooter fires a shot at angle θ; the pellet would hit the wall at location x, where • Solving this equation for θ yields • Taking the derivative of the first equation with respect to θ yields • This derivative is what I’ll call the “strafing speed”, which is the speed of the target location along the wall as θ increases. The probability of hitting a given point on the wall is inversely related to strafing speed.
  • 9. • If we know the coordinates of the shooter and a location along the wall, we can compute strafing speed: • alpha and beta are the coordinates of the shooter; x is the location of a spatter. The result is the derivative of x with respect to theta.
  • 10. • Now we can compute a Pmf that represents the probability of hitting any location on the wall. MakeLocationPmf takes alpha and beta, the coordinates of the shooter, and locations, a list of possible values of x. • MakeLocationPmf computes the probability of hitting each location, which is inversely related to strafing speed. The result is a Pmf of locations and their probabilities.
  • 11. • Figure 9.3 shows the Pmf of location with alpha = 10 and a range of values for beta. For all values of beta the most likely spatter location is x = 10; as beta increases, so does the spread of the Pmf.
  • 12. 9.4 Likelihood • Now all we need is a likelihood function. We can use MakeLocationPmf to compute the likelihood of any value of x, given the coordinates of the opponent. • Again, alpha and beta are the hypothetical coordinates of the shooter, and x is the location of an observed spatter. pmf contains the probability of each location, given the coordinates of the shooter. From this Pmf, we select the probability of the observed location. •
  • 13. • And we’re done. To update the suite, we can use UpdateSet, which is inherited from Suite. • The result is a distribution that maps each (alpha, beta) pair to a posterior probability.
  • 14. 9.5 Joint distributions • When each value in a distribution is a tuple of variables, it is called a joint distribution because it represents the distributions of the variables together, that is “jointly”. A joint distribution contains the distributions of the variables, as well information about the relationships among them.
  • 15. • • • Given a joint distribution, we can compute the distributions of each variable independently, which are called the marginal distributions. thinkbayes.Joint provides a method that computes marginal distributions: i is the index of the variable we want; in this example i=0 indicates the distribution of alpha, and i=1 indicates the distribution of beta
  • 16. • Here’s the code that extracts the marginal distributions: • Figure 9.2 shows the results (converted to CDFs). The median value for alpha is 18, near the center of mass of the observed spatters. For beta, the most likely values are close to the wall, but beyond 10 feet the distribution is almost uniform, which indicates that the data do not distinguish strongly between these possible locations.
  • 17. • Given the posterior marginals, we can compute credible intervals for each coordinate independently: • The 50% credible intervals are (14, 21) for alpha and (5, 31) for beta. So the data provide evidence that the shooter is in the near side of the room. But it is not strong evidence. The 90% credible intervals cover most of the room!
  • 18. 9.6 Conditional distributions • • • • The marginal distributions contain information about the variables independently, but they do not capture the dependence between variables, if any. One way to visualize dependence is by computing conditional distributions.thinkbayes.Joint provides a method that does that: Again, i is the index of the variable we want; j is the index of the conditioning variable, and val is the conditional value. The result is the distribution of the ith variable under the condition that the jth variable is val.
  • 19. • • For example, the following code computes the conditional distributions of alpha for a range of values of beta:
  • 20. • Figure 9.4 shows the results, which we could fully describe as “posterior conditional marginal distributions.” Whew! • If the variables were independent, the conditional distributions would all be the same. Since they are all different, we can tell the variables are dependent. For example, if we know (somehow) that beta = 10, the conditional distribution of alpha is fairly narrow. For larger values of beta, the distribution of alpha is wider.
  • 21. 9.7 Credible intervals • • • Another way to visualize the posterior joint distribution is to compute credible intervals. When we looked at credible intervals in Section 3.5, I skipped over a subtle point: for a given distribution, there are many intervals with the same level of credibility. For example, if you want a 50% credible interval, you could choose any set of values whose probability adds up to 50%. When the values are one-dimensional, it is most common to choose the central credible interval; for example, the central 50% credible interval contains all values between the 25th and 75th percentiles. In multiple dimensions it is less obvious what the right credible interval should be. The best choice might depend on context, but one common choice is the maximum likelihood credible interval, which contains the most likely values that add up to 50% (or some other percentage).
  • 22. • thinkbayes.Joint provides a method that computes maximum likelihood credible intervals. def MaxLikeInterval(self, percentage=90): interval = [] total = 0 t = [(prob, val) for val, prob in self.Items()] t.sort(reverse=True) for prob, val in t: interval.append(val) total += prob if total >= percentage / 100.0: break return interval • The first step is to make a list of the values in the suite, sorted in descending order by probability. Next we traverse the list, adding each value to the interval, until the total probability exceeds percentage. The result is a list of values from the suite. Notice that this set of values is not necessarily contiguous.
  • 23. • To visualize the intervals, I wrote a function that “colors” each value according to how many intervals it appears in: def MakeCrediblePlot(suite): d = dict((pair, 0) for pair in suite.Values()) percentages = [75, 50, 25] for p in percentages: interval = suite.MaxLikeInterval(p) for pair in interval: d[pair] += 1 thinkplot.Contour(d, contour=False, pcolor=True) pyplot.text(17, 4, '25', color='white') pyplot.text(17, 15, '50', color='white') pyplot.text(17, 30, '75') thinkplot.Save('paintball5', xlabel='alpha', ylabel='beta', formats=FORMATS) • • d is a dictionary that maps from each value in the suite to the number of intervals it appears in. The loop computes intervals for several percentages and modifies d.
  • 24. • • Figure 9.5 shows the result. The 25% credible interval is the darkest region near the bottom wall. For higher percentages, the credible interval is bigger, of course, and skewed toward the right side of the room.
  • 25. 9.8 Discussion • • • • • This chapter shows that the Bayesian framework from the previous chapters can be extended to handle a two-dimensional parameter space. The only difference is that each hypothesis is represented by a tuple of parameters. Given the joint distribution, you can compute marginal and conditional distributions. With enough conditional distributions, you could re-create the joint distribution, at least approximately. But given the marginal distributions you cannot re-create the joint distribution because you have lost information about the dependence between variables. If there are n possible values for each of two parameters, most operations on the joint distribution take time proportional to n2. If there are d parameters, run time is proportional to nd, which quickly becomes impractical as the number of dimensions increases. If you can process a million hypotheses in a reasonable amount of time, you could handle two dimensions with 1000 values for each parameter, or three dimensions with 100 values each, or six dimensions with 10 values each. If you need more dimensions, or more values per dimension, there are optimizations you can try. I present an example in Chapter 15.