Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to...

25
Tutorial 1 Building Decision Tree & Implementing in CLIPs

Transcript of Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to...

Page 1: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Tutorial 1

Building Decision Tree

& Implementing in CLIPs

Page 2: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Tutor Information

• Song Shen

• PhD Candidate in Medical Informatics

• Email: [email protected]

• Office hours: T.B.A.

• If you have any questions regarding Tutorials outside tutoring you may email me directly

Page 3: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Assignment Problems

Two tasks in this assignment:

- Modeling knowledge by using decision tree

- Implementing the modeled knowledge (decision tree) in CLIPS

Page 4: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

• Find a SIMPLE problem you can diagnosis

- e.g. “I can’s connect to Internet” or “choosing a mobile phone”

• Diagnosis : is to use your experience (heuristic knowledge) to analysis the problem and find out all probable reasons causing the problem, then accordingly give suggestions of how to resolve it.

Page 5: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

• In Knowledge Modeling, decision tree has > Root node : is decision node

> Node (parent node or child node) : is either decision node or consequence node

> leaf node : is consequence node

• decision node : is a symptom needed to be diagnosed

• consequence node : is a suggestion outcome

Page 6: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Procedure of building decision tree: 1. Decide the perspective from which the diagnosis should be conducted.

2. What is the fundamental symptom (root node) causing the problem from the

decided perspective.

3. Define its constraints (e.g. yes/no) and analysis its all possible children nodes

4. Add children nodes of the fundamental symptom into decision tree. - probable symptoms (decision nodes) - conclusions (consequence nodes) 5. If any of children node is decision node, define its constraints and add its

children nodes into decision tree.

6. Repeat step 5 until all leaf nodes are consequence nodes.

Page 7: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Example:

>Problem:

‘ car does not work properly!’

>Perspectives of diagnosis: - Tyre breakdown

- Mechanical breakdown

- Running out of petrol

Problem: ‘ car does not work properly!’

Page 8: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Example:

>Problem:

‘ car does not work properly!’

>Perspectives of diagnosis: - Tyre breakdown

- Mechanical breakdown

- Running out of petrol

Perspective of diagnosis : ‘Mechanical breakdown’

Problem: ‘ car does not work properly!’

Page 9: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Example:

>Problem:

‘ car does not work properly!’

>Perspectives of diagnosis: - Tyre breakdown

- Mechanical breakdown

- Running out of petrol

Perspective of diagnosis : ‘Mechanical breakdown’

Fundamental symptom : ‘Car does not start!’ (root node)

Problem: ‘ car does not work properly!’

Page 10: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Example:

>Problem:

‘ car does not work properly!’

>Perspectives of diagnosis: - Tyre breakdown

- Mechanical breakdown

- Running out of petrol

Perspective of diagnosis : ‘Mechanical breakdown’

Fundamental symptom : ‘Car does not start!’ (root node)

Problem: ‘ car does not work properly!’

Constraints : ‘yes’ or ‘no’

Page 11: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Example:

>Problem:

‘ car does not work properly!’

>Perspectives of diagnosis: - Tyre breakdown

- Mechanical breakdown

- Running out of petrol

Perspective of diagnosis : ‘Mechanical breakdown’

Fundamental symptom : ‘Does car start?’ (root node)

Problem: ‘ car does not work properly!’

Constraints : ‘yes’ or ‘no’

Constraint = ‘yes’ ==> ‘just didn’t turn car on’ Constraint = ‘no’ ==> ‘starter motor turns?’

Page 12: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Here, we get the root node and two children nodes of root node (consequence node and decision node)

Now let’s work on diagnosis of the decision node “

starter motor turns?” > to define this decision node’s constraints and find its children nodes

(decision nodes or consequence nodes) corresponding to its constraint values.

Page 13: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Diagnose decision node “ starter motor turns?”, we get two decision nodes as its children nodes.

Page 14: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Iterate diagnosis of children nodes till all leaf nodes are consequence nodes and then decision tree is built.

Page 15: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Note

- Specify problem domain

> comments on decision tree diagram

> or comments in the code

> or banner displayed when running code

- Create your own decision tree

Page 16: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

ts

Decision nodes

Consequence node

Page 17: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

ts

at least one decision node’s children are also decision nodes

Page 18: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

ts

No less than 8 decision nodes

Page 19: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

ts

Every consequence node should be

reachable in your implemented expert

system

Page 20: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 1: Modeling knowledge by using decision tree

Something Extra

• Build a real graph

- look less like a sequential flowchart

- e.g. at least one or two parent nodes have two or more decision nodes as children nodes

• More than two choices for at least one decision node

- not only “yes/no” constraints

- e.g. weather = “sunny” or “cloudy” or “rainy”

Page 21: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 2: Implementing decision tree in CLIPS

CLIPS :

- stands for C Language Integrated Production System

- a free expert system shell distributed by NASA from 1985 to 1998.

- general-purpose problem-solving "engine”

- like other expert system languages, CLIPS deals with rules and facts

-Statements start with left bracket ‘(‘ and terminated with right bracket ‘)’

Page 22: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 2: Implementing decision tree in CLIPS

Where to download CLIPS: http://clipsrules.sourceforge.net/ For example, to wins user: -> in the link above, click “CLIPS 6.3 Beta for Windows Release 3” -> click “SourceForge CLIPS Download Page.” -> there is a list of .zip files , download

“windows_executables_624.zip” -> decompose the zip file, click “CLIPWin.exe” -> and here we go!

Page 23: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 2: Implementing decision tree in CLIPS

Page 24: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 2: Implementing decision tree in CLIPS

Some useful functions

Read Value: (bind <variable> <expression>*)

IF-THEN-ELSE: (if <expression>

then <action>*

[else <action>*])

Page 25: Tutorial 1 - University of Auckland- a free expert system shell distributed by NASA from 1985 to 1998. - general-purpose problem-solving "engine - like other expert system languages,

Task 2: Implementing decision tree in CLIPS

Note

• It is OK to reuse or modify an example CLIP code!

• Please do remember to reference the reused or modified source code.

-e.g. “adapted from auto.clp” or “ modified from example.clp”