Download presentation
Presentation is loading. Please wait.
1
Expert Systems 3 1 Rewriting Rules, CLIPS Content of this lecture: 1.Interpretation of rules 2.Example: CLIPS Sorting 3.Non-determinism 4.Control regimes: Selection 5.Conflict Resolution Content of next lecture: 1.Serious CLIPS: Language Understanding 2.Interpreter issue: Rete C Language Integrated Production System (NASA, 1985)
2
Expert Systems 3 2 Rules as Declarative Knowledge Example of a declarative rule: IFX is a rabbit THEN X is four-legged Meaning independent of program state. Premisse: X is rabbit Conclusion: X is four-legged Procedural interpretation: IFthe memory state has X stored as a rabbit THENupdate the state to make X four-legged When will this happen?? Rule gives Z-knowledge: Rabbit Non-four-legged Four-legged Non-Rabbit Rabbit We don’t know the situation when X is not a rabbit
3
Expert Systems 3 3 Conditional statement in programming Form of conditional: ifc ifc thenS1 thenS1 elseS2 Executed at some point; know exactly what happens! Condition c at that moment gives action S1, non c gives action S2. Form of production rule: Theoretical: {c} S1 Informal in Rule-based: IF c THEN S1 But not conditional statement! In CLIPS: (defrule NAME c => S1 ) Truth of c allows application of action S1
4
Expert Systems 3 4 What if more rules apply? Life experiment with four volunteers Describe the positions of these heroes
5
Expert Systems 3 5 Representation of facts: Relations Define table structure: (deftemplate neighbor (field left (type SYMBOL)) (field right (type SYMBOL)) ) Provide facts: (deffacts inputs (neighbor (left Anneke) (right Bert)) (neighbor (left Bert) (right Carol)) (neighbor (left Carol) (right Danny)) ) Object, Attribute, Value neighbor leftright AnnekeBert CarolDanny BertCarol Table nameColumn name Table content: 3 facts Facts are numbered (time stamped)
6
Expert Systems 3 6 Numerical inputs for the volunteers (deftemplate holds (field person (type SYMBOL)) (field number (type INTEGER)) ) (holds (person Anneke) (number 17)) (holds (person Bert) (number 6)) (holds (person Carol) (number 7)) (holds (person Danny) (number 27)) holds personnumber Anneke17 Goal: put numbers in ordered sequence
7
Expert Systems 3 7 The sorting rule: swap IFneighbor X Y X holds a Y holds b b > a THENX gets b Y gets a Procedural sorting knowledge: parties exchange their numbers when locally in wrong order
8
Expert Systems 3 8 The sorting rule in CLIPS (defrule swap (neighbor (left ?X) (right ?Y)) ?Xhas <- (holds (person ?X) (number ?a)) ?Yhas <- (holds (person ?Y) (number ?b&:(> ?b ?a))) => (modify ?Xhas (number ?b)) (modify ?Yhas (number ?a)) ) Rule name Value condition Value wildcard Tuple wildcard Action part modifies two existing facts Value wildcard Matching instantiation: Facts w. common value of X, Y, a, b Defines (binds) values for wildcards
9
Expert Systems 3 9 Non-determinism “Program determines behavior of Computer” Sorting rule allows different behaviors depending on chosen instantiation: Non-determinism Theorem 1: Each sequence of swaps is finite. Theorem 2: In any blocked situation, numbers are descending. Conclusion: Non-determinism is not necessarily a problem.
10
Expert Systems 3 10 The Recognize-Act Cycle Rule interpretation is a three- stroke engine: 1.Match: Form Conflict Set by finding satisfied rule instances. 2.Choose: Select one instance from the conflict set by applying a Conflict Resolution strategy. 3.Apply: Modify memory according to selected rule. Conflict set is usually formed explicitly. Match Choose Apply works as
11
Expert Systems 3 11 Beyond Sorting: Selection Find the second largest number 1.Sort the numbers; 2.Find the person on position 2 (from neighbor relation); 3.Output the number of person on position 2. Sequential programming: sort program ; indexer program ; output program. Sorting Rules Output Rules Indexing Rules Production rule set:
12
Expert Systems 3 12 Rules for indexing (deftemplate index (field person (type SYMBOL)) (field place (type INTEGER)) ) (defrule pickfirst (neighbor (left ?X)) (not (neighbor (right ?X))) => (assert (index (person ?X) (place 1))) ) (defrule picknext (neighbor (left ?X) (right ?Y)) (index (person ?X) (place ?I)) => (assert (index (person ?Y) (place (+ ?I 1)))) ) Add object Absence of tuple cannot bind wildcard Clutter Logic in Parenthesis Spaghetti
13
Expert Systems 3 13 Rule for output (defrule answer (index (person ?X) (place 2)) (holds (person ?X) (number ?A)) => (printout t crlf "The second greatest number is “ ?A "." t crlf ) ) Summary of rules: Sorting: swap Indexing: pickfirst, picknext Output: answer See program select.clp and play with it in the CLIPS interpreter
14
Expert Systems 3 14 Control the firing of rules Conflict Resolution can be Local control Preference among rules is explicit in program Strategy is problem dependent Ex.Meta-Rules (not in CLIPS) Salience, Goal variable Global control Use built-in mechanism of interpreter Bad adaptation to domain, but can select best one Ex.Depth, Breadth, Specificity, MEA, LEX (Non-determinism of the second type: not relevant for CLIPS.)
15
Expert Systems 3 15 Salience: Ordering on Rules Add in rule: (declare (salience 30)) Range -100 … 100, default 0. Selection program ( selectSalience.clp ): Sorting 30, indexing 20, output 10. Note: firing of rule may enable a rule of higher salience Higher rule will be preferred in next cycle! Sorting gets high priority permanently!! No resolution among instantiations of same rule Easily overcontrolled: sorting and indexing can overlap
16
Expert Systems 3 16 Control with goal variable Simple variable has two names! (deftemplate goal (field phase (type SYMBOL)) ) Add condition to rules: (defrule answer (goal (phase output)) (index (person ?X) (place 2)) Explicit switch of goal (new rule!): (defrule endindexing ?c <- (goal (phase indexing)) (index (place 2)) => (modify ?c (phase output)) ) Ex.: selectGoal.clp. Fine control over subtasks Alternation possible goal phase sorting Table name Column name Table storage: multiple goals simultaneously
17
Expert Systems 3 17 Global control regimes Order in program Refraction: never repeat an instantiation. (defrule pickfirst (not (neighbor (right ?X))) => (assert (index (person ?X) (place 1))) ) Need not condition on uncomputed place Recency: order by time tags of matching facts Specificity: prefer instantiations with more facts bird => fly bird, penguin => not fly Suitable for coding exceptions or shift of goal.
18
Expert Systems 3 18 Depth and Breadth Depth strategy: Prefer instantiations by new facts Breadth strategy: Prefer instantiations by old fact Start state QED
19
Expert Systems 3 19 Complexity used to switch subtasks (defrule swap (goal sort) (neighbor ?X ?Y) ?Xs <- (holds ?X ?a) ?Ys ?a) => (modify ?Xs (number ?b)) (modify ?Ys (number ?a)) ) (defrule endsort ?c <- (goal sort) => (modify ?c indexing) ) Conditions of endsort less complex than swap Goal is changed only when no swap applies Explicit switch prevents later uncontrolled swap ping (cp. with salience) Requires the global regime complexity to be selected! Abbreviation!
20
Expert Systems 3 20 LEX (lexicographic) Each fact has time stamp To choose from conflict set: 1.Dump all instantiations not using the most recent fact present in the CS; 2.From remaining facts, drop this most recent fact Repeat until choice is made. LEX implies Recency and Complexity MEA variation: first order by time stamp of fact in first condition of rule Live experiment
21
Expert Systems 3 21 Summary and conclusions Production rules encode steps towards solution Non-determinism results from collection of rules Local control regimes resolve conflicts by adding meta- knowledge to the program Eliciting and coding meta-knowledge is difficult Knowledge and meta-knowledge are not well-separated in rule-based program (CLIPS) Global control regimes use properties of the interpreter Different global regimes cannot be combined Selection is not a typical Expert System task! Next class (4): Language understanding
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.