logical agents ece457 applied artificial intelligence spring 2007 lecture #6

37
Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

Upload: basil-johnson

Post on 13-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

Logical Agents

ECE457 Applied Artificial IntelligenceSpring 2007 Lecture #6

Page 2: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 2

Outline Logical reasoning Propositional Logic Wumpus World Inference

Russell & Norvig, chapter 7

Page 3: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 3

Logical Reasoning Recall: Game-playing with

imperfect information Partially-observable environment Need to infer about hidden

information Two new challenges

How to represent the information we have (knowledge representation)

How to use the information we have to infer new information and make decisions (knowledge reasoning)

Page 4: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 4

Knowledge Representation Represent facts about the environment

Many ways: ontologies, mathematical functions, …

Statements that are either true or false Language

To write the statements Syntax: symbols (words) and rules to

combine them (grammar) Semantics: meaning of the statements Expressiveness vs. efficiency

Knowledge base (KB) Contains all the statements Agent can TELL it new statements (update) Agent can ASK it for information (query)

Page 5: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 5

Knowledge Representation Example: Language of arithmetic Syntax describes well-formed

formulas (WFF) X + Y > 7 (WFF) X 7 @ Y + (not a WFF)

Semantics describes meanings of formulas “X + Y > 7” is true if and only if the

value of X and the value of Y summed together is greater than 7

Page 6: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 6

Knowledge Reasoning Inference

Discovering new facts and drawing conclusions based on existing information

During ASK or TELL “All humans are mortal”

“Socrates is human” Entailment

A sentence is inferred from sentences is true given that the are true entails

Page 7: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 7

Propositional Logic Sometimes called “Boolean Logic”

Sentences are true (T) or false (F) Words of the syntax include

propositional symbols… P, Q, R, … P = “I’m hungry”, Q = “I have money”,

R = “I’m going to a restaurant” … and logical connectives

¬ negation NOT conjunction AND disjunction OR implication IF-THEN biconditional IF AND ONLY IF

Page 8: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 8

Propositional Logic Atomic sentences

Propositional symbols True or false

Complex sentences Groups of propositional symbols

joined with connectives, and parenthesis if needed

(P Q) R Well-formed formulas following

grammar rules of the syntax

Page 9: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 9

Propositional Logic Complex

sentences evaluate to true or false

Using truth tables Semantics

P Q R P Q (P Q) R

T T T T T

F T T F T

T F T F T

F F T F T

T T F T F

F T F F T

T F F F T

F F F F T

Page 10: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 10

Propositional Logic Semantics

P Q ¬P

P Q P Q P Q P Q

T T F T T T T

F T T F T T F

T F F F T F F

F F T F F T T

Truth tables for all connectives Given each possible truth value of each

propositional symbol, we can get the possible truth values of the expression

Page 11: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 11

Propositional Logic Example

Propositional symbols: A = “The car has gas” B = “I can go to the

store” C = “I have money” D = “I can buy food” E = “The sun is

shining” F = “I have an

umbrella” G = “I can go on a

picnic”

If the car has gas, then I can go to the store A B

I can buy food if I can go to the store and I have money (B C) D

If I can buy food and either the sun is not shining or I have an umbrella, I can go on a picnic D (¬E F) G

Page 12: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 12

D E F G ¬E

¬E F D (¬E F) D (¬E F) G

T T T T F T T T

F T T T F T F T

T F T T T T T T

F F T T T T F T

T T F T F F F T

F T F T F F F T

T F F T T T T T

F F F T T T F T

T T T F F T T F

F T T F F T F T

T F T F T T T F

F F T F T T F T

T T F F F F F T

F T F F F F F T

T F F F T T T F

F F F F T T F T

Page 13: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 13

Wumpus World 2D cave divided

in rooms Gold

Glitters Agent has to pick

it up Pits

Agent falls in and dies

Agent feels breeze near pit

Wumpus Agent gets eaten and dies if Wumpus alive Agent can kill Wumpus with arrow Agent smells stench near Wumpus (alive or dead)

4321

1

2

3

4

Page 14: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 14

Wumpus World Initial state:

(1,1) Goal:

Get the gold and get back to (1,1)

Actions: Turn 90°,

move forward, shoot arrow, pick up gold

Cost: +1000 for getting gold, -1000 for dying,

-1 per action, -10 for shooting the arrow

4321

1

2

3

4

Page 15: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 15

Exploring the Wumpus World

4321

1

2

3

4

OK

OKPit?

Pit?

Wumpus?

Wumpus?OK

Page 16: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 16

Wumpus World Logic Propositional symbols

