l13 clips tut

Upload: bomezzz-enterprises

Post on 06-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 L13 Clips Tut

    1/38

    241-320 Design Architecture and Engineeringfor Intelligent System

    Suntorn Witosurapot

    Contact Address:Phone: 074 287369 or

    Email: [email protected]

    January 2010

  • 8/3/2019 L13 Clips Tut

    2/38

    Lecture 13:

    Expert System

    (CLIPS Tutorial)

  • 8/3/2019 L13 Clips Tut

    3/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 3

    Recall: CLIPS Expert System Shell

    It is an XPS shell tool for building expert systems.

    rule-based, forward-chaining system

    multi-paradigm programming language (rule-based,

    object-oriented and procedural like LISP)

    We will use CLIPS to illustrate many of the conceptsand methods

    Suggest to download the latest version of ApplicationInstaller on Windows Platform

  • 8/3/2019 L13 Clips Tut

    4/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 4

    In this lecture, you should

    be familiar with the important concepts and methodsused in rule-based XPS shells

    facts, rules, pattern matching, agenda, working memory,

    forward chaining understand the fundamental workings of an XPS shell

    knowledge representation

    reasoning

    apply rule-based techniques to simple examples evaluate the suitability of rule-based systems for

    specific tasks dealing with knowledge

  • 8/3/2019 L13 Clips Tut

    5/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 5

    Recall: CLIPS Expert System Shell

    a tool for building expert systems.

    Its name stands for C Language Integrated Production System

    CLIPS is a multi-paradigm programming languagethat provides support for rule-based, object-oriented,and procedural programming.

    You can download it from:

    http://clipsrules.sourceforge.net/index.html Download Installer version on Windows Platform

  • 8/3/2019 L13 Clips Tut

    6/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 6

    CLIPS in PC

    Double click from the shortcuts

  • 8/3/2019 L13 Clips Tut

    7/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 7

    CLIPS Desktop Environment

    You can clear the desktop area with a command fromthe menu bar.

  • 8/3/2019 L13 Clips Tut

    8/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 8

    CLIPS Tutorial

    We will take the tutorial given in the CLIPS mainpage to study in our class.

  • 8/3/2019 L13 Clips Tut

    9/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 9

    CLIPS Tutorial 1: Facts and Rules

    After the prompt CLIPS>, any valid commands canbe use, e.g. the commands in below table.

  • 8/3/2019 L13 Clips Tut

    10/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 10

    Facts and rules: General view

  • 8/3/2019 L13 Clips Tut

    11/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 11

    Facts and rules: General view of Facts

  • 8/3/2019 L13 Clips Tut

    12/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 12

    Example: Insert / list / remove facts

    1

  • 8/3/2019 L13 Clips Tut

    13/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 13

    Example: Clear the system

    We should now clear everything before moving tolearn about the next topic.

    Recheck to seewhether or not it

    is really clear.

  • 8/3/2019 L13 Clips Tut

    14/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 14

    Facts and rules: General view of Facts

  • 8/3/2019 L13 Clips Tut

    15/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 15

    Example: Rules

    Rules: IF THEN

    The IF part

    The THEN part

    The rule name

    Q: Can you explain the rule above?

  • 8/3/2019 L13 Clips Tut

    16/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 16

    Example: Rules (cont.)

    Doing what??

    Q: Explain why a new fact is

    occurred after running theduck rule?

    This is a new fact!

    A: It is inferred by the rule.

  • 8/3/2019 L13 Clips Tut

    17/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 17

    Example: Rules (cont.)

    This is the power of rule-based programming - theability to make inferences from data, particularly as the results of

    one rule can be used as the pattern for another.

    Now add the rule

    Clear all facts, but therules will be untouched

    Q: Can you explain the rule above?

  • 8/3/2019 L13 Clips Tut

    18/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 18

    Example: Rules (cont.)

    Since we just clear all facts, it is easy to see that nofact exists. Then, we insert 2 new facts.

    No fact is left!

    Adding

    2 rules

  • 8/3/2019 L13 Clips Tut

    19/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 19

    Example: Rules (cont.)

    Q: Guess how many factswill be in the system, afterrunning the rule?

    A: See the picture below

    Two new facts

  • 8/3/2019 L13 Clips Tut

    20/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 20

    Example: Rules (cont.)

    Rewrite the first rule, this time with the multiple actions

    Whenever you run the rules, you'll get a message onscreen as well as the asserted quack fact.

  • 8/3/2019 L13 Clips Tut

    21/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 21

    CLIPS Tutorial

    We will take the tutorial given in the CLIPS mainpage to study in our class.

  • 8/3/2019 L13 Clips Tut

    22/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 22

    Tips: Loading scripts from file

    You can download scripts from a file (rather thantyping them every time you use them).

  • 8/3/2019 L13 Clips Tut

    23/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 23

    CLIPS Tutorial 2: Patterns and actions

    We can specify facts using the deffacts structure,but if you add the word startup it will loaded it willrecreated every time a (reset) is executed.

  • 8/3/2019 L13 Clips Tut

    24/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 24

    CLIPS Tutorial 2:Patterns & actions

    (cont.)

    Here is showing thatit has triggered four

    times, once for eachfact matching the(animal ?) pattern.

    The ? symbol is a

    wildcard, which willmatch any symbol.

    No fact atthis moment

    But scripts is inaction after thisreset command

  • 8/3/2019 L13 Clips Tut

    25/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 25

    CLIPS Tutorial 2: Matching things

    From the facts and rule above,

    this results is produced.Q: What animal are represented

    are on each line?

  • 8/3/2019 L13 Clips Tut

    26/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 26

    CLIPS Tutorial 2: Variables in patterns

    We can use variablee.g. ?name in the rule

    Rule: (animal dog) (animal cat) (animal duck) (animal turtle)

  • 8/3/2019 L13 Clips Tut

    27/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 27

    CLIPS Tutorial 2: Getting data from the user

    CLIPS gets information from the user by means ofthe (read) function.

  • 8/3/2019 L13 Clips Tut

    28/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 28

    Tips: Naming the rules and facts

    Please be noticed how rules or factsshould be named in this example.

    This decision treerepresents a small

    section of the diagnosisof a cars failure to start.

    Each rounded box is arecommended remedy

    Each rectangular box is pieceof evidence, which might berepresented by a fact such as(lights-working no) or(petrol yes).

  • 8/3/2019 L13 Clips Tut

    29/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 29

    Tips: Save the script to file

    If you want to save your working script for future use,you can use the save function which returns TRUEif there were no errors in the process of saving.

  • 8/3/2019 L13 Clips Tut

    30/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 30

    CLIPS Tutorial

    We will take the tutorial given in the CLIPS mainpage to study in our class.

  • 8/3/2019 L13 Clips Tut

    31/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 31

    CLIPS Tutorial 4: Templates & conditions

    We have learned how facts can be created. In somecase, we may need to link them together.

    (age Andrew 20)(weight Andrew 80)(height Andrew 188)(blood-pressure Andrew 130 80)(age brenda 23)

    (weight brenda 50)(height brenda 140)(blood-pressure brenda 120 60)

    Ex: an application

    which is to try todetermine thegeneral fitness ofpeople

    Q: What is thecommon amongeach set of facts?

  • 8/3/2019 L13 Clips Tut

    32/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 32

    CLIPS Tutorial 4: Templates & conditions(cont.)

    A kind of record datastructure can be used;here it is called template

    (deftemplate personal-data(slot name)(slot age)(slot weight)(slot height)

    (multislot blood-pressure) )

    (assert (personal-data (name Andrew) (age 20)(weight 80) (height 188) (blood-pressure 130 80)))

    You don't have to specify all the information;

    (assert (personal-data (weight 150) (age 23) (name Brenda)))

  • 8/3/2019 L13 Clips Tut

    33/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 33

    CLIPS Tutorial 4: Templates & conditions(cont.)

    Or use in a deffactsstructure;

    (deftemplate personal-data(slot name)(slot age)(slot weight)(slot height)

    (multislot blood-pressure) )

    (deffacts people(personal-data (name Andrew) (age 20) (weight 80)

    (height 188) (blood-pressure 130 80))

    (personal-data (name Cyril) (age 63) (weight 70)(height 1678) (blood-pressure 180 90)))

  • 8/3/2019 L13 Clips Tut

    34/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 34

    CLIPS Tutorial 4: Templates & conditions(cont.)

    Any slot can be referred by name

    The function modify is used tochange the value of one or moreslots on a fact.

    (deftemplate personal-data(slot name)(slot age)(slot weight)(slot height)(multislot blood-pressure) )

    (defrule birthday?birthday

  • 8/3/2019 L13 Clips Tut

    35/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 35

    CLIPS Tutorial 4: Templates & conditions(cont.)

    Template-based facts can be used in rules just asordinary facts.

    (defrule birthday?birthday

  • 8/3/2019 L13 Clips Tut

    36/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 36

    CLIPS Tutorial

    You may proceed to the other tutorials on your own!

  • 8/3/2019 L13 Clips Tut

    37/38

    241-320 Design Architecture &Engineering for Intelligent System Knowledge Representation andReasoning - part 3 (Rule-based) 37

    Last note & Exercise

    You are now roughly understand how to programCLIPS for building the expert system.

    For better understanding, you are encouraged to learn

    more tutorials that will be uploaded to LMS server later.

    Although CLIPS can do more than what we learned,that are all enough for our learning in this course.

    Since it would be useless if we havent done anythingon CLIPS, let exercise on a homework, which detailsare in next slide.

  • 8/3/2019 L13 Clips Tut

    38/38

    241 320 Design Architecture &S Kno ledge Representation and 38

    Exercise:

    You are about todevelop an expertsystem that canhave the diagnosisof a cars failure

    The decision treegiven here can beused as a guideline

    Interaction with useris preferred