1 / 39

Logical Agents

Logical Agents. Chapter 7. Outline. Knowledge-based agents Wumpus world Logic in general models entailment inference Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem proving resolution forward chaining backward chaining.

rafael
Download Presentation

Logical Agents

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Logical Agents Chapter 7

  2. Outline • Knowledge-based agents • Wumpus world • Logic in general • models • entailment • inference • Propositional (Boolean) logic • Equivalence, validity, satisfiability • Inference rules and theorem proving • resolution • forward chaining • backward chaining

  3. Knowledge bases • Knowledge base = set of sentences in a knowledge representation language • Inference engine (Declarative approach) • Tell (update) it what it knows • Ask (inference) itself what to do - answers should follow from the KB

  4. A simple knowledge-based agent • The agent must be able to: • Represent states, successor functions, goals, and costs • Incorporate new percepts • Update internal representations of the world • Deduce hidden properties of the world • Deduce appropriate actions Pg. 236

  5. Wumpus World

  6. Performance measure (scoring) gold +1000, death -1000, kill wumpus +500 -1 per action, -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 Sensors: Stench, Breeze, Glitter, Bump, Scream (agent can’t sense its own location) Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot Wumpus World PEAS description Pg. 237

  7. Wumpus world characterization • FullyObservable 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. Exploring a wumpus world

  9. 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 the truth of a sentence with respect to each possible 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 Every sentence must be either T or F in each possible world – there is no “in between”. (vs. possibility or fuzzy logic)

  10. Entailment • Entailment means that one thing logically follows from another: KB ╞α • Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is true

  11. Models • Logicians typically think in terms of models, which are formally structured worlds with respect to which truth can be evaluated. • We say Mis a model of a sentence α if α is true in M. • M(α) is the set of all models of α. • Then KB ╞ α iff M(KB)  M(α). (Model Checking)

  12. Entailment in the wumpus world y Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for KB assuming only pits (can has multiple pits). 3 Boolean choices  8 possible models. C(3, 0) + C(3,1) + C(3,2) + C(3,3) = 23 = 8 4 3 2 1 1 2 3 4 x

  13. Wumpus models KB = wumpus-world rules + observations α1 = "[1,2] is safe", KB ╞ α1, proved by model checking.

  14. Wumpus models KB = wumpus-world rules + observations α2 = "[2,2] is safe", KB ╞ α2?

  15. Inference • KB ├i α = sentence α can be derived from KB by procedure i (a logic such as proposition or first-order) • Soundness: i is sound if whenever KB ├i α, it is also true that KB╞ α. (Any sentence derived is true in KB) • Completeness: i is complete if whenever KB╞ α, it is also true that KB ├i α. (Derive any sentence that is entailed) • Preview: we will define a logic (proposition or first-order logic) which is expressive enough to say almost anything of interest, and for which there exists a sound and complete inference procedure. • That is, the procedure will answer any question whose answer follows from what is known by the KB.

  16. Propositional logic: Syntax • Propositional logic is the simplest logic – illustrates basic ideas. • The proposition symbols P, Q etc are atomic sentences. • Complex sentences (, , , , ) • If P is a sentence, P is a sentence (negation) • If P and Q are sentences, P  Q is a sentence (conjunction) • If P and Q are sentences, P  Q is a sentence (disjunction) • If P and Q are sentences, P  Q is a sentence (implication) • If P and Q are sentences, P  Q is a sentence (biconditional, iff)

  17. Propositional logic: Semantics Each model specifies true/false for each proposition symbol E.g. m1={ P1,2=F , P2,2=T, P3,1=F } With these symbols, 8 possible models, can be enumerated automatically. Simple recursive process evaluates an arbitrary sentence, E.g.,P1,2(P2,2P3,1)=T(TF)=TT=T.

  18. A simple KB- Wumpus world KB 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]. Facts: R1:  P1,1 R2: B1,1 R3: B2,1 Rules:"Pits cause breezes in adjacent squares" R4: B1,1 (P1,2 P2,1) (incomplete B1,1 (P1,2 P2,1)) R5: B2,1  (P1,1 P2,2  P3,1) KB: R1 R2  R3  R4  R5 1= P1,2 ,KB╞ 1 ? 2= P2 2 , KB╞ 2 ?

  19. A simple inference procedure- Truth table (TT) inference by enumeration • A model checking approach that is a direct implementation of the definition of entailment: enumerate the models, and check that  is true in every model in which KB is true. • Models are assignments of true or false to every proposition symbol. • In wumpus world, the relevant proposition symbols are B1,1, B2,1, P1,1, P2,1, P2,2, and P3,1. • With 7 symbols, there are 27=128 possible models. • In three of these, KB is true.

  20. Truth tables for inference

  21. Algorithm Pg. 248 Depth-first enumeration of all models is sound and complete . For n symbols, time complexity is O(2n), space complexity is O(n).

  22. Logical equivalence • Two sentences are logically equivalent iff true in same models: α ≡ ß iff α╞ βand β╞ α Pg. 249

  23. Validity and satisfiability • A sentence is valid if it is true in all models (tautology) 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 (contradiction), e.g., AA • Satisfiability is connected to inference via Proof by contradiction: KB ╞ α if and only if (KBα) is unsatisfiable (KB α) ≡ (KBα) ≡ (KB α)

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

  25. Resolution • Conjunctive Normal Form (CNF) • Literals: atomic sentences, E.g. A, B, B • Clauses: disjunctions of literals, E.g. A(B) • CNF: conjunction of clauses, E.g., (A B)  (B C D) • Resolution inference rule (for CNF): l1…li…lk, m1…mj…mn li … li-1 li+1  … lkm1 … mj-1 mj+1... mn where li and mj are complementary literals, i.e. li = mj E.g., P1,3P2,2, P2,2 P1,3

  26. Resolution Soundness of resolution inference rule: (l1 … li-1 li+1  … lk)  li mj  (m1 … mj-1 mj+1... mn) (l1 … li-1 li+1  … lk)  (m1 … mj-1 mj+1... mn) l1 … li-1 li+1  … lk m1 … mj-1 mj+1... mn transitive Completeness of resolution inference rule. P.g 255 (old 217). Ground resolution theorem: If a set of clauses is unsatisfiable, then the resolution closure of those clauses contains the empty clause.

  27. Conversion to CNF B1,1 (P1,2 P2,1)

  28. Resolution algorithm • Proof by contradiction, i.e., show KBα=F (unsatisfiable) Pg. 255 Two results: 1. If two clauses resolve to yield the empty clause (False), so KB╞α. 2. Else there are no new clauses that can be added, so KB╞α.

  29. Resolution Example • KB = (B1,1 (P1,2 P2,1))  B1,1 • Prove α = P1,2 • First convert (KB   α) into CNF T Many resolution steps are pointless. (exponential time)

  30. Forward and backward chaining • A clause is called a Horn clause if it contains at most one positive literal. l1l2 l3 … ln  l  l1l2 l3 … ln l • Horn KB = conjunction of Horn clauses. E.g., C  (B  A)  (C  D  B) • 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. premise/antecedent/body conclusion/consequent/head fact

  31. Forward chaining • Idea: fire any rule whose premises are satisfied in the KB, • add its conclusion to the KB, until query is found And-Or graph 1 2 2 2 2

  32. Forward chaining algorithm p.g. 258

  33. Forward chaining example

  34. Forward chaining is sound and complete for Horn KB • Proof of soundness: • Proof of completeness: • Complexity is linear with the size of KB.

  35. 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 • has already been proved true, or • has already failed

  36. Backward chaining example (DFS)

  37. 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., medical diagnostic system, fault-shooting system • Complexity of BC can be much less than linear in size of KB

  38. Expressiveness limitation of prop. logic • KB contains "physics" sentences for every single square P1,1 W1,1 Bx,y (Px,y+1 Px,y-1 Px+1,y Px-1,y) Sx,y (Wx,y+1 Wx,y-1 Wx+1,y Wx-1,y) W1,1 W1,2 …  W4,4 (there is at least one wumpus) W1,1W1,2 (there is at most one wumpus) W1,1W1,3 … => Initially 64 distinct prop. symbols, 155 sentences • Keeping track of location and orientation • L1,1FacingRight Forward L2,1 (wrong) • For every time t and every location [x,y], Ltx,yFacingRighttForwardtLtx+1,y

  39. 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 • Resolution – CNF • Resolution inference rules • Sound and complete for propositional logic • FC & BC – Horn Form • Modus Ponens • Sound and complete for Horn clauses • linear-time with size(KB) • Propositional logic lacks expressive power

More Related