Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 7: Knowledge Representation and Logic Heshaam Faili University of Tehran Motivation Knowledge bases and inferences Logic as.

Similar presentations


Presentation on theme: "Lecture 7: Knowledge Representation and Logic Heshaam Faili University of Tehran Motivation Knowledge bases and inferences Logic as."— Presentation transcript:

1 Lecture 7: Knowledge Representation and Logic Heshaam Faili hfaili@ece.ut.ac.ir University of Tehran Motivation Knowledge bases and inferences Logic as a representation language Propositional logic

2 2 Motivation (1) Up to now, we concentrated on search methods in worlds that can be relatively easily represented by states and actions on them a few objects, rules, relatively simple states problem-specific heuristics to guide the search complete knowledge: know all what’s needed no new knowledge is deduced or added well-defined start and goal states Appropriate for accessible, static, discrete problems.

3 3 Motivation (2) What about other types of problems? More objects, more complex relations Not all knowledge is explicitly stated Dynamic environments: the rules change! Agents change their knowledge Deduction: how to derive new conclusions Examples 1. queries on family relations 2. credit approval 3. diagnosis of circuits

4 4 Example 1: family relations Facts: Sarah is the mother of Tal and Mor Moshe is married to Sarah Fanny is the mother of Gal Query: Is Moshe the father of Tal? Deduction: people have a mother and a father Moshe is married to Sarah, who has 2 children Sarah’s children are Moshe’s children (no divorce) New knowledge deduced, assumptions apply!

5 5 Example 2: credit approval Facts Moshe is employed for 5 years and earns 10,000 shekels a month. Credit approval rules: must be employed at least 3 years, earn at least 5,000 shekels, have no outstanding debts. Query: is Moshe eligible for credit? Decision procedure: build a decision tree procedural check the rulesdeclarative Advantages and disadvantages of each.

6 6 Example 3: circuit diagnosis Facts: circuit topology, components, inputs/outputs component and connection rules faulty output for given input Query: What are the components that are likely to be faulty? Deduction: classify all possible faults and their explanation deductive process for fault detection

7 7 Knowledge based Agent Knowledge base Sentences Knowledge representation language Inference Logical Agent TELL & ASK Knowledge level & Implementation level

8 8 Logical Agent

9 9 Procedural vs. Declarative knowledge Procedural: how to achieve a goal, procedure to answer queries hard wired, efficient, specific to a problem and situation; difficult to change and update. Declarative: relations that hold between entities + general inference mechanism more general: decouples knowledge from deduction, easier to update, possibly less efficient We will focus on declarative representations.

10 10 Example: Wumpus world Sensors: 1- In the square containing the wumpus and in adjacent squares the agent will perceive a stench. 2- In the squares directly adjacent to a pit, the agent will perceive a breeze. 3- In the square where the gold is, the agent will perceive a glitter 4- When an agent walks into a wall, it will perceive a bump. 5- When the wumpus is killed, it emits a woeful scream that can be perceived any- anywhere in the cave.

11 11 Example: Wumpus world

12 12 Example: Wumpus world

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

14 14 Knowledge base issues Representation language: how expressive is it? What can and cannot be said? Inference procedure: general procedure to derive new conclusions Is it sound? Do all conclusions follow rationally from the facts and rules? Is it complete? If a conclusion rationally follows from the KB, can I deduce it? Is it efficient? Does it take time polynomial in the number of facts and rules?

15 15 The world, its representation, and its implementation microworld representation implementation Facts ==> Facts Sentences ==> Sentences FOLLOWS INFERENCE

16 16 Domain model Specifies how the microworld will be modeled Ontology: microworld we are modeling. Family relations between individuals Domain theory: type of facts and relations persons: sarah, tal, mor relations: mother_of, married, … A fact is true if it follows from a set of facts based on rational arguments

17 17 Representation language 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

18 18 KB Inference procedure Works on the syntactic representation of sentences: a => b and a, deduce b Independent of the meaning (semantics) of the knowledge represented Captures a subset of rational rules of thought modus ponens, entailment, resolution. Note: these inference rules are different from the KB rules! Base sentences are called axioms, derived sentences theorems, derivations proofs.

