Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jörg Kewisch, June 10, 2013, LILUG Meeting CLIPS C Language Integrated Production System Developed at the Software Development Branch, NASA Lyndon B. Johnson.

Similar presentations


Presentation on theme: "Jörg Kewisch, June 10, 2013, LILUG Meeting CLIPS C Language Integrated Production System Developed at the Software Development Branch, NASA Lyndon B. Johnson."— Presentation transcript:

1 Jörg Kewisch, June 10, 2013, LILUG Meeting CLIPS C Language Integrated Production System Developed at the Software Development Branch, NASA Lyndon B. Johnson Space Center

2 Jörg Kewisch, June 10, 2013, LILUG Meeting www.siliconevalleyone/founder/clips

3 Jörg Kewisch, June 10, 2013, LILUG Meeting Artificial Intelligence AI features: –Knowledge is added, the system learns AI methods: –Neural nets –Rule based systems »LISP, PROLOG, OPS5, CLIPS

4 Jörg Kewisch, June 10, 2013, LILUG Meeting Expert System Programs designed to replace an expert The solution is not well understood at design time Knowledge is collected and added during the use of the system Instead of one procedural program the problem is solved by a large number of independent “rules” Rules may be conflicting Famous expert systems: –ELIZA (Josef Weizenbaum) –MYCIN CLIPS is an expert system tool, not an expert system CLIPS is a programming language

5 Jörg Kewisch, June 10, 2013, LILUG Meeting “Facts” Facts are equivalent to data in procedural programs Facts are lists of words. Words are –Symbols –Strings –Numbers –Other Facts have no inherent meaning; an interpretation must be supplied by “rules” Example: The sentence “ Birne is doof ” has no meaning The difficult part in designing an expert system is to define a language (i. e. a format for facts and an interpretation) that is able to describe the system.

6 Jörg Kewisch, June 10, 2013, LILUG Meeting Birne

7 Jörg Kewisch, June 10, 2013, LILUG Meeting Rules Rules are the equivalent of statements in a procedural program Rule have the form: –If (list of facts) is asserted then do (list of actions) There is no “else” clause –Rules are “fired” by the existence of facts –CLIPS does not know what the opposite is There is however a construct to say: if fact1 exists and fact2 does not exist. –Such rule is fired by the existence of “fact1”

8 Jörg Kewisch, June 10, 2013, LILUG Meeting Firing of rules Whenever a new fact is asserted all rules are checked if the new fact fulfills all or part of the requirements to “fire” the rule. If all requirements are fulfilled the rule and the facts are put on the “agenda' The (run) function selects a rule from the agenda and executes it. The following selection strategies are used: –Depth: newest rule (default) –Breath: oldest rule –Simplicity: lowest number of facts –Complexity: highest number of facts –Lex and Mea: OPS5 strategy –Random: random

9 Jörg Kewisch, June 10, 2013, LILUG Meeting Creating Facts and Rules Facts are created in CLIPS using the “assert” function: (assert (Birne ist doof)) Rules are defined in CLIPS by: ( defrule rule_name “optional comment” (fact 1)... (fact n) => (function 1) … (function n) )

10 Jörg Kewisch, June 10, 2013, LILUG Meeting Loops Each set of facts fires a rule only once Infinite Loops : (defrule on_and_on ?r ← (next) => (retract ?r) (printout t “do too!!!” crlf) (assert (next)) ) The fact (initial_fact) exists by default

