880 likes | 1.54k Views
Intro to AI Knowledge Representation & Reasoning. Ruth Bergman Fall 2002. Logic & AI. One of the original problem areas in AI was mathematical theorem proving: logic theorist, GPS first complete inference procedure was computational
E N D
Intro to AIKnowledge Representation &Reasoning Ruth Bergman Fall 2002
Logic & AI • One of the original problem areas in AI was mathematical theorem proving: logic theorist, GPS • first complete inference procedure was computational • Early on many researchers realized that it was essential to have a “formal” language for talking about knowledge • logic seems like the obvious language • These two facts have led logic and logical inference to be generally viewed as essential to symbolic AI • explicit language for expressing “knowledge” • formal inference procedures • nothing “hidden” in the code --- a fully declarative approach
Knowledge-Based Agent Sensors Knowledge Environment Inference Agent Effectors
Knowledge-Based Agent • Knowledge or epistemological level “What the agent can know about” The Golden Gate Bridge links San Francisco and Marin County • Logical level representation of facts as sentences in a formal language Links(GGBridge, SF, Marin) • Implementation level how inference is implemented on the agent architecture
Building KB Agent • Initially input designer’s knowledge in the form of sentences - declarative approach • Design learning mechanism - autonomous agent
Representation & Reasoning • Knowledge representation : express knowledge in computer-tractable form • Syntax : the written form of sentences • Semantics : facts in the world to which the sentences refer • Reasoning : a process of constructing new physical configurations from old ones
Representation • Programming language • good for describing algorithms and concrete data structures • hard to represent “there is a blue flower” • Natural language • expressive • ambiguous, depend on context “small dog and cat” • Good KB representation language • expressive, concise, unambiguous, effective • first-order predicate calculus (first order logic)
Syntax of First Order Logic • Term: • Constant p, q, AI • Variable x • Predicate of n arguments (Pn : Un {True,False}) brother, LeftLegOf • Function of n arguments (fn : Un U) Before, HasColor, Raining • connective: ^ | v | | | • quantifier: |
Well-Formed Formulae • AtomicSentence: pred (term1, term2, .. termn) Brother(Joseph, Reuven) • Sentence: • AtomicSentence • Sentence Brother(Joseph,Jacob) • Sentence connective Sentence Brother(Joseph, Reuven) ^ Brother(Joseph, Judea) • quantifier Sentence x Brother(Joseph,x) -> Son(x, Jacob) • (Sentence)
Semantics • Semantics is the link between what we write (syntax) and what it means (semantics) • We must define an interpretation for the sentences we write. The interpretation gives the sentence meaning in the world. • We will assume all of our languages of compositional: we can recursively define the meaning of sentences in terms of their components
U P Q Models • A model of a sentence is any world in which a sentence is true under a particular interpretation Example: any world where {p=False, q = False} is a model for p -> q • The more claims, the fewer the models • Models of complex sentences are described by the models of their component, and can be viewed as sets Example: Let the set P be the set of all the models of p and Q the set of all models of q. Then the set Q v P is the set of all models of p -> q U is the set of all models
Models for FOL • Universe U of objects • A interpretation function I that • maps constants to elements of U • maps function symbols f of n arguments to elements of U • maps predicates P of n arguments to relations, i.e. a subset PUof Un • Example: a model of integral arithmetic • Integers U = {1,2,3,…} • Functions symbols, f1= successor ={(0,1), (1,2), (2,3),…} f2= + ={(0,1,1), (0,2,2), (1,2,3), (0,3,3),…} • Predicate symbols, p=lessThan={(0,1), (0,2), (1,2), (0,3)…}
Interpretation in FOL • meaning of constants 1, 2, jacob, … • meaning of functions I(f(t1, t2, ... tn)) = u U if f(I(t1),…I(tn))= u • meaning of predicates I(P(t1, t2, ... tn)) = true if <I(t1),…I(tn)> PU false otherwise • meaning of connectives ^ | v | | | Connectives operate on truth values {True, False} Truth table gives true values for every possible input values imply connective: any implication is true whenever its antecedent is false • The meaning of a complex sentence is derived from its parts
Variable Substitution • Consider a substitution s to be a list of pairs x/u where x is a variable in the language and u is an element of U • a [s] is the sentence a with all of the variable assignments given in s • Example: a = x,y childof(y,x) parentof(x,y) a [x/jacob, y/issac] = childof(issac,jacob) parentof(jacob,issac)
Interpretation of Quantifiers • meaning of variables x[x/u] = u • meaning of quantifiers x P(x) the predicate P holds for all objects x U x P(x) the predicate P holds for some object x U • Order of quantification is very important • The term Well-Formed Formula (wff) is often used for sentences that have all their variables quantified • A term with no variables is called a ground term • x y Loves(x,y) • Everybody loves somebody • y x Loves(x,y) • There is someone who is loved by everyone
An Example • x male(x) v female(x) ^ x (male(x) ^ female(x)) • x y z parentof(x,y) ^ ancesterof(y,z) ancesterof(x,z) • x y parentof(x,y) ancesterof(x,y) • x parentof(fatherof(x),x) ^ parentof(motherof(x),x) ^ male(fatherof(x)) ^ female(motherof(x)) • x y1, y2 parentof(y1,x) ^ parentof(y2,x) ^ (y1 = y2) • x,y childof(y,x) parentof(x,y) • male(jacob), female(rebecca), parentof(rebecca,jacob) ..... • E.g. show x y ancesterof(y,x)
Logical Reasoning • We need a proof theory for our representation • Two notions of determining what follows from what we know • KB |= KB entails a; if KB is true, then so is Sentence is entailed by KB if all models of KB are models of • KB |-i inference procedure i derives from the sentences in KB
Representation & the “Real World” entailment sentences sentences representation Semantics Semantics world facts facts follows
Inference • Sound reasoning = logical inference = deduction A sentence s is valid if it is true in all interpretations in all possible worlds necessarily true, tautologies, analytic sentence Valid A sentence s is satisfiable if it is true for some interpretation in some world Satisfiable A sentence s is unsatisfiable if there is no interpretation in all possible world for which it it true Unsatisfiable
Inference Procedure • We can make up any way of creating new sentences from old • i is sound if KB |-ia implies that KB |= a • we only derive statements that are true given what we know • the record of the derivation is called a proof • i is complete if KB |= a implies that KB |-ia • if a fact is true, we can derive it • Soundness is essential (and usually easy) • Completeness is hard (and sometimes impossible!)
Inference for Propositional Logic • [Reminder] Propositional Logic • Atomic sentence: True, False, p, jacob • connective: ^ | v | | | • We could do inference for propositional logic just by checking models • 2n potential true values for a sentence with n atoms • Impractical even for propositional logic • Cannot extend this inference procedure for FOL with infinitely large universe U
Rules of Inference Involving Quantifiers • The connection between the universal and existential quantifiers • P(x) == x P(x) • x P(x) == x P(x) Sentence a, variable n, ground term g Sentence a, variable n, constant k no in KB Sentence a, variable n not in a, ground term g in a
Example • From our previous axiomitization • x male(x) v female(x) ^ (male(x) ^ female(x)) • x y z parentof(x,y) ^ ancesterof(y,z) ancesterof(x,z) • x y parentof(x,y) ancesterof(x,y) • x parentof(fatherof(x),x) ^ parentof(motherof(x),x) ^ male(fatherof(x)) ^ female(motherof(x)) • x y1, y2 parentof(y1,x) ^ parentof(y2,x) ^ (y1 = y2) • x,y childof(y,x) parentof(x,y) • male(jacob), female(rebecca), parentof(rebecca,jacob) ... • show • x y ancesterof(y,x) ^ female(y) • childof(jacob, rebecca) • childof(rebecca,jacob)
Notes on Proofs by Inference • A proof may require many steps • The proof process requires matching, substitution and application of the inference rules
An Inference Procedure for FOL? • This inference procedure will find a proof for any true sentence • For false sentences this procedure may not halt. This procedure is semi-decidable. • An inference procedure • If a is in KB return yes • Apply inferences rules on KB • Add new sentences to KB • Go to 2
Building a Knowledge Base • The process of building a knowledge base is called knowledge engineering • The knowledge engineer must encode domain knowledge in logic sentences • Typically, the knowledge engineer is a logician, not a domain expert. • Thus, the knowledge engineer interviews domain expert(s) to learn about the domain. This process is called knowledge acquisition. • A realistic domain typically requires thousands of rules • The knowledge is not available in rule form • The domain expert’s time is precious ($$$) • This process may take years – the knowledge engineering bottleneck
Knowledge Engineering • 5-step methodology • Decide what to talk about • Decide on a vocabulary of predicates, functions, and constants : ontology of the domain • Encode general knowledge about domain : writing logical sentences or axioms • Encode descriptions of the specific problem instances : writing simple atomic sentences • Pose queries to the inference procedure and get answers
X1 X2 A2 O1 A1 Electronic Circuits Domain • What to talk about: circuits, terminals, signals, gates, gate types C1 1 1 2 3 2
Electronic Circuits Ontology • Representation of constants • Gates X1,X2,… • Gate types XOR, OR, AND and NOT • Signal value constants : On, Off • Representation of objects • Output terminals Out(1, X1) , In(2, X1) • Representation of predicates on objects • Type (X1) = XOR v.s. Type(X1, XOR) v.s. XOR(X1) • Signal(X1) = On • Representation of relations between objects • Connected(Out(1, X1) , In(1, X2) )
Electronic Circuits Representation • Encode general rules • If two terminals are connected, then they have the same signal i1, i2 Connected (i1, i2) Signal(i1) = Signal(i1) • An XOR gate’s output is on iff its inputs are different • g Type(g)=XOR • Signal(Out(1,g)) = on Signal(In(1,g)) != Signal(In(2,g)) • … Five more rules for this domain • Encode specific instances • Type(X1) = XOR, … • Connected(Out(1, X1) , In(1, X2)) … • Pose queries to the inference procedure • What are the inputs for Sum bit = Off and Carry bit = On ? i1, i2, i3 Signal(In(1, C1)) = i1 Signal(In(2, C1)) = i2 Signal(In(3, C1)) = i3 Signal(Out(1, C1)) = Off Signal(Out(2, C1)) = On
General Relations and Predicates • Representation of general predicates • If x is a parent of y then it is an ancestor of y • x y parentof(x,y) ancesterof(x,y) x y z parentof(x,y) ^ ancesterof(y,z) ancesterof(x,z) • Representation of general relations on predicates • Ancestor is transitive x y z ancestorof(x,y) ^ ancesterof(y,z) ancesterof(x,z) • Ancestor is asymmetric x y z ancestorof(x,y) ancesterof(y,x)
Higher Order Logics • General relations on predicates • Predicate p is transitive • p Transitive(p) • x y p(x,y) ^ p(y,z) ancesterof(x,z) • Predicate p is asymmetric • p Transitive(p) • x y p(x,y) p(y,x) • Higher-order logic have strictly greater expressive power than first-order logic. • Logicians have little understanding of how to reason effectively with sentences in higher-order logic.
Representation limits of FOL • Inheritance • x bird(x) flies(x) • x penguin(x) bird(x) • Inheritance with exceptions • x penguin(x) flies(x) penguin(opus) Can deduce both flies(opus) and flies(opus) A contradiction. • The property of monotonicity FOL is a monotonic logic. If P follows from KB, then it still follows when KB is augmented with a new sentence s. There are nonmonotonic logics that explicitly deal with default values
General Ontologies • Special-purpose ontologies • Are the most efficient representation to solve problems for the given domain • Lack re-usability. Portions of knowledge have to be duplicated from one ontology to another. • General purpose ontologies • more demanding to construct • once done, many advantages • General purpose ontologies should be applicable in any special-purpose domain • Add domain specific rules • General purpose ontologies enable reasoning in several areas simultaneously. • In sufficiently demanding domains, different areas of knowledge must be unified
General Ontologies • Categories – define a taxonomic hierarchy where properties are inherited from more general categories Birds Pigeons, x Bird(x) fly(x) • Measures – a representation for mass, age, price, length, etc. • Composite objects – objects belong to categories based on their composition from subparts. E.g a chair has four legs and a flat seat • Time, Space and Change– represent a universe of continuous temporal and spatial dimensions. Times places and objects are part of this universe. • Events and processes – events are things that occur with space and time extent; processes are continuous events.
General Ontologies • Physical objects – allow objects to have different properties at different times. E.g. PrimeMinister(Israel) • Substances – describe properties that are intrinsic to the substances, rather than properties of the object as a whole. E.g., x,y x Butter ^ part of(y,x) y Butter • Mental objects and Beliefs – in multi-agent domains, it is important for an agent to reason about the mental processes of the other agents.
General purpose ontology • Categories : objects having certain common properties • Measures : quantities of particular type, age, mass... • Composite objects : car with wheels, engines, ... • Time, Space, and Change • Events and Processes : individual event and continuous events • Physical Objects • Substances : Tomato juice is category? Physical object? • Mental Objects and Beliefs : reason about belief of its own or others
West Wessex Marathon Race (by Martin Hollis) • With a field of five for the west wessex marathon race, there was little to interest the bettors. So, Peter Piper opened one of his ingenious books where he accepts multiple bets at high odds. To place a multiple bet, you must bet on two propositions, and you will win only if you are wholly successful. Peter Piper is now on an extended vacation because of the bettors who lost these bets: • A will not win the gold, nor B the silver. • C will win a medal, and D will not. • D and E will both win medals. • D will not win the silver, nor E the bronze. • A will win a medal, and C will not. Who won which of the medals?
West Wessex Marathon Race • A racer medals iff he receives a gold, silver or bronze medal x medal(x) (gold(x) v silver(x) v bronze(x)) • A racer can only receive one medal • x gold(x) medal(x) ^ (silver(x) v bronze(x)) • x silver(x) medal(x) ^ (gold(x) v bronze(x)) • x bronze(x) medal(x) ^ (silver(x) v gold(x)) • Only one race can receive a gold (silver, bronze) medal • x,y gold(x) ^ x != y gold(y) • x,y silver(x) ^ x != y silver(y) • x,y bronze(x) ^ x != y bronze(y) • Some participant must win a gold (silver, bronze) medal • x gold(x) • x silver(x) • x bronze(x)
West Wessex Marathon Race • A will not win the gold, nor B the silver is false gold(A) v silver(B) • C will win a medal, and D will not is false medal(C) v medal(D) • D and E will both win medals is false medal(D) v medal(E) • D will not win the silver, nor E the bronze is false silver(D) v bronze(E) • A will win a medal, and C will not is false medal(A) v medal(C) • Who won which of the medals? Proof in class.
Knights & Knaves • A very special island is inhabited only by knights and knaves. Knights always tell the truth, and knaves always lie.You meet two inhabitants Zoey and Mel. Zoey tells you Mel and I are both knaves. • Is Zoey a knight or knave? • Is Mel a knight or knave?
Knights & Knaves • A very special island is inhabited only by knights and knaves. knight(x) knave(x) • Knights always tell the truth x,s knight(x) ^ tell(x,s) TV(s) • knaves always lie x,s knave(x) ^ tell(x,s) TV(s) • The meaning of the truth value predicate (TV) s TV(s) s, s TV(s) s • Zoey tells you Mel and I are both knaves. tell(Zoey, knave(Zoey)^knave(Mel)) • Is Zoey a knight or knave? • Is Mel a knight or knave?