Download presentation

Presentation is loading. Please wait.

Published byDarby Ledwell Modified about 1 year ago

1
1 CSC 8520 Spring Paula Matuszek CS 8520: Artificial Intelligence Logical Agents and First Order Logic Paula Matuszek Spring 2013

2
2 CSC 8520 Spring Paula Matuszek References These slides draw from a number of sources, including: –Hwee Tou Ng, –Russell, pdfhttp://aima.eecs.berkeley.edu/slides- pdf –Diagrams are based on AIMA. –Matuszek, Logic/logic-for-AI.ppt Logic/logic-for-AI.ppt

3
3 CSC 8520 Spring Paula Matuszek Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic First Order Logic Inference rules and theorem proving –forward chaining –backward chaining –resolution

4
4 CSC 8520 Spring Paula Matuszek Knowledge bases Knowledge base = set of sentences in a formal language Declarative approach to building an agent (or other system): –Tell it what it needs to know Then it can Ask itself what to do - answers should follow from the KB Agents can be viewed at the knowledge level –i.e., what they know, regardless of how implemented Or at the implementation level –i.e., data structures in KB and algorithms that manipulate them

5
5 CSC 8520 Spring Paula Matuszek A simple knowledge-based agent

6
6 CSC 8520 Spring Paula Matuszek Simple Knowledge-Based Agent This agent tells the KB what it sees, asks the KB what to do, tells the KB what it has done (or is about to do). The agent must be able to: –Represent states, actions, etc. –Incorporate new percepts –Update internal representations of the world –Deduce hidden properties of the world –Deduce appropriate actions

7
7 CSC 8520 Spring Paula Matuszek Wumpus World PEAS Description Performance measure –gold +1000, death –-1 per step, -10 for using the arrow Environment –Squares adjacent to wumpus are smelly –Squares adjacent to pit are breezy –Glitter iff gold is in the same square –Shooting kills wumpus if you are facing it –Shooting uses up the only arrow –Grabbing picks up gold if in same square –Releasing drops the gold in same square Sensors: Stench, Breeze, Glitter, Bump, Scream Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot

8
8 CSC 8520 Spring Paula Matuszek Wumpus world characterization Fully Observable? No – only local perception Deterministic? Yes – outcomes exactly specified Static? Yes – Wumpus and Pits do not move Discrete? Yes Episodic? No – sequential at the level of actions Single-agent? Yes – The wumpus itself is essentially a natural feature, not another agent

9
9 CSC 8520 Spring Paula Matuszek More Environment Some versions of Wumpus have a bat (“You hear squeaking”.) If you enter the room with a bat, it carries you off and drops you elsewhere. Does that change the environment description? –Fully Observable? –Deterministic? –Static? –Discrete? –Episodic? –Single-agent? What about the Wumpus game we played?

10
10 CSC 8520 Spring Paula Matuszek Exploring a Wumpus world Directly observed: S: stench B: breeze G: glitter A: agent Inferred (mostly): OK: safe square P: pit W: wumpus

11
11 CSC 8520 Spring Paula Matuszek Exploring a wumpus world In 1,1 we don’t get B or S, so we know 1,2 and 2,1 are safe. Move to 1,2. In 1,2 we feel a breeze.

12
12 CSC 8520 Spring Paula Matuszek Exploring a wumpus world In 1,2 we feel a breeze. So we know there is a pit in 1,3 or 2,2.

13
13 CSC 8520 Spring Paula Matuszek Exploring a wumpus world So go back to 1,1 then to 2,1 where we smell a stench.

14
14 CSC 8520 Spring Paula Matuszek Exploring a wumpus world W W S Stench in 2,1, so the wumpus is in 3,1 or 2,2. We don't smell a stench in 1,2, so 2,2 can't be the wumpus, so 3,1 must be the wumpus.

15
15 CSC 8520 Spring Paula Matuszek Exploring a wumpus world We don't feel a breeze in 2,1, so 2,2 can't be a pit, so 1,3 must be a pit. 2,2 has neither pit nor wumpus and is therefore okay.

