Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2002-06 Franz J. Kurfess CLIPS 1 CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly.

Similar presentations


Presentation on theme: "© 2002-06 Franz J. Kurfess CLIPS 1 CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly."— Presentation transcript:

1 © 2002-06 Franz J. Kurfess CLIPS 1 CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly

2 © 2002-06 Franz J. Kurfess CLIPS 2 Course Overview u Introduction u CLIPS Overview u Concepts, Notation, Usage u Knowledge Representation u Semantic Nets, Frames, Logic u Reasoning and Inference u Predicate Logic, Inference Methods, Resolution u Reasoning with Uncertainty u Probability, Bayesian Decision Making u Pattern Matching u Variables, Functions, Expressions, Constraints u Expert System Design u ES Life Cycle u Expert System Implementation u Salience, Rete Algorithm u Expert System Examples u Conclusions and Outlook

3 © 2002-06 Franz J. Kurfess CLIPS 3 Overview CLIPS u Motivation u Objectives u CLIPS Background u History u Main ideas u Terminology u Facts and Rules u Formats u Using Facts and Rules u Variables and Pattern Matching u Variables u Pattern Matching u Execution of Programs u Invoking and leaving CLIPS u Watching u Important Concepts and Terms u Chapter Summary

4 © 2002-06 Franz J. Kurfess CLIPS 4 Logistics u Introductions u Course Materials u textbooks (see below) u lecture notes u PowerPoint Slides will be available on my Web page u handouts u Web page u http://www.csc.calpoly.edu/~fkurfess http://www.csc.calpoly.edu/~fkurfess u Term Project u Lab and Homework Assignments u Exams u Grading

5 © 2002-06 Franz J. Kurfess CLIPS 5 Bridge-In

6 © 2002-06 Franz J. Kurfess CLIPS 6 Pre-Test

7 © 2002-06 Franz J. Kurfess CLIPS 7 Motivation u CLIPS is a decent example of an expert system shell u rule-based, forward-chaining system u it illustrates many of the concepts and methods used in other ES shells u it allows the representation of knowledge, and its use for solving suitable problems

8 © 2002-06 Franz J. Kurfess CLIPS 8 Objectives u be familiar with the important concepts and methods used in rule-based ES shells u facts, rules, pattern matching, agenda, working memory, forward chaining u understand the fundamental workings of an ES shell u knowledge representation u reasoning u apply rule-based techniques to simple examples u evaluate the suitability of rule-based systems for specific tasks dealing with knowledge

9 © 2002-06 Franz J. Kurfess CLIPS 9 Evaluation Criteria

10 © 2002-06 Franz J. Kurfess CLIPS 10 Introduction u CLIPS stands for u C Language Implementation Production System u forward-chaining u starting from the facts, a solution is developed u pattern-matching u Rete matching algorithm: find ``fitting'' rules and facts u knowledge-based system shell u empty tool, to be filled with knowledge u multi-paradigm programming language u rule-based, object-oriented (Cool) and procedural

11 © 2002-06 Franz J. Kurfess CLIPS 11 The CLIPS Programming Tool u history of CLIPS u influenced by OPS5 and ART u implemented in C for efficiency and portability u developed by NASA, distributed & supported by COSMIC u runs on PC, Mac, UNIX, VAX VMS u CLIPS provides mechanisms for expert systems u a top-level interpreter u production rule interpreter u object oriented programming language u LISP-like procedural language [Jackson 1999]

12 © 2002-06 Franz J. Kurfess CLIPS 12 Components of CLIPS u rule-based language u can create a fact list u can create a rule set u an inference engine matches facts against rules u object-oriented language (COOL) u can define classes u can create different sets of instances u special forms allow you to interface rules and objects [Jackson 1999]

13 © 2002-06 Franz J. Kurfess CLIPS 13 Notation u symbols, characters, keywords u entered exactly as shown:  (example)  square brackets [...] u contents are optional:  (example [test])  pointed brackets (less than / greater than signs) u replace contents by an instance of that type  (example )  star * u replace with zero or more instances of the type  *  plus + u replace with one or more instances of the type  + (is equivalent to * )  vertical bar | u choice among a set of items:  true | false

