Probability
Probability
Instructors: Dan Klein and Pieter Abbeel --- University of California, Berkeley
[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.]
Today
§ Probability
§ Random Variables
§ Joint and Marginal Distributions
§ Conditional Distribution
§ Product Rule, Chain Rule, Bayes’ Rule
§ Inference
§ Independence
Maybe:
• Lack of observability
• Or, braked but error of sensors
Uncertainty
§ A ghost is in the grid
somewhere
§ Sensor readings tell how
close a square is to the
ghost
§ On the ghost: red
§ 1 or 2 away: orange
§ 3 or 4 away: yellow
§ 5+ away: green
§ Temperature: § Weather:
W P
T P
sun 0.6
hot 0.5
rain 0.1
cold 0.5
fog 0.3
meteor 0.0
Probability Distributions
§ Unobserved random variables have distributions
Shorthand notation:
T P W P
hot 0.5 sun 0.6
cold 0.5 rain 0.1
fog 0.3
meteor 0.0
T W P
§ Must obey: hot sun 0.4
hot rain 0.1
cold sun 0.2
cold rain 0.3
X Y P
+x +y 0.2
§ P(+x) ?
+x -y 0.3
-x +y 0.4
-x -y 0.1
§ P(-y OR +x) ?
Marginal Distributions
§ Marginal distributions are sub-tables which eliminate variables
§ Marginalization (summing out): Combine collapsed rows by adding
T P
hot 0.5
T W P
cold 0.5
hot sun 0.4
hot rain 0.1
cold sun 0.2 W P
cold rain 0.3 sun 0.6
rain 0.4
Quiz: Marginal Distributions
X P
+x
X Y P
-x
+x +y 0.2
+x -y 0.3
-x +y 0.4 Y P
-x -y 0.1 +y
-y
Conditional Probabilities
§ A simple relation between joint and conditional probabilities
§ In fact, this is taken as the definition of a conditional probability
P(a,b)
P(a) P(b)
T W P
hot sun 0.4
hot rain 0.1
cold sun 0.2
cold rain 0.3
Quiz: Conditional Probabilities
§ P(+x | +y) ?
X Y P
+x +y 0.2 § P(-x | +y) ?
+x -y 0.3
-x +y 0.4
-x -y 0.1
§ P(-y | +x) ?
Conditional Distributions
§ Conditional distributions are probability distributions over
some variables given fixed values of others
Conditional Distributions
Joint Distribution
W P
T W P
sun 0.8
hot sun 0.4
rain 0.2
hot rain 0.1
cold sun 0.2
W P cold rain 0.3
sun 0.4
rain 0.6
Normalization Trick
T W P
hot sun 0.4
W P
hot rain 0.1
sun 0.4
cold sun 0.2
rain 0.6
cold rain 0.3
Normalization Trick
§ Example 1 § Example 2
W P W P T W P T W P
Normalize
hot sun 20 Normalize hot sun 0.4
sun 0.2 sun 0.4
hot rain 5 hot rain 0.1
rain 0.3 Z = 0.5 rain 0.6
cold sun 10 Z = 50 cold sun 0.2
cold rain 15 cold rain 0.3
Probabilistic Inference
§ Probabilistic inference: compute a desired
probability from other known probabilities (e.g.
conditional from joint)
§ Step 1: Select the § Step 2: Sum out H to get joint § Step 3: Normalize
entries consistent of Query and evidence
with the evidence
1
⇥
Z
Inference by Enumeration
§ P(W)? S T W P
summer hot sun 0.30
summer hot rain 0.05
summer cold sun 0.10
§ P(W | winter)? summer cold rain 0.05
winter hot sun 0.10
winter hot rain 0.05
winter cold sun 0.15
§ P(W | winter, hot)? winter cold rain 0.20
Inference by Enumeration
S T W P
§ P(W)? summer hot sun 0.30
§ Step 1: no
summer hot rain 0.05
§ Step 2: sum over S and T
summer cold sun 0.10
summer cold rain 0.05
winter hot sun 0.10
W P winter hot rain 0.05
sun 0.30+0.10+0.10+0.15= 0.65 winter cold sun 0.15
rain 0.05+0.05+0.05+0.20= 0.35 winter cold rain 0.20
Inference by Enumeration
S T W P
§ P(W)? summer hot sun 0.30
§ Step 1: no
summer hot rain 0.05
§ Step 2:
summer cold sun 0.10
§ Step 3: normalize
summer cold rain 0.05
winter hot sun 0.10
W P winter hot rain 0.05
sun 0.30+0.10+0.10+0.15= 0.65/1 winter cold sun 0.15
rain 0.05+0.05+0.05+0.20= 0.35/1 winter cold rain 0.20
Inference by Enumeration
§ P(W | winter)? S T W P
§ Step 1: select S=winter summer hot sun 0.30
summer hot rain 0.05
summer cold sun 0.10
S T W P summer cold rain 0.05
winter hot sun 0.10 winter hot sun 0.10
winter hot rain 0.05 winter hot rain 0.05
winter cold sun 0.15 winter cold sun 0.15
winter cold rain 0.20 winter cold rain 0.20
Inference by Enumeration
§ P(W | winter)? S T W P
§ Step 2: Sum over T summer hot sun 0.30
summer hot rain 0.05
S T W P summer cold sun 0.10
winter hot sun 0.10 summer cold rain 0.05
winter hot rain 0.05 winter hot sun 0.10
winter cold sun 0.15 winter hot rain 0.05
winter cold rain 0.20 winter cold sun 0.15
winter cold rain 0.20
S W P
winter sun 0.10+0.15= 0.25
winter rain 0.05+0.25= 0.25
Inference by Enumeration
§ P(W | winter)? S T W P
§ Step 3: normalize summer hot sun 0.30
§ Z = 0.25 + 0.25 = 0.5 summer hot rain 0.05
summer cold sun 0.10
summer cold rain 0.05
W P(W|Winter)
winter hot sun 0.10
sun 0.25/0.5 = 0.5
winter hot rain 0.05
rain 0.25/0.5= 0.5
winter cold sun 0.15
winter cold rain 0.20
Inference by Enumeration
W P
sun 0.10/0.15
rain 0.05/0.15
Inference by Enumeration
§ Obvious problems:
§ Worst-case time complexity O(dn)
§ Space complexity O(dn) to store the joint distribution
The Product Rule
§ Sometimes have conditional distributions but want the joint
The Product Rule
§ Example:
D W P D W P
wet sun 0.1 wet sun 0.08
R P
dry sun 0.9 dry sun 0.72
sun 0.8
wet rain 0.7 wet rain 0.14
rain 0.2
dry rain 0.3 dry rain 0.06
The Chain Rule
§ Dividing, we get:
§ Says the joint distribution factors into a product of two simple ones
§ Usually variables aren’t independent!
T P
hot 0.5
cold 0.5 P2 (T, W ) = P (T )P (W )
T W P T W P
hot sun 0.4 hot sun 0.3
hot rain 0.1 hot rain 0.2
cold sun 0.2 cold sun 0.3
cold rain 0.3 cold rain 0.2
W P
sun 0.6
rain 0.4
Example: Independence
§ N fair, independent coin flips:
§ Equivalent statements:
§ P(Toothache | Catch , Cavity) = P(Toothache | Cavity)
§ P(Toothache, Catch | Cavity) = P(Toothache | Cavity) P(Catch | Cavity)
§ One can be derived from the other easily
Conditional Independence
§ Unconditional (absolute) independence very rare (why?)
§ Traffic
§ Umbrella
§ Raining
Traffic Umbrella
Conditional Independence
§ What about this domain: Raining
§ Traffic
§ Umbrella
§ Raining
Traffic Umbrella
Conditional Independence
§ What about this domain:
Fire
§ Fire
§ Smoke
§ Alarm
Smoke
Alarm
Conditional Independence
§ What about this domain:
Fire
§ Fire
§ Smoke
§ Alarm
Smoke
Alarm
Probability Recap
§ Conditional probability
§ Product rule
§ Chain rule