Knowledge and reasoning second part Knowledge representation Logic

  • Slides: 57
Download presentation
Knowledge and reasoning – second part • • • Knowledge representation Logic and representation

Knowledge and reasoning – second part • • • Knowledge representation Logic and representation Propositional (Boolean) logic Normal forms Inference in propositional logic Wumpus world example CS 561, Sessions 9 -10 1

Knowledge-Based Agent • Agent that uses prior or acquired knowledge to achieve its goals

Knowledge-Based Agent • Agent that uses prior or acquired knowledge to achieve its goals Domain independent algorithms ASK Inference engine TELL Knowledge Base Domain specific content • Can make more efficient decisions • Can make informed decisions • Knowledge Base (KB): contains a set of representations of facts about the Agent’s environment • Each representation is called a sentence • Use some knowledge representation language, to TELL it what to know e. g. , (temperature 72 F) • ASK agent to query what to do • Agent can use inference to deduce new facts from TELLed facts CS 561, Sessions 9 -10 2

Generic knowledge-based agent 1. TELL KB what was perceived Uses a KRL to insert

Generic knowledge-based agent 1. TELL KB what was perceived Uses a KRL to insert new sentences, representations of facts, into KB 2. ASK KB what to do. Uses logical reasoning to examine actions and select best. CS 561, Sessions 9 -10 3

Wumpus world example CS 561, Sessions 9 -10 4

Wumpus world example CS 561, Sessions 9 -10 4

Wumpus world characterization • Deterministic? • Accessible? • Static? • Discrete? • Episodic? CS

Wumpus world characterization • Deterministic? • Accessible? • Static? • Discrete? • Episodic? CS 561, Sessions 9 -10 5

Wumpus world characterization • Deterministic? Yes – outcome exactly specified. • Accessible? No –

Wumpus world characterization • Deterministic? Yes – outcome exactly specified. • Accessible? No – only local perception. • Static? Yes – Wumpus and pits do not move. • Discrete? Yes • Episodic? (Yes) – because static. CS 561, Sessions 9 -10 6

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus OK = Safe V = Visited G = Glitter CS 561, Sessions 9 -10 7

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus OK = Safe V = Visited G = Glitter CS 561, Sessions 9 -10 8

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus OK = Safe V = Visited G = Glitter CS 561, Sessions 9 -10 9

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus OK = Safe V = Visited G = Glitter CS 561, Sessions 9 -10 10

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus OK = Safe V = Visited G = Glitter CS 561, Sessions 9 -10 11

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus OK = Safe V = Visited G = Glitter CS 561, Sessions 9 -10 12

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus OK = Safe V = Visited G = Glitter CS 561, Sessions 9 -10 13

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus

Exploring a Wumpus world A= Agent B= Breeze S= Smell P= Pit W= Wumpus OK = Safe V = Visited G = Glitter CS 561, Sessions 9 -10 14

Other tight spots CS 561, Sessions 9 -10 15

Other tight spots CS 561, Sessions 9 -10 15

Another example solution No perception 1, 2 and 2, 1 OK B in 2,

Another example solution No perception 1, 2 and 2, 1 OK B in 2, 1 2, 2 or 3, 1 P? Move to 2, 1 1, 1 V no P in 1, 1 Move to 1, 2 (only option) CS 561, Sessions 9 -10 16

Example solution S and No S when in 2, 1 1, 3 or 1,

Example solution S and No S when in 2, 1 1, 3 or 1, 2 has W 1, 2 OK 1, 3 W No B in 1, 2 2, 2 OK & 3, 1 P CS 561, Sessions 9 -10 17

Logic in general CS 561, Sessions 9 -10 18

Logic in general CS 561, Sessions 9 -10 18

Types of logic CS 561, Sessions 9 -10 19

Types of logic CS 561, Sessions 9 -10 19