16
16 CSC 8520 Spring Paula Matuszek Exploring a wumpus world We move to 2,2. We don’t get any sensory input.

17
17 CSC 8520 Spring Paula Matuszek Exploring a wumpus world So we know that 2,3 and 3,2 are ok.

18
18 CSC 8520 Spring Paula Matuszek Exploring a wumpus world Move to 3,2, where we observe stench, breeze and glitter! We have found the gold and won. Do we want to kill the wumpus? (hint: look at the scoring function)

19
19 CSC 8520 Spring Paula Matuszek Representing Knowledge The agent that solves the wumpus world can most effectively be implemented by a knowledge-based approach Need to represent states and actions, update internal representations, deduce hidden properties and appropriate actions Need a formal representation for the KB And a way to reason about that representation

20
20 CSC 8520 Spring Paula Matuszek Logic in general Logics are formal languages for representing information such that conclusions can be drawn Syntax defines the sentences in the language Semantics define the "meaning" of sentences; –i.e., define truth of a sentence in a world E.g., the language of arithmetic x+2 ≥ y is a sentence; x2+y > {} is not a sentence –x+2 ≥ y is true iff the number x+2 is no less than the number y. –x+2 ≥ y is true in a world where x = 7, y = 1 –x+2 ≥ y is false in a world where x = 0, y = 6

21
21 CSC 8520 Spring Paula Matuszek What is logic? We can also think of logic as an “algebra” for manipulating only two values: true ( T ) and false ( F ) We will cover: –Propositional logic--the simplest kind –Predicate logic (a.k.a. predicate calculus)--an extension of propositional logic –Resolution theory--a general way of doing proofs in predicate logic (and the basis for Prolog’s inference).

22
22 CSC 8520 Spring Paula Matuszek Propositional logic: Syntax Propositional logic is the simplest logic – illustrates basic ideas The proposition symbols P1, P2 etc are sentences –If S is a sentence, ¬S is a sentence (negation, not) –If S1 and S2 are sentences, S1 ∧ S2 is a sentence (conjunction, AND) –If S1 and S2 are sentences, S1 ∨ S2 is a sentence (disjunction, OR) –If S1 and S2 are sentences, S1 ⇒ S2 is a sentence (implication, IMPLIES) –If S1 and S2 are sentences, S1 ⇔ S2 is a sentence (biconditional)

23
23 CSC 8520 Spring Paula Matuszek Propositional logic Propositional logic consists of: –The logical values true and false ( T and F ) –Propositions: “Sentences,” which Are atomic (that is, they must be treated as indivisible units, with no internal structure), and Have a single logical value, either true or false –Operators, both unary and binary; when applied to logical values, yield logical values The usual operators are and, or, not, and implies

24
24 CSC 8520 Spring Paula Matuszek Truth tables Logic, like arithmetic, has operators, which apply to one, two, or more values (operands) A truth table lists the results for each possible arrangement of operands –Order is important: x op y may or may not give the same result as y op x The rows in a truth table list all possible sequences of truth values for n operands, and specify a result for each sequence –Hence, there are 2 n rows in a truth table for n operands