14 © 2002-06 Franz J. Kurfess CLIPS 14 Tokens and Fields u tokens u groups of characters with special meaning for CLIPS,  e.g. ( ) \ separated by delimiters  ( space, tab, Carriage Return,...) u fields u particularly important group of tokens u CLIPS primitive data types v float, integer, symbol, string, external address, instance name, instance address

15 © 2002-06 Franz J. Kurfess CLIPS 15 CLIPS Primitive Data Types  float: decimal point ( 1.5 ) or exponential notation ( 3.7e10 )  integer: [sign] +  symbol: +  e.g. this-is-a-symbol, wrzlbrmft, !?@*+ u string: delimited by double quotes  e.g. "This is a string" u external address v address of external data structure returned by user-defined functions u instance name (used with Cool) v delimited by square brackets u instance address (used with Cool) v return values from functions

16 © 2002-06 Franz J. Kurfess CLIPS 16 Invoke / Exit CLIPS u entering CLIPS double-click on icon, or type program name(CLIPS) system prompt appears: CLIPS> u exiting CLIPS at the system prompt CLIPS> type (exit) u Note: enclosing parentheses are important; they indicate a command to be executed, not just a symbol

17 © 2002-06 Franz J. Kurfess CLIPS 17 Facts u elementary information items (“chunks”) u relation name u symbolic field used to access the information u often serves as identifier for the fact u slots (zero or more) u symbolic fields with associated values  deftemplate construct u used to define the structure of a fact v names and number of slots  deffacts u used to define initial groups of facts