Pi,j = “there is a pit at (i,j)” Bi,j = “there is a breeze at (i,j)” Si,j = “there is a stench at (i,j)” Wi,j = “there is a Wumpus at (i,j)” Ki,j = “(i,j) is ok”

Rules Pi,j (Bi+1,j Bi-1,j Bi,j+1 Bi,j-1) Wi,j (Si+1,j Si-1,j Si,j+1 Si,j-1) Bi,j (Pi+1,j Pi-1,j Pi,j+1 Pi,j-1) Si,j (Wi+1,j Wi-1,j Wi,j+1 Wi,j-1) Ki,j (¬Wi,j ¬Pi,j)

Have to be written out for every (i,j)

Page 17: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 17

Wumpus World KB

4321

1

2

3

41. K1,1

2. ¬B1,1

3. ¬S1,1

a. B1,1 (P2,1 P1,2)

b. S1,1 (W2,1 W1,2)

c. K2,1(¬W2,1¬P2,1)

d. K1,2(¬W1,2¬P1,2)

Page 18: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 18

Wumpus World Inference

B1,

1

P1,2 P2,1 ¬B1,

1

P1,2P2,1 B1,1 (P1,2P2,1)

T T T F T T

T F T F T T

T T F F T T

T F F F F F

F T T T T F

F F T T T F

F T F T T F

F F F T F T

1. K1,1 3. ¬S1,1

2. ¬B1,1

1. K1,1 3. ¬S1,1 5. ¬P2,1

2. ¬B1,1 4. ¬P1,2

Page 19: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 19

1. K1,1 3. ¬S1,1 5. ¬P2,1 7. ¬W2,1

2. ¬B1,1 4. ¬P1,2 6. ¬W1,2

Wumpus World Inference

S1,

1

W1,

2

W2,

1

¬S1,

1

W1,2W2,1 S1,1 (W1,2W2,1)

T T T F T T

T F T F T T

T T F F T T

T F F F F F

F T T T T F

F F T T T F

F T F T T F

F F F T F T

Page 20: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 20

1. K1,1 3. ¬S1,1 5. ¬P2,1 7. ¬W2,1

2. ¬B1,1 4. ¬P1,2 6. ¬W1,2

1. K1,1 3. ¬S1,1 5. ¬P2,1 7. ¬W2,1 9. K2,1

2. ¬B1,1 4. ¬P1,2 6. ¬W1,2 8. K1,2

Wumpus World Inference

P1,

2

W1,

2

K1,

2

¬P1,

2

¬W1,

2

¬W1,2¬P1,

2

K1,2 (¬W1,2¬P1,2)

T T T F F F F

F T T T F F F

T F T F T F F

F F T T T T T

T T F F F F T

F T F T F F T

T F F F T F T

F F F T T T F

Page 21: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 21

10.B2,1

11.P3,1

12.¬S2,1

13.¬W2,2

14.¬W3,1

15.¬B1,2

16.¬P1,3

17.¬P2,2

18.S1,2

19.W1,3

20.K2,2

Wumpus World KB1. K1,1

2. ¬B1,1

3. ¬S1,1

4. ¬P1,2

5. ¬P2,1

6. ¬W1,2

7. ¬W2,1

8. K1,2

9. K2,1

4321

1

2

3

4

OK

OKPit?

Pit?

Wumpus?

Wumpus?OK

10.B2,1

11.P2,2 P3,1

12.¬S2,1

13.¬W2,2

14.¬W3,115.¬B1,2

16.¬P1,3

17.¬P2,2

18.S1,2

19.W1,3 W2,2

Page 22: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 22

Inference with Truth Tables Sound

Only infers true conclusions from true premises

Complete Finds all facts entailed by KB

Time complexity = O(2n) Checks all truth values of all symbols

Space complexity = O(n)

Page 23: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 23

Inference with Rules Speed up inference by using

inference rules Use along with logical

equivalences No need to enumerate and

evaluate every truth value

Page 24: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 24

Rules and Equivalences Logical equivalences

(α β) (β α) (α β) (β α) ((α β) γ) (α (β γ)) ((α β) γ) (α (β γ)) ¬(¬α) α (α β) (¬β ¬α) (α β) (¬α β) (α β) ((α β) (β α)) ¬(α β) (¬α ¬β) ¬(α β) (¬α ¬β) (α (β γ)) ((α β) (α γ)) (α (β γ)) ((α β) (α γ))

Inference rules (α β), α

β (α β)

α α, β

(αβ) (α β), ¬β

α (αβ), (¬βγ)

(α γ))

Page 25: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 25

Wumpus World & Inference Rules

KB: ¬B1,1

1. B1,1 (P2,1 P1,2) Biconditional elimination

