L7. Logic for knowledge representation

Slides:



Advertisements
Similar presentations
Knowledge Representation using First-Order Logic
Advertisements

First-Order Logic Chapter 8.
First-Order Logic.
Russell and Norvig Chapter 7
First-Order Logic: Better choice for Wumpus World Propositional logic represents facts First-order logic gives us Objects Relations: how objects relate.
Standard Logical Equivalences
We have seen that we can use Generalized Modus Ponens (GMP) combined with search to see if a fact is entailed from a Knowledge Base. Unfortunately, there.
Logic Use mathematical deduction to derive new knowledge.
Agents That Reason Logically Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2004.
3/30/00 Agents that Reason Logically by Chris Horn Jiansui Yang Xiaojing Wu.
CS 561, Session Midterm format Date: 10/10/2002 from 11:00am – 12:20 pm Location: THH 101 Credits: 35% of overall grade Approx. 4 problems, several.
Logical Agents Chapter 7. Why Do We Need Logic? Problem-solving agents were very inflexible: hard code every possible state. Search is almost always exponential.
Knowledge Representation & Reasoning (Part 1) Propositional Logic chapter 6 Dr Souham Meshoul CAP492.
Logical Agents Chapter 7. Why Do We Need Logic? Problem-solving agents were very inflexible: hard code every possible state. Search is almost always exponential.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Lecture 8 Jim Martin.
First-Order Logic: Better choice for Wumpus World Propositional logic represents facts First-order logic gives us Objects Relations: how objects relate.
Knoweldge Representation & Reasoning
Inference in First-Order Logic
Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate.
For Monday Read chapter 9 Homework: –Chapter 8, exercises 9 and 10.
1 Logical Agents CS 171/271 (Chapter 7) Some text and images in these slides were drawn from Russel & Norvig’s published material.
1 Last time: Logic and Reasoning Knowledge Base (KB): contains a set of sentences expressed using a knowledge representation language TELL: operator to.
First-Order Logic Chapter 8. Outline Why FOL? Syntax and semantics of FOL Using FOL Wumpus world in FOL Knowledge engineering in FOL.
1 Unification ( 統一 ) Forward Chaining ( 前向き仮説推理 ) Backward Chaining ( 後ろ向き仮説推理 ) Unification ( 統一 ) Forward Chaining ( 前向き仮説推理 ) Backward Chaining ( 後ろ向き仮説推理.
지식표현 Agent that reason logically
CSE LOGIC1 Propositional Logic An “adventure game” example Thinking?
For Monday Read chapter 8 Homework: –Chapter 7, exercises 1, 8, and 9 May be done in pairs.
Logical Agents Chapter 7. Knowledge bases Knowledge base (KB): set of sentences in a formal language Inference: deriving new sentences from the KB. E.g.:
1 Logical Agents CS 171/271 (Chapter 7) Some text and images in these slides were drawn from Russel & Norvig’s published material.
For Friday Read chapter 8 Homework: –Chapter 7, exercise 1.
1 First-Order Logic Propositional logic does not represent and cannot handle objects. First-order logic is to represent and reason on objects and their.
For Wednesday Read chapter 9, sections 1-3 Homework: –Chapter 7, exercises 8 and 9.
For Friday Read chapter 8 Homework: –Chapter 7, exercises 2 and 10 Program 1, Milestone 2 due.
For Wednesday Read chapter 9, sections 1-4 Homework: –Chapter 8, exercise 6 May be done in groups.
1 Propositional logic (cont…) 命題論理 Syntax&Semantics of first-order logic 構文論と意味論 Deducing hidden properties Describing actions Propositional logic (cont…)
Lecture 8-1CS250: Intro to AI/Lisp FOPL, Part Deux Lecture 8-1 November 16 th, 1999 CS250.
First-Order Logic Reading: C. 8 and C. 9 Pente specifications handed back at end of class.
Dr. Shazzad Hosain Department of EECS North South Universtiy Lecture 04 – Part B Propositional Logic.
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
1 UNIT-3 KNOWLEDGE REPRESENTATION. 2 Agents that reason logically(Logical agents) A Knowledge based Agent The Wumpus world environment Representation,
First-Order Logic Chapter 8. Problem of Propositional Logic  Propositional logic has very limited expressive power –E.g., cannot say "pits cause breezes.
For Wednesday Finish chapter 8 Homework: –Chapter 8, exercise 6 May be done in pairs.
1 Knowledge Representation Logic and Inference Propositional Logic Vumpus World Knowledge Representation Logic and Inference Propositional Logic Vumpus.
Logical Agents. Inference : Example 1 How many variables? 3 variables A,B,C How many models? 2 3 = 8 models.
L3. Knowledge Representation and Matching in Java Matching.java Unify.java.
Propositional Logic: Logical Agents (Part I)
L7. Logic for knowledge representation
Knowledge and reasoning – second part
First-order Logic Propositional logic (cont…)
First-Order Logic Chapter 8.
Introduction to Knowledge-bases
EA C461 – Artificial Intelligence Logical Agent
Logical Agents Chapter 7.
Logic Use mathematical deduction to derive new knowledge.
First-Order Logic Chapter 8.
Artificial Intelligence
L9. Matching Program in Java
Knowledge and reasoning – second part
Logical Agents Chapter 7.
First-order Logic Propositional logic (cont…)
Unification Unification (Unify.java) Doing exercises.
CS 416 Artificial Intelligence
Knowledge Representation I (Propositional Logic)
Propositional Logic CMSC 471 Chapter , 7.7 and Chuck Dyer
L9. Matching Program in Java
First-Order Logic Chapter 8.
Lecture 5-2 February 4th, 1999 CS250
First-order logic: a more expressive KR language that can handle facts, objects, relations between objects, and object properties. Consider the statement.
Logical Agents Prof. Dr. Widodo Budiharto 2018
Presentation transcript:

L7. Logic for knowledge representation and inference 知識表現 推理 Propositional logic (continue …) Propositional logic versus first-order logic (命題論理対一階述語論理 ) Apply first-order logic e.g. A family relations A proof

Sentence in propositional logic Sentence  AtomicSentence | ComplexSentence AtomicSentence  proposition symbols like P, Q, R True | False ComplexSentence  (Sentence) | Sentence Connectives like P  Q  (P  Q)  ( P   Q) Connectives:  (not),  (and),  (or),  (implies), and  (equivalent) 原子文 複文 連結語 (必然的に)伴う

FOL: basic elements and sentences Constant (定数) symbols: refer to the same object in the same interpretation Predicate (述語) symbols: refer to a particular relation in the model. Function (関数) symbols: refer to particular objects without using their names. Logic connectives:  (not),  (and),  (or),  (implies), and  (equivalent) Equality (対等): = e.g. Father(John) = Henry Variables (変数): substitute (取り替える) for the name of an object. e.g., x, y, a, b,… x, Cat(x)  Mammal(x)           //Mammal:哺乳動物.  Quantifiers (数量詞):  (universal (一般) quantification symbol)       (existential (存在に関する) quantification symbol)       x, for any x, … x, there is a x, … Atomic sentences = predicate(term1, term2, …termn) Term = function(term1, term2, …termn) or constant or variable Complex sentences: made from atomic sentences using connectives.

Seven inference rules for propositional Logic R(1) Implication-Elimination R(2) And-Elimination R(3) And-Introduction R(4) Or-Introduction R(5) Double-Negation Elimination R(6) Unit Resolution R(7) Logic connectives:    ,  i 1  2 … n 1  2 … n 1, 2, …, n 1  2  …  n i        ,     ,       

The three new inference rules added to FOL R(8) Universal-Elimination: For any sentence , variable v, and ground term g: e. g.,  x Likes(x, IceCream), we can use the substitute {x/Rose} and infer Like(Rose, IceCream). R(9) Existential-Elimination: For any sentence , variable v, and constant symbol k that does not appear elsewhere in the knowledge base: e. g.,  x Kill(x, Victim), we can infer Kill(Murderer, Victim), as long as Murderer does not appear elsewhere in the knowledge base. R(10) Existential-Introduction: For any sentence , variable v that does not occur in , and ground term g that does occur in : e. g., from Likes(Rose, IceCream) we can infer  x Likes(x, IceCream). SUBST({v/g}, )  v  Ground term is a term that contains no variables.  v/g SUBST({v/k}, )  v   k  v SUBST({g/v}, ) 

Representing Simple Rules Variables: x, P, C, ... Generalised Facts: female(P), parent(P, C), ... Conjunctions: parent(P, C)  female(P) Rules:  P, C parent(P, C)  female(P)  mother(P, C)

Knowledge Bases: Rules Family Relations  GP, P, C parent(P, C)  female(P)  mother(P, C) parent(P, C)  male(P)  father(P, C) parent(GP, P)  parent(P, C)  grandparent(GP, C) parent(GP, P)  female(GP)  parent(P, C) grandmother(GP, C) grandparent(GP, C)  male(GP)  grandfather(GP, C)

Knowledge Base Architecture Updates KNOWLEDGE BASE (KB) facts and rules Query Answer INFERENCE MECHANISM

Example of proof in first-order logic Bob is a buffalo | 1. Buffalo(Bob) --f1 Pat is a pig | 2. Pig(Pat) --f2 Buffaloes run faster than pigs | 3.  x, y Buffalo(x)  Pig(y)  Faster(x,y) --r1 ---------------------------------------------------------------------------------------------------- To proof: Bob runs faster than Pat --------------------------------------------------------------------------------------------------- Apply R(3) to f1 And f2 | 4. Buffalo(Bob)  Pig(Pat) --f3 (And-Introduction) Apply R(8) to r1 {x/Bob, y/Pat} | 5. Buffalo(Bob)  Pig(Pat)  Faster(Bob,Pat) --f4 (Universal-Elimination) Apply R(1) to f3 And f4 | 6. Faster(Bob,Pat) --f5 (Inplication-Elimination )

Search with primitive inference rules Operators are inference rules States are sets of sentences Goal test checks state to see if it contains query sentence R(1) to R(10) are common inference pattern 1 2 3 Apply R(3) to 1 & 2 1 2 3 4 Apply R(8) to 3 1 2 3 4 5 Apply R(1) to 4 & 5 1 2 3 4 5 6

A Reasoning System Rule Base Working Memory Interaction with Inference Engine Matching Fire a Rule Select a Rule Acting

Here is the answer: the gold is in [2,3]. Finding gold The agent has been in [1,1]->[2,1]->[1,1]->[1,2] and knows there is a wumpus in [1,3] and a pit in [3,1] then goes to [2,2] continues to [3,2] (forward since it perceives nothing special) Now, percept sentences (add a new one): there is a breeze in the square [3,2]  B3,2 Since knowledge is not enough to judge whether [4,2] and [3,3] are safe or not, the agent goes back to [2,2], turn left and goes to [2,3]. Now, percept sentences(add new ones):   there is a glitter in the square [2,3]  G2,3 The agent has been in [1,1]->[2,1]->[1,1]->[1,2] -> [2,2] -> [3,2] -> [2,2]-> [2,3] Here is the answer: the gold is in [2,3].

Finding a way back to the start position Go back along the path (5 steps) [1,1]->[2,1]->[1,1]->[1,2] -> [2,2] -> [3,2] -> [2,2]-> [2,3] (a doubly linked list would be a good data structure for recording agent’s history path) Using safe squares to build a tree, search a shortest path from [2,3] to [1,1] (3 steps). s s b b p w g p A p

Finding a way back to the start position Go back along the path (5 steps) [1,1]->[2,1]->[1,1]->[1,2] -> [2,2] -> [3,2] -> [2,2]-> [2,3] (a doubly linked list would be a good data structure for recording agent’s history path) Using safe squares to build a tree, search a shortest path from [2,3] to [1,1] (3 steps). Quiz: Draw a tree from the square where there is a gold) to the square [1,1] s s b b p w g p [2,3] [3,2] [1,2] [2,2] [1,1] [2,1] A p

