Knowledge Representation Logic and inference 1 Knowledgebased Agents
Knowledge Representation , Logic, and inference 1. Knowledge-based Agents 2. Knowledge Representation Schemas 2 -1 Propositional Logic 2 First order logic 3 Inference 1
Knowledge-based Agent Central component of a knowledge-based agent is its knowledge-base (KB) A KB is a set of representations of facts about the world Each individual representation is called a sentence The sentences are expressed in a language called a knowledge representation language A knowledge-based agent should be able to infer. Inference mechanism generates new sentences that are necessarily true given that the old sentences are true. 2
The Intelligent Agent as Black Box Prior knowledge Past Experience Goals and Values Observations 3 Reasoning (inference) and Representation System (RRS) Actions
Inference example Given: “The red block is above the blue block” “The green block is above the red block” Infer: “The green block is above the blue block” “The blocks form a tower” 4
Knowledge Representation Schemas (Symbolic) 1 Logic based representation – propositional logic, first order predicate logic, Prolog 2 Procedural representation – rules, production system – semantic networks, conceptual graphs 4 Structural representation – scripts, frames, objects 5 3 Network representation
Representation of Knowledge There is no single most adequate knowledge representation formalism/scheme for everything. Main points for selecting a representation formalism: what should be represented, how should the knowledge be processed. There are many more representation formalisms. All the above mentioned are symbolic. There are non-symbolic ones, e. g. Neural networks. 6
What is Knowledge? Data – primitive verifiable facts, of any representation. Data reflects the current world. Knowledge – relation among sets of data (information), that is very often used for further information deduction. Knowledge contain information about behaviour of abstract models of the world. 7
Knowledge Representation The object of KR is to express knowledge in a computer-tractable form, so that it can be used to help agents perform well. A KR language is defined by two aspects: Syntax: describes how to make sentences OR describes the possible configurations that can constitute sentences. Semantics: determine the facts (meaning) in the world to which the sentences refer OR the “things” in the sentence. 8
Knowledge Representation Example The syntax of the language of arithmetic expressions says that x and y are expressions denoting numbers, the x y is a sentence. The semantics of the language say that x y is false when y is a bigger number than x, and true otherwise. Inference: 9 The terms “inference” and “reasoning” are generally used to cover any process by which conclusions are reached. Logical inference deduction
Types of logic Logic is a language for KR which tells us how to build up sentences in the language. Ontological commitment: what exists - facts? objects? time? beliefs? Epistemological commitment: what states of knowledge? Language Ontological Commitment Epistemological Commitment Propositional Logic Facts True/false/unknown First order logic Facts, objects, relations True/false/unknown Temporal logic Facts, objects, relations, time True/false/unknown Probability theory Facts Degree of belief 0… 1 10 Fuzzy logic Degree of belief 0… 1 Degree of truth
Knowledge Representation 1 - Logic Propositional Logic (Propositional Calculus): • Propositional Logic has limitations, - it is not expressive enough. First-order Logic (First-order Predicate Calculus): • First-Order Logic is an improvement and is useful. 11
) (ﺿﺎﺭﺗﻔﺎ Propositions Statements that can be either true or false The sky is blue The moon is made of cheese Artificial intelligence is my favourite subject Each statement takes one of the truthvalues T or F (or, 1 and 0) Each statement is represented by a propositional variable such as p, q, r, … 12
Logical operators We can use logical operators (or connectives) to build more complex statements from our simple propositions The moon is not made of cheese I am bored and I am tired You are a man or you are a mouse If it is snowing then it is cold 13
Negation p represents “It is snowing” The negation of p represents “It is not snowing” This is written p pronounced “not p” If p takes the value T then p takes the value F, and vice versa 14
Conjunction p represents “It is snowing” q represents “It is cold” The conjunction of p and q represents “It is snowing and it is cold” This is written as p q pronounced “p and q” Commutative, associative 15
Disjunction q represents “It is cold” r represents “It is raining” The disjunction of q and r represents “It is cold or it is raining” This is written as q r pronounced “q or r” Commutative (q r = r q), Associative (q (r p))=(q r) (q p) 16
Implication p represents “It is snowing” q represents “It is cold” Implication gives statements such as “If it is snowing then it is cold” This is written p q pronounced “p implies q” Not commutative, not associative 17
18
Propositional Calculus example Read: Logic Nat. Lang. Or And Implies Not Let, Fact P: "Ali likes chips'' Let, Fact Q: "Ali eats chips'' Other possible facts: 19 P Q : "Ali likes chips or Ali eats chips” P Q : "Ali likes chips and Ali eats chips'’ Q : "Ali doesn't eat chips'’ P Q : "If Ali likes chips then Ali eats chips''
Truth tables for logical connectives P Q T T T F F ~P F F T T P Q T F F F P Q T T T F P Q T F T T Ex: Give the truth table for: ( p q) (p q) Solu: 20 ( p q) (p q) false true P Q T F F T
Examples of PL sentences P means "It is hot" Q means "It is humid" R means "It is raining" P ^ Q => R "If it is hot and humid, then it is raining" Q => P "If it is humid, then it is hot" Q "It is humid. " 21
Propositional formulae A formula can be built from propositions and operators to represent a more complex statement We can construct a truth-table for any formula Upper-case letters are used to represent formulae e. g. P might represent (p q) r An interpretation of P is an assignment of truthvalues to all the propositional variables 22 i. e. it is a single row of the truth table
Example formula and truth-table (p q) r p q r q p q T T 23 T T T F F T T T (p q) r T F T T T F
) (ىﻨﻌﻤﻼ ﺭﺍﺭﻛﺖ Tautologies A propositional formula P that takes the truth-value T for every possible interpretation is called a tautology. This is written using the metasymbol╞ like this: ╞ P e. g. ╞ ( p p ) Any formula that is a tautology is said to be a valid formula. 24
Establishing tautologies An easy way to determine whether or not a proposition is a tautology is to substitute truth values for the atomic propositions. For example, given the proposition p p, if we substitute true for p, then the overall proposition is equivalent to true and if we substitute false for p then the overall proposition is equivalent to true Therefore we conclude that p p is a tautology. 25
Questions Which of the following propositions are tautologies? p ( p q) p (q p) (p q) 26
Contradictions and ) (ﺋﺮﺍﻁ contingencies A proposition that is always false is called contradiction If a proposition is neither a tautology nor a contradiction then it is called a contingency 27
Propositional Inference: Enumeration Method Let and KB = ( C) B C) Is it the case that KB ╞ ? I. e. , is true in all worlds where KB is true. Check all possible models -- must be true whenever KB is true. KB= = ( C) A B C B C) 28 False False True True False True
Propositional Inference: Enumeration Method Let and KB = ( C) B C) Is it the case that KB ╞ ? I. e. , is true in all worlds where KB is true Check all possible models -- must be true whenever KB is true 29 A B C KB ( C) B C) False False False True True False True False True True
Propositional Inference: Enumeration Method Let and KB = ( C) B C) Is it the case that KB ╞ ? Check all possible models -- must be true whenever KB is true 30 A B C KB ( C) B C) False False True False True False True True False True True True
Propositional Inference: Enumeration Method Let and KB = ( C) B C) Is it the case that KB ╞ ? Check all possible models -- must be true whenever KB is true 31 A B C KB ( C) B C) False False True False True False True True False True True True
Reasoning in Propositional Logic Similarly, if we assume a few things, we can determine if something follows. E. g. , if we assume P, then P Q, say, degenerates into True Q, which a truth table will tell us is always true. So, we can always draw valid conclusions from premises, regardless of what any of this means 32
Rules of inference There are rules of inference which can be applied to logic, These follow the syntax: A Premise ) ةﻴﻘﻄﻨﻤﻼ ةﻤﺪﻗﻤﻼ ( B Conclusion When something in the knowledge base matches the pattern above the line, then the system concludes that the part below the line is true. or, sometimes we may write it, as , , … |- meaning, if we know , , …, it is okay to conclude . 33
An Inference Rule: And - Elimination From a conjunction, you can infer any of the conjuncts. Premise Conclusion 1 2 … n i An inference rule is sound if the conclusion is true in all cases where the premises are true. 34
An Inference Rule: Modus Ponens From an implication and the premise of the implication, you can infer the conclusion. Premise Conclusion An inference rule is sound if the conclusion is true in all cases where the premises are true. i. e. If is true, and is true, then is true. Generalized Modus Ponens (GMP) 35
Common Inference Rules Modus Ponens: , |- And-Elimination: 1 2 |- i And-Introduction: 1, 2 |- 1 2 Or-Introduction: |- Double-Negation Elimination: ¬¬ |- Resolution: 3 6 , ¬ |-
Propositional Logic: Rules of Inference (cont. ) Or-Introduction: From a sentence, you can infer its disjunction with anything else at all. i 1 2 . . . n Double-Negation Elimination: From a doubly negated sentence, you can infer a positive sentence And-Introduction: From a list you can infer their conjunction. 37 1, 2 , . . . , n 1 2 . . . n
Predicate Logic or First-order logic (FOL) 38
Limitations of Propositional Logic p represents ‘My car is red’ q represents ‘This pen is red’ r represents ‘The planet Mars is red’ Cannot work with lower-level objects like ‘my car’, ‘this pen’, ‘the planet Mars’ For most practical applications, we need to be able to talk about objects and properties within our logical system 39
First-order logic (FOL) models the world in terms of Objects, which are things with individual identities Properties of objects that distinguish them from other objects Relations that hold among sets of objects Functions, which are a subset of relations where there is only one “value” for any given “input” Examples: Objects: Students, lectures, companies, cars. . . Properties: blue, oval, even, large, . . . Relations: Brother-of, bigger-than, outside, part-of, hascolor, occurs-after, owns, visits, precedes, . . . F 4 u 0 nctions: father-of, best-friend, second-half, one-morethan. . .
Syntax of FOL Predicates: P(x[1], . . . , x[n]) P: predicate name; (x[1], . . . , x[n]): argument list Examples: human(x), /* x is a human */ father(x, y) /* x is the father of y */ When all arguments of a predicate is assigned values , the predicate becomes either true or false, i. e. , it becomes a proposition. Ex. Father(Fred, Joe) 41
Quantifiers Quantification allows us to make statements about more than one object at a time , Universal quantification (or forall) ( x)P(x) means that P holds for all values of x in the domain associated with that variable. E. g. , ( x) dolphin(x) => mammal(x) ( x) human(x) => mortal(x) Universal quantifiers often used with "implication (=>)" to form "rules" about properties of a class ( x) student(x) => smart(x) (All students are smart) Often associated with English words “all”, “everyone”, “always”, etc. 42
Existential quantification This means “there exists at least one object x such that x is a king and x is a person” ( x)P(x) means that P holds for some value(s) of x in the domain associated with that variable. E. g. , ( x) mammal(x) ^ lays-eggs(x) ( x) taller(x, Fred) Existential quantifiers usually used with “^ (and)" to specify a list of properties about an individual. ( x) student(x) ^ smart(x) (there is a student who is smart. ) ( x) student(x) => smart(x) Mean that if there is a student x then he is smart (w 43 rong).
Nested Quantifiers Same quantifier: Can reduce to one x y Brother(x, y) Brother(y, x) Same as: x, y Brother(x, y) Brother(y, x) Same as: y, x Brother(x, y) Brother(y, x) Same as: y, x Brother(x, y) Brother(y, x) Example; Some dogs bark x. Dog x Barks x xy. Dog x Bark y makes_sound x All barking dogs are irritating. x. Dog x Barking x Irritating x 44
Forward Chaining Used to produce new facts Start from atomic sentences and fire rules until no further inference is possible, Example: KB = All men like apples, men buy everything they like, and Socrates is a man. In FOL, the KB is 1 ( x) man(x) => likes(x, apples) 2 ( x)( y) (man(x) ^ likes(x, y)) => buys(x, y) 3 Man(Socrates) Goal query: Does Socrates buy apples? Proof: Use GMP with (1) and (3) to derive: “(4) likes(Socrates, apples)” Use GMP with (3), (4) and (2) man(Socrates) ^ likes(Socrates, apples) => buys(Socrates, apples) to derive “(5) buys(Socrates, apples)” Resu 45 lt: Yes, Socrates buys apples
Example: KB = All cats like fish, cats eat everything they like, and Ziggy is a cat. In FOL, KB = 1. x cat(x) => likes(x, Fish) 2. x y (cat(x) ^ likes(x, y)) => eats(x, y) 3. cat(Ziggy) Goal query: Does Ziggy eat fish? Proof: Use GMP with (1) and (3) to derive: 4. likes(Ziggy, Fish) Use GMP with (3), (4) and (2) to derive eats(Ziggy, Fish) So, Yes, Ziggy eats fish. 46
Backward chaining Used to deduce whether statements are true or not Start backwards from the goal to find known facts that support the goal Used in advisory expert systems User asks questions System asks leading questions, then produces answer if it can, Backward chaining is the basis for “logic programming, ” e. g. , 47 Prolog.
- Slides: 47