Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logical Agents Chapter 7 Part I. 2 Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic.

Similar presentations


Presentation on theme: "Logical Agents Chapter 7 Part I. 2 Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic."— Presentation transcript:

1 Logical Agents Chapter 7 Part I

2 2 Outline 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

3 3 Knowledge bases Knowledge base = set of sentences in a formal language 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 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

4 4 A simple knowledge-based agent 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 function KB-Agent(percept) returns an action static:KB, a knowledge base t, a counter, initially 0, indicating time Tell(KB, Make-Percept-Sentence(percept, t)) action←Ask(KB, Make-Action-Query(t)) Tell(KB, Make-Action-Sentence(action, t)) t←t + 1 return action

5 5 Wumpus World PEAS description Performance measure –gold +1000, death -1000 –-1 per step, -10 for using the arrow Environment –4X4 grid of rooms –Start from (1,1), facing to the right –Locations of gold and wumpus are chosen randomly –Squares other than the start square can be a pit with probability 0.2

6 6 Wumpus World PEAS description Sensors –Perceive a stench if adjacent to wumpus –Perceive a breeze if adjacent to a pit –Perceive a glitter iff in the same square where the gold is –Perceive a bump if walk into a wall –Perceive a scream when wumpus is killed Actuators –Turn Left; turn right; forward –Shoot kills wumpus if you are facing it, using up the only arrow –Grab picks up gold if in same square –Release drops the gold in same square  Die if enter a square with a live wumpus or a pit

7 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

8 8 Exploring a wumpus world

9 9

10 10 Exploring a wumpus world

11 11 Exploring a wumpus world

12 12 Exploring a wumpus world

13 13 Exploring a wumpus world

14 14 Exploring a wumpus world

15 15 Exploring a wumpus world

16 16 Some tight spots Breeze in (1,2) and (2,1)  not safe Assume not many pits –Either pits in (3,1) and (1,3) –Or a pit in (2,2) –P(pit(3,1), pit(1,3)) : P(pit(2,2)) = 1:4  guess a pit in (2,2) Stench in (1,1)  not safe Shoot ahead! –Perceive a scream  wumpus was there  safe –No scream  wumpus was not there  safe

17 17 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

18 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 –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

19 19 Logicians typically think in terms of models, which are formally structured worlds with respect to which truth can be evaluated Model: a truth assignment to all symbols 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  Models

20 20 Entailment in the wumpus world Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for ? s –assuming only pits 3 Boolean choices  8 possible models

21 21 Wumpus models

22 22 Wumpus models KB = wumpus-world rules + observations

23 23 Wumpus models  1 = "[1,2] is safe", KB ⊨  1, proved by model checking

24 24 Wumpus models  2 = "[2,2] is safe", KB ⊭  2

25 25 Inference KB ⊢ i  : sentence  can be derived from KB by procedure i Soundness: i is sound if whenever KB ⊢ i , it is also true that KB ⊨  Completeness: i is complete if whenever KB ⊨ , it is also true that KB ⊢ i  Preview: we will define a logic (first-order logic) which is expressive enough to say almost anything of interest, and for which there exists a sound and complete inference procedure.

26 26 Propositional logic: Syntax Propositional logic is the simplest logic – illustrates basic ideas The proposition symbols P 1, P 2 etc are sentences –If S is a sentence,  S is a sentence (negation) –If S 1 and S 2 are sentences, S 1  S 2 is a sentence (conjunction) –If S 1 and S 2 are sentences, S 1  S 2 is a sentence (disjunction) –If S 1 and S 2 are sentences, S 1  S 2 is a sentence (implication) –If S 1 and S 2 are sentences, S 1  S 2 is a sentence (biconditional)

27 27 Propositional logic: Semantics Each model specifies true/false for each proposition symbol E.g. P 1,2 P 2,2 P 3,1 false true false (With these symbols, 8 possible models, can be enumerated automatically.) Rules for evaluating truth with respect to a model m:  Sis true iff S is false S 1  S 2 is true iff S 1 is true and S 2 is true S 1  S 2 is true iff S 1 is true or S 2 is true S 1  S 2 is true iffS 1 is false orS 2 is true i.e., is false iffS 1 is true andS 2 is false S 1  S 2 is true iff S 1  S 2 is true and S 2  S 1 is true

