Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computer Science & Engineering

Similar presentations


Presentation on theme: "School of Computer Science & Engineering"— Presentation transcript:

1 School of Computer Science & Engineering
Artificial Intelligence Logical Reasoning and Inference Dae-Won Kim School of Computer Science & Engineering Chung-Ang University

2 AI Scope Revisited Agents, AI Problems and Modeling
Solving Problems by Searching Learning (ML, PR, DM) Knowledge, Logic, Reasoning, and Inference Uncertain and Probabilistic Acting Alife, Affective Computing, Planning, Robotics …

3 Outline Knowledge-based agents Wumpus world
Logic in general – models and entailment Propositional logic Inference rules and theorem proving

4 Knowledge Base KB = set of sentences in a formal language
TELL it what it needs to know Then it can ASK itself what to do: answers should follow from the KB.

5 A Simple Knowledge-based Agent
Agents can be viewed at the knowledge level; what they know, regardless of how implemented.

6 Wumpus World

7 Wumpus World: PEAS 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 the square

8 Wumpus World: PEAS Performance measure
gold (+100), death (-100), -1 per step -10 for using the arrow Actuators Forward, Grab, Release, Shoot Sensors Smell, Glitter, Breeze

9 Exploring a Wumpus World

10 Exploring a Wumpus World

11 Exploring a Wumpus World

12 Exploring a Wumpus World

13 Exploring a Wumpus World

14 Exploring a Wumpus World

15 Exploring a Wumpus World

16 Exploring a Wumpus World

17 Logic in General Logics are formal language for representing information such that conclusions can be drawn Syntax defines the sentences in the language Semantics define the meaning of sentences; define the truth of a sentence in a world

18 Logic in General: Example
The language of arithmetic x+2>y is a sentence; x2+y> is not a sentence 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

19 Entailment Entailment means that one thing follows from another:
KB   Knowledge base KB entails sentence  if and only if  is true in all worlds where KB is true

20 Entailment: Example The KB containing “the Giants won” and “the Reds won” entails “Either the Giants won or the Reds won” x+y=4 entails 4=x+y Entailment is a relationship between sentences (i.e., syntax) that is based on semantics.

21 Entailment in the Wumpus World
Situation after detecting nothing in [1,1], moving right, breeze in [2,1] KB = wumpus world rules + observations  = [1,2] is safe (o)  = [2,2] is safe (x)

22 Inference KB i  : sentence  can be derived from KB by inference procedure i. The procedure will answer any question whose answer follows from what is known by the KB. Soundness Completeness

23 Inference KB i  : sentence  can be derived from KB by inference procedure i. The procedure will answer any question whose answer follows from what is known by the KB. Soundness whenever KB i , it is also true that KB   Completeness whenever KB  , it is also true that KB i 

24 Propositional Logic: Syntax
Propositional logic is the simplest logic. The proposition symbols P1, P2 are sentences. If S is a sentence, S is a sentence (negation) If S1 and S2 are sentences, S1  S2 is a sentence (conjunction) S1  S2 is a sentence (disjunction) S1  S2 is a sentence (implication) S1  S2 is a sentence (biconditional)

25 Propositional Logic: Semantics
Specifies true/false for each proposition symbol. S1 (true), S2 (true), S3 (false) S1 is true and S2 is true iff S1  S2 is true.

26 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]. 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)

27 Inference by Enumeration
Depth-first enumeration of all models is sound and complete. O(2n) for n symbols; problem is NP-complete.

28 Truth Table for Inference

29 Logical Equivalence

30 Validity and Satisfiability
A sentence is valid if it is true in all models, e.g., true, A  A, A  A Validity is connected to inference via the Deduction Theorem: KB   iff KB   is valid. A sentence is satisfiable if it is true in some model, e.g., A  B A sentence is unsatisfiable if it is true in no models, e.g., A  A

31 Forward and Backward Chaining
Horn Form KB = conjunction of Horn clauses Horn clause = proposition symbol; or (conjunction of symbols)  symbol E.g., C  (B  A)  (C  D  B)

32 Forward and Backward Chaining
Modus Ponens (for Horn Form): complete for Horn KBs. Can be used with forward chaining or backward chaining. These inference algorithms are very natural and run in linear time.

33 Forward Chaining Idea: fire any rule whose premises are satisfied in the KB, add its conclusion to the KB, until query is found.

34 Forward Chaining

35 Forward Chaining: Example

36 Forward Chaining: Example

37 Forward Chaining: Example

