Notes 8: Predicate logic and inference ICS 270a Spring 2003 Outline New ontology objects,relations,properties,functions. New Syntax Constants, predicates,properties,functions New semantics meaning of new syntax Inference rules for Predicate Logic (FOL) Resolution Forward-chaining, Backword-chaining unification Readings: Nillson’s Chapters 15-16, Russel and Norvig Chapter 8, chapter 9 Propositional logic is not expressive Needs to refer to objects in the world, Needs to express general rules On(x,y) ~ clear(y) All man are mortal Everyone who passed age 21 can drink One student in this class got perfect score Etc…. First order logic, also called Predicate calculus allows more expressiveness Syntax Components Infinite set of object constants, alphanumerc strings Bb, 12345, Jerusalem, 270a, Irvine Function constants of all aritys (convention: start with lower case) motherOf, times, greaterThan, color Relation constants, Predicates of all aritys (start with capital) B21, Parent, multistoried, XYZ, prime Terms An object constant is a term A function constant of arity n followed by n terms in parenthesis is a term (called functional expression) motherOf(Silvia), Sam, leftlegof(John), add1(5), times(5,plus(3,6)) Wffs sentences An atomic sentence is formed from a predicate (relation) symbol followed by a parenthesized list of symbols Atoms: a relation constant (predicate) followed by n terms in parenthesis seperated by commas. GreaterThan(6,3), Q, Q(A,B,C,D), Brother(Richard,John) Married(FatherOf(Richard),MotherOf(John)) Complex propositional wffs: ,, , Use logic connectives: Brother(Richard,John) /\ Brother(John,Richard) Older(John,30) V Younger(John,30) Older(John) --> ~Younger(John,30) V P Semantics: Worlds The world consists of objects that has properties. There are relations and functions between these objects Objects in the world, individuals: people, houses, numbers, colors, baseball games, wars, centuries Clock A, John, 7, the-house in the corner, Tel-Aviv Functions on individuals: father-of, best friend, third inning of, one more than Relations: brother-of, bigger than, inside, part-of, has color, occurred after Properties (a relation of arity 1): red, round, bogus, prime, multistoried, beautiful Semantics: Interpretation An interpretation of a wff is an assignment that maps object constants to objects in the worlds, n-ary function symbols to n-ary functions in the world, n-ary relation symbols to n-ary relations in the world Given an interpretation, an atom has the value “true” in case it denotes a relation that holds for those individuals denoted in the terms. Otherwise it has the value “false” Example: A,B,C,floor, On, Clear World: On(A,B) is false, Clear(B) is true, On(C,F1) is true… Semantics: Models An interpretation satisfies a wff (sentence) if the wff has the value “true” under the interpretation. An interpretation that satisfies a wff is a model of that wff Any wff that has the value “true” under all interpretations is valid Any wff that does not have a model is inconsistent or unsatisfiable If a wff w has a value true under all the models of a set of sentences delta then delta logically entails w Example of models The formulas: On(A,F1) Clear(B) Clear(B) and Clear(C) On(A,F1) Clear(B) or Clear(A) Clear(B) Clear(C) Possible interpretations which are models: On = {<B,A>,<A,floor>,<C,Floor>} Clear = {<C>,<B>} Quantification Universal and existential quantifiers allow expressing general rules with variables Universal quantification All cats are mammals x Cat ( x) Mammal ( x) It is equivalent to the conjunction of all the sentences obtained by substitution the name of an object for the variable x. Syntax: if w is a wff then (forall x) w is a wff. Cat ( Spot ) Mammal( Spot ) Cat ( Rebbeka) Mammal( Rebbeka) Cat ( Felix ) Mammal( Felix ) ,,,, Quantification: Existential Existential quantification : an existentially quantified sentence is true in case one of the disjunct is true xSister ( x, spot ) Cat ( x ) Equivalent to disjunction: Sister(Spo t , Spot) Cat(Spot) Sister(Reb ecca,Spot) Cat(Rebecca) Sister(Fel ix,Spot) Cat(Felix) Sister(Ric hard,Spot) Cat(Richar d)... We can mix existential and universal quantification. Useful Equivalences De Morgan laws Inference rules: Universal instantiation: foall x f(x) |-- f(alpha) Existential generalization: from f(alpha) |-- exist x f(x) Modeling a domain; Conceptualization The kinship domain: object are people Properties include gender and they are related by relations such as parenthood, brotherhood,marriage predicates: Male, Female (unary) Parent,Sibling,Daughter,Son... Function:Mother Father Resolution in the predicate calculus Unification Algorithm unify Using unification in predicate calculus resolution Completeness and soundness Converting a wff to clause form The mechanics of resolution Answer extraction Inference Rules in FOL All the inference rules for propositional logic applies and additional three rules that use substitution; assigning constants to variables Subst(x/constant) Subst({x/Sam,y/Pam},Likes(x,y)) = Likes(Sam,Pam) Universal elimination From fromall x Likes(x,IceCream) we can substitute {x/Ben} and infer Likes(Ben,IceCream) Existential Elimination For any sentence and for any symbol k that does not appear elsewhere in the knowledge-base exists x Kill(x,Victim) we can infer Kill(Murderer,victim) As long as Murdered soes not appear anywhere Existential introduction From Likes(Jerry,IceCream) we can infer exists x Likes(x,IceCream) Predicate calculus resolution Suppose the 1 and 2 are two clauses represented as set of literals. If there is an atom in 1 and a literal ~ in 2 such as and have a common unifier Then these two clauses have a resolvent row. It is obtained by applying the substitution to 1 2 leaving out complementary literals Example: {P( f ( y ), A) Q ( B, C )}, {P( x, A) R( x, C )} subst f ( y ) x Converting to clause form x, y P( x) P( y ) I ( x,27) I ( y,28) S ( x, y ) P( A), P( B ) I ( A,27) I ( A,28) I ( B,27) S ( B, A) Example: Answer Extraction Example: Resoluction Refutation Prove I(A,27) Rule-Based Systems Rule-based Knowledge Representation and Inference combines rules if DOG(x) then TAIL(X) with working memory, DOG(SPOT) DOG(LUNA) is not a formal knowledge representation scheme like logic somewhat like a combination of propositional and FOPL uses simple methods for inference often combined with other mechanisms such as inheritance motivated by practical use rather than theoretical properties also has some basis in cognitive models Forward Chaining Procedure While (rules can still fire or goal is not reached) for each rule in the rulebase which has not fired 1. try to bind premises by matching to assertions in WM 2. if all premises in a rule are supported then assert the conclusion and add to WM Repeat 1. and 2. for all matching/ instantiation alternatives end continue Example: Zoo Rulebase Want to identify animals based on their characteristics could have rules like if A1 and A2 and A3.....and A27 then animal is a monkey i.e., one very specific rule per animal Better to use intermediate concepts e.g., the intermediate concept of a mammal if ?x is a mammal and B1...and B3 then ?x is a monkey Why are intermediate concepts useful? rules are easier to create rulebase is easier to maintain easier to perform inference however: finding good intermediate concepts is non-trivial! Where do the rules come from ? Manual Knowledge Acquisition interview experts expert describes the rules process of translating expert knowledge into a formal representation is also known as knowledge engineering this is notoriously difficult experts are often very poor at explicitly describing what they do e.g., ask Michael Jordan how he plays basketball or ask Tiger Woods how he plays golf Automated Knowledge Acquisition derive rules automatically from formal specifications e.g., by automatic analysis of solution manuals machine learning Inference Network Representation has Wehair can represent forward chaining with rules as a network: is a mammal eats meat is a carnivore tawny color black stripes has a tail is a tiger Inference using Backward Chaining Establish a hypothesis e.g., Tony is a tiger a hypothesis is as assertion whose truth we wish to test i.e., assert the hypothesis see if that is consistent with other data Work backwards, i.e., match the hypothesis to the conclusion of the rules look at the premise conditions of the rule if these are unknown, declare these as intermediate hypotheses backward chain recursively (depth-first manner) Can use search algorithms to control how backward chaining proceeds Inference Network Representation of Backward Chaining • We can represent backward chaining as a network: has hair is a mammal eats meat forward pointing eyes has claws has teeth tawny color black stripes is a carnivore is a tiger Backward Chaining Procedure While (unsupported hypotheses exist or goal is not reached) for each hypothesis H for each rule R whose conclusion matches with H try to support each rule’s premises by 1. matching assertions in WM 2. recursively applying backward chaining if rule’s premises are supported conclude that H is true end end continue Forward Chaining or Backward Chaining: which is better? Which direction is better depends on the circumstances 4 main factors of relevance the number of possible start states and number of possible goal states smaller is better the branching factor in each direction smaller is better what type of explanation the user wants more natural explanations may be important the typical action which triggers a rule i.e., data-driven or hypothesis-driven? What is a rule-based expert system (ES)? ES performs a task in limited domains that require human expertise medical diagnosis; fault diagnosis; status monitoring; data interpretation; mineral exploration; credit checking; tutoring; computer configuration ES solves problems by application of domain specific knowledge rather than weak methods. Domain knowledge is acquired by interviewing human experts ES can explain a problem solution in human-understandable terms Examples of Expert Systems 1965 1965 1972 1972 1975 1978 1979 1980 1982 1983 1983 1984 1986 1986 1986 1987 1992 1995 1997 DENDRAL MACSYMA MYCIN Prospector Cadeceus DIGITALISMIT PUFF R1 XCON KNOBS ACE FAITH ACES DELTA/CATS MAX Stanford analyze mass spectrometry data MIT symbolic mathematics problems Stanford diagnosis of blood diseases SRI Mineral Exploration U. of PITT Internal Medicine digitalis therapy advise Stanford obstructive airway diseases CMU computer configuration DEC computer configuration MITRE mission planning AT&T diagnosis faults in telephone cables JPL spacecraft diagnosis Aerospace satellite anomaly diagnosis Cambpell diagnose cooker malfunctions GE diagnosis of diesel locomotives AMEX credit authorization NYNEX telephone network troubleshooting Caltech PacBell network management UCI planning drug treatment for HIV Mycin: Diagnosis and treatment of blood diseases RULES PREMISE ($AND (SAME CNTXT GRAM GRAMNEG) (SAME CNTXT MORH ROD) (SAME CNTXT AIR AEROBIC)) ACTION: (CONCLUDE CNTXT CLASS ENTEROBACTERIACEAE .8) If THEN the stain of the organism is gramneg, and the morphology of the organism is rod, and the aerobicity of the organism is aerobic there is strongly suggestive evidence (.8) that the class of organism is enterocabateriaceae DATA ORGANISM-1: GRAM = (GRAMNEG 1.0) MORP = (ROD .8) (COCCUS .2) AIR = (AEROBIC .6)(FACUL .4) The XCON Application A rule-based expert system expert in the sense that the rules capture expert design knowledge addresses a design/configuration problem Digital Equipment Corporation (or Compaq by now!) XCON = rule-based expert system for computer configuration decides how peripherals are configured on new orders has 10,000 rules developed in early 1980’s based on “reactive rule-based systems” if antecedents then action forward chaining in style estimated to have saved DEC several hundred million $’s Limitations of Rule-Based Representations Can be difficult to create the “knowledge engineering” problem Can be difficult to maintain in large rule-bases, adding a rule can cause many unforeseen interactions and effects => difficult to debug Many types of knowledge are not easily represented by rules uncertain knowledge: “if it is cold it will probably rain” information which changes over time procedural information (e.g. a sequence of tests to diagnose a disease) Summary Knowledge Representation methods formal logic rule-based systems (less formal) Rule-based representations are composed of Working memory: Rules Inference occurs by forward or backward chaining Rule-based expert systems useful for certain classes of problems which do not have direct algorithmic solutions