1 / 48

From Propositional Logic to PROLOG

From Propositional Logic to PROLOG. CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004. Tonight. Discussion of assignment 1 Games of chance Basic elements of logic Resolution Ground [Application: diagnosis] With variables With function symbols Prolog.

Download Presentation

From Propositional Logic to PROLOG

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. From Propositional Logic to PROLOG CSE P573 Applications of Artificial Intelligence Henry Kautz Fall 2004

  2. Tonight • Discussion of assignment 1 • Games of chance • Basic elements of logic • Resolution • Ground [Application: diagnosis] • With variables • With function symbols • Prolog

  3. Nondeterministic Games • Involve chance: dice, shuffling, etc. • Chance nodes: calculate the expected value • E.g.: weighted average over all possible dice rolls

  4. In Practice... • Chance adds dramatically to size of search space • Backgammon: number of distinct possible rolls of dice is 21 • Branching factor b is usually around 20, but can be as high as 4000 (dice rolls that are doubles) • Alpha-beta pruning is generally less effective • Best Backgammon programs use other methods

  5. Imperfect Information • E.g. card games, where opponents’ initial cards are unknown • Idea: For all deals consistent with what you can see • compute the minimax value of available actions for each of possible deals • compute the expected value over all deals

  6. Probabilistic STRIPS Planning • domain: Hungry Monkey • shake: if (ontable) • Prob(2/3) -> +1 banana • Prob(1/3) -> no change • else • Prob(1/6) -> +1 banana • Prob(5/6) -> no change • jump: if (~ontable) • Prob(2/3) -> ontable • Prob(1/3) -> ~ontable • else • ontable

  7. What is the expected reward? • [1] shake • [2] jump; shake • [3] jump; shake; shake; • [4] jump; if (~ontable){ jump; shake} • else { shake; shake }

  8. ExpectiMax

  9. shake jump 1/6 5/6 1/3 2/3 shake shake jump shake jump shake jump jump 2/3 5/6 1/3 5/6 1/6 1/3 5/6 1/6 1/6 2/3 1/3 2/3 1/3 1/3 2/3 2/3 0 0 0 0 1 0 0 1 1 1 0 1 2 0 0 1 Hungry Monkey: 2-Ply Game Tree

  10. ExpectiMax 1 – Chance Nodes shake jump 1/6 5/6 1/3 2/3 shake shake jump shake jump shake jump jump 2/3 7/6 1 0 0 0 1/6 1/6 2/3 5/6 1/3 5/6 1/6 1/3 5/6 1/6 1/6 2/3 1/3 2/3 1/3 1/3 2/3 2/3 0 0 0 0 1 0 0 1 1 1 0 1 2 0 0 1

  11. ExpectiMax 2 – Max Nodes shake jump 1/6 5/6 1/3 2/3 1/6 2/3 7/6 1/6 shake shake jump shake jump shake jump jump 2/3 7/6 1 0 0 0 1/6 1/6 2/3 5/6 1/3 5/6 1/6 1/3 5/6 1/6 1/6 2/3 1/3 2/3 1/3 1/3 2/3 2/3 0 0 0 0 1 0 0 1 1 1 0 1 2 0 0 1

  12. ExpectiMax 3 – Chance Nodes shake jump 1/2 1/3 1/6 5/6 1/3 2/3 1/6 2/3 7/6 1/6 shake shake jump shake jump shake jump jump 2/3 7/6 1 0 0 0 1/6 1/6 2/3 5/6 1/3 5/6 1/6 1/3 5/6 1/6 1/6 2/3 1/3 2/3 1/3 1/3 2/3 2/3 0 0 0 0 1 0 0 1 1 1 0 1 2 0 0 1

  13. ExpectiMax 4 – Max Node 1/2 shake jump 1/2 1/3 1/6 5/6 1/3 2/3 1/6 2/3 7/6 1/6 shake shake jump shake jump shake jump jump 2/3 7/6 1 0 0 0 1/6 1/6 2/3 5/6 1/3 5/6 1/6 1/3 5/6 1/6 1/6 2/3 1/3 2/3 1/3 1/3 2/3 2/3 0 0 0 0 1 0 0 1 1 1 0 1 2 0 0 1

  14. Policies • The result of the ExpectiMax analysis is a conditional plan(also called apolicy): • Optimal plan for 2 steps: jump; shake • Optimal plan for 3 steps:jump; if (ontable) {shake; shake} else {jump; shake} • Probabilistic planning can be generalized in many ways, including action costs and hidden state • The general problem is that of solving a Markov Decision Process (MDP)

  15. Summary • Deterministic games • Minimax search • Alpha-Beta pruning • Static evaluation functions • Games of chance • Expected value • Probabilistic planning • Strategic games with large branching factors (Go) • Relatively little progress

  16. Desiderata for Knowledge Representation • Declarative • Separate knowledge from specific use • Expressive • General rules as well as facts • Incomplete information • Concise • Can draw many new conclusions • Effectively computable • Unambiguous How does STRIPS measure up?

  17. Basic Idea of Logic • By starting with true assumptions, you can deduce true conclusions. • Francis Bacon (1561-1626) • No pleasure is comparable to the standing upon the vantage-ground of truth. • Thomas Henry Huxley (1825-1895) • Irrationally held truths may be more harmful than reasoned errors. • John Keats (1795-1821) • Beauty is truth, truth beauty; that is all • Ye know on earth, and all ye need to know. • Blaise Pascal (1623-1662) • We know the truth, not only by the reason, but also by the heart. • François Rabelais (c. 1490-1553) • Speak the truth and shame the Devil. • Daniel Webster (1782-1852) • There is nothing so powerful as truth, and often nothing so strange.

  18. The Big Three   

  19. Entailment • m – something that determines whether a sentence S is true or false – a “possible world” • m S • S is true in m • m is a model of S • S  T • S entails T • Every model of S is a model of T • When S is true, then T must be true

  20. Implication xy xy

  21. Consequence • A logic includes a set of mechanical rules for determining which sentences can be derived from other sentences • S T • T is a consequence of S • Sound: ifS  TthenS  T • Complete: ifS  TthenS T

  22. Resolution Bush or Kerry will get a popular majority. Bush won’t get a popular majority. • P v Q, ~P • Q Bush or Kerry will get a popular major. If Bush gets a popular majority, the country will unite. • P v Q, ~P v R • Q v R If neither Bush or Kerry get a popular majority, the Supreme Court will pick the president.If Kerry gets a popular majority, the Supreme Court will pick the president. • P v Q v S , ~Q v S • P v S

  23. Conjunctive Normal Form • Any sentence is equivalent to one where: • Top level is a conjunction of clauses • Each clause is a disjunction of literals • Each literal is a proposition or its negation In the worst-case, how muchlarger is the CNF form of asentence? What canwe do about it?

  24. New Variable Trick • Putting a formula in clausal form may increase its size exponentially • But can avoid this by introducing dummy variables • (abc)(def)  {(ad),(ae),(af), • (bd),(be),(bf), • (cd),(ce),(cf) } • (abc)(def)  {(gh), • (abcg),(ga),(gb),(gc), • (defh),(hd),(he),(hf)} Dummy variables don’t change satisfiability!

  25. Proof by Refutation • S  T • iff (S  T) false • Model theory: • S  T • iff S  T has no models (is unsatisfiable)

  26. Resolution Proof • DAG, where leaves are input clauses • Internal nodes are resolvants • Root is false (empty clause) • If the unicorn is mythical, then it is immortal, but if it is not mythical, it is a mortal mammal. If the unicorn is either immortal or a mammal, then it is horned. • Prove:the unicorn is horned. (A  H) (I  H) (H) (M  A) (A) (I) (M  I) (M) (M) ()

  27. Expert System for Automobile Diagnosis • Knowledge Base: GasInTank  FuelLineOK  GasInEngine GasInEngine  GoodSpark  EngineRuns PowerToPlugs  PlugsClean  GoodSpark BatteryCharged  CablesOK  PowerToPlugs • Observed:  EngineRuns,GasInTank, PlugsClean, BatteryCharged • Prove:  FuelLineOK   CablesOK

  28. Solution by Resolution • Knowledge Base and Observations: ( GasInTank   FuelLineOK  GasInEngine) ( GasInEngine   GoodSpark  EngineRuns) ( PowerToPlugs   PlugsClean  GoodSpark) ( BatteryCharged   CablesOK  PowerToPlugs) (EngineRuns) (GasInTank) (PlugsClean) (BatteryCharged) • Negation of Conclusion: (FuelLineOK) (CablesOK) Unit propagation = Resolution where one clause must be a single literal

  29. How Do You Know What to Prove? • In this example were given the diagnosis we wanted to prove: • FuelLineOK   CablesOK But, in general, how do you know what to prove? A powerful and widely-used technique for finding an hypothesis that explains an observed system fault( EngineRuns) is Consistency Based Diagnosis.

  30. Consistency-Based Diagnosis • Make some Observations O. • Initialize the Assumption Set A to assert that all components are working properly. • Check if the KB, A, O together are inconsistent (can deduce false). • If so, delete propositions from A until consistency is restored (cannot deduce false). The deleted propositions are a diagnosis. There may be many possible diagnoses

  31. Example • Is KB ObservationsAssumptionsconsistent? • KB { EngineRuns, GasInTank, PlugsClean, BatteryCharged} { FuelLineOK, CablesOK } false • Must restore consistency! • KB { EngineRuns,GasInTank, PlugsClean, BatteryCharged} {CablesOK }false • So  FuelLineOK is a possible diagnosis! • KB { EngineRuns,GasInTank, PlugsClean, BatteryCharged} {FuelLineOK}false • So  CablesOK is a possible diagnosis!

  32. Complexity of Diagnosis • If KB is Horn, then each consistency test takes linear time. • Complexity = ways to delete propositions from Assumption Set that are considered. • Single fault diagnosis – O(n2) • Double fault diagnosis – O(n3) • Triple fault diagnosis – O(n4) …

  33. Deep Space One • Autonomous diagnosis & repair “Remote Agent” • Compiled systems schematic to 7,000 var SAT problem Started: January 1996 Launch: October 15th, 1998 Experiment: May 17-21

  34. Tonight • Discussion of assignment 1 • Games of chance • Basic elements of logic • Resolution • Ground [Application: diagnosis] • With variables • With function symbols • Prolog

  35. First-Order Logic • All men are mortal. •  x . (man(x) mortal(x)) • No man is not mortal. •   x . (man(x)  mortal(x) ) • Everybody has somebody they lean on.  x . (person(x)   y . (person(y) leans_on(x,y)) A number is less than it’s successor.  n . (number(x) less_than(x, successor(x)) ) Nothing is less than zero.   x . less_than(x, ZERO) Quantifiers Variables Constants Function Symbols

  36. First-Order Clausal Form • Begin with universal quantifiers (implicit) • Rest is a clause • No , but may use function symbols instead • Variables in each clause are unique • man(x) mortal(x) • person(x)  person(friend(x)) • person(y) leans_on(friend(y)) • number(x) less_than(x, successor(x))

  37. Unification • Can resolve clauses if can unify one pair of literals • Same predicate, one positive, one negative • Match variable(s) to other variables, constants, or complex terms (function symbols) • Carry bindings on variables through to all the other literals in the result! (Mortal(y)Fallible(y)) (Mortal(HENRY)) (Fallible(HENRY))

  38. Unification with Multiple Variables • You always hurt the ones you love. • Politicians love themselves. • Therefore, politicians hurt themselves.  love(x,y)hurt(x,y) politician(z)love(z,z) politician(w)hurt(w,w)

  39. Unification with Function Symbols A number is less than its successor “Less than” is transitive (Less(a,suc(a))) (Less(b,c) Less(c,d) Less(b,d)) {c/a, d/suc(a)} (Less(b,a) Less(b,suc(a))) rename variables: (Less(e,f) Less(e,suc(f))) {e/a,f/suc(a)} A number is less than the successor of its successor Less(a,suc(suc(a)))

  40. Tonight • Discussion of assignment 1 • Games of chance • Basic elements of logic • Resolution • Ground [Application: diagnosis] • With variables • With function symbols • Prolog

  41. Making FOL Practical • Barriers to using FOL: • Choice of clauses to resolve • Huge amount of memory to store DAG • Getting useful answers to queries (not just “yes” or “no”) • PROLOG’s answers: • Simple backward-chaining resolution strategy – left/right, first to last clause • Tree-shaped proofs – no need to store entire proof in memory at one time • Extract answers to queries by returning variable bindings

  42. Prolog Interpreter • binding_list disprove(literal neglit){ • choose (clause c) such that (binding = unify(head(c),neglit)) • if (no choice possible){ • backtrackto last choice;} • for (each lit in body(c)){ • binding = binding U disprove(substitute(lit,binding)); • } • return binding; • }

  43. Example • Rich people are happy. • People who love happy people are happy. • Your spouse loves you. • Your mother loves you. • Bill is rich. • Melinda is Bill’s spouse. • Elaine is Melinda’s mother. • Mary is Bill’s mother. • Paul is rich. • Barbara is Henry’s mother. run prolog, consult(happy)

  44. happy.pl • happy(X) :- rich(X). • happy(X) :- loves(X,Y),happy(Y). • loves(X,Y) :- spouse(X,Y). • loves(X,Y) :- mother(X,Y). • rich(bill). • spouse(melinda,bill). • mother(elaine,melinda). • mother(mary,bill). • rich(paul). • mother(barbara,henry).

  45. Prolog Limitations • Only handles definite clauses (exactly one positive literal per clause) • No true disjuction: cannot express e.g. happy(bill) v happy(henry) • Tree-shaped proofs means some sub-steps may be repeatedly derived • DATALOG: does forward-chaining inference and caches derived unit clauses • Interpreter can get into an infinite loop if care is not taken in form & order of clauses

  46. toohappy.pl • happy(X) :- rich(X). • happy(X) :- loves(X,Y),happy(Y). • loves(X,Y) :- spouse(X,Y). • loves(X,Y) :- mother(X,Y). • rich(bill). • spouse(melinda,bill). • mother(elaine,melinda). • mother(mary,bill). • rich(paul). • mother(barbara,henry). • loves(bill,melinda). • loves(henry,barbara).

  47. Exercise • You have just been hired by snacks.com, an Internet startup that provides snacking recommendations. Your first assignment is to create an expert system that will recommend snacks according to the following rules: • Every snack should contain one beverage and one munchie. • Sweet beverages are good with salty munchies. • Bitter beverages are good with sweet munchies or salty munchies. • Define a predicate snack(X,Y) that makes such recommendations. • Get started with: prolog/snack.pl

  48. Next Week • Data structures in Prolog • Natural language processing

More Related