L3. Knowledge Representation and Matching in Java Matching.java Unify.java.

Slides:



Advertisements
Similar presentations
First-Order Logic Chapter 8.
Advertisements

Some Prolog Prolog is a logic programming language
First-Order Logic.
Standard Logical Equivalences
Agents That Reason Logically Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 7 Spring 2004.
Expert Systems Dr. Samy Abu Nasser.
Knowledge Based Systems: Logic and Deduction Department of Computer Science & Engineering Indian Institute of Technology Kharagpur.
Predicate Calculus Russell and Norvig: Chapter 8,9.
Knowledge Representation Methods
Intro to AI Fall 2004 © L. Joskowicz 1 Introduction to Artificial Intelligence LECTURE 7: Knowledge Representation and Logic Motivation Knowledge bases.
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
CPE/CSC 481: Knowledge-Based Systems
First-Order Logic. Limitations of propositional logic Suppose you want to say “All humans are mortal” –In propositional logic, you would need ~6.7 billion.
Logic. Propositional Logic Logic as a Knowledge Representation Language A Logic is a formal language, with precisely defined syntax and semantics, which.
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.
Knowledge Representation using First-Order Logic (Part II) Reading: Chapter 8, First lecture slides read: Second lecture slides read:
FIRST-ORDER LOGIC FOL or FOPC
Knoweldge Representation & Reasoning
Inference in First-Order Logic
Predicate Calculus.
Agents that Reason Logically Logical agents have knowledge base, from which they draw conclusions TELL: provide new facts to agent ASK: decide on appropriate.
Propositional Logic Agenda: Other forms of inference in propositional logic Basics of First Order Logic (FOL) Vision Final Homework now posted on web site.
© C. Kemke Reasoning and Inference 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Artificial Intelligence
First Order Logic Chapter 7. PL is a Weak Representational Language §Propositional Logic (PL) is not a very expressive language because: §Hard to identify.
Fall 98 Introduction to Artificial Intelligence LECTURE 7: Knowledge Representation and Logic Motivation Knowledge bases and inferences Logic as a representation.
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
Pattern-directed inference systems
1 Knowledge Representation. 2 Definitions Knowledge Base Knowledge Base A set of representations of facts about the world. A set of representations of.
1 Last time: Logic and Reasoning Knowledge Base (KB): contains a set of sentences expressed using a knowledge representation language TELL: operator to.
11 Artificial Intelligence CS 165A Thursday, November 1, 2007  First-order logic (Ch 8)  Inference in FOL (Ch 9) 1.
Lecture 7: Knowledge Representation and Logic Heshaam Faili University of Tehran Motivation Knowledge bases and inferences Logic as.
First-Order Logic Introduction Syntax and Semantics Using First-Order Logic Summary.
1 Unification ( 統一 ) Forward Chaining ( 前向き仮説推理 ) Backward Chaining ( 後ろ向き仮説推理 ) Unification ( 統一 ) Forward Chaining ( 前向き仮説推理 ) Backward Chaining ( 後ろ向き仮説推理.
111 Artificial Intelligence CS 165A Tuesday, November 6, 2007  Inference in FOL (Ch 9) 1.
지식표현 Agent that reason logically
9/30/98 Prof. Richard Fikes Inference In First Order Logic Computer Science Department Stanford University CS222 Fall 1998.
1 Unification ( 統一 ) Forward Chaining ( 前向き推論 ) Backward Chaining ( 後ろ向き推論 ) Unification ( 統一 ) Forward Chaining ( 前向き推論 ) Backward Chaining ( 後ろ向き推論 )
Artificial Intelligence 7. Making Deductive Inferences Course V231 Department of Computing Imperial College, London Jeremy Gow.
Artificial Intelligence First-Order Logic (FOL). Outline of this Chapter The need for FOL? What is a FOL? Syntax and semantics of FOL Using FOL.
For Wednesday Read chapter 9, sections 1-3 Homework: –Chapter 7, exercises 8 and 9.
Propositional Logic Predicate Logic
For Friday Read chapter 8 Homework: –Chapter 7, exercises 2 and 10 Program 1, Milestone 2 due.
1 Propositional logic (cont…) 命題論理 Syntax&Semantics of first-order logic 構文論と意味論 Deducing hidden properties Describing actions Propositional logic (cont…)
Knowledge Repn. & Reasoning Lec. #5: First-Order Logic UIUC CS 498: Section EA Professor: Eyal Amir Fall Semester 2004.
First-Order Logic Reading: C. 8 and C. 9 Pente specifications handed back at end of class.
1-1 An Introduction to Logical Programming Sept
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
1 First Order Logic CS 171/271 (Chapter 8) Some text and images in these slides were drawn from Russel & Norvig’s published material.
First-Order Logic Chapter 8. Problem of Propositional Logic  Propositional logic has very limited expressive power –E.g., cannot say "pits cause breezes.
Logic and Reasoning 1 Sentences and the Real World  syntax  describes the principles for constructing and combining sentences  e.g. BNF grammar for.
Artificial Intelligence Logical Agents Chapter 7.
Logical Agents. Outline Knowledge-based agents Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability.
L7. Logic for knowledge representation
Knowledge Representation using First-Order Logic
Last time: Logic and Reasoning
First-order Logic Propositional logic (cont…)
The function of knowledge representation scheme is
Introduction to Knowledge-bases
Knowledge Representation
L7. Logic for knowledge representation
Logic Use mathematical deduction to derive new knowledge.
L9. Matching Program in Java
MA/CSSE 474 More Math Review Theory of Computation
First-order Logic Propositional logic (cont…)
Unification Unification (Unify.java) Doing exercises.
Knowledge Representation I (Propositional Logic)
Propositional Logic CMSC 471 Chapter , 7.7 and Chuck Dyer
L9. Matching Program in Java
L10. Unify Program in Java Unify.java.
Presentation transcript:

L3. Knowledge Representation and Matching in Java Matching.java Unify.java

What to Represent Facts about the world Definitions and general rules An agent’s beliefs and those of other agents Plans of action Degrees of certainty and uncertainty

How to represent Logical representation schemes Procedural representation schemes Network representation schemes Structured representation schemes different inference mechanisms

Representing Simple Facts Objects: potato, mike. Cooker, … Predicates : male, father, at, … Properties: male(mike), female(rose), rich(john), … Relations: father(mike, rose), in(john, restaurant, now), …

Knowledge Base: Facts parent(jock, morag) parent(jock, alasdair) parent(jock, hamish) parent(mairi, morag) parent(mairi, alasdair) parent(mairi, hamish) parent(fergus, jock) parent(rhoda, jock) parent(fergus, flora) parent(rhoda, flora) male(fergus) male(jock) male(alasdair) male(hamish) female(rhoda) female(mairi) female(morag) female(flora)

The Need for Rules Some facts can be inferred from others, e.g. fergus is morag’s grandfather Need generality variables stand for arbitrary objects, e.g. X Define some relations in terms of others e.g. mother is female parent

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

Knowledge Bases: Rules Family Relations 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)

