1 / 55

TP2623 : Knowledge Representation & Reasoning

TP2623 : Knowledge Representation & Reasoning. Topic 2 : Propositional Logic. By : Shereena Arif Room : T2/8, Blok H Email : shereen@ftsm.ukm.my / shereen.ma@gmail.com. Learning Outcomes. At the end of this topic, students will:

Télécharger la présentation

TP2623 : Knowledge Representation & Reasoning

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TP2623 : Knowledge Representation & Reasoning Topic 2 : Propositional Logic By : Shereena Arif Room : T2/8, Blok H Email : shereen@ftsm.ukm.my / shereen.ma@gmail.com

  2. Learning Outcomes At the end of this topic, students will: • Understand the concept of knowledge-bases and propositional logic • Able to construct knowledge base according to propositional logic representation. TP2623, shereen@ftsm.ukm.my

  3. Introduction • What is ‘Knowledge Representation & Reasoning’ ? • Also known as KRR. • Is a sub-area in AI- Artifical Intelligence. • Fundamental goal  to represent knowledge in a manner that facilitatesinferencing(i.e. drawing conclusions) from knowledge. • It analyzes how to formally think – • how to use a symbol system to represent a domain of discourse (that which can be talked about), along with functions that allow inference (formalized reasoning) about the objects TP2623, shereen@ftsm.ukm.my

  4. These concepts are central to the entire field of AI: • The representation of knowledge • The reasoning processes that bring knowledge to life • The importance of KR&R : • To artificial agents  successful behavior that would be very hard to achieve otherwise. • E.g : permainancatur. • In partially observable situation • E.g : doktordanpesakit • Understanding natural language • E.g : Hamzahtertarikdengansebentukcincindidalamkotakpamerandanberhasratmembelinya. • Flexibility to changes in the environment by updating the relevant knowledge. TP2623, shereen@ftsm.ukm.my

  5. Knowledge-Based Agents • The central component of a knowledge-based agent is its knowledge base, KB. • Informally, a KB is a set of sentences related, but not identical to natural languages. • Each sentence is expressed in a language called knowledge representation language. • How to : • Add new sentences into KB  TELL • Query about something already known  ASK TP2623, shereen@ftsm.ukm.my

  6. Both tasks may involved inference  deriving new sentences from old ones. • In logical agents, inference must obey the requirement : • When one ASKs a question of the KB, • The answer should follow from what has been told (or TELLed) to the KB previously. TP2623, shereen@ftsm.ukm.my

  7. function KB-AGENT (percept) returns an action static :KB, a knowledge base t, a counter, initially 0, indicating time TELL (KB, MAKE-PERCEPT-SENTENCE(percept, t)) action ASK(KB, MAKE-ACTION-QUERY(t)) TELL(KB, MAKE-ACTION-SENTENCE(action, t)) t t + 1 returnaction • Agent takes percept as input and returns an action. • Agent maintains a knowledge base, KB, which may initially contain some background knowledge. TP2623, shereen@ftsm.ukm.my

  8. Each time the agent program is called it does two things. • It TELLs the knowledge base what it perceives. • It ASKs the knowledge base what action it should perform. • In the process of answering, extensive reasoning may be done about the current state, about outcomes of possible actions, and so on. • Once the action is chosen, the agent records its choice with TELL and executes the action. TP2623, shereen@ftsm.ukm.my

  9. The wumpus world • The wumpus world is a cave consisting of rooms connected by passageways. • Lurking somewhere in the cave is the wumpus, a beast that eats anyone who enters its room • The wumpus can be shot by an agent, but the agent has only one arrow. • Some rooms contain bottomless pits that will trap anyone who wanders into these room (except the wumpus, who are too big). • Why ??.. The possibility of finding a heap of gold. • Wumpus world  an excellent testbed environment for intelligent agents. TP2623, shereen@ftsm.ukm.my

  10. Wumpus World PEAS description • Performance measure • gold +1000, death -1000 • -1 per step, -10 for using the arrow • Environment • Squares adjacent to wumpus are smelly • Squares adjacent to pit are breezy • Glitter if gold is in the same square • Shoot kills wumpus if you are facing it • Shooting uses up the only arrow • Grab picks up gold if in same square • Release drops the gold in same square • Sensors: The percept [Stench, Breeze, Glitter, Bump, Scream] • Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot TP2623, shereen@ftsm.ukm.my

  11. Exploring a wumpus world [None, None, None, None, None] [None, Breeze, None, None, None] TP2623, shereen@ftsm.ukm.my

  12. [Stench, None, None, None, None] [Stench, Breeze, Glitter, None, None] TP2623, shereen@ftsm.ukm.my

  13. From the fact that there was no stench or breeze in [1,1], the agent can infer that [1,2] and [2,1] are free of dangers. • From the fact that it is still alive, it can infer than [1,1] is also OK. • A cautious agent will only move into a square that it knows is OK. • Let us suppose the agent moves to [2,1], giving us (b) in page 11. • The agent detects a breeze in [2,1], so there must be a pit in a neighbouring square, either [2,2] or [3,1]. (The notation P? indicates a possible pit.) • The pit cannot be in [1,1] because the agent has already been there and did not fall in. • At this point, there is only one known square that is OK and has not yet been visited. • So the prudent agent turns back and goes to [1,1] and then [1,2], giving us (a) in page 12 below. TP2623, shereen@ftsm.ukm.my

  14. The stench in [1,2] means that there must be a wumpus nearby. • But the wumpus cannot be in [1,1] and it cannot be in [2,2] (or the agent would have detected a stench when it was in [2,1]. • Therefore, the agent can infer that the wumpus is in [1,3]. • The notation W! indicates this. • Moreover, the lack of a Breeze in [1,2] implies that there is no pit in the [2,2]. • Yet, we already inferred that there must be a pit in either [2,2] or [3,1], so this means it must be in [3,1]. • This is fairly a difficult inference because it combines knowledge gained at different times in different places. • When the agent moved to [2,3], it detects a glitter, which means that the gold must be there. TP2623, shereen@ftsm.ukm.my

  15. In each case where the agent draws a conclusion from the available information, that conclusion is guaranteed to be correct if the available information is correct  fundamental property of reasoning. • In the rest of discussion, we will learn how to build logical agents that can represent the necessary information and draw the conclusions that were described. TP2623, shereen@ftsm.ukm.my

  16. Logic in general • Logics are formal languages for representing information so 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 to each possible world • E.g x+y =4 is true if x=y=2, but false in x=y=1 • E.g., the language of arithmetic • x+2 ≥ y is a sentence; x2+ y > {} is not a sentence • x+2 ≥ y is true if 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 TP2623, shereen@ftsm.ukm.my

  17. Entailment • Entailment means that one thing follows from another: KB ╞ α • Knowledge base KB entails sentence α if and only if in all worlds where KB is true, α is also true • Another way to say this is if KB is true, then αmust also be true • E.g., the KB containing “the RumahKuning won” and “the RumahMerah won” entails “Either the RumahKuning won or the RumahMerah won” • E.g., x+y = 4 entails 4 = x+y • Entailment is a relationship between sentences (i.e., syntax) that is based on semantics TP2623, shereen@ftsm.ukm.my

  18. 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 3 Boolean choices  8 possible models 4 3 2 1 1 2 3 4 TP2623, shereen@ftsm.ukm.my

  19. Wumpus models TP2623, shereen@ftsm.ukm.my

  20. Wumpus models • KB = wumpus-world rules + observations TP2623, shereen@ftsm.ukm.my

  21. Wumpus models • KB = wumpus-world rules + observations • α1 = "[1,2] is safe", KB ╞ α1, proved by model checking • In every model in which KB is true,α1 is also true TP2623, shereen@ftsm.ukm.my

  22. Wumpus models • KB = wumpus-world rules + observations TP2623, shereen@ftsm.ukm.my

  23. Wumpus models • KB = wumpus-world rules + observations • In some models in which KB is true, α2 is false • α2 = "[2,2] is safe", KB ⊭α2 • The agent cannot conclude that [2,2] is safe. • The example shows how definition of entailment can be used to derive conclusions  logical inference TP2623, shereen@ftsm.ukm.my

  24. Inference • Entailment & inference : • KB is a haystack & α is the needle • Entailment  needle in the haystack • Inference  how to find the needle • If an inference i can deriveα from KB : KB ├i α • “α can be derived from KB by procedure i” • “i derives α from KB” • Soundness/Truth preserving: • An inference algo is sound if it derives only entailed sentences • i is sound if whenever KB ├i α, it is also true that KB╞ α • an unsound inference procedure makes things up as it goes along  announces the discovery nonexistent needles. • Model checking (if exist) is a sound procedure • Completeness • An inference algo is complete if it can derive any sentence that is entailed • i is complete if whenever KB╞ α, it is also true that KB ├i α TP2623, shereen@ftsm.ukm.my

  25. Recap : • Described a reasoning process whose conclusions are guaranteed to be true in any world in which the premises are true. • “if KB is true in the real world, then any sentence α is also true in the real world” • Sentences  physical configurations of the agent • Reasoning  a process of constructing new physical configurations from the old ones. • Logical reasoning  ensures that the new ones actually follow the old ones. • Preview: we will define a logic (first-order logic) which is expressive enough to say almost anything of interest, and for which there exists a sound and complete inference procedure. • That is, the procedure will answer any question whose answer follows from what is known by the KB. TP2623, shereen@ftsm.ukm.my

  26. Propositional Logic or Calculus • Propositional logic • A very simple logic • Also called as Boolean logic. • Syntax & Semantics  The way in which the truth of sentences is determined. • Syntax • Defines allowable sentences.Two types of sentences : • Atomic sentences • Complex sentences TP2623, shereen@ftsm.ukm.my

  27. Atomic sentences (indivisible) • consist of proposition symbol. • Each symbol stands for a proposition that can be true or false  P, Q, R etc. • Ex : W1,3  Wumpus is in [1,3] • Two proposition symbols with fixed meaning : True & False. • Complex sentences • Constructed from simpler sentences. • The sentences connected by logical connectives. • , , , ,  TP2623, shereen@ftsm.ukm.my

  28. Logical Connectives •  • Not (negation) • Ex :  W1,3  negation of W1,3 •  • And (conjunction) • A  B  A and B •  • Or (disjunction) • A  B  A or B TP2623, shereen@ftsm.ukm.my

  29. Logical Connectives •  • Implies also known as rules or if-then statements. • Conditional of A and B • Implication of B given A • Sometimes written as → or ⊃ • Ex : (W1,3  P3,1 )   W2,2 • Premise/Antecedent : (W1,3  P3,1 ) • Conclusion/Consequent :  W2,2 • Ex : A  B • If A, then B • A implies B • B when A • A only if B • A is antecedent, B is consequent TP2623, shereen@ftsm.ukm.my

  30. Logical Connectives •  • If and only if (biconditional or equivalence) A  B • is the same as (A  B)  (A  B) • if A, then B, and if B, then A • Recap Sentence  AtomicSentence | ComplexSentence AtomicSentence  True | False | Symbol Symbol  P | Q | R ComplexSentence   Sentence | (Sentence  Sentence) | (Sentence V Sentence) | (Sentence  Sentence) | (Sentence  Sentence) TP2623, shereen@ftsm.ukm.my

  31. Propositional Logic Syntax ORValid Sentences • Logical constants by themselves • T or F • Propositional symbol by itself • P or Q • Parents around a sentence • (P) • Sentences can be combined with logical connectives • (P Q) • Order of precedence (highest to lowest) •      • So P  Q  R  S is the same as ((P)  (Q  R))  S TP2623, shereen@ftsm.ukm.my

  32. 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) • If S1 and S2 are sentences, S1 S2 is a sentence (conjunction) • If S1 and S2 are sentences, S1 S2 is a sentence (disjunction) • If S1 and S2 are sentences, S1 S2 is a sentence (implication) • If S1 and S2 are sentences, S1 S2 is a sentence (biconditional) TP2623, shereen@ftsm.ukm.my

  33. Example Expressions • A • F • A • A A • A F • AB • (A B) (B) TP2623, shereen@ftsm.ukm.my

  34. Propositional logic: Semantics • Semantics  rules for determining the truth of a sentence with respect to a particular model • Each model specifies true/false for each proposition symbol • Ex : P1,2 P2,2 P3,1 false true false • m1 = {P1,2 = false, P2,2= true, P3,1 = false} TP2623, shereen@ftsm.ukm.my

  35. Propositional logic: Semantics • The semantics for propositional logic must specify how to compute the truth value of any sentence, given a model. • Sentences are constructed from atomic sentences and the 5 connectives : • Atomic sentences  true in every model or false? • Complex sentences  rules, summarized in a truth table. TP2623, shereen@ftsm.ukm.my

  36. Propositional logic: Semantics Rules for evaluating truth with respect to a model m: S is true iff S is false S1 S2 is true iff S1 is true and S2 is true S1 S2 is true iff S1is true or S2 is true S1 S2 is true iff S1 is false or S2 is true i.e., is false iff S1 is true andS2 is false S1 S2 is true iff S1S2 is true andS2S1 is true Simple recursive process evaluates an arbitrary sentence, e.g., P1,2  (P2,2 P3,1) = true (true  false) = true true = true TP2623, shereen@ftsm.ukm.my

  37. Truth Table P Q P P  Q P  Q P  Q P  Q F F T F F T T F T T F T T F T F F F T F F T T F T T T T TP2623, shereen@ftsm.ukm.my

  38. Solving Problems with Truth Tables(Enumeration Method) • Problem • If Ali starts playing with his Playstation, then he will stay up late. If he stays up late, he will miss his morning class. He was in class. • Did he start playing his playstation? • Propositions • P1: Ali plays playstation • P2: Ali stays up late • P3: Ali attends class • Premises • P1 -> P2 • P2 -> -P3 • P3 Answer TP2623, shereen@ftsm.ukm.my

  39. Truth Tables • Truth tables are effective, but impractical • n propositions requires a table with 2n rows • More efficient methods of proving conclusions from premises exist • E.g. Wang’s Algorithm TP2623, shereen@ftsm.ukm.my

  40. Some Exercises Using Truth Table • (T  F)  T • Answer: • (F  F)  T • Answer: • ((F  T)  F)  ((T  F)) • Answer: TP2623, shereen@ftsm.ukm.my

  41. Things we can say with Propositional Calculus • The sky is grey = S1 • It will rain = R1 • I have three arms = A1 • If S1 and R1 are T, then The sky is grey  It will rain is also T • If S1 is T and A1 is F then The sky is grey I have three arms is T TP2623, shereen@ftsm.ukm.my

  42. Combining expressions in Propositional Calculus • (A1 B1) C1 • (A2 ( C1 B4)  C3 • (A4 B2) C2 Is equivalent to • ((A1 B1) C1) ((A2 ( C1 B4) C3) ((A4 B2) C2) TP2623, shereen@ftsm.ukm.my

  43. Logical equivalence • Two sentences are logically equivalent} iff true in same models: α ≡ ß iff α╞ β and β╞ α TP2623, shereen@ftsm.ukm.my

  44. Logical equivalence • Two sentences are logically equivalent} iff true in same models: α ≡ ß iff α╞ β and β╞ α TP2623, shereen@ftsm.ukm.my

  45. Validity and satisfiability A sentence is valid if it is true in all models, also known as tautology e.g., True, A A, A  A, (A  (A  B))  B Validity is connected to inference via the Deduction Theorem: KB ╞ α if and only if (KB α) is valid A sentence is satisfiable if it is true in some model e.g., A  B, C e.g, if sentence α is true in a model m m satisfies α, or m is a model of α A sentence is unsatisfiable if it is true in no models e.g., AA α is valid iff α is unsatisfiable Satisfiability is connected to inference via the following: KB ╞ α if and only if (KBα) is unsatisfiable TP2623, shereen@ftsm.ukm.my

  46. Entailment: Propositional Inference(Enumeration Method) Let  = AB and KB = (AB)(B C) Is it the case that KB ╞ ? Check all possible models -  must be true wherever KB is true A B C AB B C KB  F F F F F T F T F F T T T F F T F T T T F T T T Answer TP2623, shereen@ftsm.ukm.my

  47. The Method of Deduction

  48. Intro • Previously we used the truth table to test arguments for validity • Here we develop an alternative approach  the method of deduction • We can use rules of inference and rules of replacement • Covers standard patterns of inference that can be applied to derive chains of conclusions that lead to the desired goal  inference rules TP2623, shereen@ftsm.ukm.my

  49. Inference & Replacement with Propositional Calculus • Modus Ponens (Implication elimination) Assume P  Q, Given P ----------------- Then Q • For example: • If the statement “If it is raining, then you get wet” is true, and the statement “It is raining” is true, Then you can infer that “you get wet.” TP2623, shereen@ftsm.ukm.my

  50. Inference & Replacement with Propositional Calculus • Disjunctive Syllogism (or introduction) Assume P -------------- Then P Q • For example: • If the statement “It is raining” is true, Then you can infer that the compound statement “It is raining” OR <anything> will be true TP2623, shereen@ftsm.ukm.my

More Related