25
25 CSC 8520 Spring Paula Matuszek Unary operators There are four possible unary operators: Only the last of these (negation) is widely used (and has a symbol, ¬,for the operation XConstant TConstant FIdentity ¬X¬X TTFTF FTFFT

26
26 CSC 8520 Spring Paula Matuszek Useful binary operators Here are the binary operators that are traditionally used: Notice in particular that material implication ( ) only approximately means the same as the English word “implies” Any other binary operators can be constructed from a combination of these (along with unary not, ¬ ) XY AND X Y OR X Y IMPLIES X Y BICONDITIONAL X Y TTTTTT TFFTFF FTFTTF FFFFTT

27
27 CSC 8520 Spring Paula Matuszek Logical expressions All logical expressions can be computed with some combination of and ( ), or ( ), and not ( ) operators For example, logical implication can be computed this way: Notice that X Y is equivalent to X Y XY XX X YX Y TTFTT TFFFF FTTTT FFTTT

28
28 CSC 8520 Spring Paula Matuszek Another example Exclusive or ( xor ) is true if exactly one of its operands is true Notice that ( X Y) (X Y) is equivalent to X xor Y XY XX YY X YX Y( X Y) (X Y) X xor Y TTFFFFFF TFFTFTTT FTTFTFTT FFTTFFFF

29
29 CSC 8520 Spring Paula Matuszek Worlds A world is a collection of prepositions and logical expressions relating those prepositions Example: –Propositions: JohnLovesMary, MaryIsFemale, MaryIsRich –Expressions: MaryIsFemale MaryIsRich JohnLovesMary A proposition “says something” about the world, but since it is atomic (you can’t look inside it to see component parts), propositions tend to be very specialized and inflexible

30
30 CSC 8520 Spring Paula Matuszek Models A model is an assignment of a truth value to each proposition, for example: – JohnLovesMary: T, MaryIsFemale: T, MaryIsRich: F An expression is satisfiable if there is a model for which the expression is true –For example, the above model satisfies the expression MaryIsFemale MaryIsRich JohnLovesMary An expression is valid if it is satisfied by every model –This expression is not valid: MaryIsFemale MaryIsRich JohnLovesMary because it is not satisfied by this model: JohnLovesMary: F, MaryIsFemale: T, MaryIsRich: T –But this expression is valid: MaryIsFemale MaryIsRich MaryIsFemale

31
31 CSC 8520 Spring Paula Matuszek Wumpus world sentences Let P i,j be true if there is a pit in [i, j]. Let B i,j be true if there is a breeze in [i, j]. We have –¬ P 1,1 –¬B 1,1 –B 2,1 "Pits cause breezes in adjacent squares" –B 1,1 ⇔ (P 1,2 ∨ P 2,1 ) –B 2,1 ⇔ (P 1,1 ∨ P 2,2 ∨ P 3,1 )

32
32 CSC 8520 Spring Paula Matuszek Grounding We must also be aware of the issue of grounding: the connection between our KB and the real world. –Straightforward for Wumpus or adventure games –More difficult when reasoning about real situations –Real problems seldom perfectly grounded, because we must ignore details. Is the connection good enough to get useful answers?

33
33 CSC 8520 Spring Paula Matuszek Entailment Entailment means that one thing follows from another. Knowledge base KB entails sentence S if and only if S is true in all worlds where KB is true –E.g., the KB containing “the Wildcats won” and “the Bearcats won” entails “Either the Wildcats won or the Bearcats won” –E.g., x+y = 4 entails 4 = x+y –Entailment is a relationship between sentences (i.e., syntax) that is based on semantics

34
34 CSC 8520 Spring Paula Matuszek Entailment in the wumpus world Situation after detecting nothing in [1,1], moving right, breeze in [2,1] Consider possible models for KB assuming only pits: there are 3 Boolean choices ⇒ 8 possible models (ignoring sensory data)

35
35 CSC 8520 Spring Paula Matuszek Wumpus models for pits

36
36 CSC 8520 Spring Paula Matuszek What Do We Know? –¬ P 1,1 –¬B 1,1 –B 2,1

37
37 CSC 8520 Spring Paula Matuszek Wumpus models KB = wumpus-world rules + observations. Only the three models in red are consistent with KB.

38
38 CSC 8520 Spring Paula Matuszek Wumpus Models Consider S1: pit is not in 1.2. S1 model is dotted yellow boundary. KB is contained within S1 model, so KB entails S1; in every model in which KB is true, so is S1. We can conclude that the pit is not in1.2. Consider S2: pit is not in 2.2. S2 is dotted brown boundary. KB is not within S1, so KB does not entail S2; nor does S2 entail KB. So we can't conclude anything about the truth of S2 given KB.

39
39 CSC 8520 Spring Paula Matuszek Pros of propositional logic Declarative Allows partial/disjunctive/negated information Compositional: meaning of B 1,1 ∧ P 1,2 is derived from meaning of B 1,1 and of P 1,2 Meaning in propositional logic is context- independent (unlike natural language, where meaning depends on context) Has a sound, complete inference procedure

40
40 CSC 8520 Spring Paula Matuszek Cons of Propositional Logic V ery limited expressive power (unlike natural language) - Rapid proliferation of clauses. –For instance, Wumpus KB contains "physics" sentences for every single square E.g., cannot say "pits cause breezes in adjacent squares“ except by writing one sentence for each square

41
41 CSC 8520 Spring Paula Matuszek Inference Given some sentences how do we get to new sentences? Inference!

42
42 CSC 8520 Spring Paula Matuszek Inference KB entails i S means sentence S can be derived from KB by procedure i Soundness: i is sound if it derives only sentences S that are entailed by KB Completeness: i is complete if it derives all sentences S that are entailed by KB. Logic: –Has a sound and complete inference procedure –Which will answer any question whose answer follows from what is known by the KB.

43
43 CSC 8520 Spring Paula Matuszek Inference Simplest inference method is model-based inference –enumerate all possible models –check to see if a proposed sentence is true in every KB –sound, complete, slow

44
44 CSC 8520 Spring Paula Matuszek Inference by enumeration Depth-first enumeration of all models is sound and complete n symbols, time complexity is O(2n), space complexity is O(n)

45
45 CSC 8520 Spring Paula Matuszek Inference-based agents in the wumpus world A wumpus-world agent using propositional logic: –¬P1,1 –¬W1,1 –Bx,y ⇔ (Px,y+1 ∨ Px,y-1 ∨ Px+1,y ∨ Px-1,y) –Sx,y ⇔ (Wx,y+1 ∨ Wx,y-1 ∨ Wx+1,y ∨ Wx-1,y) –W1,1 ∨ W1,2 ∨ … ∨ W4,4 –¬W1,1 ∨ ¬W1,2 –¬W1,1 ∨ ¬W1,3 –… ⇒ 64 distinct proposition symbols, 155 sentences

46
46 CSC 8520 Spring Paula Matuszek

47
47 CSC 8520 Spring Paula Matuszek Inference by Theorem Proving Rather than enumerate all possible models, we can apply inference rules to the current sentences in the KB to derive new sentences A proof consists of a chain of rules beginning with known sentences (premises) and ending with the sentence we want to prove (conclusion)

48
48 CSC 8520 Spring Paula Matuszek Inference rules in propositional logic Here are just a few of the rules you can apply when reasoning in propositional logic: From aima.eecs.berkeley.edu/slides-ppt, chs 7-9

49
49 CSC 8520 Spring Paula Matuszek Implication elimination A particularly important rule allows you to get rid of the implication operator, : X Y X Y Thurs AI class AI class Thurs The symbol means “is logically equivalent to” We will use this later on as a necessary tool for simplifying logical expressions

50
50 CSC 8520 Spring Paula Matuszek Conjunction elimination Another important rule for simplifying logical expressions allows you to get rid of the conjunction ( and ) operator, : This rule simply says that if you have an and operator at the top level of a fact (logical expression), you can break the expression up into two separate facts: – Breeze 2,1 Breeze 1,2 becomes: –Breeze 2,1 – Breeze 1,2

51
51 CSC 8520 Spring Paula Matuszek Inference by Theorem Proving Given: –A set of sentences in the KB: the premises –A sentence to be proved: the conclusion –A set of sound rules Apply a rule to an appropriate sentence Add the resulting sentence to the KB Stop if we have added the conclusion to the KB Essentially a search problem –Better than model-based if many models, short proofs –But b is very large

52
52 CSC 8520 Spring Paula Matuszek Summary Logical agents apply inference to a knowledge base to derive new information and make decisions Basic concepts of logic: –syntax: formal structure of sentences –semantics: truth of sentences wrt models –entailment: necessary truth of one sentence given another –inference: deriving sentences from other sentences –soundness: derivations produce only entailed sentences –completeness: derivations can produce all entailed sentences Propositional logic lacks expressive power

53
53 CSC 8520 Spring Paula Matuszek First-order logic (Predicate Calculus) Whereas propositional logic assumes the world contains facts, first-order logic (like natural language) assumes the world contains –Objects: people, houses, numbers, colors, baseball games, wars, … –Relations: red, round, prime, brother of, bigger than, part of, comes between, … –Functions: father of, best friend, one more than, plus, …

54
54 CSC 8520 Spring Paula Matuszek Syntax of FOL: Basic elements All of propositional logic ConstantskingJohn, 2, villanova,... Predicatesbrother, >,... Functionssqrt, leftLegOf,... VariablesX, Y, A, B,... Connectives¬, ⇒, ∧, ∨, ⇔ Equality= Quantifiers ∀, ∃

55
55 CSC 8520 Spring Paula Matuszek Constants, functions, and predicates A constant represents a “thing”--it has no truth value, and it does not occur “bare” in a logical expression –Examples: paulaMatuszek, 5, earth, goodIdea Given zero or more arguments, a function produces a constant as its value: –Examples: studentof(paulaMatuszek), add(2, 2), thisPlanet() A predicate is like a function, but produces a truth value –Examples: aiInstructor(paulaMatuszek), isPlanet(earth), greater(3, add(2, 2))

56
56 CSC 8520 Spring Paula Matuszek Universal quantification The universal quantifier, ∀, is read as “for each” or “for every” or “for all” –Example: ∀ x, x 2 0 (for all x, x 2 is greater than or equal to zero) Typically, is the main connective with ∀ : ∀ x, at(x,villanova) smart(x) means “Everyone at Villanova is smart” Common mistake: using as the main connective with ∀ : ∀ x, at(x,villanova) smart(x) means “Everyone is at Villanova and everyone is smart” If there are no values satisfying the condition, the result is true –Example: ∀ x, isPersonFromMars(x) smart(x) is true

57
57 CSC 8520 Spring Paula Matuszek Existential quantification The existential quantifier, ∃, is read “for some” or “there exists” –E.G.: ∃ x, x 2 < 0 (there exists an x such that x 2 < zero) Typically, is the main connective with ∃ : ∃ x, at(x,villanova) smart(x) means “There is someone who is at Villanova and is smart” Common mistake: using as the main connective with ∃ : ∃ x, at(x,villanova) smart(x) This is true if there is someone at Villanova who is smart......but it is also true if there is someone who is not at Villanova By the rules of material implication, the result of F T is T

58
58 CSC 8520 Spring Paula Matuszek Properties of quantifiers ∀ x ∀ y is the same as ∀ y ∀ x ∃ x ∃ y is the same as ∃ y ∃ x ∃ x ∀ y is not the same as ∀ y ∃ x ∃ x ∀ y Loves(x,y) –“There is a person who loves everyone in the world” –More exactly: ∃ x ∀ y (person(x) person(y) Loves(x,y)) ∀ y ∃ x Loves(x,y) –“Everyone in the world is loved by at least one person”

59
59 CSC 8520 Spring Paula Matuszek More rules Quantifier duality: each can be expressed using the other ∀ x Likes(x,IceCream) ∃ x Likes(x,IceCream) ∃ x Likes(x,Broccoli) ∀ x Likes(x,Broccoli) Two additional important rules: ∀ x, p(x) ∃ x, p(x) “If not every x satisfies p(x), then there exists a x that does not satisfy p(x) ” ∃ x, p(x) ∀ x, p(x) “If there does not exist an x that satisfies p(x), then all x do not satisfy p(x)

60
60 CSC 8520 Spring Paula Matuszek Terms and Atomic sentences A term is a logical expression that refers to an object. –book(andrew). Andrew’s book. –textbook(8520). Textbook for An atomic sentence states a fact. –student(andrew). –student(andrew, aaula). –atudent(andrew, ai). –Note that the interpretation of these is different; it depends on how we consider them to be grounded.

61
61 CSC 8520 Spring Paula Matuszek Complex sentences Complex sentences are made from atomic sentences using connectives ¬S, S1 ∧ S2, S1 ∨ S2, S1 ⇒ S2, S1 ⇔ S2, E.g. sibling(kingJohn,richard) ⇒ sibling(richard,kingJohn)

62
62 CSC 8520 Spring Paula Matuszek Truth in first-order logic Sentences are true with respect to a model and an interpretation Model contains objects (domain elements) and relations among them Interpretation specifies referents for –constant symbols → objects –predicate symbols → relations –function symbols →functional relations An atomic sentence predicate(term 1,...,term n ) is true iff the objects referred to by term 1,...,term n are in the relation referred to by predicate

63
63 CSC 8520 Spring Paula Matuszek Knowledge base for the wumpus world Perception – ∀ t,s,b Percept([s,b,Glitter],t) ⇒ Glitter(t) Reflex – ∀ t Glitter(t) ⇒ BestAction(Grab,t)

64
64 CSC 8520 Spring Paula Matuszek Deducing hidden properties ∀ x,y,a,b Adjacent([x,y],[a,b]) ⇔ (x=a ∧ (y=b-1 ∨ y=b+1) ∨ (y=b ∧ (x=a-1 ∨ x=a+1)) Properties of squares: – ∀ s,t At(Agent,s,t) ∧ Breeze(t) ⇒ Breezy(s) –Squares are breezy near a pit: Diagnostic rule---infer cause from effect ∀ s Breezy(s) ⇔ ∃ r Adjacent(r,s) ∧ Pit(r) Causal rule---infer effect from cause ∀ r Pit(r) ⇒ [ ∀ s Adjacent(r,s) ⇒ Breezy(s)]

65
65 CSC 8520 Spring Paula Matuszek Knowledge engineering in FOL Identify the task Assemble the relevant knowledge: knowledge acquisition Decide on a vocabulary of predicates, functions, and constants: an ontology Encode general knowledge about the domain Encode a description of the specific problem instance Pose queries to the inference procedure and get answers Debug the knowledge base

66
66 CSC 8520 Spring Paula Matuszek Summary First-order logic: –objects and relations are semantic primitives –syntax: constants, functions, predicates, equality, quantifiers Increased expressive power: sufficient to define wumpus world compactly

67
67 CSC 8520 Spring Paula Matuszek Inference When we have all this knowledge we want to do something with it Typically, we want to infer new knowledge –An appropriate action to take –Additional information for the Knowledge Base Some typical forms of inference include –Forward chaining –Backward chaining –Resolution

68
68 CSC 8520 Spring Paula Matuszek Example knowledge base The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American. Prove that Col. West is a criminal

69
69 CSC 8520 Spring Paula Matuszek Example knowledge base contd.... it is a crime for an American to sell weapons to hostile nations: American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x) Nono … has some missiles: Owns(Nono,M1) Missile(M1) … all of its missiles were sold to it by Colonel West Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) Missiles are weapons: Missile(x) ⇒ Weapon(x) An enemy of America counts as "hostile“: Enemy(x,America) ⇒ Hostile(x) West, who is American: American(West) The country Nono, an enemy of America: Enemy(Nono,America)