Note: compare with problem solving as search KNOWLEDGE BASE (KB) facts and rules INFERENCE MECHANISM Updates QueryAnswer Knowledge Base Architecture

Formal language to represent facts and rules about a microworld as sentences. Interpreted sentences represent a model of the microworld Syntax: how sentences formed mother_of(sarah,tal)  mother_of(sarah,mor) Semantics: how to interpret sentences True/False Set of all sentences (axioms, rules) is the abstract representation of the KB Base sentences are called axioms, derived sentences theorems, derivations proofs Representing Language

Mathematical logics have well-defined syntax, semantics, and models: –Propositional: facts are True/False –First Order: facts, objects, relations are True/False –Temporal logic: First Order + time –Probability theory: facts, degree of belief [0…1] Interpretation: truth assignment to each element on the formulaA is True Reasoning with Logic

Sentence in propositional logic Sentence  AtomicSentence | ComplexSentence AtomicSentence  proposition symbols like P, Q, R True | False ComplexSentence  (Sentence) | Setence Connective Sentence like P  Q  (P  Q)  (  P   Q) True | False Connectives:  (not),  (and),  (or),  (implies), and  (equivalent)

Sentences in first-order logic Atomic sentences = predicate(term 1, term 2, …term n ) or term 1 = term 2 Term = function(term 1, term 2, …term n ) or constant or variable Complex sentences: made from atomic sentences using connectives.  (not),  (and),  (or),  (implies), and  (equivalent)

