0/0/4 Knowledge based agents Logical Agents Agents need to be able to: Store information about their environment Update and reason about that information Russell and Norvig, chapter 7 Knowledge based agents Agents need to be able to: Store information about their environment Update and reason about that information To achieve that we will introduce: A knowledge base (KB): a list of facts that are known to the agent. Rules to infer new facts from old facts using rules of inference. Knowledge based agents Agents need to be able to: Store information about their environment Update and reason about that information To achieve that we will introduce: A knowledge base (KB): a list of facts that are known to the agent. Rules to infer new facts from old facts using rules of inference. Logic provides the natural language for this. 3 4 Knowledge Bases The Wumpus World Knowledge base: q set of sentences in a formal language. Declarative approach to building an agent: q Tell it what it needs to know. q Ask it what to do à answers should follow from the KB. 5 6
0/0/4 The Wumpus World The Wumpus World Environment Performance measure q gold: +000, death: -000 q - per step, -0 for using the arrow Environment q Squares adjacent to wumpus: smelly q Squares adjacent to pit: breezy q Glitter iff gold is in the same square q Shooting kills wumpus if you are facing it q Shooting uses up the only arrow q Grabbing picks up gold if in same square Sensors: Stench,, Glitter, Bump Actuators: Left turn, Right turn, Forward, Grab, Release,Shoot Fully Observable? No, only local perception Deterministic? Yes, outcome exactly specified Static? Yes, Wumpus and pits do not move Discrete? Yes Single-agent? Yes 7 8,4,4 3,4 4,4,3,3 3,3 4,3,, 3, 4, A = Agent B = G = Glitter, Gold = Safe square A = Agent B = G = Glitter, Gold = Safe square,4,4 3,4 4,4,3,3 3,3 4,3,, 3, 4, P?,, 3, 4, A,, 3, 4, A P? V B (b) Initial state (a) After move s are next to pits. Which is the pit? 9 0 After 3 moves Stench here Means Wumpus here,4,4 3,4 4,4,3,3 3,3 4,3 W!,, 3, 4, A S,, 3, 4, B P! V V A = Agent B = G = Glitter, Gold = Safe square After 5 moves A B G = Agent = = Glitter, Gold = Safe square Found gold, Avoided Wumpus,4,4 3,4 4,4 P?,3,3 3,3 4,3 W! A P? S G B,, 3, 4, S V V,, 3, 4, B P! V V (a) (b)
0/0/4 Logic We used logical reasoning to find the gold. Formal language for representing information such that conclusions can be drawn Syntax defines the sentences in the language Semantics define the "meaning" of sentences; q i.e., define truth of a sentence in a world Logic Syntax defines the sentences in the language Semantics define the "meaning" of sentences; q i.e., define truth of a sentence in a world E.g., the language of arithmetic q Syntax: x+ y is a sentence; x+y > {} is not a sentence q Semantics: x+ y is true in a world where x = 7, y = 3 4 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 Models Model: a formally structured world with respect to which truth can be evaluated q Example: a model for x+y=4 is an assignment of values to x and y q It is true in a world where x is and y is q Example: in a knowledgebase of arithmetic x+y = 4 entails 4 = x+y 5 6 Entailment in the wumpus world Wumpus models Let s consider possible models for wumpus KB, restricting our attention to pits, and focusing on a region of the wumpus world. Situation after: nothing in [,], moving right, breeze in [,] All possible models 7 8 3
3 3 3 3 3 3 3 3 0/0/4 KB α α = no pit in [,] KB = all possible wumpus-worlds consistent with the observations and behavior of Wumpus world. KB α can be proved by model checking α = no pit in [,]", KB α 9 0 Logical inference The notion of entailment can be used for logic inference. q Model checking: check all possible models q Is this a good inference method? KB i α - sentence α can be derived from KB by procedure i If an algorithm only derives entailed sentences it is called sound or truth preserving. q Otherwise it just makes things up. i is sound if whenever KB i α it is also true that KB α Completeness: the algorithm can derive any sentence that is entailed. i is complete if whenever KB α it is also true that KB i α Logic Needed: Representation: formalism for storing knowledge. Reasoning: mechanism for deriving new knowledge from old: deduction Propositional logic Propositional logic is a simple logic based on propositions: q Propositions are either true or false Examples of propositions q Your textbook is green q The sky is falling Propositional logic Propositions: statements of fact q It is raining becomes raining Connectives: operators on propositions q If it is raining, then it is not sunny. becomes raining sunny 3 4 4
0/0/4 Propositional logic: Syntax The proposition symbols P, P etc are sentences If S is a sentence, S is a sentence (negation) If S and S are sentences, S S is a sentence (conjunction) If S and S are sentences, S S is a sentence (disjunction) If S and S are sentences, S S is a sentence (implication) If S and S are sentences, S S is a sentence (biconditional) Truth Values This sentence S S is true S S is false is true when (iff) (S ^ S ) S is true and S is true (S v S ) At least one of S or S is true (S S ) S is false or S is true (S S ) S & S have the same truth value 5 6 Truth tables for connectives Evaluating truth value Simple recursive process evaluates an arbitrary sentence, e.g., P, (P, P 3, ) = true (true false) = true true = true OR: P or Q is true or both are true. XOR: P or Q is true but not both. Implication is always true when the premises are False! 7 8 Question Does {A B, B} entail {A}? q Written as {A B, B} {A} q How do you know if this is true? A B (A B)^B A T T T T T F F T F T T F F F F F No, {A} is not entailed 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]. start: P, B, "Pits cause breezes in adjacent squares" B, (P, P, ) B, (P, P, P 3, ) 30 5
0/0/4 Truth tables for inference Inference by enumeration Enumeration of all models is sound and complete. For n symbols, time complexity is O( n ). Need a smarter way to do inference! 3 3 6