Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for...

126
Introduction to Artificial Intelligence with Python

Transcript of Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for...

Page 1: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Introduction to Artificial Intelligence

with Python

Page 2: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Uncertainty

Page 3: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities
Page 4: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities
Page 5: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities
Page 6: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Probability

Page 7: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(ω)

Possible Worlds

Page 8: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(ω)

Page 9: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

0 ≤ P(ω) ≤ 1

Page 10: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

0 ≤ P(ω) = 1∑ω∈Ω

Page 11: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

16

16

16

16

16

16

Page 12: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P( ) = 1/616

Page 13: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities
Page 14: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities
Page 15: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

234567

345678

456789

5678910

67891011

789101112

Page 16: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

234567

345678

456789

5678910

67891011

789101112

Page 17: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

234567

345678

456789

5678910

67891011

789101112

Page 18: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(sum to 7) =

P(sum to 12) =136636

=16

Page 19: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

unconditional probability

degree of belief in a proposition in the absence of any other evidence

Page 20: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

conditional probability

degree of belief in a proposition given some evidence that has already been revealed

Page 21: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

conditional probability

P(a | b)

Page 22: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(rain today | rain yesterday)

Page 23: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(route change | traffic conditions)

Page 24: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(disease | test results)

Page 25: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(a |b) =P(a ∧ b)

P(b)

Page 26: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(sum 12 | )

Page 27: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities
Page 28: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

=16

P( )

Page 29: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

=16

P( )

=136

P(sum 12)

=16

P(sum 12 | )

Page 30: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(a |b) =P(a ∧ b)

P(b)

P(a ∧ b) = P(b)P(a |b)

P(a ∧ b) = P(a)P(b |a)

Page 31: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

random variable

a variable in probability theory with a domain of possible values it can take on

Page 32: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

random variable

Roll

{1, 2, 3, 4, 5, 6}

Page 33: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

random variable

Weather

{sun, cloud, rain, wind, snow}

Page 34: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

random variable

Traffic

{none, light, heavy}

Page 35: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

random variable

Flight

{on time, delayed, cancelled}

Page 36: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

probability distribution

P(Flight = on time) = 0.6 P(Flight = delayed) = 0.3 P(Flight = cancelled) = 0.1

Page 37: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

probability distribution

P(Flight) = ⟨0.6, 0.3, 0.1⟩

Page 38: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

independence

the knowledge that one event occurs does not affect the probability of the other event

Page 39: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

independence

P(a ∧ b) = P(a)P(b |a)

Page 40: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

independence

P(a ∧ b) = P(a)P(b)

Page 41: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

independence

P( ) = P( )P( )

=16

⋅16

=136

Page 42: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

independence

P( ) ≠ P( )P( )

=16

⋅16

=136

Page 43: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

independence

P( ) ≠ P( )P( | )

=16

⋅ 0 = 0

Page 44: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Bayes' Rule

Page 45: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(a ∧ b) = P(b) P(a |b)

P(a ∧ b) = P(a) P(b |a)

Page 46: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

= P(b) P(a |b)P(a) P(b |a)

Page 47: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

= P(b) P(a |b)P(a)

P(b |a)

Bayes' Rule

Page 48: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

= P(b)P(a |b)P(a)

P(b |a)

Bayes' Rule

Page 49: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

PMAM

Given clouds in the morning, what's the probability of rain in the afternoon?

• 80% of rainy afternoons start with cloudy mornings. • 40% of days have cloudy mornings. • 10% of days have rainy afternoons.

Page 50: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(rain |clouds) =P(clouds |rain)P(rain)

P(clouds)

=(.8)(.1)

.4

= 0.2

Page 51: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(cloudy morning | rainy afternoon)

Knowing

we can calculate

P(rainy afternoon | cloudy morning)

Page 52: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(visible effect | unknown cause)

Knowing

we can calculate

P(unknown cause | visible effect)

Page 53: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(medical test result | disease)

Knowing

we can calculate

P(disease | medical test result)

Page 54: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(blurry text | counterfeit bill)

Knowing

we can calculate

P(counterfeit bill | blurry text)

Page 55: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Joint Probability

Page 56: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

C = cloud C = ¬cloud

0.4 0.6

AM

R = rain R = ¬rainC = cloud 0.08 0.32

C = ¬cloud 0.02 0.58

PM

R = rain R = ¬rain

0.1 0.9

AMPM

Page 57: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(C | rain)

R = rain R = ¬rainC = cloud 0.08 0.32

C = ¬cloud 0.02 0.58

P(C | rain) = P(C, rain)

P(rain)= αP(C, rain)

= α⟨0.08, 0.02⟩ = ⟨0.8, 0.2⟩

Page 58: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Probability Rules

Page 59: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(¬a) = 1 − P(a)

