Artificial Intelligence Lecture 9 – Knowledge-Based Agents and Logic Dr. Muhammad Adnan Hashmi 26 December 2018
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. 26 December 2018
Knowledge Base 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. 26 December 2018
A 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. 26 December 2018
Wumpus World 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. 26 December 2018
Wumpus World Characterization 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 26 December 2018
Exploring the Wumpus World 26 December 2018
Exploring the Wumpus World 26 December 2018
Exploring the Wumpus World 26 December 2018
Exploring the Wumpus World 26 December 2018
Exploring the Wumpus World 26 December 2018
Exploring the Wumpus World 26 December 2018
Exploring the Wumpus World 26 December 2018
Exploring the Wumpus World 26 December 2018
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 26 December 2018
Entailment 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. 26 December 2018
Models 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 26 December 2018
Models M(B) 26 December 2018
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, i.e., 8 possible models 26 December 2018
Wumpus Models 26 December 2018
Wumpus Models KB = Wumpus World Rules + Observations 26 December 2018
Wumpus Models KB = Wumpus World Rules + Observations Alpha_1 = “(1,2) is safe, KB |= Alpha_1 26 December 2018
Wumpus Models KB = Wumpus World Rules + Observations 26 December 2018
Wumpus Models KB = Wumpus World Rules + Observations Alpha_2 = “(2,2) is safe, KB |= Alpha_2 is false 26 December 2018
Inference First Order Logic (FOL): Allows complete and sound inference procedures Will answer any question whose answer follows from what is known by the KB. 26 December 2018 25
Propositional Logic Order of Precedence If S1 then S2 If and Only If 26 December 2018 If and Only If 26
Propositional Logic: Semantics If S1 is true, then I am claiming that S2 is true 26 December 2018 27
Truth Table for Connectives 26 December 2018 28
Wumpus World Sentences 26 December 2018 29
Wumpus World Sentences 26 December 2018 30
Wumpus World Truth Table 128 possible rows, only 3 make the KB true P1,2 is false for all 3; hence, no pit in P1,2 Evaluate the entailed sentences in these rows P2,2 is both false and true; hence, no conclusion can be drawn about the pit being in P2,2 26 December 2018 31
Inference by Enumeration 26 December 2018 32
Logical Equivalence 26 December 2018 33
Validity and Satisfiability 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 26 December 2018 34
Proof (A Sequence of Application of Inference Rules) 26 December 2018 35
Two Famous Inference Rules Modus Ponens And Rule Given that P implies Q, and I know that P is true, then I can infer Q Given that P AND Q is true, I can infer that P is true, and I can also infer that Q is true. 26 December 2018 36
Resolution 26 December 2018 37
Conversion to CNF 26 December 2018 38
Resolution Algorithm 26 December 2018 39
Example 26 December 2018 40
Resolution Example Add P1,2 P2,1 already added Del P2,1 Del P1,2 This returns an empty clause. So, alpha is true. 26 December 2018 41
Forward and Backward Chaining If this is true, and we know that the set of alphas is true, then we can infer beta. 26 December 2018 42
A and B are facts (leaves) Forward Chaining What you want to check whether it can be entailed (or not) A and B are facts (leaves) of the AND-OR graph) AND-OR Graph – Multiple links with Arcs indicate Conjunction, and without Arcs indicate Disjunction 26 December 2018 43
Forward Chaining Algorithm 26 December 2018 44
Forward Chaining Example 26 December 2018 45
Forward Chaining Example 26 December 2018 46
Forward Chaining Example 26 December 2018 47 47
Forward Chaining Example 26 December 2018 48
Forward Chaining Example 26 December 2018 49
Forward Chaining Example 26 December 2018 50
Forward Chaining Example 26 December 2018 51
Forward Chaining Example 26 December 2018 52
Soundness and Completeness It is sound: every inference is an application of Modus Ponens 26 December 2018 53
Backward Chaining 26 December 2018 54
Backward Chaining Example 26 December 2018 55
Backward Chaining Example 26 December 2018 56
Backward Chaining Example 26 December 2018 57
Backward Chaining Example 26 December 2018 58
Backward Chaining Example 26 December 2018 59
Backward Chaining Example 26 December 2018 60
Backward Chaining Example 26 December 2018 61
Backward Chaining Example 26 December 2018 62
Backward Chaining Example 26 December 2018 63
Backward Chaining Example 26 December 2018 64
Backward Chaining Example 26 December 2018 65
FC vs. BC 26 December 2018 66
Questions 26 December 2018