Presentation is loading. Please wait.

Presentation is loading. Please wait.

Knowledge Representation and Reasoning University "Politehnica" of Bucharest Department of Computer Science Fall 2009 Adina Magda Florea

Similar presentations


Presentation on theme: "Knowledge Representation and Reasoning University "Politehnica" of Bucharest Department of Computer Science Fall 2009 Adina Magda Florea"— Presentation transcript:

1 Knowledge Representation and Reasoning University "Politehnica" of Bucharest Department of Computer Science Fall 2009 Adina Magda Florea http://turing.cs.pub.ro/krr_09 curs.cs.pub.ro Master of Science in Artificial Intelligence, 2009-2011

2 2 Lecture 7 Rule Based Systems; RETE algorithm Lecture outline  Rule Based Systems - intro  Production rules  RETE algorithm

3 3 1. Rule Based Systems  Procedural knowledge encoded in a declarative format  Most popular for KBS if LHS then RHD  Many languages and systems  Can be traced to different (correlated) formalisms

4 4 1.1 Well known RBS Many RB languages and systems:  Soar  OPS, CLIPS, JESS  Web Rule Languages: RuleML, SWRL  Business frameworks, e.g. TIBCO Suite with TIBCO Business Events  Prolog, ECLiPSe (CPS based on logic programming)

5 5 1.2 Formalisms  Rewriting/Reduction Systems (RS)  (A,R), A - set of objects and a binary relation R:A x A, called reduction relation or rewrite relation.  String Rewriting System (SRS) or semi-Thue system (Σ,R), Σ - alphabet, R: Σ* x Σ* is a binary relation between strings in the alphabet Rewrite rules  s,  t  Σ* s  R t iff  x,  y,  u,  v  Σ* such that s = xuy, t = xvy and uRv  Are Turing complete (Chomsky unrestricted grammar, semi-Thue grammar)

6 6 Formalisms  Markov algorithm – SRS in which the set of rules is ordered  Formal grammar – SRS which separates the alphabet in terminals, nonterminals and fixes a starting symbol  Lambda calculus – RS with lambda conversion rules

7 7 Example  A = {a, b, c}  Rewrite rules (P1) $ -> a$a (P2) $ -> b$b (P3) $ -> c$c  Apply P1 to c and get aca  Then apply P2 and get bacab  Using a different order gives a different result  Apply P2 to c and get bcb  Apply P1 and get abcba String Rewriting SystemMarkov algorithm

8 8 Formalisms  Term Rewriting Systems (TRS) – RS with rewrite rules applied to terms (PL, FOPL) Rewrite rules  x,  y  L (terms) x  R y iff x is not a variable and every variable from y occurs in x A reduction/rewrite step for term r – if  =unif(r, x) then r  R y  A reduction/rewrite step for term r = t 1 r't 2 – if  = unif(r', x) then r  R t 1  y  t 2   Being linked to FOPL – adds semantics of FOPL

9 9 2 Production Rules Rules can be seen as:  TRS  a subset of the FOPL formal system (together with the associated formal semantics) if L1 and L2 and … then P1 and P2 and … where L1, L2, … P1, P2.. are literals in FOPL LHS, antecedent, conditions RHS, consequent, conclusions, actions

10 10 2.1 Syntax of rules  Very diverse  (most) Common  The vocabulary consists of a set N of names of objects in the domain a set P of property names that give attributes to objects a set V of values that the attributes can have.  OAV triples (object, attribute, value) triples  Predicates in literals refer to attributes

11 11 2.2 RBS WORKING MEMORY RULE BASE EXECUTION ENGINE INFERENCE ENGINE PATTERN MATCHER AGENDA

12 12 RBS  RBS Inference Cycle Match  Conflict Set (CS) Select Act (Execute)  RBS strategy Rule chaining direction: forward, backward Rule selection from CS  Computational effort Match – 80-90%

13 Rule example (deftemplatestudent (slot name) (slot sex) (slot placed_in (default nil)) (slot special_considerations (default no)) (deftemplate room (slot number) (slot capacity (type INTEGER)(default 4)) (slot sexes_are) (slot vacancies (type INTEGER)) (multislot occupants)) (deffacts start (student (name Mary) (sex F)) (student (name Peter) (sex M)) (special_consideration yes)) (room (number 221) (capacity 1) (vacancies 1)) (room (number 346) (capacity 2) (vacancies 1))) WMEs 41 (student name Mary sex F placed_in nil special_consideration no) 52 (student name Peter sex M placed_in nil special_consideration yes) 9 (room number 221 capacity 1 vacancies 1) 12 (room number 346 capacity 2 vacancies 1)