Negation

Page 60: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(a ∨ b) = P(a) + P(b) − P(a ∧ b)

Inclusion-Exclusion

Page 61: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(a) = P(a, b) + P(a, ¬b)

Marginalization

Page 62: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(X = xi) = ∑j

P(X = xi, Y = yj)

Marginalization

Page 63: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

MarginalizationR = rain R = ¬rain

C = cloud 0.08 0.32C = ¬cloud 0.02 0.58

P(C = cloud)= P(C = cloud, R = rain) + P(C = cloud, R = ¬rain)= 0.08 + 0.32= 0.40

Page 64: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(a) = P(a |b)P(b) + P(a |¬b)P(¬b)

Conditioning

Page 65: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(X = xi) = ∑j

P(X = xi |Y = yj)P(Y = yj)

Conditioning

Page 66: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Bayesian Networks

Page 67: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Bayesian network

data structure that represents the dependencies among random variables

Page 68: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Bayesian network

• directed graph • each node represents a random variable • arrow from X to Y means X is a parent of Y • each node X has probability distribution

P(X | Parents(X))

Page 69: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

Page 70: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Rain {none, light, heavy}

none light heavy

0.7 0.2 0.1

Page 71: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Maintenance {yes, no}

Rain {none, light, heavy}

R yes nonone 0.4 0.6light 0.2 0.8heavy 0.1 0.9

Page 72: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

R M on time delayednone yes 0.8 0.2none no 0.9 0.1light yes 0.6 0.4light no 0.7 0.3heavy yes 0.4 0.6heavy no 0.5 0.5

Page 73: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

T attend miss

on time 0.9 0.1delayed 0.6 0.4

Page 74: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

Page 75: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

P(light)

P(light)

Computing Joint Probabilities

Page 76: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

P(light, no)

P(light) P(no | light)

Computing Joint Probabilities

Page 77: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

P(light, no, delayed)

P(light) P(no | light) P(delayed | light, no)

Computing Joint Probabilities

Page 78: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

P(light, no, delayed, miss)

P(light) P(no | light) P(delayed | light, no) P(miss | delayed)

Computing Joint Probabilities

Page 79: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Inference

Page 80: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Inference

• Query X: variable for which to compute distribution

• Evidence variables E: observed variables for event e

• Hidden variables Y: non-evidence, non-query variable.

• Goal: Calculate P(X | e)

Page 81: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

P(Appointment | light, no)

= α P(Appointment, light, no)

= α [P(Appointment, light, no, on time) + P(Appointment, light, no, delayed)]

Page 82: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Inference by Enumeration

P(X | e) = α P(X, e) = α y

P(X, e, y)

X is the query variable. e is the evidence. y ranges over values of hidden variables. α normalizes the result.

Page 83: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Approximate Inference

Page 84: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Sampling

Page 85: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

Page 86: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Rain {none, light, heavy}

none light heavy

0.7 0.2 0.1

R = none

Page 87: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Maintenance {yes, no}

Rain {none, light, heavy}

R yes nonone 0.4 0.6light 0.2 0.8heavy 0.1 0.9

R = noneM = yes

Page 88: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

R M on time delayednone yes 0.8 0.2none no 0.9 0.1light yes 0.6 0.4light no 0.7 0.3heavy yes 0.4 0.6heavy no 0.5 0.5

R = noneM = yes

T = on time

Page 89: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

T attend miss

on time 0.9 0.1delayed 0.6 0.4

R = noneM = yes

T = on timeA = attend

Page 90: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

R = noneM = yes

T = on timeA = attend

Page 91: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

R = noneM = yes

T = on timeA = attend

R = noneM = no

T = on timeA = attend

R = lightM = yes

T = delayedA = attend

R = lightM = no

T = on timeA = miss

R = noneM = yes

T = on timeA = attend

R = noneM = yes

T = on timeA = attend

R = heavyM = no

T = delayedA = miss

R = lightM = no

T = on timeA = attend

Page 92: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(Train = on time) ?

Page 93: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

R = noneM = yes

T = on timeA = attend

R = noneM = no

T = on timeA = attend

R = lightM = yes

T = delayedA = attend

R = lightM = no

T = on timeA = miss

R = noneM = yes

T = on timeA = attend

R = noneM = yes

T = on timeA = attend

R = heavyM = no

T = delayedA = miss

R = lightM = no

T = on timeA = attend

Page 94: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

R = noneM = yes

T = on timeA = attend

R = noneM = no

T = on timeA = attend

R = lightM = yes

T = delayedA = attend

R = lightM = no

T = on timeA = miss

R = noneM = yes

T = on timeA = attend

R = noneM = yes

T = on timeA = attend

R = heavyM = no

T = delayedA = miss

R = lightM = no

