chapter 7 logical agents - hacettepe

125
1 Logical Agents Artificial Intelligence Slides are mostly adapted from AIMA and MIT Open Courseware

Upload: others

Post on 13-Mar-2022

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 7 Logical Agents - Hacettepe

1

Logical Agents

Artificial Intelligence

Slides are mostly adapted from AIMA and MIT Open Courseware

Page 2: Chapter 7 Logical Agents - Hacettepe

2

Outline

• Knowledge-based agents

• Wumpus world

• Logic in general - models and entailment

• Propositional (Boolean) logic

• Equivalence, validity, satisfiability

• Inference rules and theorem proving

• Resolution

• Forward chaining

• Backward chaining

Page 3: Chapter 7 Logical Agents - Hacettepe

3

Introduction

• The representation of knowledge and the reasoning processes that bring

knowledge to life are central to entire field of artificial intelligence

• Knowledge and reasoning are important to artificial agents because they

enable successful behaviors that would be very hard to achieve otherwise (no

piece in chess can be on two different squares at the same time)

• Knowledge and reasoning also play a crucial role in dealing with partially

observable environments (inferring hidden states in diagnosing diseases,

natural language understanding)

• Knowledge also allows flexibility.

Page 4: Chapter 7 Logical Agents - Hacettepe

4

Knowledge bases

• Knowledge base = set of sentences in a formal language

• Each sentence is expressed in a knowledge representation language and represents some assertions about the world

• There should be a way to add new sentences to KB, and to query what is known

• Declarative approach to building an agent (or other system):

– TELL it what it needs to know

– Then it can ASK itself what to do - answers should follow from the KB

• Both tasks may involve inference – deriving new sentences from old

• In logical agents – when one ASKs a question to KB, the answer should follow from what has been TELLed

• Agents can be viewed at the knowledge level

i.e., what they know, regardless of how implemented

• Or at the implementation level

– i.e., data structures in KB and algorithms that manipulate them

Page 5: Chapter 7 Logical Agents - Hacettepe

5

A simple knowledge-based agent

• KB : maintain the background knowledge

• Each time the agent program is called it does three things

– TELLs the KB what it perceives

– ASK the KB what action it should perform

– TELL the KB that the action is executed

• The agent must be able to:

– Represent states, actions, etc.

– Incorporate new percepts

– Update internal representations of the world

– Deduce hidden properties of the world

– Deduce appropriate actions

• Declarative versus procedural approaches

Page 6: Chapter 7 Logical Agents - Hacettepe

6

Wumpus World PEAS description

• Performance measure

– gold +1000, death -1000

– -1 per step, -10 for using the arrow

• Environment

– Squares adjacent to wumpus are smelly (stench)

– Squares adjacent to pit are breezy

– Glitter iff gold is in the same square

– Shooting kills wumpus if you are facing it

– Shooting uses up the only arrow

– Grabbing picks up gold if in same square

– Releasing drops the gold in same square

• Sensors: Stench, Breeze, Glitter, Bump, Scream

• Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot

Page 7: Chapter 7 Logical Agents - Hacettepe

7

Wumpus world characterization

• Fully Observable No – only local perception

• Deterministic Yes – outcomes exactly specified

• Episodic No – sequential at the level of actions

• Static Yes – Wumpus and Pits do not move

• Discrete Yes

• Single-agent? Yes – Wumpus is essentially a natural

feature

Page 8: Chapter 7 Logical Agents - Hacettepe

8

Exploring a wumpus world

[1,1] is OK

Because

Haven’t fallen into a pit

Haven’t been eaten by a Wumpus

[1,2] and [2,1] are OK

Because

No stench

No breeze

Page 9: Chapter 7 Logical Agents - Hacettepe

9

Exploring a wumpus world

We move to [1,2] and

Feel a Breeze

Page 10: Chapter 7 Logical Agents - Hacettepe

10

Exploring a wumpus world

Page 11: Chapter 7 Logical Agents - Hacettepe

11

Exploring a wumpus world

Page 12: Chapter 7 Logical Agents - Hacettepe

12

Exploring a wumpus world

Page 13: Chapter 7 Logical Agents - Hacettepe

13

Exploring a wumpus world

Page 14: Chapter 7 Logical Agents - Hacettepe

14

Exploring a wumpus world

Page 15: Chapter 7 Logical Agents - Hacettepe

15

Exploring a wumpus world