2. (B1,1 (P2,1 P1,2)) ((P2,1 P1,2) B1,1) And elimination

3. (P2,1 P1,2) B1,1 Contraposition

4. ¬B1,1 ¬(P2,1 P1,2) Modus Ponens

5. ¬(P2,1 P1,2) De Morgan’s Rule

¬P2,1 ¬P1,2

Page 26: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 26

Resolution Inference with rules is sound, but only

complete if we have all the rules Resolution rule is both sound and

complete (αβ), (¬βγ)

(α γ)) But it only works on disjunctions!

Conjunctive normal form (CNF) Eliminate biconditionals:

(αβ) ((αβ)(βα)) Eliminate implications: (α β) (¬α β) Move/Eliminate negations: ¬(¬α) α,

¬(α β) (¬α ¬β), ¬(α β) (¬α ¬β) Distribute over : (α (βγ)) ((αβ) (αγ))

Page 27: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 27

CNF Example1. B1,1 (P2,1 P1,2)

Eliminate biconditionals

2. (B1,1 (P2,1 P1,2)) ((P2,1 P1,2) B1,1) Eliminate implications

3. (¬B1,1 P2,1 P1,2) (¬(P2,1 P1,2) B1,1) Move/Eliminate negations

(¬B1,1 P2,1 P1,2) ((¬P2,1 ¬P1,2) B1,1)1. Distribute over

1. (¬B1,1 P2,1 P1,2) (¬P2,1 B1,1) (¬P1,2 B1,1)

Page 28: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 28

Resolution Algorithm Given a KB Need to answer a query α

KB α ? Proof by contradiction

Show that (KB ¬α) is unsatisfiable i.e. leads to a contradiction

If (KB ¬α), then (KB α) must be true

Page 29: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 29

Resolution Algorithm Convert (KB ¬α) into CNF For every pair of clauses that

contain complementary symbols Apply resolution to generate a new

clause Add new clause to sentence

End when Resolution gives the empty clause (KB

α) No new clauses can be added (fail)

Page 30: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 30

Wumpus World & Resolution (¬B1,1 P1,2 P2,1) (¬P1,2 B1,1) (¬P2,1

B1,1) CNF form of B1,1 (P2,1 P1,2)

¬B1,1

Query: ¬P1,2

(¬B1,1 P1,2 P2,1) (¬P1,2 B1,1) (¬P2,1 B1,1) ¬B1,1 P1,2

(¬B1,1 P1,2 P2,1) (¬P1,2 B1,1) ¬P2,1 P1,2

(¬B1,1 P1,2 P2,1) (¬P1,2 B1,1) Empty clause!

KB ¬P1,2

Page 31: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 31

Resolution Algorithm Sound Complete Not efficient

Page 32: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 32

Horn Clauses Resolution algorithm can be further

improved by using Horn clauses Disjunction clause with at most

one positive symbol ¬α ¬β γ

Can be rewritten as implication (α β) γ

Inference in linear time! Using Modus Ponens Forward or backward chaining

Page 33: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 33

Forward Chaining Data-driven reasoning

Start with known symbols Infer new symbols and add to KB Use new symbols to infer more new symbols Repeat until query proven or no new

symbols can be inferred Work forward from known data, towards

proving goal1. KB: α, β, δ, ε2. (α β) γ3. (δ ε) λ4. (λ γ) q

Page 34: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 34

Backward Chaining Goal-driven reasoning

Start with query, try to infer it If there are unknown symbols in the

premise of the query, infer them first If there are unknown symbols in the

premise of these symbols, infer those first Repeat until query proven or its premise

cannot be inferred Work backwards from goal, to prove

needed information1. KB: α, β, δ, ε2. (λ γ) q3. (δ ε) λ4. (α β) γ

Page 35: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 35

Forward vs. Backward Forward chaining

Proves everything Goes to work as soon as new information is

available Expands the KB a lot

Improves understanding of the world Typically used for proving a world model

Backward chaining Proves only what is needed for the goal Does nothing until a query is asked Expands the KB as little as needed

More efficient Typically used for proofs by contradiction

Page 36: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 36

Assumptions Utility-based agent Environment

Fully observable / Partially observable (approximation)

Deterministic / Strategic / Stochastic Sequential Static / Semi-dynamic Discrete / Continuous Single agent / Multi-agent

Page 37: Logical Agents ECE457 Applied Artificial Intelligence Spring 2007 Lecture #6

ECE457 Applied Artificial Intelligence R. Khoury (2007) Page 37

Assumptions Updated Learning agent Environment

Fully observable / Partially observable Deterministic / Strategic / Stochastic Sequential Static / Semi-dynamic Discrete / Continuous Single agent / Multi-agent