18 © 2002-06 Franz J. Kurfess CLIPS 18 Examples of Facts u ordered fact (person-name Franz J. Kurfess) u deftemplate fact (deftemplate person "deftemplate example” (slot name) (slot age) (slot eye-color) (slot hair-color))

19 © 2002-06 Franz J. Kurfess CLIPS 19 Defining Facts u Facts can be asserted CLIPS> (assert (today is sunday)) u Facts can be listed CLIPS> (facts) f-0 (today is sunday) u Facts can be retracted CLIPS> (retract 0) CLIPS> (facts) [Jackson 1999]

20 © 2002-06 Franz J. Kurfess CLIPS 20 Instances u an instance of a fact is created by (assert (person (name "Franz J. Kurfess") (age 46) (eye-color brown) (hair-color brown)) )

21 © 2002-06 Franz J. Kurfess CLIPS 21 Initial Facts (deffacts kurfesses "some members of the Kurfess family" (person (name "Franz J. Kurfess") (age 46) (eye-color brown)(hair-color brown)) (person (name "Hubert Kurfess") (age 44) (eye-color blue)(hair-color blond)) (person (name "Bernhard Kurfess") (age 41) (eye-color blue)(hair-color blond)) (person (name "Heinrich Kurfess") (age 38) (eye-color brown)(hair-color blond)) (person (name "Irmgard Kurfess") (age 37) (eye-color green)(hair-color blond)) )

22 © 2002-06 Franz J. Kurfess CLIPS 22 Usage of Facts u adding facts u (assert +) u deleting facts u (retract +) u modifying facts  (modify ( )+ ) v retracts the original fact and asserts a new, modified fact u duplicating facts  (duplicate ( )+ ) v adds a new, possibly modified fact u inspection of facts  (facts) v prints the list of facts  (watch facts) v automatically displays changes to the fact list

23 © 2002-06 Franz J. Kurfess CLIPS 23 Rules u general format (defrule ["comment"] * ; left-hand side (LHS) ; or antecedent of the rule => *) ; right-hand side (RHS) ; or consequent of the rule

24 © 2002-06 Franz J. Kurfess CLIPS 24 Rule Components u rule header u defrule keyword, name of the rule, optional comment string u rule antecedent (LHS) u patterns to be matched against facts u rule arrow u separates antecedent and consequent u rule consequent (RHS) u actions to be performed when the rule fires

25 © 2002-06 Franz J. Kurfess CLIPS 25 Examples of Rules u simple rule (defrule birthday-FJK (person (name "Franz J. Kurfess") (age 46) (eye-color brown) (hair-color brown)) (date-today April-13-02) => (printout t "Happy birthday, Franz!") (modify 1 (age 47)) )

26 © 2002-06 Franz J. Kurfess CLIPS 26 Properties of Simple Rules u very limited: u LHS must match facts exactly u facts must be accessed through their index number u changes must be stated explicitly u can be enhanced through the use of variables

27 © 2002-06 Franz J. Kurfess CLIPS 27 Variables, Operators, Functions u variables  symbolic name beginning with a question mark " ? " u variable bindings v variables in a rule pattern (LHS) are bound to the corresponding values in the fact, and then can be used on the RHS v all occurrences of a variable in a rule have the same value v the left-most occurrence in the LHS determines the value v bindings are valid only within one rule u access to facts v variables can be used to make access to facts more convenient: ?age <- (age harry 17)

28 © 2002-06 Franz J. Kurfess CLIPS 28 Wildcards  question mark ? u matches any single field within a fact  multi-field wildcard $? u matches zero or more fields in a fact

29 © 2002-06 Franz J. Kurfess CLIPS 29 Field Constraints  not constraint ~ u the field can take any value except the one specified  or constraint | u specifies alternative values, one of which must match  and constraint & u the value of the field must match all specified values u mostly used to place constraints on the binding of a variable

30 © 2002-06 Franz J. Kurfess CLIPS 30 Mathematical Operators  basic operators ( +,-,*,/) and many functions (trigonometric, logarithmic, exponential) are supported u prefix notation u no built-in precedence, only left-to-right and parentheses u test feature u evaluates an expression in the LHS instead of matching a pattern against a fact u pattern connectives  multiple patterns in the LHS are implicitly AND -connected  patterns can also be explicitly connected via AND, OR, NOT u user-defined functions u external functions written in C or other languages can be integrated u Jess is tightly integrated with Java

31 © 2002-06 Franz J. Kurfess CLIPS 31 Examples of Rules u more complex rule (defrule find-blue-eyes (person (name ?name) (eye-color blue)) => (printout t ?name " has blue eyes." crlf))

32 © 2002-06 Franz J. Kurfess CLIPS 32 Example Rule with Field Constraints (defrule silly-eye-hair-match (person (name ?name1) (eye-color ?eyes1&blue|green) (hair-color ?hair1&~black)) (person (name ?name2&~?name1) (eye-color ?eyes2&~?eyes1) (hair-color ?hair2&red|?hair1)) => (printout t ?name1 " has "?eyes1 " eyes and " ?hair1 " hair."crlf) (printout t ?name2 " has "?eyes2 " eyes and " ?hair2 " hair."crlf))

33 © 2002-06 Franz J. Kurfess CLIPS 33 Using Templates (deftemplate student “a student record” (slot name (type STRING)) (slot age (type NUMBER) (default 18))) CLIPS> (assert (student (name fred))) (defrule print-a-student (student (name ?name) (age ?age)) => (printout t ?name “ is “ ?age) ) [Jackson 1999]

34 © 2002-06 Franz J. Kurfess CLIPS 34 An Example CLIPS Rule (defrule sunday “Things to do on Sunday” (salience 0); salience in the interval [-10000, 10000] (today is Sunday) (weather is sunny) => (assert (chore wash car)) (assert (chore chop wood)) ) [Jackson 1999]

35 © 2002-06 Franz J. Kurfess CLIPS 35 [Jackson 1999] Getting the Rules Started u The reset command creates a special fact CLIPS> (load “today.clp”) CLIPS> (facts) CLIPS> (reset) CLIPS> (facts) f-0 (initial-fact)... (defrule start (initial-fact) => (printout t “hello”) )

36 © 2002-06 Franz J. Kurfess CLIPS 36 Variables & Pattern Matching u Variables make rules more applicable (defrule pick-a-chore (today is ?day) (chore is ?job) => (assert (do ?job on ?day)) ) u if conditions are matched, then bindings are used [Jackson 1999]

37 © 2002-06 Franz J. Kurfess CLIPS 37 Retracting Facts from a Rule (defrule do-a-chore (today is ?day); ?day must have a consistent binding ?chore <- (do ?job on ?day) => (printout t ?job “ done”) (retract ?chore) ) u a variable must be assigned to the item for retraction [Jackson 1999]

38 © 2002-06 Franz J. Kurfess CLIPS 38 Pattern Matching Details u one-to-one matching (do ?job on ?day) (do washing on monday) u use of wild cards (do ? ? monday) (do ? on ?) (do ? ? ?day) (do $?) (do $? monday) (do ?chore $?when) [Jackson 1999]

39 © 2002-06 Franz J. Kurfess CLIPS 39 Defining Functions in CLIPS u Uses a LISP or Scheme-like syntax (deffunction function-name (arg... arg) action... action) (deffunction hypotenuse (?a ?b) (sqrt (+ (* ?a ?a) (* ?b ?b)))) (deffunction initialize () (clear) (assert (today is sunday))) [Jackson 1999]

40 © 2002-06 Franz J. Kurfess CLIPS 40 Defining Classes & Instances u defining the class CAR (defclass car (is-a user) (name) (made-by)) u defining an instance of CAR (make-instance corvette of car (made-by chevrolet)) [Jackson 1999]

41 © 2002-06 Franz J. Kurfess CLIPS 41 Concrete & Abstract Classes u some classes only exist for inheritance purposes Person ManWoman JackJill [Jackson 1999]

42 © 2002-06 Franz J. Kurfess CLIPS 42 Managing Instances u Commands to display instances CLIPS> (instances) [corvette] of car CLIPS> (send [corvette] print) [corvette] of car (made-by chevrolet) u Command to group instances (in a file) (definstances (corvette of car (made-by chevrolet)) (thunderbird of car (made-by ford))) [Jackson 1999]

43 © 2002-06 Franz J. Kurfess CLIPS 43 Clearing & Resetting Instances u deleting an instance CLIPS> (send [corvette] delete) u deleting all instances CLIPS> (unmake-instance *) u resetting creates an initial object CLIPS> (reset) CLIPS> (instances) [initial-object] of INITIAL-OBJECT [Jackson 1999]

44 © 2002-06 Franz J. Kurfess CLIPS 44 Manipulation of Constructs u show list of constructs (list-defrules), (list-deftemplates), (list-deffacts) v prints a list of the respective constructs u show text of constructs (ppdefrule ), (ppdeftemplate ), (ppdeffacts ) v displays the text of the construct (``pretty print'') u deleting constructs (undefrule ), (undeftemplate ), (undeffacts ) v deletes the construct (if it is not in use) u clearing the CLIPS environment (clear) v removes all constructs and adds the initial facts to the CLIPS environment

45 © 2002-06 Franz J. Kurfess CLIPS 45 Input / Output u print information (printout *) v logical device frequently is the standard output device t (terminal) u terminal input (read [ ]), (readline [ ]) v read an atom or string from a logical device v the logical device can be a file which must be open u open / close file (open [ ]), (close [ ]) v open /close file with as internal name u load / save constructs from / to file (load ), (save ) v backslash \ is a special character and must be ``quoted'' (preceded by a backslash \) v e.g. (load "B:\\clips\\example.clp")

46 © 2002-06 Franz J. Kurfess CLIPS 46 Program Execution u agenda u if all patterns of a rule match with facts, it is put on the agenda  (agenda) displays all activated rules u salience u indicates priority of rules u refraction u rules fire only once for a specific set of facts v prevents infinite loops  (refresh ) v reactivates rules

47 © 2002-06 Franz J. Kurfess CLIPS 47 Execution of a Program  (reset) prepares (re)start of a program: u all previous facts are deleted u initial facts are asserted u rules matching these facts are put on the agenda  (run [ ]) starts the execution u breakpoints  (set-break [ ]) v stops the execution before the rule fires,  continue with ( run ) u (remove-break [ ]) u (show-breaks)

48 © 2002-06 Franz J. Kurfess CLIPS 48 Watching u watching the execution  (watch ) prints messages about activities concerning a  (facts, rules, activations, statistics, compilation, focus, all)  (unwatch ) v turns the messages off

49 © 2002-06 Franz J. Kurfess CLIPS 49 Watching Facts, Rules and Activations u facts u assertions (add) and retractions (delete) u of facts u rules u message for each rule that is fired u activations u activated rules: matching antecedents u these rules are on the agenda

50 © 2002-06 Franz J. Kurfess CLIPS 50 More Watching... u statistics u information about the program execution u (number of rules fired, run time,... ) u compilation (default)  shows information for constructs loaded by (load) v Defining deftemplate:... v Defining defrule:... +j=j v +j, =j indicates the internal structure of the compiled rules »+jjoin added »=j join shared v important for the efficiency of the Rete pattern matching network u focus u used with modules u indicates which module is currently active

51 © 2002-06 Franz J. Kurfess CLIPS 51 User Interface u menu-based version u most relevant commands are available through windows and menus u command-line interface u all commands must be entered at the prompt u (don’t forget enclosing parentheses)

52 © 2002-06 Franz J. Kurfess CLIPS 52 Limitations of CLIPS u single level rule sets u in LOOPS, you could arrange rule sets in a hierarchy, embedding one rule set inside another, etc u loose coupling of rules and objects u rules can communicate with objects via message passing u rules cannot easily be embedded in objects, as in Centaur u CLIPS has no explicit agenda mechanism u the basic control flow is forward chaining u to implement other kinds of reasoning you have to manipulate tokens in working memory [Jackson 1999]

53 © 2002-06 Franz J. Kurfess CLIPS 53 Alternatives to CLIPS u JESS u see below u Eclipse u enhanced, commercial variant of CLIPS u has same syntax as CLIPS (both are based on ART) u supports goal-driven (i.e., backwards) reasoning u has a truth maintenance facility for checking consistency u can be integrated with C++ and dBase u new extension RETE++ can generate C++ header files u not related to the (newer) IBM Eclipse environment u NEXPERT OBJECT u another rule- and object-based system u has facilities for designing graphical interfaces u has a ‘script language’ for designing user front-end u written in C, runs on many platforms, highly portable [Jackson 1999]

54 © 2002-06 Franz J. Kurfess CLIPS 54 JESS u JESS stands for Java Expert System Shell u it uses the same syntax and a large majority of the features of CLIPS u tight integration with Java u can be invoked easily from Java programs u can utilize object-oriented aspects of Java u some incompatibilities with CLIPS u COOL replaced by Java classes u a few missing constructs v more and more added as new versions of JESS are released

55 © 2002-06 Franz J. Kurfess CLIPS 55 Post-Test

56 © 2002-06 Franz J. Kurfess CLIPS 56 Evaluation u Criteria

57 © 2002-06 Franz J. Kurfess CLIPS 57 CLIPS Summary u notation u similar to Lisp, regular expressions u facts  (deftemplate), (deffacts), assert / retract u rules  (defrule...), agenda u variables, operators, functions u advanced pattern matching u input/output  (printout...), (read...), (load...) u program execution  (reset), (run), breakpoints u user interface u command line or GUI

58 © 2002-06 Franz J. Kurfess CLIPS 58 Important Concepts and Terms u agenda u antecedent u assert u backward chaining u consequent u CLIPS u expert system shell u fact u field u forward chaining u function u inference u inference mechanism u instance u If-Then rules u JESS u knowledge base u knowledge representation u pattern matching u refraction u retract u rule u rule header u salience u template u variable u wild card

59 © 2002-06 Franz J. Kurfess CLIPS 59


Download ppt "© 2002-06 Franz J. Kurfess CLIPS 1 CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly."

Similar presentations


Ads by Google