Page 16: Chapter 7 Logical Agents - Hacettepe

16

Logic in general

• Logics are formal languages for representing information such that conclusions can be

drawn

• Syntax defines the sentences in the language

• Semantics define the "meaning" of sentences;

– i.e., define truth of a sentence in a world

• E.g., the language of arithmetic

– x+2 ≥ y is a sentence; x2+y > {} is not a sentence

– x+2 ≥ y is true iff the number x+2 is no less than the number y

– x+2 ≥ y is true in a world where x = 7, y = 1

– x+2 ≥ y is false in a world where x = 0, y = 6

Page 17: Chapter 7 Logical Agents - Hacettepe

17

Entail : involve (something) as a necessary or inevitable part or consequence.

Page 18: Chapter 7 Logical Agents - Hacettepe

18

Entailment

• Entailment means that one thing follows from another:

KB ╞ α

• Knowledge base KB entails sentence α if and only if α is

true in all worlds where KB is true

– If α true then KB must also be true

– E.g., the KB containing “the Giants won” and “the Reds won”

entails “Either the Giants won or the Reds won”

– E.g., x+y = 4 entails 4 = x+y

– Entailment is a relationship between sentences (i.e., syntax) that is

based on semantics

Page 19: Chapter 7 Logical Agents - Hacettepe

19

Models

• Logicians typically think in terms of models, which are formally structured

worlds with respect to which truth can be evaluated

• We say m is a model of a sentence α if α is true in m

• M(α) is the set of all models of α

• Then KB ╞ α iff M(KB) M(α)

– E.g. KB = Giants won and Reds won

α = Giants won

Possible world – model m is a model of α – the sentence α is true in model m

Page 20: Chapter 7 Logical Agents - Hacettepe

20

Entailment in the wumpus world

• Situation after detecting nothing in [1,1], moving right, breeze in [2,1]

Page 21: Chapter 7 Logical Agents - Hacettepe

21

Wumpus models

3 Boolean choices 8 possible models

for the adjacent squares [1,2], [2,2] and [3,1] to contain pits

Page 22: Chapter 7 Logical Agents - Hacettepe

22

Wumpus models

• KB = wumpus-world rules + observations

• KB is false in any model in which [1,2] contains a

pit, because there is no breeze in [1,1]

Consider possible models for KB assuming only pits

Page 23: Chapter 7 Logical Agents - Hacettepe

23

Wumpus models

• Consider α1 = “[1,2] is safe” = “There is no pit in [1,2]”

• In every model KB is true α1 is also true

• KB ╞ α1, proved by model checking

• We can conclude that there is no pit in [1,2]

Page 24: Chapter 7 Logical Agents - Hacettepe

24

Wumpus models

• Consider α2 = “[2,2] is safe” = “There is no pit in [2,2]”

• In some models in which KB is true α2 is false

• KB ╞/ α2

• We cannot conclude that there is no pit in [2,2]

Page 25: Chapter 7 Logical Agents - Hacettepe

25

Inference

• KB ├i α = sentence α can be derived from KB by a procedure i (an inference

algorithm)

• Soundness: i is sound if whenever KB ├i α, it is also true that KB╞ α

• An inference algorithm that derives only entailed sentences is sound or truth

preserving (model checking is a sound procedure)

– If the system proves that something is true, then it is really true. The system

doesn’t derive contradictions

• Completeness: i is complete if whenever KB╞ α, it is also true that KB ├i α

• An inference algorithm is complete if it can derive any sentence that is entailed

– If something is really true, it can be proven using the system. The system can be

used to derive all the true statements one by one

• If KB is true in the real world then any sentence α derived from KB by a sound

inference procedure is also true in real world

– The conclusions of the reasoning process are guaranteed to be true in any world

in which the premises are true

Page 26: Chapter 7 Logical Agents - Hacettepe

26

Inference

• An unsound inference procedure essentially makes things up as it goes

along – it announces the discovery of non-existent needles

• For completeness, a systematic examination can always decide

whether the needle is in the haystack which is finite

Cartoon illustrations by John P. Weiss

All consequences of a KB is a haystack

α is a needle

Entailment

The needle being in the haystack

Inference

Finding the needle

Page 27: Chapter 7 Logical Agents - Hacettepe

27

Semantics and Inference

• Interpretation: establishing a correspondence between sentences and

facts

• Compositional: the meaning of a sentence is a function of the

meaning of its parts