Syntax of FOL: basic element Constant symbols: refer to the same object in the same interpretation e.g. Mike Jason, 4, A, B, … Predicate symbols: refer to a particular relation in the model. e.g., Brother, >, Function symbols: refer to particular objects without using their names. Some relations are functional, that is, any given object is related to exactly one other object by the relation. (one-one relation) e.g., Cosine, FatherOf, Variables: substitute the name of an objec. e.g., x, y, a, b,…  x, Cat(x)  Mammal(x) if x is a cat then x is a mammal. Logic connectives:  (not),  (and),  (or),  (implies), and  (equivalent) Quantifiers:  (universal quantification symbol),  (existential quantification symbol)  x, for any x, …  x, there is a x, … Equality: = e.g. Father(John) = Henry

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

The three new inference rules (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). (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. (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. SUBST({v/k},  )  v   v SUBST({g/v},  ) 

Example of proof Bob is a buffalo | 1. Buffalo(Bob) Pat is a pig | 2. Pig(Pat) Buffaloes outrun pigs | 3.  x, y Buffalo(x)  Pig(y)  Faster(x,y) Bob outruns Pat Apply (3) to 1 And 2 | 4. Buffalo(Bob)  Pig(Pat) Apply (8) to 3 {x/Bob, y/Pat} | 5. Buffalo(Bob)  Pig(Pat)  Faster(Bob,Pat) Apply (1) to 4 And 5 | 6. Faster(Bob,Pat)

Unification and Matching The process of matching is called unification: for example, - p(x) matches p(Jack) with x = Jack - q(fatherof(x),y) matches q(y,z) with y=fatherof(x) and z = y note the result of the match is q(fatherof(x),fatherof(x)) - p(x) matches p(y) with x = Jack and y = Jack x = John and y = John or x = y - The match that makes the least commitment is called the most general unifier (MGU)

String matching: string1 = string2 e.g. “rose” = “rose” if string1.equals(string2) “I am Rose” = “I am Rose” “I am ?x” = “I am Rose” “I am ?x” = “?y am Rose” I = ?y am = am ?x = Rose ? Check? String  Tokens 40: // 同じなら成功 41: if(string1.equals(string2)) return true; 44: st1 = new StringTokenizer(string1); 45: st2 = new StringTokenizer(string2); 46: 47: // 数が異なったら失敗 48: if (st1.countTokens() != st2.countTokens()) 49: return false; 51: int length = st1.countTokens(); // 定数同士 52: for (int i = 0 ; i < length; i++){ 53: if (!tokenMatching(st1.nextToken(),st2.nextToken())){ 54: // トークンが一つでもマッチングに失敗したら失敗 55: return false; 56: } 57: } Unify

Token matching: token1 = token2 e.g. two strings’ matching, “I am ?x” = “?y am Rose” Three pairs of tokens’ matching: I = ?y am = am ?x = Rose 64: boolean tokenMatching(String token1,String token2){ 65: if(token1.equals(token2)) return true; 66: if( var(token1) && !var(token2)) 67: return varMatching(token1,token2); 68: if(!var(token1) && var(token2)) 69: return varMatching(token2,token1); 70: return false; 71: } 73: boolean varMatching(String vartoken,String token){ 74: if(vars.containsKey(vartoken)){ 75: if(token.equals(vars.get(vartoken))){ 76: return true; 77: } else { 78: return false; 79: } 80: } else { 81: vars.put(vartoken,token); 82: } 83: return true; 84: } 86: boolean var(String str1){ 87: // 先頭が ? なら変数 88: return str1.startsWith("?"); 89: } 27: Matcher(){ 28: vars = new Hashtable(); 29: }

Output: Matching.java vs. Unify.java Output from Matching.java ?x is ?y and ?x Rose is rose and ?y false Output from Unify.java ?x is ?y and ?x Rose is rose and ?y {?y=rose, ?x=Rose} true