70
70 CSC 8520 Spring Paula Matuszek Forward chaining proof

71
71 CSC 8520 Spring Paula Matuszek Forward chaining proof

72
72 CSC 8520 Spring Paula Matuszek Forward chaining proof

73
73 CSC 8520 Spring Paula Matuszek Properties of forward chaining Sound and complete for first-order definite clauses Datalog = first-order definite clauses + no functions FC terminates for Datalog in finite number of iterations May not terminate in general if α is not entailed This is unavoidable: entailment with definite clauses is semidecidable

74
74 CSC 8520 Spring Paula Matuszek Efficiency of forward chaining Incremental forward chaining: no need to match a rule on iteration k if a premise wasn't added on iteration k- 1 – ⇒ match each rule whose premise contains a newly added positive literal Matching itself can be expensive: Database indexing allows O(1) retrieval of known facts –e.g., query Missile(x) retrieves Missile(M1) Forward chaining is widely used in deductive databases

75
75 CSC 8520 Spring Paula Matuszek Backward chaining example

76
76 CSC 8520 Spring Paula Matuszek Backward chaining example

77
77 CSC 8520 Spring Paula Matuszek Backward chaining example

78
78 CSC 8520 Spring Paula Matuszek Backward chaining example

79
79 CSC 8520 Spring Paula Matuszek Backward chaining example

