1 / 31

CS 4100 Artificial Intelligence

CS 4100 Artificial Intelligence. Prof. C. Hafner Class Notes Jan 24, 2012. Topics for today. Finish discussion of propositional logic Forms of clauses Refutation resolution Forward chaining in PL (review) Backward chaining in PL Discussion of Homework 2

urbano
Télécharger la présentation

CS 4100 Artificial Intelligence

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. CS 4100 Artificial Intelligence Prof. C. Hafner Class Notes Jan 24, 2012

  2. Topics for today • Finish discussion of propositional logic • Forms of clauses • Refutation resolution • Forward chaining in PL (review) • Backward chaining in PL • Discussion of Homework 2 • Review wumpus world model using PL • First order logic • Wumpus world model using FOL

  3. Disjunctive and Implicative form of clauses • ~P1 v ~P2 v . . . v ~Pn v Q V R – disjunctive form • Same as: P1 ^ P2 ^ . . . ^ Pn  Q V R -- implicative form • What about: ~P1 v ~P2 v . . . v ~Pn Implicative form is: P1 ^ P2 ^ . . . ^ Pn  {} {} == False • What about Q (single positive literal). Implicative form is: True  Q (or just Q) Any logical sentence can be converted to (one or more) clauses!!

  4. Horn clauses and Definite clauses All Clauses Horn clauses: 0 or 1 positive literals Definite clauses: 1 positive literal

  5. Review: The Resolution Rule for Propositional Logic [P1 v P2 v . . . Pk ]  [ P1 v Q2 v . . . Qn ] --------------------------------------------------- P2 v . . . Pk v Q2 v . . . Qn A generalization of modus ponens: P1  [ P1 v Q] Note: [ P1 v Q] equivalent to ------------------------ P1  Q Q

  6. Refutation Resolution • Assert the negation of what you want to prove and resolve with current database to obtain {}. Very useful when we move to FOL • A simple example: E  A ~E  B Prove: A v B using refutation resolution

  7. Any KB (i.e., any sentence) can be transformed into an equivalent CNF representation • Replace P => Q with  P v Q • Replace   P with P • Replace  (P v Q) with  P ^  Q • Replace (P ^ Q) with  P v  Q • Apply distributive rule replacing: (P ^ Q) v R with (P v R) ^ (Q v R)

  8. Class ExerciseConvert the following to CNF (a list of clauses)Convert the CNF clauses to implicative form • A v B v C • A ^ B ^ C • ~A v ~B • ~A ^ ~B • ~A v ~B v C v D v E • (A ^ B) v C • ~(A ^ ~B) v C

  9. Class Exercise (from text) • Given the following, can you prove that the unicorn is mythical? Magical? Horned? If the unicorn is mythical, then it is immortal, but if it is not mythical, then it is a mortal mammal. If the unicorn is either immortal or a mammal, then it is horned. The unicorn is magical if it is horned.

  10. Convert to Clause form If the unicorn is mythical, then it is immortal, C1 mythical  ~mortal C1a ~mythical v ~mortal If not mythical, then it is a mortal mammal C2. ~mythical  mortal ^ mammal C2a mythical v mortal C2b mythical v mammal If the unicorn is either immortal or a mammal, then it is horned. C3 (~mortal v mammal)  horned == (mortal ^ ~mammal) v horned C3a mortal v horned C3b ~mammal v horned The unicorn is magical if it is horned. C4 horned  magical C4a ~horned v magical Prove “magical” by refutation

  11. A common error • Derive: ~mortal v mortal v horned • Does this imply horned ?? NO • Why? Because it is true whether horned is T or F

  12. Review: Forward chaining: takes a KB of Horn clauses • Basis of forward chaining P  Q is an assertion in the KB P is a new percept ---------- Conclude Q • Two views of KB • All implications are made explicit vs. • Reasoning on demand • “Pure” forward chaining suggests the former

  13. Forward chaining algorithm (KB of Definite Clauses) ALGORITHM (recursive): PLForwardChain() uses KBase -- a knowledge base of Horn clauses for each new percept p PLForwardChain1(p) #use a recursive "helper function" PLForwardChain1(percept) if percept is already in KBase, return else add percept to KBase for r in rules where conclusion of r is not already in KBase if percept is a premise of r and all the other premises of r are known PLForwardChain1(conclusion of r) Notes: 1. An efficient implementation requires an index of the rules by LHS symbols 2. How are infinite loops prevented by this algorithm ?

  14. Review forward chaining algorithm ALGORITHM (recursive): PLForwardChain() uses KBase -- a knowledge base of Horn clauses for each new percept p PLForwardChain1(p) #use a recursive "helper function" PLForwardChain1(percept) if percept is already in KBase, return else add percept to KBase for r in rules where conclusion of r is not already in KBase if percept is a premise of r and all the other premises of r are known PLForwardChain1(conclusion of r) How are infinite loops prevented by this algorithm ?

  15. HW2: Input format for this knowledge base vegetable  edible vegetable ^ green  healthy edible ^ healthy  recommended apple  fruit • edible edible IF vegetablehealthy IF vegetable greenrecommended IF edible healthyfruit IF appleedible Python: tokenlist = line.split() #string  list of strings

  16. Backward chaining: goal driven reasoning triggered by a new percept (fact) • Basis of backward chaining P ^ R  Q is an assertion in the KB Q is a query we want to prove (or disprove) ---------- Set up P and R as sub-queries, if they are true then Q is proved • What if we cannot find Q or a rule that succeeds in proving Q. Then we answer False. This is called negation by failure. (It is not the same as a real logical proof of ~Q). • Note: P  ~Q is not a Horn Clause. It normalizes to P V Q, which has two positive literals

  17. Backward chaining: goal-driven reasoning – triggered by a question being asked KB:fruit  edible vegetable  edible edible ^ green  healthy apple  fruit banana  fruit spinach  vegetable spinach  green edible ^ healthy  recommended • apple Consider some queries: ? apple ? fruit ? banana ? edible ? healthy

  18. Sketch of Backward Chaining algorithm backwardChain(KB, query) returns Boolean if query is in KB, return True for each rule r in KB such that RHS(r) == query testing = True for each element e of the LHS(r) if backwardChain(KB, e) = False testing = False break if testing = True return True return False NOTE that backward chaining does not update the KB

  19. The Wumpus World in PL What we need to represent: I. Static knowledge The relevant ontology of possible world configurations: locations on a 4 by 4 grid and their properties ex: Pxy means a pit at location x,y Player’s current state (Lxy, has-arrow) The axioms of the world’s configurations L21 ^ Breeze  P22 v P31 Player’s current percepts: Breeze, Stench, etc.

  20. The Wumpus World in PL Additional static world axioms: There is exactly one wumpus: W21 v W31 v . . . W44 == there is at least one There is at most one: ~(W21 ^ W22) -- one axiom like this for each pair

  21. The Wumpus World in PL (cont) What we need to represent: II. Dynamic knowledge The agent’s possible actions: up, down, left right, grab, shoot The result of the agent’s actions: requires temporal indexing: L110 ^ up0  L211 -- one for each location X action X timestep L110 ^ has-arrow0 ^ shoot0  L111 ^ ~has-arrow1 The frame problem requires more: L110 ^ up0  L211 ^ ~L111 But it is even worse: L110 ^ has-arrow0 ^ up0  L211 ^ ~L111 ^ has-arrow1 L110 ^ ~has-arrow0 ^ up0  L211 ^ ~L111 ^ ~has-arrow1 The frame problem arises when we use temporal indexing!!! It causes axioms to multiply almost without limit.

  22. First Order Logic (FOL) • Why FOL? • Syntax and semantics of FOL • Using FOL • Wumpus world in FOL • Knowledge engineering in FOL

  23. Pros and cons of propositional logic  Propositional logic is declarative  Propositional logic allows partial/disjunctive/negated information • (unlike most data structures and databases) • (Horn clauses an intermediate form) • Propositional logic is compositional: • meaning of B1,1 P1,2 is derived from meaning of B1,1 and of P1,2  Meaning in propositional logic is context-independent • (unlike natural language, where meaning depends on context)  Propositional logic has very limited expressive power • (unlike natural language) • E.g., cannot say "pits cause breezes in adjacent squares“ • except by writing one sentence for each square

  24. First-order logic • Whereas propositional logic limits world models to atomicfacts such as P12  B22 • first-order logic (like natural language) can manipulate world models that include: • Objects: people, houses, numbers, colors, baseball games, wars, … • Relations: red, round, prime, brother of, bigger than, part of, comes between, … • Functions: father, nationality, one more than, plus, … and structured facts such as: Adjacent([x,y], [z,w]) ^ Pit([x,y])  Breeze([z,w])

  25. Syntax of FOL: Basic elements • Constant symbols KingJohn, 2, NU,... • Predicate symbols IsHappy, Likes, >,... • Function symbols Sqrt, Nationality,... • Variablesx, y, a, b,... • Connectives , , , ,  • Equality = • Quantifiers ,  • The constant, predicate and function symbols are called a “logical language”. Given a LL we can then define all the logical sentences that can be expressed.

  26. Atomic sentences Atomic sentence = predicate (term1,...,termn) | term1 = term2 Term = constant | variable | function (term1,...,termn) • E.g., Brother(KingJohn,RichardTheLionheart) • Greater (AgeOf(Richard), AgeOf(John)) • Brother (AgeOf(Richard), AgeOf(John))

  27. Complex sentences • Complex sentences are made from atomic sentences using connectives (with the same semantics as propositional logic) S, S1 S2, S1  S2, S1 S2, S1S2, E.g. Sibling(John,Richard) < Sibling(Richard,John) >(1,2)  ≤ (1,2) >(1,2)  >(1,2)

  28. Complex sentences (cont.) • Additional complex sentences may include quantifiers:  and  var [S]  var [S] Abbreviate:  x  y  z [S] as  x, y, z [S] Abbreviate:  x  y  z [S] as  x, y, z [S]

  29. Meaning and truth in first-order logic • Sentences of FOL are true with respect to a model and an interpretation • A model for a FOL language is a “world” of objects (domainelements) and relations among them (compare with propositional logic model) • InterpretationIspecifies referents for constantsymbols→objects predicatesymbols→relations functionsymbols→ functions • An atomic sentence P(term1,...,termn) is true iff the objects referred to by term1,...,termn are in the relationI(P)

  30. Meaning and truth in first-order logic (cont.) • Complex sentences: truth is defined using the same truth tables: S1 S2 is true iff S1 is true and S2 is true. • x [S] is true iff, for any object C in the model S[x/C] is true •  x [S] is true iff, for at least one object C in the model S[x/C] is true

  31. Models for FOL: Example symbols: constant relation function

More Related