• A sentence is TRUE under a particular interpretation if the state of

the affairs it represents is the case

• S1,2 would be true

– under the interpretation

“there is a stench in [1,2]”

– on this Wumpus world

Page 28: Chapter 7 Logical Agents - Hacettepe

28

Validity and satisfiability

A sentence is valid if it is true in all models,

e.g. “There is a stench at [1,1] or there is not a stench at [1,1]”

Valid sentences are also called as tautologies

Every valid sentence is equivalent to True

A sentence is satisfiable if it is true in some model

e.g. “There is a Wumpus at [1,2]”

If a sentence is true in a model m, then we say m satisfies the sentence, or a model of the sentence

A sentence is unsatisfiable if it is true in no models

e.g. “There is a wall in front of me and there is no wall in front of me”

Page 29: Chapter 7 Logical Agents - Hacettepe

29

Logics - Summary

Logic consists of

• A formal system consisting of

– syntax

– semantics

• The proof theory

Page 30: Chapter 7 Logical Agents - Hacettepe

30

Propositional logic: Syntax

• Propositional logic is the simplest logic – illustrates basic ideas

• Atomic sentences : consists of

– logical constants True and False

– proposition symbols P1, P2

• Complex sentences : constructed from atomic sentences using logical connectives , , , , and parentheses

– If S is a sentence, S is a sentence (negation)

– If S1 and S2 are sentences, S1 S2 is a sentence (conjunction)

– If S1 and S2 are sentences, S1 S2 is a sentence (disjunction)

– If S1 and S2 are sentences, S1 S2 is a sentence (implication)

– If S1 and S2 are sentences, S1 S2 is a sentence (biconditional, equivalence)

Page 31: Chapter 7 Logical Agents - Hacettepe

31

Page 32: Chapter 7 Logical Agents - Hacettepe

32

Precedence– Use parentheses to specify the precedence

– Otherwise the precedence from highest to lowest is: , , , ,

– A B C is not allowed

Page 33: Chapter 7 Logical Agents - Hacettepe

33

Propositional logic: Semantics

Semantics defines the rules for determining the truth of a sentence with respect to a particular model

Each model specifies true/false for each proposition symbol

E.g. P1,2 P2,2 P3,1

false true false

True is true in every model, False is false in every model

The truth value of every other proposition symbol must be specified directly in the model

For the complex sentences

Rules for evaluating truth with respect to a model m:

S is true iff S is false

S1 S2 is true iff S1 is true and S2 is true

S1 S2 is true iff S1is true or S2 is true

S1 S2 is true iff S1 is false or S2 is true

i.e., is false iff S1 is true and S2 is false

S1 S2 is true iff S1S2 is true and S2S1 is true

Page 34: Chapter 7 Logical Agents - Hacettepe

34

Truth tables for connectives

Most sentences are sometimes true:

e.g. P Q

Some sentences are always true (valid)

e.g. P P

Some sentences are never true (unsatisfiable)

e.g. P P

Page 35: Chapter 7 Logical Agents - Hacettepe

35

Implication and Biconditional

Implication: if P is true then I am claming that Q is true, otherwise I am making no claim

The sentence is false, if P is true but Q is false

P => Q is equivalent to ~P V Q

Pigs_Fly => EveryOneGetsAnA

Biconditional: True whenever both P->Q and Q->P is true

(e.g. a square is breezy if and only if adjacent square has a pit: implication requires the presence of

pit if there is a breeze, biconditional also requires the absence of pit if there is no breeze)

Page 36: Chapter 7 Logical Agents - Hacettepe

36

Validity and Inference

Page 37: Chapter 7 Logical Agents - Hacettepe

37

Logical equivalence

Page 38: Chapter 7 Logical Agents - Hacettepe

38

Logical equivalence

Two sentences are logically equivalent iff they are true in same models:

α ≡ ß iff α╞ β and β╞ α

Page 39: Chapter 7 Logical Agents - Hacettepe

39

Examples

Page 40: Chapter 7 Logical Agents - Hacettepe

40

Satisfiability

• Related to constraint satisfaction

• Given a sentence S, try to find an interpretation i

where S is true

• Analogous to finding an assignment of values to

variables such that the constraint hold

• Example problem: scheduling nurses in a hospital

– Propositional variables represent for example that Nurse1

is working on Tuesday at 2

– Constraints on the schedule are represented using logical

expressions over the variables

• Brute force method: enumerate all interpretations