80
80 CSC 8520 Spring Paula Matuszek Backward chaining example

81
81 CSC 8520 Spring Paula Matuszek Backward chaining example

82
82 CSC 8520 Spring Paula Matuszek Backward chaining example

83
83 CSC 8520 Spring Paula Matuszek Properties of backward chaining Depth-first recursive proof search: space is linear in size of proof Incomplete due to infinite loops – ⇒ fix by checking current goal against every goal on stack Inefficient due to repeated subgoals (both success and failure) – ⇒ fix using caching of previous results (extra space) Widely used for logic programming

84
84 CSC 8520 Spring Paula Matuszek Forward vs. backward chaining FC is data-driven, automatic, unconscious processing, –e.g., object recognition, routine decisions May do lots of work that is irrelevant to the goal BC is goal-driven, appropriate for problem-solving, –e.g., Where are my keys? How do I get into a PhD program? Complexity of BC can be much less than linear in size of KB Choice may depend on whether you are likely to have many goals or lots of data.

85
85 CSC 8520 Spring Paula Matuszek Resolution

86
86 CSC 8520 Spring Paula Matuszek Inference is Expensive! You start with a lot of facts (predicates) and a lot of possible transformations (rules) –Some rules apply to a single fact to yield a new fact –Some rules apply to a pair of facts to yield a new fact So at every step you must: –Choose some rule to apply –Choose one or two facts to apply it to If there are n facts –There are n potential ways to apply a single-operand rule –There are n * (n - 1) potential ways to apply a two-operand rule –Add the new fact to your ever-expanding fact base The search space is huge!