28 28 Truth tables for connectives

29 29 Wumpus world sentences Let P i,j be true if there is a pit in [i, j]. Let B i,j be true if there is a breeze in [i, j].  P 1,1  B 1,1 B 2,1 "Pits cause breezes in adjacent squares" B 1,1  (P 1,2  P 2,1 ) B 2,1  (P 1,1  P 2,2  P 3,1 )

30 30 Truth tables for inference Enumerate all truth assignments. If KB is true, check that  is, too.

31 31 Inference by enumeration Depth-first enumeration of all models is sound and complete For n symbols, time complexity is O(2 n ), space complexity is O(n) function TT-Entails?(KB,  ) returns true or false inputs:KB, the knowledge base, a sentence in propositional logic , the query, a sentence in propositional logic symbols ← a list of the proposition symbols in KB and  return TT-Check-All(KB, , symbols, [ ]) function TT-Check-All(KB, , symbols, model) returns true or false if Empty?(symbols) then if PL-True?(KB, model) then return PL-True?( , model) else return true else do P ← First(symbols); rest ← Rest(symbols) returnTT-Check-All(KB, , rest, Extend(P, true, model)) and TT-Check-All(KB, , rest, Extend(P, false, model))

32 32 Logical equivalence Two sentences are logically equivalent iff true in same models:  ≡  iff  ⊨  and  ⊨ 

33 33 Validity and satisfiability A sentence is valid if it is true in all models, e.g., True, A  A, A  A, (A  (A  B))  B Validity is connected to inference via the Deduction Theorem: KB ⊨  if and only if (KB   ) is valid A sentence is satisfiable if it is true in some model e.g., A  B, C A sentence is unsatisfiable if it is true in no models e.g., A  A Satisfiability is connected to inference via the following: KB ⊨  if and only if (KB   ) is unsatisfiable If A is valid, then  A is unsatisfiable.

34 34 Proof methods Proof methods divide into (roughly) two kinds: –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

35 35 Inference Rules Modus Ponens   ,   And-Elimination  1   2  …   n  i And-Introduction  1,  2, …,  n  1   2  …   n

36 36 Inference Rules Or-Introduction  i  1   2  …   i  …   n Double-Negation Elimination   Resolution

37 37 Resolution Conjunctive Normal Form (CNF) conjunction of disjunctions of literals E.g., (A   B)  (B   C   D) Resolution inference rule (for a clause in a CNF): l i  …  l k, m 1  …  m n l i  …  l i-1  l i+1  …  l k  m 1  …  m j-1  m j+1 ...  m n where l i =  m j. E.g., P 1,3  P 2,2,  P 2,2 P 1,3 Resolution is sound and complete for propositional logic

38 38 Resolution Soundness of resolution inference rule: (recall that l i =  m j )  ( l i  …  l i-1  l i+1  …  l k )  l i  m j  ( m 1  …  m j-1  m j+1 ...  m n )  ( l i  …  l i-1  l i+1  …  l k )  ( m 1  …  m j-1  m j+1 ...  m n )

39 39 Conversion to CNF E.g. B 1,1  (P 1,2  P 2,1 ) 1. Eliminate , replacing   with (   )  (   ). (B 1,1  (P 1,2  P 2,1 ))  ((P 1,2  P 2,1 )  B 1,1 ) 2. Eliminate , replacing  with  . (  B 1,1  P 1,2  P 2,1 )  (  (P 1,2  P 2,1 )  B 1,1 ) 3. Move  inwards using de Morgan's rules and double- negation: (  B 1,1  P 1,2  P 2,1 )  ((  P 1,2   P 2,1 )  B 1,1 ) 4. Apply distributivity law (  over  ) and flatten: (  B 1,1  P 1,2  P 2,1 )  (  P 1,2  B 1,1 )  (  P 2,1  B 1,1 )


Download ppt "Logical Agents Chapter 7 Part I. 2 Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic."

Similar presentations


Ads by Google