and check

Page 41: Chapter 7 Logical Agents - Hacettepe

41

Wumpus world sentences

Let Pi,j be true if there is a pit in [i, j].

Let Bi,j be true if there is a breeze in [i, j].

Knowledge base includes:

R1: P1,1 No pit in [1,1]

R2: B1,1 No breeze in [1.1]

R3: B2,1 Breeze in [2,1]

• "Pits cause breezes in adjacent squares"

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

R5: B2,1 (P1,1 P2,2 P3,1)

KB = R1 R2 R3 R4 R5

Page 42: Chapter 7 Logical Agents - Hacettepe

42

Truth tables for inference R1: P1,1

R2: B1,1

R3: B2,1

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

R5: B2,1 (P1,1 P2,2 P3,1)

KB = R1 R2 R3 R4 R5

α1 = P1,2

α2 = P2,2

α1 is true in all models that

KB is true

α2 is true only in

two models that KB is true,

but false in the other one

• Decide whether KB╞ α

• First method: enumerate the models and

check that α is true in every model

in which KB is true

• B1,1 B2,1, P1,1 , P1,2, P2,1, P2,2, P3,1

• 7 symbols : 27 = 128 possible models

Page 43: Chapter 7 Logical Agents - Hacettepe

43

Inference by enumeration

• Depth-first enumeration of all models is sound and complete

• For n symbols, time complexity is O(2n), space complexity is O(n)

Page 44: Chapter 7 Logical Agents - Hacettepe

44

Example Problem

Page 45: Chapter 7 Logical Agents - Hacettepe

45

Checking Interpretations

• Start by figuring out what set of interpretations make our original sentences true.

• Then, if G is true in all those interpretations, it must be OK to conclude it from the sentences we started out with (our knowledge base).

• In a universe with only three variables, there are 8 possible interpretations in total.

Page 46: Chapter 7 Logical Agents - Hacettepe

46

Checking Interpretations

• Only one of these interpretations makes all the sentences in our knowledge base true:

• S = true, H = true, G = true.

Page 47: Chapter 7 Logical Agents - Hacettepe

47

Checking Interpretations

• it's easy enough to check that G is true in that interpretation, so it seems like it must be reasonable to draw the conclusion that the lecture will be good.

Page 48: Chapter 7 Logical Agents - Hacettepe

48

Computing entailment

Model checking

Truth table enumeration (sound and complete for

propositional logic)

For n symbols the time complexity is O(2^n)

Need a smarter way to do inference

Page 49: Chapter 7 Logical Agents - Hacettepe

49

Validity and Inference

premises conclusion

Page 50: Chapter 7 Logical Agents - Hacettepe

50

Entailment and Proof

Page 51: Chapter 7 Logical Agents - Hacettepe

51

Proof

Page 52: Chapter 7 Logical Agents - Hacettepe

52

Rules of ınference

• Recall that

• KB ├i α = sentence α can be derived from KB by a

procedure i (an inference algorithm)

• If we generalize it to any two sentences α and β

• α ├ β means that β is derived from α by an

inference

• The alternative notation:

α premise

β conclusion

Page 53: Chapter 7 Logical Agents - Hacettepe

53

Some inference rules

Page 54: Chapter 7 Logical Agents - Hacettepe

54

Example

Page 55: Chapter 7 Logical Agents - Hacettepe

55

Example

Page 56: Chapter 7 Logical Agents - Hacettepe

56

Example

Page 57: Chapter 7 Logical Agents - Hacettepe

57

Example

Page 58: Chapter 7 Logical Agents - Hacettepe

58

Example

Page 59: Chapter 7 Logical Agents - Hacettepe

59

Example

Page 60: Chapter 7 Logical Agents - Hacettepe

60

Page 61: Chapter 7 Logical Agents - Hacettepe

61

Logical equivalence

Page 62: Chapter 7 Logical Agents - Hacettepe

62

Example from Wumpus World

R1: P1,1

R2: B1,1

R3: B2,1

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

R5: B2,1 (P1,1 P2,2 P3,1)

KB = R1 R2 R3 R4 R5

Prove α1 = P1,2

Page 63: Chapter 7 Logical Agents - Hacettepe

63

Example from Wumpus World

R1: P1,1

R2: B1,1

R3: B2,1

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

R5: B2,1 (P1,1 P2,2 P3,1)

R6 : B1,1 (B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1) Biconditional elimination