87
87 CSC 8520 Spring Paula Matuszek The magic of resolution Here’s how resolution works: –You transform each of your facts into a particular form, called a clause –You apply a single rule, the resolution principle, to a pair of clauses Clauses are closed with respect to resolution--that is, when you resolve two clauses, you get a new clause You add the new clause to your fact base So the number of facts you have grows linearly –You still have to choose a pair of facts to resolve –You never have to choose a rule, because there’s only one

88
88 CSC 8520 Spring Paula Matuszek The fact base A fact base is a collection of “facts,” expressed in predicate calculus, that are presumed to be true (valid) These facts are implicitly “ and ed” together Example fact base: – seafood(X) likes(John, X) (where X is a variable) –seafood(shrimp) – pasta(X) likes(Mary, X) (where X is a different variable) –pasta(spaghetti) That is, – (seafood(X) likes(John, X)) seafood(shrimp) (pasta(Y) likes(Mary, Y)) pasta(spaghetti) –Notice that we had to change some X s to Y s –The scope of a variable is the single fact in which it occurs

89
89 CSC 8520 Spring Paula Matuszek Clause form A clause is a disjunction (" or ") of zero or more literals, some or all of which may be negated Example: sinks(X) dissolves(X, water) ¬denser(X, water) Notice that clauses use only “or” and “not”—they do not use “and,” “implies,” or either of the quantifiers “for all” or “there exists” The impressive part is that any predicate calculus expression can be put into clause form –Existential quantifiers, ∃, are the trickiest ones And any FOL expression can be expressed as a conjunction of clauses: Conjunctive Normal Form

