1 / 20

(FO) Inference Methods

(FO) Inference Methods. CPSC 386 Artificial Intelligence Ellen Walker Hiram College. Inference Methods. Unification (prerequisite) Forward Chaining Production Systems RETE Method (OPS) Backward Chaining Logic Programming (Prolog) Resolution Transform to CNF

Download Presentation

(FO) Inference Methods

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. (FO) Inference Methods CPSC 386 Artificial Intelligence Ellen Walker Hiram College

  2. Inference Methods • Unification (prerequisite) • Forward Chaining • Production Systems • RETE Method (OPS) • Backward Chaining • Logic Programming (Prolog) • Resolution • Transform to CNF • Generalization of Prop. Logic resolution

  3. Forward Chaining • Given a new fact, generate all consequences • Assumes all rules are of the form • C1 and c2 and c3 and…. --> result • Each rule & binding generates a new fact • This new fact will “trigger” other rules • Keep going until the desired fact is generated • (Semi-decidable as is FOL in general)

  4. Efficient Forward Chaining • Order conjuncts appropriately • E.g. most constrained variable • Don’t generate redundant facts; each new fact should depend on at least one newly generated fact. • Production systems • RETE matching • CLIPS (on CS)

  5. OPS • Facts • Type, attributes & values • (goal put-on yellow-block red-block) • Rules • If conditions, then action. • Variables (<x>, <y>, etc) can be bound • If (goal put-on <x> <y>) AND • (clear <x>) THEN add (goal clear <y>)

  6. RETE Network • Based only on Left Sides (conditions) of rules • Each condition (test) appears once in the network • Tests with “AND” are connected with “JOIN” • Join means all tests work with same bindings

  7. Example Rules • If (goal put-on <x> <y>) AND (clear <x>) AND (clear <y>) THEN add (on <x> <y>) delete (clear <y>) 2. If (goal clear <x>) AND (on <y> <x>) AND (clear <y>) THEN add (clear <x>) add (on <y> table) delete (on <y> <x>) 3. If (goal clear <x>) AND (on <y> <x>) THEN add (goal clear <y>) 4. If (goal put-on <x> <y>) AND (clear <x>) THEN add (goal clear <y>) 5. If (goal put-on <x> <y>) AND (clear <y>) THEN add (goal clear <x>)

  8. RETE Network

  9. Using the RETE Network • Each time a fact comes in… • Update bindings for the relevant node (s) • Update join(s) below those bindings • Note new rules satisfied • Each processing cycle • Choose a satisfied rule

  10. Example (Facts) • (goal put-on yellow-block red-block) • (on blue-block yellow-block) • (on yellow-block table) • (on red-block table) • (clear red-block) • (clear blue-block)

  11. Why RETE is Efficient • Rules are “pre-compiled” • Facts are dealt with as they come in • Only rules connected to a matching node are considered • Once a test fails, no nodes below are considered • Similar rules share structure • In a typical system, when rules “fire”, new facts are created / deleted incrementally • This incrementally adds / deletes rules (with bindings) to the conflict set

  12. CLIPS • CLIPS is a forward-chaining production system that uses the RETE method. • Important commands • (assert fact) (deffacts fact1 fact2 … ) • (defrule rule-name rule) • (reset) - eliminates all facts except “initial-fact” • (load file) (load-facts file) • (run) • (watch all) • (exit)

  13. CLIPS Rule Example (defrule putting-on ?g <- (goal put-on ?x ?y) (clear ?x) ?bottomclear <- (clear ?y) ==> (assert (on ?x ?y)) (retract ?g) (retract ?bottomclear) )

  14. Blocks example • (load “blocks.clp”) • (assert (on blue table)) • (assert (clear blue)) • (assert (on red table)) • (assert (on green red)) • (assert (clear green) • (assert (goal put-on red blue)) • (watch all) • (run)

  15. Backward Chaining • Consider the item to be proven a goal • Find a rule whose head is the goal (and bindings) • Apply bindings to the body, and prove these (subgoals) in turn • If you prove all the subgoals, increasing the binding set as you go, you will prove the item. • Logic Programming (gprolog, on CS)

  16. Prolog Rules • Rule Example • puton(X,Y) :- cleartop(X), cleartop(Y),takeoff(X,Y). • Capital letters are variables • Three parts to the rule • Head (thing to prove) • Neck :- • Body (subgoals, separated by ,) • Rules end with .

  17. Prolog Environment • SWI-Prolog on windows – to start, double-click plwin • To read a file, consult(‘file’). • To enter data directly, consult(user). Type control-D when done. • Every statement must end in a period. If you forget, put it on the next line. • To prove a fact, enter the fact directly at the command line. gprolog will respond Yes, No, or give you a binding set. If you want another answer, type ; otherwise return. • Trace(predicate) or trace(all) will allow you to watch the backward chaining process.

  18. Monkey and Banana in Prolog movedTo(X,Y) :- at(X,Y,Z). movedTo(monkey,Y) :- at(monkey,X,floor), write('Walk to '), write(Y), nl. movedTo(ladder,Y) :- at(ladder,X,floor), movedTo(monkey,X), write('Drag ladder to '), write(Y), nl. reachable(X) :- at(X,Y,ceiling), movedTo(ladder,Y), movedTo(monkey,Y). reach(X) :- reachable(X), write('Reach for '), write(X), nl.

  19. Running the Monkey & Banana consult(user). compiling user for byte code... at(monkey,corner,floor). at(monkey,corner,floor). at(ladder,left,floor). at(ladder,left,floor). at(banana,center,ceiling). at(banana,center,ceiling). Control-D reach(banana).

  20. In-class assignment • Try the following in both Prolog and Clips: • Define the concept of a prerequisite, and at least the following facts: • Prerequisite of 172 is 171 Prerequisite of 201 is 172 • Prerequisite of 400 is 201 Prerequisite of 386 is 172 • Create a rule that a course cannot be taken unless its prerequisite has been taken • Create facts to indicate that Mary has taken 172 and 171. • Prove the following in your system: • Mary can take 386, Mary cannot take 400

More Related