11 Jörg Kewisch, June 10, 2013, LILUG Meeting Binding of variables (defrule gramps ( ?x is father of ?y) ( ?y is father of ?z) => (assert (?x is grandfather of ?z) )

12 Jörg Kewisch, June 10, 2013, LILUG Meeting Multi-field variables (defrule why (I $?x you) => ( printout t “Why do you” ?x “me?” ctlf) ) (assert (I hate You)) (assert (I really really hate you)) (assert ( I you)) (run) Why do you me? Why do you really really hate me? Why do you hate me?

13 Jörg Kewisch, June 10, 2013, LILUG Meeting Salience Rules may have a defined priority: (defrule important (define salience 100) (fire alarm) => (leave building) ) The salience should not be used to enforce sequential execution of the rules

14 Jörg Kewisch, June 10, 2013, LILUG Meeting CLIPS functions Creating and deleting rules: defrule, undefrule Creating and deleting facts: assert, retract, facts, reset Creating (local) variables: bind Math functions: +,-,*,/,sin,cos,tan.atan,exp,ln Comparison: eq, neq String functions: str-cat, sub-str, index Control structures: if, while Input/Output: open, read, readline, write, close, printout, load, save User functions: deffunction

15 Jörg Kewisch, June 10, 2013, LILUG Meeting Functions written in C UserFunctions() { int fun1(); double fun2(); DefineFunction(“fun1”, “i”, fun1, “fun1”); DefineFunction(“fun2”, “f”, fun2, “fun2”); } C functions are provided to access variables, return values, assert and retract facts and rules, and error handling CLIPS can be called from a C program

16 Jörg Kewisch, June 10, 2013, LILUG Meeting Example: Evaluate an expression Facts have the form: varName = exprssion Example: a = b + c b = 5 c = b*(b+1) The facts are transformed into: a = 35 b = 5 c = 30

17 Jörg Kewisch, June 10, 2013, LILUG Meeting Variable substitution (defrule insert-variable- into-expression (?n2 "=" ?value&:(numberp ?value)) ?z <- (?n1 "=" $?head ?n2 $?tail) => (retract ?z) (assert (?n1 "=" ?head ?value ? tail)) )

18 Jörg Kewisch, June 10, 2013, LILUG Meeting Addition (defrule plus (declare (salience 20)) ?z <- (?n1 "=" $?head ?x&:(numberp ?x) "+" ?y&:(numberp ?y) $?tail) => (retract ?z) (assert (?n1 "=" ?head =(+ ?x ?y) ?tail)) )

19 Jörg Kewisch, June 10, 2013, LILUG Meeting Subtraction (defrule minus (declare (salience 20)) ?z <- (?n1 "=" $?head "-" ?x&:(numberp ?x) $?tail) => (retract ?z) (if (> (length ?head) 0) then (assert (?n1 "=" ?head "+" = (- 0 ?x ) ?tail)) else (assert (?n1 "=" = (- 0 ?x ) ?tail)) )

20 Jörg Kewisch, June 10, 2013, LILUG Meeting Multiplication (defrule cut-times (declare (salience 30)) ?z <- (?n1 "=" $?head ?x "*" ?y $?tail) => (retract ?z) (bind ?g (gensym)) (assert (?n1 "=" ?head ?g ?tail)) (assert (?g "=" ?x “*_” ?y)) )

21 Jörg Kewisch, June 10, 2013, LILUG Meeting Multiplication (defrule calc-times ?z <- (?n1 "=" $?head ?x&:(numberp ?x) “*_” ?y&:(numberp ?y) $?tail) => (retract ?z) (assert (?n1 "=" ?head = (* ?x ?y) ? tail)) )

22 Jörg Kewisch, June 10, 2013, LILUG Meeting Parenthesis (defrule parenthesis (declare (salience 40)) ?z <- (?n1 "=" $?head "\(" $?tail) => (retract ?z) (bind ?pcount 1) (bind ?i 1) (bind ?this (nth ?i ?tail)) (while (and (neq ?pcount 0) (neq ?this nil)) (if (eq ?this "\(" ) then (bind ?pcount (+ ?pcount 1))) (if (eq ?this "\)" ) then (bind ?pcount (- ?pcount 1))) (bind ?i (+ ?i 1)) (bind ?this (nth ?i ?tail)) ) (bind ?g (gensym)) (assert (?g "=" (subseq$ ?tail 1 (- ?i 2)))) (assert (?n1 "=" ?head ?g (subseq$ ?tail ?i (length ?tail)))) )

23 Jörg Kewisch, June 10, 2013, LILUG Meeting When to use CLIPS If the language describing the problem is defined, but the solution is unclear. If the problem involves recognition of patterns. If the problem involves decision making, and the criteria for the decisions are rapidly changing.

24 Jörg Kewisch, June 10, 2013, LILUG Meeting When NOT to use CLIPS If you know it can not be done in a procedural programming language. If the problem and the solution is well defined If you end up with too many rules that are executed only once. If the rules are executed always in the same order.

25 Jörg Kewisch, June 10, 2013, LILUG Meeting Conclusion


Download ppt "Jörg Kewisch, June 10, 2013, LILUG Meeting CLIPS C Language Integrated Production System Developed at the Software Development Branch, NASA Lyndon B. Johnson."

Similar presentations


Ads by Google