38 Forward Chaining: Example

39 Forward Chaining: Example

40 Forward Chaining: Example

41 Forward Chaining: Example

42 Backward Chaining Idea: work backwards from the query q: to prove q, check if q is known already, or prove it by all premises of some rule concluding q. Avoid loops: check if new subgoal is already on the goal stack. Avoid repeated work: check if new subgoal 1) has been proved true, or 2) has already failed.

43 Backward Chaining: Example

44 Backward Chaining: Example

45 Backward Chaining: Example

46 Backward Chaining: Example

47 Backward Chaining: Example

48 Backward Chaining: Example

49 Backward Chaining: Example

50 Backward Chaining: Example

51 Backward Chaining: Example

52 Backward Chaining: Example

53 Backward Chaining: Example

54 Forward vs. Backward Forward chaining
Data-driven; e.g., object recognition. Backward chaining Goal-driven, appropriate for problem-solving; e.g., how do I get into a PhD program?

55 Preliminary Summary Logical agents apply inference to a KB to derive new information and make decision. Basic concepts of logic: 1. syntax: formal structure of sentences 2. semantics: truth of sentences 3. entailment: necessary truth of one sentence given another 4. inference: deriving sentences from other sentences 5. soundness: derivations produce only entailed sentences 6. completeness: derivations can produce all entailed sentences Forward, backward chaining are complete for Horn clauses.

56 Resolution Q: Are FC/BC complete for propositional logic?
Conjunctive Normal Form (CNF): conjunction of disjunctions of literals. E.g., (A  B)  (B  C  D) Resolution inference rule (for CNF) is sound and complete for propositional logic.

57 Conversion to CNF

58 Resolution Algorithm Idea: proof by contradiction;
it shows that KB   is unsatisfiable.

59 Resolution: Example KB = (B(1,1)  P(1,2)  P(2,1))  B(1,1)
We want to infer P(1,2)  = P(1,2)

60 School of Computer Science & Engineering
Artificial Intelligence First-order Logic Dae-Won Kim School of Computer Science & Engineering Chung-Ang University

61 Outline Why First-order logic? Syntax and semantics of FOL
Wumpus word in FOL Inference in FOL

62 Example KB 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.

63 Propositional Logic Advantages:
Declarative: pieces of syntax for facts Compositional: P(1,2)  P(2,1) Context-independent Disadvantages: Limited expressive power (unlike natural language)

64 First-order Logic Whereas propositional logic assumes world contains facts, first-order logic (like natural language) assumes the world contains Objects: people, houses, numbers, colors, … Relations: red, round, bigger than, … Functions: father of, best friend, …

65 Logics in General

66 Syntax Constants: KingJohn, 2, CAU, … Predicates: Brother, >, …
Functions: Sqrt, LeftLegOf, … Variables: x, y, a, b, … Connectives/Equality: , , , =, … Quantifiers: , 

67 Atomic Sentences Atomic sentence
= predicate(term1, …, termn) or term1 = term2 Term = function(term1, …, termn) or constant or variable E.g., Brother(KingJohn, RichardTheLionheart)

68 Complex Sentences Complex sentences are made from atomic sentences using connectives. S1  S2, S1  S2, S1  S2, S1  S2 E.g., Brother(KingJohn, Richard) Sibling(Richard, KingJohn)

69 Models for FOL: Example

70 Truth Example Consider the interpretation in which
Richard: Richard the LionHeart John: the evil King John Brother: the brotherhood relation Under this interpretation, Brother(Richard, John) is true just in case Richard the Lionheart and the evil King John are in the brotherhood relation in the model.

71 Models for FOL Entailment in propositional logic can be computed by enumerating models. We can enumerate the FOL models for a given KB vocabulary. Computing entailment by enumerating FOL models is not easy!

72 Universal Quantification
 <variable> <sentence> Everyone at Berkeley is smart: x At(x, Berkeley)  Smart(x) x P is true iff P is true with x being each possible object in the model. At(KingJohn, Berkeley)  Smart(KingJohn)  At(Richard, Berkeley)  Smart(Richard) …

73 A Common Mistake to Avoid
Typically,  is the main connective with  Common mistake: using  as the main connective with : x At(x, Berkeley)  Smart(x) means “Everyone is at Berkeley and everyone is smart”

74 Existential Quantification
 <variable> <sentence> Someone at Stanford is smart: x At(x, Stanford)  Smart(x) x P is true iff P is true with x being some possible object in the model. (At(KingJohn, Stanford)  Smart(KingJohn))  (At(Richard, Stanford)  Smart(KingJohn)) …