19 19 Implementation How sentences are represented in the computer: data structures for facts and relations. How to perform inferences based on abstract inference procedure rules. Typical procedures: pattern matching knowledge base management

20 20 Logical Theory Structure Ontology Procedures Domain Theory Axioms Formal Language Data Structures Implementation Axiomatic System Domain Model Operates on Describes Stated in Definition Justified by Formal semantics Note: contrast with standard algorithms and math domains

21 21 Example: family relations Ontology: family relations microworld Domain theory: sarah, tal, mother_of relation, Formal language: first order logic Axioms: mother_of(sarah,tal), ….  X,  Y mother_of(Y,X), ….. Data structures: functions, structs, lists Procedures: matching, rule ordering,...

22 22 Logic and knowledge representation (1) 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

23 23 Logic and knowledge representation (2) A sentence is valid (a tautology) if it is true for any truth assignement (A \/ ~A) satisfiable if there exists a truth assignment that makes it true (A /\ B) unsatisfiable if there is no truth assignment that makes it true (A /\ ~A) model of a sentence is an interpretation that satisfies the sentence E.g. Sentence  : X+Y=4  model of  are all possible assignments of X and Y which is sum to 4 Inference rules: modus ponens, deduction

24 24 Logic: notation and properties KB |= c c logically follows from KB KB |= R cc follows from KB using rules R |= cc is a tautology Soundness and completeness of R KB |= c iff KB |= R c Monotonicity if KB 1 |= c then (KB 1 U KB 2 ) |= c Note: distinguish with KB |-- c, S => c

25 25 Example: Wumpus World  1 = no pit in [1,2]  2 = no pit in [2,2] MODEL CHECKING: Enumerates all possible models to check that  is true in all models in which KB is true

26 26 Propositional Logic -- Syntax Sentence ----> Atomic_Sentence | Complex_Sentence Atomic_Sentence ----> True | False | P | Q | R … Complex_Sentence ----> (Sentence) | ~Sentence Sentence Connective Sentence Connective -----> /\ | \/ | => | | …. Facts, boolean relations between them, True/False truth assignements to boolean sentences SYNTAX:

27 27 Recursively defined by the truth value of atomic sentences. Boolean truth tables for each connective and for  The validity of a sentence is determined by constructing a truth table ((P \/ Q) /\ ~Q) => P Propositional Logic -- Semantics PQ P /\ Q P \/ Q FalseFalseFalse False False TrueFalse True True FalseFalse True TrueTrueTrue True

28 28 Validity by truth-table construction

29 29 Proof methods Given a knowledge base KB = {S 1, S 2,  … , S n } and a sentence c, determine if c logically follows from KB:KB |= c Two proof methods use inference rules R to determine if KB |= R c build a truth table to test the validity of the sentence ( S 1 /\ S 2 /\ …/\ S n ) => c

30 30 Propositional Logic -- Inference Rules Modus Ponens And-Elimination And-Introduction Or-Introduction Resolution Double negation

31 31 Propositional logic example (1) Given: “Heads I win, tails you loose” Prove: “I always win” Propositions: heads, tail, winme, looseyou Axioms: 1. heads => winmeheads I win 2. tails => looseyoutails you loose 3. heads \/ tailseither heads or tails 4. looseyou => winmeyou loose I win

32 32 Propositional logic example (2) 1. ~heads \/ winme 2. ~tails \/ looseyou 3. heads \/ tails 4. ~looseyou \/ winme Resolution: a \/ b, ~b \/ c a \/ c 1’ (1,3)  tails \/ winme 2’ (2,4)  ~tails \/ winme 3’ (1’,2’) winme \/ winme 3” winme

33 33 Conjunctive normal form CNF: conjunction of disjunctions of literals K-CNF: has exactly k literals per clause Every sentence can be transformed to 3-CNF? Steps of conversion any sentence to CNF (B11  P12  P21) Eliminate  (   (  )  (  )) Eliminate  (      ) Move  into parentheses using demorgan or negation Distribute  over 

34 34 Resolution

35 35 Example : Resolution

