logical agents (2)

Upload: malik-hassan

Post on 06-Jan-2016

230 views

Category:

Documents


0 download

DESCRIPTION

cs

TRANSCRIPT

Propositional Logic

Logical AgentsRussell and Norvig: Chapter 7

Thinking RationallyComputational models of human thought processesComputational models of human behaviorComputational systems that think rationallyComputational systems that behave rationally2Knowledge-Based Agentenvironmentagent?sensorsactuatorsKnowledge baseInference EngineDomain-independent algorithmsDomain-specific contentLogical AgentsLogic (Knowledge-Based) agents combine general knowledge with current percepts to infer hidden aspects of current state prior to selecting actionsCrucial in partially observable environments

4OutlineKnowledge-based agentsWumpus worldLogic in generalPropositional and first-order logicInference, validity, equivalence and satisfiabilityReasoning patterns ResolutionForward/backward chaining5Knowledge BaseKnowledge Base: set of sentences represented in a knowledge representation language and represents assertions about the world.

Inference rule: when one ASKs questions of the KB, the answer should follow from what has been TELLed to the KB previously.

tellask6Types of Knowledge Procedural, e.g.: functions Such knowledge can only be used in one way -- by executing it

Declarative, e.g.: constraints and rules It can be used to perform many different sorts of inferencesThe Wumpus World The Wumpus computer gameThe agent explores a cave consisting of rooms connected by passageways. Lurking somewhere in the cave is the Wumpus, a beast that eats any agent that enters its room. Some rooms contain bottomless pits that trap any agent that wanders into the room. Occasionally, there is a heap of gold in a room.The goal is to collect the gold and exit the world without being eatenHistory of Hunt the WumpusWUMPUS /wuhm'p*s/ n. The central monster (and, in many versions, the name) of a famous family of very early computer games called Hunt The Wumpus, dating back at least to 1972 (several years before ADVENT) on the Dartmouth Time-Sharing System. The wumpus lived somewhere in a cave with the topology of a dodecahedron's edge/vertex graph (later versions supported other topologies, including an icosahedron and Mobius strip). The player started somewhere at random in the cave with five crooked arrows; these could be shot through up to three connected rooms, and would kill the wumpus on a hit (later versions introduced the wounded wumpus, which got very angry). Unfortunately for players, the movement necessary to map the maze was made hazardous not merely by the wumpus (which would eat you if you stepped on him) but also by bottomless pits and colonies of super bats that would pick you up and drop you at a random location (later versions added anaerobic termites that ate arrows, bat migrations, and earthquakes that randomly changed pit locations).This game appears to have been the first to use a non-random graph-structured map (as opposed to a rectangular grid like the even older Star Trek games). In this respect, as in the dungeon-like setting and its terse, amusing messages, it prefigured ADVENT and Zork and was directly ancestral to both. (Zork acknowledged this heritage by including a super-bat colony.) Today, a port is distributed with SunOS and as freeware for the Mac. A C emulation of the original Basic game is in circulation as freeware on the net. Wumpus PEAS descriptionPerformance measure:gold +1000, death -1000, -1 per step, -10 use arrowEnvironment:Squares adjacent to wumpus are smellySquares adjacent to pit are breezyGlitter iff gold is in the same squareBump iff move into a wallWoeful scream iff the wumpus is killedShooting kills wumpus if you are facing itShooting uses up the only arrowGrabbing picks up gold if in same squareReleasing drops the gold in same squareSensors: Stench, Breeze, Glitter, Bump, ScreamActuators: Let turn, Right turn, Forward, Grab, Release, ShootA typical Wumpus world The agent always starts in [1,1]. The task of the agent is to find the gold, return to the field [1,1] and climb out of the cave.

Wumpus World CharacteristicsObservable?Deterministic?Static?Discrete?Single-agent?Wumpus World CharacterizationObservable? No, only local perceptionDeterministic? Yes, outcome exactly specifiedStatic? Yes, Wumpus and pits do not moveDiscrete? YesSingle-agent? Yes, Wumpus is essentially a natural feature.13The Wumpus agents first step