T = on timeA = attend

Page 95: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(Rain = light | Train = on time) ?

Page 96: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

R = noneM = yes

T = on timeA = attend

R = noneM = no

T = on timeA = attend

R = lightM = yes

T = delayedA = attend

R = lightM = no

T = on timeA = miss

R = noneM = yes

T = on timeA = attend

R = noneM = yes

T = on timeA = attend

R = heavyM = no

T = delayedA = miss

R = lightM = no

T = on timeA = attend

Page 97: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

R = noneM = yes

T = on timeA = attend

R = noneM = no

T = on timeA = attend

R = lightM = yes

T = delayedA = attend

R = lightM = no

T = on timeA = miss

R = noneM = yes

T = on timeA = attend

R = noneM = yes

T = on timeA = attend

R = heavyM = no

T = delayedA = miss

R = lightM = no

T = on timeA = attend

Page 98: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

R = noneM = yes

T = on timeA = attend

R = noneM = no

T = on timeA = attend

R = lightM = yes

T = delayedA = attend

R = lightM = no

T = on timeA = miss

R = noneM = yes

T = on timeA = attend

R = noneM = yes

T = on timeA = attend

R = heavyM = no

T = delayedA = miss

R = lightM = no

T = on timeA = attend

Page 99: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Rejection Sampling

Page 100: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Likelihood Weighting

Page 101: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Likelihood Weighting

• Start by fixing the values for evidence variables.

• Sample the non-evidence variables using conditional probabilities in the Bayesian Network.

• Weight each sample by its likelihood: the probability of all of the evidence.

Page 102: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

P(Rain = light | Train = on time) ?

Page 103: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

Page 104: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Rain {none, light, heavy}

none light heavy

0.7 0.2 0.1

T = on time

R = light

Page 105: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Maintenance {yes, no}

Rain {none, light, heavy}

R yes nonone 0.4 0.6light 0.2 0.8heavy 0.1 0.9

T = on time

R = lightR = lightM = yes

Page 106: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

R M on time delayednone yes 0.8 0.2none no 0.9 0.1light yes 0.6 0.4light no 0.7 0.3heavy yes 0.4 0.6heavy no 0.5 0.5

T = on time

R = lightR = lightM = yes

Page 107: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Appointment {attend, miss}

Train {on time, delayed}

Maintenance {yes, no}

T attend miss

on time 0.9 0.1delayed 0.6 0.4

T = on time

R = lightR = lightM = yesR = lightM = yes

A = attend

Page 108: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

R M on time delayednone yes 0.8 0.2none no 0.9 0.1light yes 0.6 0.4light no 0.7 0.3heavy yes 0.4 0.6heavy no 0.5 0.5

T = on time

R = lightR = lightM = yesR = lightM = yes

A = attend

Page 109: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Train {on time, delayed}

Maintenance {yes, no}

Rain {none, light, heavy}

R M on time delayednone yes 0.8 0.2none no 0.9 0.1light yes 0.6 0.4light no 0.7 0.3heavy yes 0.4 0.6heavy no 0.5 0.5

T = on time

R = lightR = lightM = yesR = lightM = yes

A = attend

Page 110: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Uncertainty over Time

Page 111: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Xt: Weather at time t

Page 112: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Markov assumption

the assumption that the current state depends on only a finite fixed number of previous states

Page 113: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Markov Chain

Page 114: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Markov chain

a sequence of random variables where the distribution of each variable follows the Markov assumption

Page 115: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

0.8 0.2

0.3 0.7Today (Xt)

Tomorrow (Xt+1)

Transition Model

Page 116: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

X0 X1 X2 X3 X4

Page 117: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Sensor Models

Page 118: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Hidden State Observation

robot's position robot's sensor data

words spoken audio waveforms

user engagement website or app analytics

weather umbrella

Page 119: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Hidden Markov Models

Page 120: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Hidden Markov Model

a Markov model for a system with hidden states that generate some observed event

Page 121: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

0.2 0.8

0.9 0.1State (Xt)

Observation (Et)

Sensor Model

Page 122: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

sensor Markov assumption

the assumption that the evidence variable depends only the corresponding state

Page 123: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

X0 X1 X2 X3 X4

E0 E1 E2 E3 E4

Page 124: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Task Definition

filteringgiven observations from start until now, calculate distribution for current state

predictiongiven observations from start until now, calculate distribution for a future state

smoothinggiven observations from start until now,

calculate distribution for past state

most likely explanation

given observations from start until now, calculate most likely sequence of states

Page 125: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Uncertainty

Page 126: Introduction to Artificial Intelligence · Likelihood Weighting •Start by fixing the values for evidence variables. •Sample the non-evidence variables using conditional probabilities

Introduction to Artificial Intelligence

with Python