36 36 Inference as Search Search method: Given a knowledge base with sentences, apply inference rules until the query sentence is generated. If it is not generated, then it cannot be inferred state: a conjunction of sentences in the KB start: initial KB Goal: KB containing the query sentence Inference rules: the ones above Are all inferences sound? Are the inference rules complete? What is their complexity?

37 37 Soundness of Inference Rules The conclusions obtained by applying inference rules are logically valid. Proof by truth table for each inference rule Example: Modus Ponens

38 38 Completeness of Inference Rules The inference rules are complete iff all sentences that follow logically from KB can be derived by the rules. The rules are refutation-complete: tautologies such as (P \/ ~P) cannot be derived. Instead, prove that the negation of the sentence yields a contradiction. Proof procedure: add the negation of the conclusion, apply the rules. If a contradiction is derived, the conclusion is true (ex: “Tails…”)

39 39 Completeness of Resolution Resolution Closure RC(S) : all clauses derivable by repeated application of resolution rule to clauses in S or their derivatives. “if the set of clauses is unsatisfiable, then the resolution closure of those clauses contains the empty clause” Prove by contradiction: if RC(S) doesn't include empty clause, then S is satisfiable: we can construct a model for S with suitable truth values for P 1,…,P k, : for i from 1 to k If there is a clause in RC(S) containing the literal  Pi such that all its other literals are false under assignment for P 1 …P i-1, assign P i = false O.W. assign P i = true

40 40 Horn Clause CNF with at most on positive literal  L  Br  B11 Can be changed to implication (L  Br)  B11 Horn with exactly on positive literal: definite clause Positive literal: head Negative literals : body Definite clause with no negative is fact Horn with no positive literals: integrity constraints Horn can be done with forward or backward chaining Entailment with Horn clause can be done in linear time in the size of knowledge base

41 41 Forward Chaining Determine whether a single proposition symbol q (query) is entailed by a knowledge base on Horn clause Begin with known fact If all premises of an implication are known, then its conclusion is added to the set of known facts It’s called DATA DRIVEN Backward chaining is goal driven

42 42 Forward Chaining

43 43 Horn Clause

44 44 Decidability and complexity Propositional logic is decidable: there exists a computational procedure to decide if a sentence logically follows from a set of axioms Complexity: exponential in the number of propositions. Proof by reduction to satisfiability problem: (a \/ ~b \/ c) /\ (c \/ ~d \/ e) …. for the restricted Horn type (at most one negation) polynomial time procedure

45 45 Truth-table inference method Let KB = {S 1, S 2,  … , S n } be a set of sentences and c a possible conclusion C logically follows from KB iff the sentence S 1  S 2  …  S n => c is a tautology Complexity: exponential in the number of propositions!

46 46 Truth-table method: example winme looseyou heads tails 1 2 3 4 (1,2,3,4) S =>winme 0 0 0 0 1 1 0 1 01 0 0 0 1 1 0 1 1 01 0 0 1 0 0 1 1 1 01 0 0 1 1 0 0 1 1 01 0 1 0 0 1 1 0 0 01 0 1 0 1 1 1 1 0 01 0 1 1 0 0 1 1 0 01 0 1 1 1 0 1 1 0 01 1 0 0 0 1 1 0 1 01 1 0 0 1 1 0 1 1 01 1 0 1 0 1 1 1 1 11 1 0 1 1 1 0 1 1 01 1 1 0 0 1 1 0 1 01 1 1 0 1 1 1 1 1 11 1 1 1 0 1 1 1 1 11 1 1 1 1 1 1 1 1 11

47 47 Expressiveness of Propositional Logic Cannot express general statements of the form “every person has a father and a mother” Must list all specific instances: father_of(moshe, tal), father_of(moshe,mor)…. Which usually yields many sentences... Extend the language to represent objects and relations between objects: First Order Logic  X  Y, Z such that father(Y,X) and mother(Z,X)

48 48 ?


Download ppt "Lecture 7: Knowledge Representation and Logic Heshaam Faili University of Tehran Motivation Knowledge bases and inferences Logic as."

Similar presentations


Ads by Google