14 Rule example (defrule assign-student-empty-room ?unplaced_student  (student (name ?stud_name) (placed_in nil) (sex ?gender)) ?empty_room  (room (number ?room_no) (capacity ?room_cap) (vacancies ?free_places)) (test (= ?room_cap ?free_places)) => (modify ?unplaced_student (placed_in ?room_no)) (modify ?empty_room (occupants ?stud_name) (sexes_are ?gender) (vacancies (-- ?free_places))))  s  r  x  y  z  t name(s,x)  placed_in(s,nil)  sex(s,y)  number(r,z)  capacity(r,t)  vacancies(r,t)  placed_in(s,z)  ….

15 15 2.3 Match step  Disadvantage of RBS – large computational requirement to perform match of LHS – determine if all instantiations of rules are satisfied by the content of the WM (Working Memory)  O(comparison to check the satisfaction of a rule) = |WM| |CE| |WM| - no of WMEs (Working Memory Elements) |CE| - number of condition elements in a rule

16 16 Match step  What is the best way to determine the changes to the CS that result from changes to the WM?  2 ways of incorporating state information in the Match step to gain efficiency  (1) Memory support Provides knowledge about which WMEs partially satisfy each individual CE An indexing scheme indicates which subset of WM partially matches each CE  alpha memory  (2) Condition relationship Provides knowledge about the interaction of CE within a rule and the partial satisfaction of rules  beta memory

17 17 3. RETE Algorithm  The Rete algorithm was designed by Charles Forgy of Carnegie Mellon University - first in 1974, and later in his 1979 Ph.D. thesis and a 1982 paper  The Rete algorithm compiles the LHS of the production rules into a discrimination network  The network is in the form of an augmented dataflow network  Changes to WM are input to the network  The network reports changes to the CS - output of the network

18 (defrule cat-job-size (message (jobs ?x) (size ?y) (status new)) (job-def (size ?y) (size-def medium)) => (assert (job (job-name ?x) (job-size ?y)))) Distribute WM changes message (status new) job-def (size-def medium) Alpha memories Test for consistent sizes Beta memory Changes to conflict set ?y RETE match Network for the rule Memory support Condition relationship

19 (defrule show-actWM (a ?x)(a 1) (b ?x ?y)(b 1 2) (b 2 3) (b 2 4) (c ?y ?z)(c 3) (c 2) => … show-act select Resulting relations (alpha memories) Intermediate partial result (beta memories) Changes to conflict set Join x Initial state of RETE Network b ca a 1b 1 2c 3 b 2 3 b 2 4 c 2 a 1b 1 2 Join y a 1b 1 2c 2

20 select Resulting relations (alpha memories) Intermediate partial result (beta memories) Changes to conflict set Join x Activity of the RETE Match during an Addition b ca a 1b 1 2c 3 b 2 3 b 2 4 c 2 a 1b 1 2 Join y a 1b 1 2c 2 a 2 + + b 2 3c 3 a 2b 2 3 a 2b 2 4 + + + (defrule show-act (a ?x) (b ?x ?y) (c ?y ?z) => …

21 select Resulting relations (alpha memories) Intermediate partial result (beta memories) Changes to conflict set Join x Activity of the RETE Match during a Deletion b ca a 1b 1 2c 3 b 2 3 b 2 4 c 2 a 1b 1 2 Join y a 1b 1 2c 2 a 2 - - b 2 3c 3 a 2b 2 3 a 2b 2 4 - - - (defrule show-act (a ?x) (b ?x ?y) (c ?y ?z) => …

22 22 PROs and CONs  PROs Sufficient state is maintained so that the comparison of 2 WMEs on two different cycles is minimized Similar rules will compile to similar networks  CONs Every time a WME is removed, the same sequence that occurred during addition must be performed and the stored state unwound A beta-memory may contain the full Cartesian product of its two-input memories – size combinatorially explosive To maintain beta-memories, the join operation must be performed in a fixed order, determined statically at compile time

23 23 RETE II and III  1980s - Charles L. Forgy developed Rete II, not in public domain Rete II claims orders-of-magnitude better performance Rete II was created by Forgy at Production Systems Technologies Inc (PST)  Mid 2000s - Rete III, successor to Rete II Was developed and copyright by Charles L. Forgy at RulesPower Better performance than Rete III for problems that involve both complex rules and large collections of facts


Download ppt "Knowledge Representation and Reasoning University "Politehnica" of Bucharest Department of Computer Science Fall 2009 Adina Magda Florea"

Similar presentations


Ads by Google