Скачать презентацию Master of Science in Artificial Intelligence 2009 -2011 Скачать презентацию Master of Science in Artificial Intelligence 2009 -2011

4e1216149babe051678c208d8ccfd83f.ppt

  • Количество слайдов: 23

Master of Science in Artificial Intelligence, 2009 -2011 Knowledge Representation and Reasoning University Master of Science in Artificial Intelligence, 2009 -2011 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 1

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

1. Rule Based Systems § Procedural knowledge encoded in a declarative format § Most 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 3

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

1. 2 Formalisms § Rewriting/Reduction Systems (RS) § (A, R), A - set of 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 u. Rv § Are Turing complete (Chomsky unrestricted grammar, semi -Thue grammar) 5

Formalisms § Markov algorithm – SRS in which the set of rules is ordered 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 6

Example § A = {a, b, c} § Rewrite rules • (P 1) $ Example § A = {a, b, c} § Rewrite rules • (P 1) $ -> a$a • (P 2) $ -> b$b • (P 3) $ -> c$c § § § String Rewriting System Markov algorithm Apply P 1 to c and get aca Then apply P 2 and get bacab Using a different order gives a different result Apply P 2 to c and get bcb Apply P 1 and get abcba 7

Formalisms § Term Rewriting Systems (TRS) – RS with rewrite rules applied to terms 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 8

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

2. 1 Syntax of rules § Very diverse § (most) Common § The vocabulary 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 10

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

RBS § RBS Inference Cycle • Match Conflict Set (CS) • Select • Act 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% 12

Rule example (deftemplate student (slot name) (slot sex) (slot placed_in (default nil)) (slot special_considerations Rule example (deftemplate student (slot name) (slot sex) (slot placed_in (default nil)) (slot special_considerations (default no)) (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))) (deftemplate room (slot number) (slot capacity (type INTEGER)(default 4)) 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) (slot sexes_are) (slot vacancies (type INTEGER)) (multislot occupants)) 13

Rule example (defrule assign-student-empty-room ? unplaced_student (student (name ? stud_name) (placed_in nil) (sex ? 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) …. 14

2. 3 Match step § Disadvantage of RBS – large computational requirement to perform 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 15

Match step § What is the best way to determine the changes to the 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 16

3. RETE Algorithm § The Rete algorithm was designed by Charles Forgy of Carnegie 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 17

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

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

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

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

PROs and CONs § PROs • Sufficient state is maintained so that the comparison 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 22

RETE II and III § 1980 s - Charles L. Forgy developed Rete II, RETE II and III § 1980 s - 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 2000 s - Rete III, successor to Rete II • Was developed and copyright by Charles L. Forgy at • Rules. Power Better performance than Rete III for problems that involve both complex rules and large collections of facts 23