[1,1] The KB initially contains the rules of the environment. The first percept is [none, none,none,none,none], move to safe cell e.g. 2,1[2,1] breeze which indicates that there is a pit in [2,2] or [3,1], return to [1,1] to try next safe cellThe Wumpus agents first step

[1,1] The KB initially contains the rules of the environment. The first percept is [none, none,none,none,none], move to safe cell e.g. 2,1[2,1] breeze which indicates that there is a pit in [2,2] or [3,1], return to [1,1] to try next safe cellNext.

[1,2] Stench in cell which means that wumpus is in [1,3] or [2,2]YET not in [1,1]YET not in [2,2] or stench would have been detected in [2,1]THUS wumpus is in [1,3]THUS [2,2] is safe because of lack of breeze in [1,2]THUS pit in [3,1]move to next safe cell [2,2]

Then

[2,2] move to [2,3][2,3] detect glitter , smell, breezeTHUS pick up goldTHUS pit in [3,3] or [2,4]World-wide web wumpihttp://en.wikipedia.org/wiki/Hunt_the_Wumpushttp://www.atariarchives.org/bcc1/showpage.php?page=247http://www.ifiction.org/games/play.phpzhttp://www.taylor.org/~patrick/wumpus/http://www.inthe70s.com/games/wumpus/index.shtml#

What is a logic?A formal languageSyntax what expressions are legal (well-formed)Semantics what legal expressions meanin logic the truth of each sentence with respect to each possible world.E.g the language of arithmeticX+2 >= y is a sentence, x2+y is not a sentenceX+2 >= y is true in a world where x=7 and y =1X+2 >= y is false in a world where x=0 and y =619Connection World-Representation World WConceptualizationFacts about WholdholdSentencesrepresentFacts about WrepresentSentencesentailInferenceKB |-i : sentence can be derived from KB by procedure i

Soundness: i is sound ifwhenever KB |-i it is also true that KB

Completeness: i is complete if whenever KB it is also true that KB |-i

Examples of Logics Propositiona logic A B C First-order logic ( x)( y) Mother(y,x) Probability Theory Logic of belief (probability about truthiness of statement) Fuzzy Logic Logic of belief (degree of belief)

Symbols of Propositional LogicConnectives: , , , Propositional symbols, e.g., P, Q, R, True, False

Syntax of Propositional Logic sentence atomic sentence | complex sentence atomic sentence Propositional symbol, True, False Complex sentence sentence | (sentence sentence) | (sentence sentence) | (sentence sentence)Examples:((P Q) R)(A B) (C)Order of Precedence Examples: A B C is equivalent to ((A)B)C Truth TablesAB AA BA BA BTrueTrueFalseTrueTrueTrueTrueFalseFalseFalseTrueFalseFalseFalseTrueFalseFalseTrueFalseTrueTrueFalseTrueTrueAbout Read A B as:If A IS True, then I claim that B is True, otherwise I make no claim.Wumpus world sentencesPij is true if there is a pit in [i,j]Bij is true if there is a breeze in [i,j] P11 B11 B21 A square is breezy if and only if there is an adjacent pit B11 P12 v P21 B21 ???

TerminologyA sentence is valid iff its truth value is t in all modelsValid sentences: true, : false, P : PA sentence is satisfiable iff its truth value is t in at least one modelSatisfiable sentences: P, true, : PA sentence is unsatisfiable iff its truth value is f in all modelsUnsatisfiable sentences: P : P, false, : true29Validity and Inference((P H) H) P

P H P H (P H) H ((P H) H) P T T T F T T F T T T F T T F T F F F F T 30Rules of Inferencea b a bValid Rules of Inference:Modus PonensAnd-EliminationAnd-IntroductionOr-IntroductionDouble NegationUnit ResolutionResolution

31Examples in Wumpus WorldModus Ponens: a b, a b(WumpusAhead WumpusAlive) Shoot, (WumpusAhead WumpusAlive) ShootAnd-Elimination: a b a(WumpusAhead WumpusAlive) WumpusAliveResolution: a b, b g a g(WumpusDead WumpusAhead), ( WumpusAhead Shoot) (WumpusDead Shoot)

