You are on page 1of 67

Lecture 9 Knowledge-Based Agents and Logic

Dr. Muhammad Adnan Hashmi


1 January 2013

Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem proving Forward chaining Backward chaining Resolution.

1 January 2013

Knowledge base: Set of sentences in a formal language Declarative approach for building an agent TELL it what it needs to know Then it can ASK itself what to do - answers should follow from the KB Agents can be viewed at the knowledge level What they know, regardless of implementation Or at the implementation level Data structures in KB and algorithms that manipulate them.
1 January 2013

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.
4

1 January 2013

Performance measure: Gold +1000, Death -1000, -1 per step, -10 for using the arrow Environment: Squares adjacent to wumpus are smelly 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 Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot Sensors: Breeze, Glitter, Smell.
1 January 2013

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

1 January 2013

1 January 2013

1 January 2013

1 January 2013

1 January 2013

10

1 January 2013

11

1 January 2013

12

1 January 2013

13

1 January 2013

14

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
15

1 January 2013

Entailment means that one thing follows from another Knowledge base KB entails sentence B iff B is true in all worlds where KB is 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.
16

1 January 2013

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 B if B is true in m M(B) is the set of all models of B Then KB |= B if and only if M(KB) M(B) E.g. KB = Giants won and Reds won B = Giants won
M(B) could be also true for worlds that are different than the worlds of KB

1 January 2013

17

M(B)

1 January 2013

18

Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for ?s, assuming only pits 3 Boolean choices, i.e., 8 possible models

1 January 2013

19

1 January 2013

20

KB = Wumpus World Rules + Observations


1 January 2013

21

1 January 2013

KB = Wumpus World Rules + Observations Alpha_1 = (1,2) is safe, KB |= Alpha_1

22

KB = Wumpus World Rules + Observations


1 January 2013

23

1 January 2013

KB = Wumpus World Rules + Observations Alpha_2 = (2,2) is safe, KB |= Alpha_2 is false

24

First Order Logic (FOL): Allows complete and sound inference procedures Will answer any question whose answer follows from what is known by the KB.
25

1 January 2013

Order of Precedence
1 January 2013

If and Only If

If S1 then S2

26

If S1 is true, then I am claiming that S2 is true

1 January 2013

27

1 January 2013

28

1 January 2013

29

R1 R4 R5

R2
R3

1 January 2013

30

128 possible rows, only 3 make the KB true Evaluate the entailed sentences in these rows 1 January 2013

P1,2 is false for all 3; hence, no pit in P1,2

P2,2 is both false and true; hence, no conclusion can be drawn about the pit being in P2,2 31

1 January 2013

32

1 January 2013

33

If KB is true, alpha is always true. Hence, I can say that alpha follows from KB

Suppose that KB=true. Then, this will become unsatisfiable only when alpha is true. Hence, I can say that alpha follows from KB
1 January 2013

34

1 January 2013

35

Modus Ponens
Given that P implies Q, and I know that P is true, then I can infer Q

And Rule
Given that P AND Q is true, I can infer that P is true, and I can also infer that Q is true.

1 January 2013

36

1 January 2013

37

1 January 2013

38

1 January 2013

39

1 January 2013

40

Add P1,2
Del P1,2 Add P2,1

P2,1 already added

Add P1,2

Del P2,1

This returns an empty clause. So, alpha is true.


1 January 2013

41

1 January 2013

If this is true, and we know that the set of alphas is true, then we can infer beta.

42

What you want to check whether it can be entailed (or not)

A and B are facts (leaves) of the AND-OR graph)


1 January 2013

AND-OR Graph Multiple links with Arcs indicate Conjunction, and without Arcs 43 indicate Disjunction

1 January 2013

44

1 January 2013

45

1 January 2013

46

1 January 2013

47

1 January 2013

48

1 January 2013

49

1 January 2013

50

1 January 2013

51

1 January 2013

52

It is sound: every inference is an application of Modus Ponens

1 January 2013

53

1 January 2013

54

1 January 2013

55

1 January 2013

56

1 January 2013

57

1 January 2013

58

1 January 2013

59

1 January 2013

60

1 January 2013

61

1 January 2013

62

1 January 2013

63

1 January 2013

64

1 January 2013

65

1 January 2013

66

1 January 2013

67

You might also like