Page 64: Chapter 7 Logical Agents - Hacettepe

64

Example from Wumpus World

R1: P1,1

R2: B1,1

R3: B2,1

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

R5: B2,1 (P1,1 P2,2 P3,1)

R6 : B1,1 (B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1) Biconditional elimination

R7 : ((P1,2 P2,1) B1,1) And Elimination

Page 65: Chapter 7 Logical Agents - Hacettepe

65

Example from Wumpus World

R1: P1,1

R2: B1,1

R3: B2,1

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

R5: B2,1 (P1,1 P2,2 P3,1)

R6 : B1,1 (B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1) Biconditional elimination

R7 : ((P1,2 P2,1) B1,1) And Elimination

R8: ( B1,1 (P1,2 P2,1)) Equivalence for contrapositives

Page 66: Chapter 7 Logical Agents - Hacettepe

66

Example from Wumpus World

R1: P1,1

R2: B1,1

R3: B2,1

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

R5: B2,1 (P1,1 P2,2 P3,1)

R6 : B1,1 (B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1) Biconditional elimination

R7 : ((P1,2 P2,1) B1,1) And Elimination

R8: ( B1,1 (P1,2 P2,1)) Equivalence for contrapositives

R9: (P1,2 P2,1) Modus Ponens with R2 and R8

Page 67: Chapter 7 Logical Agents - Hacettepe

67

Example from Wumpus World

R1: P1,1

R2: B1,1

R3: B2,1

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

R5: B2,1 (P1,1 P2,2 P3,1)

R6 : B1,1 (B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1) Biconditional elimination

R7 : ((P1,2 P2,1) B1,1) And Elimination

R8: ( B1,1 (P1,2 P2,1)) Equivalence for contrapositives

R9: (P1,2 P2,1) Modus Ponens with R2 and R8

R10: P1,2 P2,1 De Morgan’s Rule

Page 68: Chapter 7 Logical Agents - Hacettepe

68

Example from Wumpus World

R1: P1,1

R2: B1,1

R3: B2,1

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

R5: B2,1 (P1,1 P2,2 P3,1)

R6 : B1,1 (B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1) Biconditional elimination

R7 : ((P1,2 P2,1) B1,1) And Elimination

R8: ( B1,1 (P1,2 P2,1)) Equivalence for contrapositives

R9: (P1,2 P2,1) Modus Ponens with R2 and R8

R10: P1,2 P2,1 De Morgan’s Rule

R11: P1,2 And Elimination

Page 69: Chapter 7 Logical Agents - Hacettepe

69

Monotonicity

• The set of entailed sentences can only increase as

information is added to the knowledge base

• If

• KB╞ α

• Then

• KB β╞ α

Page 70: Chapter 7 Logical Agents - Hacettepe

71

Recall

• Logical Inference creates new sentences that

logically follow from a set of sentences in KB

• An inference rule is sound if every sentence X it

produces when operating on a KB logically

follows from the KB

• An inference rule is complete if it can produce

every expression that logically follows from (is

entailed by) the KB

Page 71: Chapter 7 Logical Agents - Hacettepe

72

Resolution

• Resolution is a sound and complete inference procedure

• If β is True, since we know that ¬ β ˅ γ holds, it must be

the case that γ is true

• If β is false, then since we know that ɑ ˅ β holds, it must

be the case that ɑ is true

• So either ɑ or γ is true

Page 72: Chapter 7 Logical Agents - Hacettepe

73

Resolution

or equivalently

Page 73: Chapter 7 Logical Agents - Hacettepe

74

Soundness of the resolution inference rules

• An inference rule is sound if the conclusion is true

in all cases where the premises are true

Page 74: Chapter 7 Logical Agents - Hacettepe

75

Generalized resolution rule

• Where P1 and ¬ P1 are complementary literals

Page 75: Chapter 7 Logical Agents - Hacettepe

76

Proof with resolution

Given the following hypotheses:

1.If it rains, Joe brings his umbrella

(r -> u)

2.If Joe has an umbrella, he doesn't get wet

(u -> NOT w)

3.If it doesn't rain, Joe doesn't get wet

(NOT r -> NOT w)

prove that Joes doesn't get wet (NOT w)

Page 76: Chapter 7 Logical Agents - Hacettepe

77

Proof with resolution

We first convert each hypothesis into disjunctions

1.r -> u

(NOT r OR u)

2.u -> NOT w

(NOT u OR NOT w)