75 A Common Mistake to Avoid
Typically,  is the main connective with  Common mistake: using  as the main connective with  : x At(x, Stanford)  Smart(x) is true if there is anyone who is not at Stanford.

76 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) vs. y x Loves(x,y) Quantifier duality x Likes(x, Ice)  x Likes(x, Ice) x Likes(x, Water)  x Likes(x, Water)

77 Sentences: Example Brothers are siblings
x,y Brother(x,y)  Sibling(x,y) “Sibling” is symmetric x,y Sibling(x,y)  Sibling(y,x) One’s mother is one’s female parent x,y Mother(x,y)  Female(x)  Parent(x,y)

78 Interacting with FOL KBs
Suppose a wumpus-world agent is using an FOL KB, and perceives a smell and a breeze (but no glitter) at t=5: Tell(KB, Percept([Smell, Breeze, None], 5)) ASK(KB, a Action(a, 5) i.e., does KB entail any particular actions at t=5? Answer: Yes, {a/Shoot} (substitution)

79 Interacting with FOL KBs
Given a sentence S and a substitution r, Sr denotes the result of plugging r into S; S = Smarter(x,y) r = {x/Hillary, y/Bill} Sr = Smarter(Hillary, Bill) ASK(KB, S) returns some/all r such that KB  Sr.

80 KB for Wumpus World “Perception”
b,g,t Percept([Smell, b, g], t)  Smelt(t) s,b,t Percept([s, b, Glitter], t)  AtGold(t) Reflex: t AtGold(t)  Action(Grab, t) Reflex with internal state: t AtGold(t)  Holding(Gold, t)  Action(Grab,t)

81 Deducing Hidden Properties
Definition of the Breezy predicate: y Breezy(y)  x Pit(x)  Adjacent(x,y) Diagnostic rule: infer cause from effect y Breezy(y)  x Pit(x)  Adjacent(x,y) Causal rule: infer effect from cause x,y Pit(x)  Adjacent(x,y)  Breezy(y)

82 Planning Initial condition in KB: At(Agent, [1,1], S0)
At(Gold, [1,2], S0) Query: ASK(KB, s Holding(Gold, s)) Answer: {s/Result(Grab, Result(Forward, S0))}

83 Inference Reducing first-order inference to propositional inference
Unification Generalized Modus Ponens Forward and backward chaining Resolution

84 Reduction to Propositional Inference
Suppose the KB contains just the following: x King(x)  Greedy(x)  Evil(x) King(John), Greey(John) Brother(Richard, John) Instantiating the sentence in all possible ways: King(John)  Greedy(John)  Evil(John) King(Richard)  Greedy(Richard)  Evil(Richard) King(John), Greedy(John) The new proposition symbols + resolution.

85 Problem with Propositionalization
It generates lots of irrelevant sentences. x King(x)  Greedy(x)  Evil(x) King(John) y Greedy(y) Brother(Richard, John) Evil(John) is obvious Greedy(Richard) is irrelevant

86 Unification 1. Find a substitution  such that King(x) and Greedy(x) match King(John) and Greedy(y).  = {x/John, y/John} 2. Given Knows(John, x) and Knows(y, OJ)  = {x/OJ, y/John}

87 GMP: Generalized Modus Ponens

88 Example KB 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.

89 KB Construction 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) and Missle(M1) … all of its missiles were sold to it by C. West: x 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 America …: American(West) The country Nono, an enemy of America …: Enemy(Nono, America)

90 Forward Chaining Incomplete (infinite loops).
Widely used for logic programming.

91 Forward Chaining

92 Forward Chaining

93 Forward Chaining

94 Backward Chaining Sound and complete vs. expensive (NP-hard)

95 Backward Chaining

96 Backward Chaining

97 Backward Chaining

98 Backward Chaining

99 Backward Chaining

100 Backward Chaining

101 Backward Chaining

102 Logic Programming Vs. ordinary programming
Encode information KB, ask queries, and find false facts Prolog systems Widely used in Europe, Japan Backward chaining with Horn clauses

103 Resolution  = {x/Ken} Apply resolution steps to CNF(KB  )

104 KB Construction 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) and Missle(M1) … all of its missiles were sold to it by C. West: x 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 America …: American(West) The country Nono, an enemy of America …: Enemy(Nono, America)

105


Download ppt "School of Computer Science & Engineering"

Similar presentations


Ads by Google