90
90 CSC 8520 Spring Paula Matuszek Unification From the pair of facts (not yet clauses, just facts): – seafood(X) likes(john, X) (where X is a variable) –seafood(shrimp) We ought to be able to conclude –likes(john, shrimp) We can do this by unifying the variable X with the constant shrimp –This is the same “unification” as is done in Prolog This unification turns seafood(X) likes(john, X) into seafood(shrimp) likes(john, shrimp) Together with the given fact seafood(shrimp), the final deductive step is easy

91
91 CSC 8520 Spring Paula Matuszek The resolution principle Here it is: –From X someLiterals and X someOtherLiterals conclude: someLiterals someOtherLiterals That’s all there is to it! X and X are complementary literals; someLiterals someOtherLiterals is the resolvent clause Example: – broke(Bob) well-fed(Bob) ¬broke(Bob) ¬hungry(Bob) well-fed(Bob) ¬hungry(Bob)

92
92 CSC 8520 Spring Paula Matuszek A common error You can only do one resolution at a time Example: – broke(Bob) well-fed(Bob) happy(Bob) ¬broke(Bob) ¬hungry(Bob) ∨ ¬happy(Bob) You can resolve on broke to get: – well-fed(Bob) happy(Bob) ¬hungry(Bob) ¬happy(Bob) T Or you can resolve on happy to get: – broke(Bob) well-fed(Bob) ¬broke(Bob) ¬hungry(Bob) T Note that both legal resolutions yield a tautology (a trivially true statement, containing X ¬X ), which is correct but useless But you cannot resolve on both at once to get: – well-fed(Bob) ¬hungry(Bob)