3.NOT r -> NOT w

(r OR NOT w)

Page 77: Chapter 7 Logical Agents - Hacettepe

78

Proof with resolution

We then use resolution on the hypotheses to

derive the conclusion (NOT w):

1. NOT r OR u Premise

2. NOT u OR NOT w Premise

3. r OR NOT w Premise

4. NOT r OR NOT w L1, L2, resolution

5. NOT w OR NOT w L3, L4, resolution

6. NOT w L5, idempotence

Page 78: Chapter 7 Logical Agents - Hacettepe

79

Resolution covers many cases

Page 79: Chapter 7 Logical Agents - Hacettepe

80

Rewrite

P ≡ P ˅ False

¬P ≡ False ˅ ¬P

Apply resolution (P and ¬ P are complementary literals)

P ˅ False

False ˅ ¬P

False ˅ False False ˅ False ≡ False

Page 80: Chapter 7 Logical Agents - Hacettepe

81

Page 81: Chapter 7 Logical Agents - Hacettepe

82

Recall

A sentence is valid if it is true in all models,

KB ╞ α if and only if (KB α) is valid

A sentence is unsatisfiable if it is true in no models

α is valid iff α is unsatisfiable,

KB ╞ α if and only if (KB α) is unsatisfiable

(KB α) is equivalent to (KB ˅ α )

(KB α) is equivalent to (KB α )

Page 82: Chapter 7 Logical Agents - Hacettepe

83

Page 83: Chapter 7 Logical Agents - Hacettepe

85

Proof by contradiction using resolution

1. NOT r OR u Premise

2. NOT u OR NOT w Premise

3. r OR NOT w Premise

4. w Negation of conclusion

5. NOT r OR NOT w L1, L2, resolution

6. NOT w OR NOT w L3, L5, resolution

7. NOT w L6, idempotence

8. FALSE L4, L7, resolution

Page 84: Chapter 7 Logical Agents - Hacettepe

86

Page 85: Chapter 7 Logical Agents - Hacettepe

87

Conjunctive Normal form

Page 86: Chapter 7 Logical Agents - Hacettepe

88

Converting to CNF

Page 87: Chapter 7 Logical Agents - Hacettepe

89

CNF Conversion Example

Page 88: Chapter 7 Logical Agents - Hacettepe

90

Resolution

Page 89: Chapter 7 Logical Agents - Hacettepe

92

Example

Page 90: Chapter 7 Logical Agents - Hacettepe

93

Example

Page 91: Chapter 7 Logical Agents - Hacettepe

94

Example

Page 92: Chapter 7 Logical Agents - Hacettepe

95

The power of false

Page 93: Chapter 7 Logical Agents - Hacettepe

96

Example

Page 94: Chapter 7 Logical Agents - Hacettepe

97

Example

Page 95: Chapter 7 Logical Agents - Hacettepe

99

Conversion to CNFGivem

B1,1 (P1,2 P2,1)

B1,1

Prove: P1,2

1. Eliminate , replacing α β with (α β)(β α).

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

2. Eliminate , replacing α β with α β.

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

3. Move inwards using de Morgan's rules and double-negation:

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

4. Apply distributivity law ( over ) and flatten:

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

Page 96: Chapter 7 Logical Agents - Hacettepe

100

Resolution example

• KB = (B1,1 (P1,2 P2,1)) B1,1 α = P1,2

Page 97: Chapter 7 Logical Agents - Hacettepe

101

Resolution algorithm

• Proof by contradiction, i.e., show KBα unsatisfiable

Page 98: Chapter 7 Logical Agents - Hacettepe

102

Horn Clauses• Horn Form (restricted)

KB = conjunction of Horn clauses

Horn clause =

proposition symbol (conjunction of symbols) symbol

P1 P2 ….. Pn Q

where Pi and Q are nonnegated atoms

– E.g., C (B A) (C D B)

• When Q is False we get a sentence that is equivalent to

P1 P2 ….. Pn

• When n=1 and p1 is True we get True Q

which is equivalent to Q

Page 99: Chapter 7 Logical Agents - Hacettepe

103

Forward and backward chaining

• Modus Ponens (for Horn Form): complete for Horn KBs

α1, … ,αn, α1 … αn β

β

• Can be used with forward chaining or backward chaining.

• These algorithms are very natural and run in linear time

Page 100: Chapter 7 Logical Agents - Hacettepe

104

