Presentation is loading. Please wait.

Presentation is loading. Please wait.

Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002.

Similar presentations


Presentation on theme: "Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002."— Presentation transcript:

1 Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002

2 Agenda Rule-based systems –Backward-chaining II: Variables, unification, and search –RETE method: Relational model: Databases Efficient rule-based reasoning Conclusions

3 Rule-based Systems Represent knowledge as: –Assertions: (mother-of ?x ?y), (female ?x) –Rules: If (parent-of ?x ?y) Antecedent –(female ?x) then (mother-of ?x) Consequent Manipulate knowledge with: –Rule interpreter: Forward-Chain: Rules & assertions => New assertions Backward-Chain: Hypothesis (consequent)=>Antecedents

4 Rule Manipulation w/Variables Forward-chaining: –Match antecedents with variables to assertions WITHOUT variables –Match (bind) variables to constants Backward-chaining: –Match hypothesis to consequent May contain variables: e.g. (grandparent A ?x) –Match variables to constants AND variables! –Requires general unification

5 Backward Chaining with Variables R1: if (parent ?x ?y) (parent ?y ?z) then (grandparent ?x ?z) R2: if (father ?v1 ?w1) then (parent ?v1 ?w1) R3: if (mother ?v2 ?w2) then (parent ?v2 ?w2) Assertions: (father A B) (mother B C) Hypothesis: (grandparent A ?m) (grandparent ?x ?z)?x:A ?z:?m (parent ?x ?y)(parent ?y ?z) (parent ?v1 ?w1)(parent ?v2 ?w2) ?x:A ?z:?m ?y:?? ?x:A ?z:?m ?y:?w1:B (father ?v1 ?w1) ?x:A:?v1 ?z:?m ?y:??:?w1 (mother ?v2 ?w2) ?x:A:?v1 ?z:?m:?w2 ?y:?w1:?v2:B (father A B) ?x:A:?v1 ?z:?m ?y:?w1:B (mother B C) ?x:A:?v1 ?z:?m:?w2:C ?y:w1:?v2:B

6 Unification: Variable Renaming Matching: (grandparent A ?m) (grandparent ?x ?z) –No problem: bind ?x=A, ?z=?m –If match hypothesis (grandparent A ?y) (grandparent ?x ?z) => (parent ?y ?y): Problem!!! Just an artefact, though, so Without loss of generality, rename variables –if (parent ?x1 ?y1) (parent ?y1 ?z1) –then (grandparent ?x1 ?z1)

7 Unification: Occurs Check How do we unify: (?z likes ?z) (?y likes (house-of ?x)) Need (?z = ?y) and (?z = (house-of ?x)), Implies (?y = (house-of ?x)): FINE Now, how do we unify: (?z likes ?z) (?x likes (house-of ?x)) Need (?z = ?x) and (?z = (house-of ?x)) –Implies (?x = (house-of ?x)) : problematic. In unification, a variable cannot be assigned to an expression where that variable occurs (called the “occurs check”).

8 RETE Method Rule chaining problem: Efficiency! For each rule, –For each antecedent, For each assignment of variables to assertions Assert consequent –E.g. for grandparent example, k=2 antecedents, n=4 assertions: 16 steps –Worst case: n^k!!!! Different representation & implementation

9 (parent ?x ?y) (parent ?y ?z) (grand-parent ?x ?z) (x:A y:B) (y:A z:B)conflict in y (y:A z:C)conflict in y (y:B z:D)(x:A y:B z:D) (y:C z:E)conflict in y (x:A y:C) (y:A z:B)conflict in y (y:A z:C)conflict in y (y:B z:D)conflict in y (y:C z:E)(x:A y:C z:E) (x:B y:D) (y:A z:B ) conflict in y (y:A z:C)conflict in y (y:B z:D)conflict in y (y:C z:E)conflict in y (x:C y:E) (y:A z:B)conflict in y (y:A z:C)conflict in y (y:B z:D)conflict in y (y:C z:E)conflict in y Forward Chaining with variables IF (parent ?x ?y) (parent A B) (parent ?y ?z) (parent A C) THEN (grand-parent ?x ?z) (parent B D) (parent C E)

10 Rule System as Relational DB Working memory: relations in database table Rules and rule interpretations as relational database operations R1: if (parent ?x ?y) (parent ?y ?z) (is ?x female) then (grandmother ?x ?z) (parent A B) (parent A C) (parent B D) (parent C E) (is A female)

11 Working Memory as Database Table Columns: Fields (Header: field name); Rows: records: assertions Relation: Database Table “data”

12 Pattern Matching as Relational DB Ops Which rules triggered? –Which antecedents match? What bindings apply? “Select” matching assertions “Project” new bindings “Join” bindings across antecedents

13 Selecting Assertions (parent ?x ?y) => Select data with First = parent

14 Projecting Bindings A1 = Project result over Second and Third

15 Projecting Bindings A2 = Project [Select Data with First=parent] over Second and Third

16 Joining for Consistency Join tables for consistency: B1= Join A1 and A2 with Y=Y

17 Produce Consequent XAXA A3 =Project [Select Data with First=Is and Third=Female] over Second B2= Project [Join B1 and A3 with X = X] over X and Z (Grandmother A D) (Grandmother A E)

18 Analysis Relational database representation performs forward-chaining –Finds all new assertions based on rules, assertions But, still expensive: –n antecedents => – n selects +n projects + n-1 joins + n-1 projects –PER RULE! –Also Joins very expensive - others linear in table

19 Incremental Efficiency Solution: Compile out rules+interpreter into –RETE: Network to incrementally process each assertion At any time, operate on SUBSET of relations Steps: –Each assertion/relation passed thru Select filters –Project to alpha node = store in table –Joins represented by beta nodes Only small # of comparisons at each stage

20 Compiled Out Rete Assertions: Parent A B First 2nd 3rd Select new with First=Parent Select new with First=is and 3rd=female A1 A2A3 X Y A B Y Z A B XAXA B1 B2

21 Compiled Out Rete Assertions: Parent A C First 2nd 3rd Select new with First=Parent Select new with First=is and 3rd=female A1 A2A3 X Y A B A C Y Z A B A C XAXA B1 B2

22 Compiled Out Rete Assertions: Parent B D First 2nd 3rd Select new with First=Parent Select new with First=is and 3rd=female A1 A2A3 X Y A B A C B D Y Z A B A C B D XAXA B1 B2 X Y Z A B D X Z A D ETC..

23 Summary Rule-based systems: Mechanisms Unification supports matching patterns to constants AND variables –Variable renaming preserves generality RETE method –Relational databases and operations –Incremental processing Efficient rule-based reasoning


Download ppt "Rule-based Systems: Mechanisms & Efficiency Artificial Intelligence CMSC 25000 January 10, 2002."

Similar presentations


Ads by Google