The Semantic Wall Physical Symbol System World +BLOCKA+ +BLOCKB+ +BLOCKC+ P 1: (IS_ON +BLOCKA+

The Semantic Wall Physical Symbol System World +BLOCKA+ +BLOCKB+ +BLOCKC+ P 1: (IS_ON +BLOCKA+ +BLOCKB+) P 2: ((IS_RED +BLOCKA+) CS 561, Sessions 9 -10 20

Truth depends on Interpretation Representation 1 World A B ON(A, B) T ON(B, A)

Truth depends on Interpretation Representation 1 World A B ON(A, B) T ON(B, A) F ON(A, B) F A ON(B, A) T B CS 561, Sessions 9 -10 21

Entailment is different than inference CS 561, Sessions 9 -10 22

Entailment is different than inference CS 561, Sessions 9 -10 22

Logic as a representation of the World Representation: Sentences entails Sentence Refers to (Semantics)

Logic as a representation of the World Representation: Sentences entails Sentence Refers to (Semantics) World Facts follows CS 561, Sessions 9 -10 Fact 23

Models CS 561, Sessions 9 -10 24

Models CS 561, Sessions 9 -10 24

Inference CS 561, Sessions 9 -10 25

Inference CS 561, Sessions 9 -10 25

Basic symbols • Expressions only evaluate to either “true” or “false. ” • •

Basic symbols • Expressions only evaluate to either “true” or “false. ” • • • P ¬P PVQ P^Q P => Q P Q “P is true” “P is false” negation “either P is true or Q is true or both” disjunction “both P and Q are true” conjunction “if P is true, then Q is true” implication “P and Q are either both true or both false” equivalence CS 561, Sessions 9 -10 26

Propositional logic: syntax CS 561, Sessions 9 -10 27

Propositional logic: syntax CS 561, Sessions 9 -10 27

Propositional logic: semantics CS 561, Sessions 9 -10 28

Propositional logic: semantics CS 561, Sessions 9 -10 28

Truth tables • Truth value: whether a statement is true or false. • Truth

Truth tables • Truth value: whether a statement is true or false. • Truth table: complete list of truth values for a statement given all possible values of the individual atomic expressions. Example: P T T F F Q T F PVQ T T T F CS 561, Sessions 9 -10 29

Truth tables for basic connectives P Q ¬P ¬Q PVQ P ^ Q P=>Q

Truth tables for basic connectives P Q ¬P ¬Q PVQ P ^ Q P=>Q P Q T T F F T T F T F F F T F T T CS 561, Sessions 9 -10 T F F T 30

Propositional logic: basic manipulation rules • ¬(¬A) = A Double negation • ¬(A ^

Propositional logic: basic manipulation rules • ¬(¬A) = A Double negation • ¬(A ^ B) = (¬A) V (¬B) • ¬(A V B) = (¬A) ^ (¬B) Negated “and” Negated “or” • • Distributivity of ^ on V Distributivity of V on ^ by definition using negated or by definition using negated and & or A ^ (B V C) = (A ^ B) V (A ^ C) A V (B ^ C) = (A V B) ^ (A V C) A => B = (¬A) V B ¬(A => B) = A ^ (¬B) A B = (A => B) ^ (B => A) ¬(A B) = (A ^ (¬B))V(B ^ (¬A)) … CS 561, Sessions 9 -10 31

Propositional inference: enumeration method true CS 561, Sessions 9 -10 32

Propositional inference: enumeration method true CS 561, Sessions 9 -10 32

Enumeration: Solution CS 561, Sessions 9 -10 33

Enumeration: Solution CS 561, Sessions 9 -10 33

Propositional inference: normal forms “product of sums of simple variables or negated simple variables”

Propositional inference: normal forms “product of sums of simple variables or negated simple variables” “sum of products of simple variables or negated simple variables” CS 561, Sessions 9 -10 34

Deriving expressions from functions • Given a boolean function in truth table form, find

Deriving expressions from functions • Given a boolean function in truth table form, find a propositional logic expression for it that uses only V, ^ and ¬. • Idea: We can easily do it by disjoining the “T” rows of the truth table. Example: XOR function P T T F F Q T F RESULT F T T F P ^ (¬Q) (¬P) ^ Q RESULT = (P ^ (¬Q)) V ((¬P) ^ Q) CS 561, Sessions 9 -10 35

Deriving expressions from functions • Given a boolean function in truth table form, find

Deriving expressions from functions • Given a boolean function in truth table form, find a propositional logic expression for it that uses only V, ^ and ¬. • Idea: We can easily do it by disjoining the “T” rows of the truth table. Example: XOR function P T T F F Q T F RESULT F T T F P ^ (¬Q) (¬P) ^ Q RESULT = (P ^ (¬Q)) V ((¬P) ^ Q) CS 561, Sessions 9 -10 36

A more formal approach • To construct a logical expression in disjunctive normal form

A more formal approach • To construct a logical expression in disjunctive normal form from a truth table: - Build a “minterm” for each row of the table, where: - For each variable whose value is T in that row, include the variable in the minterm - For each variable whose value is F in that row, include the negation of the variable in the minterm - Link variables in minterm by conjunctions - The expression consists of the disjunction of all minterms. CS 561, Sessions 9 -10 37

Example: adder with carry Takes 3 variables in: x, y and ci (carry-in); yields

Example: adder with carry Takes 3 variables in: x, y and ci (carry-in); yields 2 results: sum (s) and carryout (co). To get you used to other notations, here we assume T = 1, F = 0, V = OR, ^ = AND, ¬ = NOT. co is: s is: CS 561, Sessions 9 -10 38

Tautologies • Logical expressions that are always true. Can be simplified out. Examples: T

Tautologies • Logical expressions that are always true. Can be simplified out. Examples: T TVA A V (¬A) ¬(A ^ (¬A)) A A ((P V Q) P) V (¬P ^ Q) (P Q) => (P => Q) CS 561, Sessions 9 -10 39

Validity and satisfiability B Theorem CS 561, Sessions 9 -10 40

Validity and satisfiability B Theorem CS 561, Sessions 9 -10 40

Proof methods CS 561, Sessions 9 -10 41

Proof methods CS 561, Sessions 9 -10 41

Inference Rules Modus Tollens: CS 561, Sessions 9 -10 42

Inference Rules Modus Tollens: CS 561, Sessions 9 -10 42

Inference Rules CS 561, Sessions 9 -10 43

Inference Rules CS 561, Sessions 9 -10 43

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 44

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 45

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 46

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 47

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 48

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 49

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 50

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 51

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 52

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS

http: //www. site. uottawa. ca/~lucia/courses/2101 -10/lecturenotes/04 Inference. Rules. Proof. Methods. pdf Inference example CS 561, Sessions 9 -10 53

Wumpus world: example • Facts: Percepts inject (TELL) facts into the KB • [stench

Wumpus world: example • Facts: Percepts inject (TELL) facts into the KB • [stench at 1, 1 and 2, 1] S 1, 1 ; S 2, 1 • Rules: if square has no stench then neither the square or adjacent squares contain the wumpus ¬W 1, 2 ¬W 2, 1 ¬S 2, 1 ¬W 1, 1 ¬W 2, 1 ¬W 2, 2 • R 1: ¬S 1, 1 ¬W 1, 1 • R 2: • … ¬W 3, 1 • Inference: • KB contains ¬S 1, 1 then using Modus Ponens we infer ¬W 1, 1 ¬W 1, 2 ¬W 2, 1 • Using And-Elimination we get: ¬W 1, 1 • … CS 561, Sessions 9 -10 ¬W 1, 2 ¬W 2, 1 54

Limitations of Propositional Logic 1. It is too weak, i. e. , has very

Limitations of Propositional Logic 1. It is too weak, i. e. , has very limited expressiveness: • Each rule has to be represented for each situation: e. g. , “don’t go forward if the wumpus is in front of you” takes 64 rules 2. It cannot keep track of changes: • If one needs to track changes, e. g. , where the agent has been before then we need a timed-version of each rule. To track 100 steps we’ll then need 6400 rules for the previous example. Its hard to write and maintain such a huge rule-base Inference becomes intractable CS 561, Sessions 9 -10 55

Summary CS 561, Sessions 9 -10 56

Summary CS 561, Sessions 9 -10 56

Next time • First-order logic: [AIMA] Chapter 7 CS 561, Sessions 9 -10 57

Next time • First-order logic: [AIMA] Chapter 7 CS 561, Sessions 9 -10 57