93
93 CSC 8520 Spring Paula Matuszek Contradiction A special case occurs when the result of a resolution (the resolvent) is empty, or “NIL” Example: –hungry(Bob) ¬hungry(Bob) NIL In this case, the fact base is inconsistent This will turn out to be a very useful observation in doing resolution theorem proving

94
94 CSC 8520 Spring Paula Matuszek A first example “Everywhere that John goes, Rover goes. John is at school.” – at(John, X) at(Rover, X) (not yet in clause form) – at(John, school) (already in clause form) We use implication elimination to change the first of these into clause form: – at(John, X) at(Rover, X) –at(John, school) We can resolve these on at(-, -), but to do so we have to unify X with school ; this gives: –at(Rover, school)

95
95 CSC 8520 Spring Paula Matuszek Refutation resolution The previous example was easy because it had very few clauses When we have a lot of clauses, we want to focus our search on the thing we would like to prove We can do this as follows: –Assume that our fact base is consistent (we can’t derive NIL ) –Add the negation of the thing we want to prove to the fact base –Show that the fact base is now inconsistent –Conclude the thing we want to prove

96
96 CSC 8520 Spring Paula Matuszek Example of refutation resolution “Everywhere that John goes, Rover goes. John is at school. Prove that Rover is at school. ” at(John, X) at(Rover, X) at(John, school) at(Rover, school) (this is the added clause) Resolve #1 and #3: at(John, X) Resolve #2 and #4: NIL Conclude the negation of the added clause: at(Rover, school) This seems a roundabout approach for such a simple example, but it works well for larger problems

97
97 CSC 8520 Spring Paula Matuszek A second example Start with: it_is_raining it_is_sunny it_is_sunny I_stay_dry it_is_raining I_take_umbrella I_take_umbrella I_stay_dry Convert to clause form: 1. it_is_raining it_is_sunny it_is_sunny I_stay_dry it_is_raining I_take_umbrella I_take_umbrella I_stay_dry Prove that I stay dry: I_stay_dry Proof: 6.(5, 2) it_is_sunny 7.(6, 1) it_is_raining 8.(5, 4) I_take_umbrella 9.(8, 3) it_is_raining 10. (9, 7) NIL Therefore, ( I_stay_dry) I_stay_dry

98
98 CSC 8520 Spring Paula Matuszek Resolution Summary Resolution is a single inference role which is both sound and complete Every sentence in the KB is represented in clause form; any sentence in FOL can be reduced to this clause form. Two sentences can be resolved if one contains a positive literal and the other contains a matching negative literal; the result is a new fact which is thedisjunction of the remaining literals in both. Resolution can be used as a relatively efficient theorem- prover by adding to the KB the negative of the sentence to be proved and attempting to derive a contradiction

99
99 CSC 8520 Spring Paula Matuszek Summary Inference is the process of adding information to the knowledge base We want inference to be sound: what we add is true if the KB is true And complete: if the KB entails a sentence we can derive it. Forward chaining, backward chaining, and resolution are typical inference mechanisms for first order logic.

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google