Appendix (追加) Apply first-order logic to making inference in the Wumpus world. (If you have time, please take a look this appendix.) A gold finding agent in the Wumpus world

Predicates and rules At(p, l, S) : Agent p is at the location l in the situation S Percept([Smell, b, g, u, v], l, S, t): Agent perceives smell at time t at the location l in the situation S Perception rules R1:  b, g, u, v, l, s, t Percept([Smell, b, g, u, v], s, t)  Smell(t) R2: sm, g, u, v, l, s, t Percept([sm, Breeze, g, u, v], s, t)  Breeze(t) R3: sm, b, u, v, l, s, t Percept([sm, b, Glitter, u, v], s, t)  AtGoldRoom(t) R4: sm, b, u, v, l, s, t Percept([sm, b, g, Wall, v], s, t)  Wall(t) R6: sm, b, g, u, v, l, s, t Percept([sm, b, g, u, v], s, t)   Smell(t)  Breeze(t)  AtGoldRoom(t)  Wall(t) Action rules R7:  i, j Result(Forward, li) = lj i  j  i, j Result(Turn, Sm) = Sn m  n Orientation rules R8:  s (Orientation(p, s ) =0  Face(p, east) )  (Orientation(p, s) = 90  Face(p, north )  (Orientation(p, s) = 180  Face(p, west)  (Orientation(p, s) = 270  Face(p, south) ) R9:  a, d, p, s Orientation(p, Result(a, s)) =d  [(a=Turn(Right) d=Mod(Orientation(p,s) – 90, 360))  (a=Turn(Left) d=Mod(Orientation(p,s) + 90, 360) )  (Orientation(p,s)=d (a=Turn(Right)  a=Turn(Left)))]

R20: l1, l2, s At(Pit, l1)  Adjacent(,l1, l2)  Breeze(l2) Location rules R10:  l, l   x, y [x, y] R11: (a)  x, y LocationToward([x, y], 0) = [x+1, y] (b)  x, y LocationToward([x, y], 90) = [x, y+1] R12: (a)  x, y LocationToward([x, y], 180) = [x-1, y] (b)  x, y LocationToward([x, y], 270) = [x+1, y-1] R13:  p, l, s At(p, l, s)  LocationAhead(p,S) = LocationToward(l, Orientation(p,s)) R14:  l1, l2 Adjacent(l1, l2)   d l1=LocationToward(l2, d) R15:  x, y Wall([x, y])  (x=0  x=5  y=0  y=5) R16:  a, d, p, s At(p, l, Result(a, s))  [(a=Forward  l = LocationAhead(p,s)  Wall(l))  (At(p,l,s)  a  Forward)] Hidden properties (rules) R17: l, s At(Agent, l, s)  Smell(s)  Smell(l) R18: l, s At(Agent, l, s)  Breeze(s)  Breeze(l) R19: l1, s Breeze(l1)   l2 At(Pit, l2,s)  (l2, = l1  Adjacent(,l1, l2)) R20: l1, l2, s At(Pit, l1)  Adjacent(,l1, l2)  Breeze(l2) R21:  l1, s Breeze(l1)   l2 At(Pit, l2, s )  (l2, = l1  Adjacent(,l1, l2))

R23: l1, l2, s At(Wumpus, l1)  Adjacent(,l1, l2)  Smell(l2) Hidden properties (rules) R22: l1, s Smell(l1)   l2 At(Wumpus, l2,s)  (l2, = l1  Adjacent(,l1, l2)) R23: l1, l2, s At(Wumpus, l1)  Adjacent(,l1, l2)  Smell(l2) R24:  l1, s Smell(l1)   l2 At(Wumpus, l2, s )  (l2, = l1  Adjacent(,l1, l2)) R25: x, y, g, u, v, s, t Percept([None, None, g, u, v], t)  At(Agent, x, s)  Adjacent(,x, y)  OK(y) R26: x, t ( At(Wumpus, x, t)  At(Pit, x, t))  OK(x) Obtaining Gold R27:  x, s AtGoldRoom( x, s)  Present(Gold, x, s) R28:  x, s Present( x, s)  Portable(x) Holding(x, Result(Grab, s)) R29:  x, s Holding(x, Result(Release, s)) R30:  a, x, s Holding(x, s)  (aRelease)  Holding(x, Result(a, s)) R31:  a, x, s Holding(x, s)  (aGrab   (Present(x, s)  Portable(x))  Holding(x, Result(a, s)) P true afterwards  [an action made P true  P true already and no action made P false] R32:  a, x, s Holding(x, Result(a, s))  [(a=Grab  (Present(x, s)  Portable(x))  (Holding(x, s)  aRelease) ]

Since the world is not changing, our inferences below drop time term. Initial state At(Agent, [1,1]) Apply And-Elimination rule to R6, we obtain C1 Smell([1,1]) , Breeze([1,1]) , AtGoldRoom([1,1]) , Wall([1,1]) Apply And-Elimination rule to R21 and apply R15, we obtain C2 At(Pit, [1,1]), At(Pit, [2,1]), At(Pit, [2,1]), Wall([1,0]), Wall([0,1]) Apply And-Elimination rule to R24, we obtain C3 At(Wumpus, [1,1]), At(Wumpus, [2,1]), At(Wumpus, [1,2]) Apply R26 to C2 and C3, we obtain C4 OK([1,1]), OK([2,1]), OK([1,2]) Apply R11(a) and R16, we obtain At(Agent, [2,1]) Apply And-Elimination rule to R2, we obtain C5 Smell([2,1]) , Breeze([2,1]) , AtGoldRoom([2,1]) , Wall([2,1]) Apply R19 to Breeze([2,1]), we obtain C6 At(Pit, [1,1])  At(Pit, [2,1])  At(Pit, [2,2])  At(Pit, [3,1])

Apply unit resolution twice to C6, we obtain C7 At(Pit, [2,2])  At(Pit, [3,1]) Use C4 and C7, (for a conservative agent, it would not go where is not sure), and apply R9, R12(a) and R16, we obtain At(Agent, [1,1]), Orientation(Agent, [1,1])=180 Use C4 and apply R9, R11(b) and R16, we obtain At(Agent, [1,2]), Orientation(Agent, [1,2])=90 Apply R22 to Smell([1,2]), we obtain C8 At(Wumpus, [1,1])  At(Wumpus, [1,3])  At(Wumpus, [1,2])  At(Wumpus, [2,2]) Apply unit resolution twice to C8, we obtain C9 At(Wumpus, [2,2])  At(Wumpus, [1,3]) Apply R24 and And-Elimination rule to Smell([2,1]), we obtain C10 At(Wumpus, [1,1]), At(Wumpus, [1,2]), At(Wumpus, [2,2]), At(Wumpus, [2,1]) Apply unit resolution to C9, we obtain C11 At(Wumpus, [1,3]) Apply R21 and And-Eleimination rule to Breeze([1,2]), we obtain C12 At(Pit, [1,1]), At(Pit, [2,1]), At(Pit, [2,2]), At(Pit, [3,1])

Apply R26 to C10 and C12, we obtain C13 OK([2,2]), Use C13 and apply R9, R11(a) and R16, we obtain At(Agent, [2,2]), Orientation(Agent, [2,2])=0 Use C4 and apply R9, R11(b) and R16, we obtain At(Agent, [1,2]), Orientation(Agent, [1,2])=90 Apply R21 and And-Elimination rule to Breeze([2,2]), and apply R24 and And-Elimination rule to Smell([2,2]), we obtain C14 At(Pit, [2,1]), At(Pit, [1,2]), At(Pit, [2,2]), At(Pit, [2, 3], At(Pit, [2, 3]) C15 At(Wumpus, [2,1]), At(Wumpus, [1,2]), At(Wumpus, [2,2]), At(Wumpus, [2,3], At(Wumpus, [3,2]) Apply R26 to C14 and C15, we obtain C16 OK([2,3]), OK([3,2]) Apply R11(a) and R16, we obtain At(Agent, [3,2]) Apply R19 to Breeze([3,2]), we obtain C17 At(Pit, [2,2])  At(Pit, [2,3])  At(Pit, [3,2])  At(Pit, [3,1])  At(Pit, [4,2]) Apply twice unit resolution to C9, we obtain C18 At(Pit, [3,2])  At(Pit, [3,1])  At(Pit, [4,2])

The rest of question is how to go back safely? For safe, agent goes back to [2, 2] Use C13 and apply R9, R12(a) and R16, we obtain At(Agent, [2,2]), Orientation(Agent, [2,2])=180 Use C16 and apply R9, R11(b) and R16, we obtain At(Agent, [2,3]), Orientation(Agent, [2,3])=90 Apply R3, we obtain C19 AtGoldRoom( [2,3]) Apply R32, we obtain C20 Holding([2,3], Result(Grab)) The rest of question is how to go back safely?