2PP

CS 188: Artificial Intelligence
Fall 2006
Lecture 14: Probability
10/17/2006
Dan Klein – UC Berkeley
Announcements
ƒ Grades:
ƒ Check midterm, p1.1, and p1.2 grades in glookup
ƒ Let us know if there are problems, so we can calculate useful
preliminary grade estimates
ƒ If we missed you, tell us your partner’s login
ƒ Readers request:
ƒ List partners and logins on top of your readme files
ƒ Turn off your debug output
ƒ Project 3.1 up: written probability problems, start now!
ƒ Extra office hours: Thursday 2-3pm (if people use them)
1
Today
ƒ Probability
ƒ
ƒ
ƒ
ƒ
Random Variables
Joint and Conditional Distributions
Bayes Rule
Independence
ƒ You’ll need all this stuff for the next few
weeks, so make sure you go over it!
Uncertainty
ƒ General situation:
ƒ Agent knows certain things
about the state of the world
(e.g., sensor readings or
symptoms)
ƒ Agent needs to reason about
other aspects (e.g. where an
object is or what disease is
present)
ƒ Agent knows something about
how the known variables relate
to the unknown variables
ƒ Probabilistic reasoning gives
us a framework for managing
our beliefs and knowledge
2
Random Variables
ƒ A random variable is some aspect of the world about
which we have uncertainty
ƒ R = Is it raining?
ƒ D = How long will it take to drive to work?
ƒ L = Where am I?
ƒ We denote random variables with capital letters
ƒ Like in a CSP, each random variable has a domain
ƒ R in {true, false}
ƒ D in [0, ∞]
ƒ L in possible locations
Probabilities
ƒ We generally calculate conditional probabilities
ƒ P(on time | no reported accidents) = 0.90
ƒ Probabilities change with new evidence:
ƒ P(on time | no reported accidents, 5 a.m.) = 0.95
ƒ P(on time | no reported accidents, 5 a.m., raining) =
0.80
ƒ i.e., observing evidence causes beliefs to be updated
3
Probabilistic Models
ƒ CSPs:
ƒ Variables with domains
ƒ Constraints: map from
assignments to true/false
ƒ Ideally: only certain variables
directly interact
ƒ Probabilistic models:
ƒ (Random) variables with
domains
ƒ Joint distributions: map from
assignments (or outcomes) to
positive numbers
ƒ Normalized: sum to 1.0
ƒ Ideally: only certain variables
directly interact
ƒ Assignments are called
outcomes
A
B
P
warm
sun
T
warm
rain
F
cold
sun
F
cold
rain
T
A
B
warm
sun
0.4
warm
rain
0.1
cold
sun
0.2
cold
rain
0.3
P
Distributions on Random Vars
ƒ A joint distribution over a set of random variables:
is a map from assignments (or outcomes, or atomic events) to reals:
ƒ Size of distribution if n variables with domain sizes d?
ƒ Must obey:
T
S
P
warm
sun
0.4
warm
rain
0.1
cold
sun
0.2
cold
rain
0.3
ƒ For all but the smallest distributions, impractical to write out
4
Examples
ƒ An event is a set E of assignments (or
outcomes)
ƒ From a joint distribution, we can calculate
the probability of any event
T
S
P
warm
sun
0.4
warm
rain
0.1
cold
sun
0.2
cold
rain
0.3
ƒ Probability that it’s warm AND sunny?
ƒ Probability that it’s warm?
ƒ Probability that it’s warm OR sunny?
Marginalization
ƒ Marginalization (or summing out) is projecting a joint
distribution to a sub-distribution over subset of variables
T
P
P
warm
0.5
cold
0.5
T
S
warm
sun
0.4
warm
rain
0.1
cold
sun
0.2
S
cold
rain
0.3
sun
0.6
rain
0.4
P
5
Conditional Probabilities
ƒ A conditional probability is the probability of an
event given another event (usually evidence)
T
S
warm
sun
P
0.4
warm
rain
0.1
cold
sun
0.2
cold
rain
0.3
Conditional Probabilities
ƒ
Conditional or posterior probabilities:
ƒ E.g., P(cavity | toothache) = 0.8
ƒ Given that toothache is all I know…
ƒ
Notation for conditional distributions:
ƒ P(cavity | toothache) = a single number
ƒ P(Cavity, Toothache) = 2x2 table summing to 1
ƒ P(Cavity | Toothache) = Two 2-element vectors, each summing to 1
ƒ
If we know more:
ƒ P(cavity | toothache, catch) = 0.9
ƒ P(cavity | toothache, cavity) = 1
ƒ
Note: the less specific belief remains valid after more evidence arrives, but
is not always useful
ƒ
New evidence may be irrelevant, allowing simplification:
ƒ
This kind of inference, guided by domain knowledge, is crucial
ƒ P(cavity | toothache, traffic) = P(cavity | toothache) = 0.8
6
Conditioning
ƒ Conditional probabilities are the ratio of two probabilities:
T
S
P
warm
sun
0.4
warm
rain
0.1
cold
sun
0.2
cold
rain
0.3
Normalization Trick
ƒ A trick to get the whole conditional distribution at once:
ƒ Get the joint probabilities for each value of the query variable
ƒ Renormalize the resulting vector
T
S
P
warm
sun
0.4
warm
rain
0.1
cold
sun
0.2
cold
rain
0.3
Select
T
P
warm
0.1
cold
0.3
Normalize
T
P
warm
0.25
cold
0.75
7
The Product Rule
ƒ Sometimes joint P(X,Y) is easy to get
ƒ Sometimes easier to get conditional P(X|Y)
ƒ Example: P(sun, dry)?
R
P
sun
0.8
rain
0.2
D
S
P
D
S
P
wet
sun
0.1
wet
sun
0.08
dry
sun
0.9
dry
sun
0.72
wet
rain
0.7
wet
rain
0.14
dry
rain
0.3
dry
rain
0.06
Lewis Carroll's Sack Problem
ƒ Sack contains a red or blue token, 50/50
ƒ We add a red token
ƒ If we draw a red token, what’s the
chance of drawing a second red token?
ƒ Variables:
ƒ F={r,b} is the original token
ƒ D={r,b} is the first token we draw
ƒ Query: P(F=r|D=r)
F
D
P
F
D
r
r
1.0
r
r
F
P
r
0.5
r
b
0.0
r
b
0.5
b
r
0.5
b
r
b
b
0.5
b
b
b
P
8
Lewis Carroll's Sack Problem
ƒ Now we have P(F,D)
ƒ Want P(F=r|D=r)
F
D
P
r
r
0.5
r
b
0.0
b
r
0.25
b
b
0.25
Bayes’ Rule
ƒ Two ways to factor a joint distribution over two variables:
That’s my rule!
ƒ Dividing, we get:
ƒ Why is this at all helpful?
ƒ Lets us invert a conditional distribution
ƒ Often the one conditional is tricky but the other simple
ƒ Foundation of many systems we’ll see later (e.g. ASR, MT)
ƒ In the running for most important AI equation!
9
More Bayes’ Rule
ƒ Diagnostic probability from causal probability:
ƒ Example:
ƒ m is meningitis, s is stiff neck
ƒ Note: posterior probability of meningitis still very small
ƒ Note: you should still get stiff necks checked out! Why?
Battleship
ƒ Let’s say we have two distributions:
ƒ Prior distribution over ship locations: P(L)
ƒ Say this is uniform
ƒ Sensor reading model: P(R | L)
ƒ Given by some known black box
ƒ E.g. P(R = yellow | L=(1,1)) = 0.1
ƒ For now, assume the reading is always for
the lower left corner
ƒ We can calculate the posterior
distribution over ship locations using
(conditionalized) Bayes’ rule:
10
Inference by Enumeration
ƒ P(sun)?
ƒ P(sun | winter)?
ƒ P(sun | winter, warm)?
S
T
R
P
summer
warm
sun
0.30
summer
warm
rain
0.05
summer
cold
sun
0.10
summer
cold
rain
0.05
winter
warm
sun
0.10
winter
warm
rain
0.05
winter
cold
sun
0.15
winter
cold
rain
0.20
Inference by Enumeration
ƒ General case:
ƒ Evidence variables:
ƒ Query variables:
ƒ Hidden variables:
All variables
ƒ We want:
ƒ First, select the entries consistent with the evidence
ƒ Second, sum out H:
ƒ Finally, normalize the remaining entries to conditionalize
ƒ Obvious problems:
ƒ Worst-case time complexity O(dn)
ƒ Space complexity O(dn) to store the joint distribution
11
Independence
ƒ Two variables are independent if:
ƒ This says that their joint distribution factors into a product two
simpler distributions
ƒ Independence is a modeling assumption
ƒ Empirical joint distributions: at best “close” to independent
ƒ What could we assume for {Weather, Traffic, Cavity}?
ƒ How many parameters in the joint model?
ƒ How many parameters in the independent model?
ƒ Independence is like something from CSPs: what?
Example: Independence
ƒ N fair, independent coin flips:
H
0.5
H
0.5
H
0.5
T
0.5
T
0.5
T
0.5
12
Example: Independence?
ƒ Arbitrary joint
distributions can be
poorly modeled by
independent factors
T
P
S
P
warm
0.5
sun
0.6
cold
0.5
rain
0.4
T
S
P
T
S
P
warm
sun
0.4
warm
sun
0.3
warm
rain
0.1
warm
rain
0.2
cold
sun
0.2
cold
sun
0.3
cold
rain
0.3
cold
rain
0.2
Conditional Independence
ƒ P(Toothache,Cavity,Catch) has 23 = 8 entries (7 independent
entries)
ƒ If I have a cavity, the probability that the probe catches in it doesn't
depend on whether I have a toothache:
ƒ P(catch | toothache, cavity) = P(catch | cavity)
ƒ The same independence holds if I don’t have a cavity:
ƒ P(catch | toothache, ¬cavity) = P(catch| ¬cavity)
ƒ Catch is conditionally independent of Toothache given Cavity:
ƒ P(Catch | Toothache, Cavity) = P(Catch | Cavity)
ƒ Equivalent statements:
ƒ P(Toothache | Catch , Cavity) = P(Toothache | Cavity)
ƒ P(Toothache, Catch | Cavity) = P(Toothache | Cavity) P(Catch | Cavity)
13
Conditional Independence
ƒ Unconditional (absolute) independence is very rare
(why?)
ƒ Conditional independence is our most basic and robust
form of knowledge about uncertain environments:
ƒ What about this domain:
ƒ Traffic
ƒ Umbrella
ƒ Raining
ƒ What about fire, smoke, alarm?
The Chain Rule II
ƒ Can always factor any joint distribution as an incremental
product of conditional distributions
ƒ Why?
ƒ This actually claims nothing…
ƒ What are the sizes of the tables we supply?
14
The Chain Rule III
ƒ Trivial decomposition:
ƒ With conditional independence:
ƒ Conditional independence is our most basic and robust
form of knowledge about uncertain environments
ƒ Graphical models (next class) will help us work with
independence
Combining Evidence
ƒ Imagine we have two sensor readings
ƒ We want to calculate the distribution over
ship locations given those observations:
ƒ List the probabilities we are given
ƒ We first calculate the non-conditional
(joint) probabilities we care about
ƒ Then we renormalize
15