a ba ba ba a b b g a g Proof Using Rules of InferenceProve A B, (A B) C, Therefore A CA B A B A B C (A B) C A B CSo A B resolves with A B C deriving A CThis is equivalent to A C

Rules of Inference (continued)And-Introduction a1, a2, , an a1 a2 anOr-Introduction ai a1 a2 ai anDouble Negation a aUnit Resolution (special case of resolution)a b Alternatively: a b b b a a 34Wumpus World KBProposition Symbols for each i,j:Let Pi,j be true if there is a pit in square i,jLet Bi,j be true if there is a breeze in square i,jSentences in KBThere is no pit in square 1,1R1: P1,1A square is breezy iff pit in a neighboring squareR2: B1,1 , (P1,2 P2,1)R3: B1,2 , (P1,1 P1,3 P2,2)Square 1,1 has no breeze, Square 1,2 has a breezeR4: B1,1R5: B1,235Inference in Wumpus WorldApply biconditional elimination to R2:R6: B1,1 (P1,2 P2,1 ) (P1,2 P2,1 ) B1,1Apply AE to R6:R7: (P1,2 P2,1) B1,1Contrapositive of R7:R8: B1,1 (P1,2 P2,1 )Modus Ponens with R8 and R4 ( B1,1):R9: (P1,2 P2,1)de Morgan:R10: P1,2 P2,136Searching for ProofsFinding proofs is exactly like finding solutions to search problems.Can search forward (forward chaining) to derive goal or search backward (backward chaining) from the goal.37Resolution Applied to Wumpus WorldAt some point we determine the absence of a pit in square 2,2:R13: P2,2Biconditional elimination applied to R3 followed by modus ponens with R5:R15: P1,1 P1,3 P2,2Resolve R15 and R13:R16: P1,1 P1,3Resolve R16 and R1:R17: P1,338Resolution: Complete Inference ProcedureAny complete search algorithm, applying only the resolution rule, can derive any conclusion entailed by any knowledge base in propositional logic.Refutation completeness: Resolution can always be used to either confirm or refute a sentence, but it cannot be used to enumerate true sentences.39Conjunctive Normal FormConjunctive Normal Form is a disjunction of literals.

Example:

(A B C) (B D) ( A) (B C)clauseliterals40CNF ExampleExample: (A B) , (C ) D)Eliminate ,((A B) ) (C ) D)) ((C ) D) ) (A B)Eliminate ) (A B) (C D)) (C D) (A B) )Drive in negations( A B) ( C D)) ((C D) (A B))Distribute( A (C D) ( B C D) (C A B) ( D A B)41Resolution AlgorithmTo show KB a, we show (KB : a) is unsatisfiable.This is a proof by contradiction.First convert (KB : a) into CNF.Then apply resolution rule to resulting clauses.The process continues until:there are no new clauses that can be added (KB does not entail a)two clauses resolve to yield empty clause (KB entails a)42Simple Inference in Wumpus WorldKB = R2 R4 = (B1,1 , (P1,2 P2,1)) : B1,1Prove : P1,2 by adding the negation P1,2 Convert KB P1,2 to CNF

PL-RESOLUTION algorithm43Horn ClausesReal World KBs are often a conjunction of Horn clausesHorn clause =proposition symbol; or(conjunction of symbols) ) symbolExample:C (B ) A) (C D ) B)

44Forward ChainingFire any rule whose premises are satisfied in the KB.Add its conclusion to the KB until query is found.

45Forward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB46Forward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB47Forward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB48Forward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB49Forward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB50Forward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB51Forward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB52Forward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB53Backward ChainingMotivation: Need goal-directed reasoning in order to keep from getting overwhelmed with irrelevant consequencesMain idea:Work backwards from query q To prove q: Check if q is known alreadyProve by backward chaining all premises of some rule concluding q54Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB55Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB56Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB57Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB58Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB59Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB60Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB61Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB62Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB63Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB64Backward Chaining Example

P ) QL M ) PB L ) MA P ) LA B ) LAB65Forward Chaining vs. Backward ChainingFC is data-drivenit may do lots of work irrelevant to the goalBC is goal-drivenappropriate for problem-solving66