Forward chaining

• Idea: fire any rule whose premises are satisfied in the KB,

– add its conclusion to the KB, until query is found

Page 101: Chapter 7 Logical Agents - Hacettepe

105

Forward chaining algorithm

• Forward chaining is sound and complete for Horn KB

Page 102: Chapter 7 Logical Agents - Hacettepe

106

Forward chaining example

Page 103: Chapter 7 Logical Agents - Hacettepe

107

Forward chaining example

Page 104: Chapter 7 Logical Agents - Hacettepe

108

Forward chaining example

Page 105: Chapter 7 Logical Agents - Hacettepe

109

Forward chaining example

Page 106: Chapter 7 Logical Agents - Hacettepe

110

Forward chaining example

Page 107: Chapter 7 Logical Agents - Hacettepe

111

Forward chaining example

Page 108: Chapter 7 Logical Agents - Hacettepe

112

Forward chaining example

Page 109: Chapter 7 Logical Agents - Hacettepe

113

Forward chaining example

Page 110: Chapter 7 Logical Agents - Hacettepe

114

Proof of completeness

• FC derives every atomic sentence that is entailed by KB

1. FC reaches a fixed point where no new atomic

sentences are derived

2. Consider the final state as a model m, assigning

true/false to symbols

3. Every clause in the original KB is true in m

a1 … ak b

4. Hence m is a model of KB

5. If KB╞ q, q is true in every model of KB, including m

Page 111: Chapter 7 Logical Agents - Hacettepe

115

Backward chaining

Idea: work backwards from the query q:

to prove q by BC,

check if q is known already, or

prove by BC all premises of some rule concluding q

Avoid loops: check if new subgoal is already on the goal

stack

Avoid repeated work: check if new subgoal

1. has already been proved true, or

2. has already failed

Page 112: Chapter 7 Logical Agents - Hacettepe

116

Backward chaining example

Page 113: Chapter 7 Logical Agents - Hacettepe

117

Backward chaining example

Page 114: Chapter 7 Logical Agents - Hacettepe

118

Backward chaining example

Page 115: Chapter 7 Logical Agents - Hacettepe

119

Backward chaining example

Page 116: Chapter 7 Logical Agents - Hacettepe

120

Backward chaining example

Page 117: Chapter 7 Logical Agents - Hacettepe

121

Backward chaining example

Page 118: Chapter 7 Logical Agents - Hacettepe

122

Backward chaining example

Page 119: Chapter 7 Logical Agents - Hacettepe

123

Backward chaining example

Page 120: Chapter 7 Logical Agents - Hacettepe

124

Backward chaining example

Page 121: Chapter 7 Logical Agents - Hacettepe

125

Backward chaining example

Page 122: Chapter 7 Logical Agents - Hacettepe

126

Forward vs. backward chaining

• FC is data-driven, automatic, unconscious processing,

– e.g., object recognition, routine decisions

• May do lots of work that is irrelevant to the goal

• BC is goal-driven, appropriate for problem-solving,

– e.g., Where are my keys? How do I get into a PhD program?

• Complexity of BC can be much less than linear in size of KB

Page 123: Chapter 7 Logical Agents - Hacettepe

127

Summary

• Logical agents apply inference to a knowledge base to derive new

information and make decisions

• Basic concepts of logic:

– syntax: formal structure of sentences

– semantics: truth of sentences wrt models

– entailment: necessary truth of one sentence given another

– inference: deriving sentences from other sentences

– soundness: derivations produce only entailed sentences

– completeness: derivations can produce all entailed sentences

• Wumpus world requires the ability to represent partial and negated

information, reason by cases, etc.

• Resolution is complete for propositional logic

Forward, backward chaining are linear-time, complete for Horn clauses

• Propositional logic lacks expressive power

Page 124: Chapter 7 Logical Agents - Hacettepe

128

Proof methods

• Application of inference rules

– Legitimate (sound) generation of new sentences from old

– Proof = a sequence of inference rule applications

Can use inference rules as operators in a standard search algorithm

– Typically require transformation of sentences into a normal form

• Model checking

– truth table enumeration (always exponential in n)

– improved backtracking, e.g., Davis--Putnam-Logemann-Loveland

(DPLL)

– heuristic search in model space (sound but incomplete)

e.g., min-conflicts-like hill-climbing algorithms

Page 125: Chapter 7 Logical Agents - Hacettepe

129

Resolution as a complete inference