Beruflich Dokumente
Kultur Dokumente
Overview
Rule-based Intelligent UI
Inference Engine
Knowledge Base (Rules)
Intelligence (Knowledge-based system)
Agenda
User Interface
Rule-based Intelligent UI
Inference Engine
Knowledge Base (Rules) Agenda Working Memory (Facts)
User Interface
CLIPS
C Language Integrated Production System Public domain software Supports:
Forward Chaining Rules based on Rete algorithm Procedural Programming Object-oriented programming (COOL)
JESS
Java Expert System Shell Inspired by CLIPS => forward chaining rule system + Rete algorithm Free demo version available (trial period of 30 days) Can be integrated with other Java code
Bakcground
Production Rules
Production rules were developed for use in automata theory, formal grammars, programming language design & used for psychological modeling before they were used for expert systems. Also called condition-action, or situation-action rules. Encode associations between patterns of data given to the system & the actions the system should perform as a consequence.
10
Canonical Systems
Production rules are grammar rules for manipulating strings of symbols. Also called rewrite rules (they rewrite one string into another). First developed by Post (1943), who studied the properties of rule systems based on productions & called his systems canonical systems. He proved any system of mathematics or logic could be written as a type of production rule system. Minsky showed that any formal system can be realized as a canonical system.
11
12
Example continued
To generate bacab P1 is applied to the axiom c to get aca Then we apply P2 to get bacab Using a different order gives a different result. If P2 is applied to c we get bcb If P1 is applied after we get abcba
13
An OAV Table
Object Beluga Whale Beluga Whale Blue Whale Blue Whale Blue Whale Attribute Dorsal Fin Tail Fin Tail Fin Dorsal Fin Size Value No No Yes Yes Very Large
16
RULES
General form: a b IF THEN IF < antecedent, condition, LHS> THEN <consequent, action, RHS> Antecedent match against symbol structure Consequent contains special operator(s) to manipulate those symbol structures
17
Syntax of Rules
The vocabulary consists of
a set N of names of objects in the domain a set P of property names that give attributes to objects a set V of values that the attributes can have.
Forward Chaining
facts Fact: Saw tail fin -NO
Backward Chaining
Concrete facts Saw dorsal Saw tail fin Fin -NO - NO
Palindrome Example
If we have the following grammar rules
(P1) $ -> a$a (P2) $ -> b$b (P3) $ -> c$c
Forward Chaining
Rule base
Working memory Fire rule
Rule found
Exit
22
23
Palindrom Example
To generate bacab P1 is applied to the axiom c to get aca Then we apply P2 to get bacab Using a different order gives a different result. If P2 is applied to c we get bcb If P1 is applied after we get abcba
24
Markov algorithm
A Markov algorithm (1954) is a string rewriting system that uses grammarlike rules to operate on strings of symbols. Markov algorithms have been shown to have sufficient power to be a general model of computation. Important difference from canonical system: now the set of rules is ordered
25
RETE algorithm
Creates a decision tree where each node corresponds to a pattern occurring at the left-hand side of a rule Each node has a memory of facts that satisfy the pattern Complete LHS as defined by a path from root to a leaf.
28
Rete example
Pattern Network x? y? x?
y?
z?
(http://aaaprod.gsfc.nasa.gov/teas/Jess/JessUMBC/sld010.htm)
29
Rete example
Pattern Network x?
y?
z?
(http://aaaprod.gsfc.nasa.gov/teas/Jess/JessUMBC/sld010.htm)
30
Rete example
Pattern Network x?
y?
z?
(http://aaaprod.gsfc.nasa.gov/teas/Jess/JessUMBC/sld010.htm)
31
Matching Patterns
At each cycle the interpreter looks to see which rules have conditions that can be satisfied. If a condition has no variables it will only be satisfied by an identical expression in working memory. If the condition contains variables then it will be satisfied if there is an expression in working memory with an attribute-value pair that matches it in a way that is consistent with the way other conditions in the same rule have already been matched.
32
Example of matching
(whale (species Beluga) (tail_fin NO)(dorsal_fin NO)) Matches the pattern (with variables)
(whale (species ?name) (tail_fin ?flukes) (dorsal_fin ?fin)
33
34
Conflict Resolution
Production systems have a decision-making step between pattern matching & rule firing. All rules that have their conditions satisfied are put on the agenda in CLIPS. The set of rules on the agenda is sometimes called the conflict set. Conflict resolution selects which rule to fire from the agenda. Packages like CLIPS provide more than one option for conflict resolution Sensibility (quick response to changes in WM) and Stability (continuous reasoning).
35
Salience
Normally the agenda acts like a stack. The most recent activation placed on the agenda is the first rule to fire. Salience allows more important rules to stay at the top of the agenda regardless of when they were added. If you do not explicitly say, CLIPS will assume the rule has a salience of 0.
a positive salience gives more weight to a rule a negative salience gives less weight to a rule
37
Refractoriness
A rule should not be allowed to fire more than once for the same data. Prevents loops Used in CLIPS and JESS (need to (refresh) to bypass it)
38
How to
39
Example
Simplified description of some varieties of cultivated apples:
Variety Cortland Golden delicious Red Delicious Size large large large Color red yellow green
Granny Smith
medium
red
40
Rules
The simple way write standard if..then rules: IF (color == red && size == large) THEN variety = Cortland
We will need: 4 rules (+ rule(s) for asking questions) => minimum 5 rules BUT: can do it in 2 rules in CLIPS/JESS
41
Define Template
(deftemplate apple (multislot variety (type SYMBOL) ) (slot size (type SYMBOL)) (slot color (type SYMBOL) (default red)) )
Other useful slot type: NUMBER JESS note: in JESS multislots dont have type CLIPS allow both SYMBOL and STRING types, JESS only STRING
42
Assert Facts
(deffacts apple_varieties (apple (variety Cortland) (size large) (color red)) (apple (variety Golden delicious) (size large) (color yellow)) (apple (variety Red Delicious) (size medium) (color red)) (apple (variety Granny Smith) (size large) (color green)) )
43
44
45
Run CLIPS
Type the code in a file, save it (e.g. apples.clp) start CLIPS (type clips or xclips in UNIX/LINUX) do: File -> Load (in XCLIPS) or type (load apples.clp) when the file is loaded CLIPS will display: defining deftemplate apple defining deffacts apple_varieties defining defrule ask-size +j defining defrule variety +j+j TRUE
46
Run CLIPS
Type (reset) to put your initial facts in the fact base
CLIPS>(run)
Please enter the apple characteristics: - color red, yellow, green: red - size (large or medium) : large Youve got a Cortland
CLIPS> (exit)
47
Run JESS
UNIX command line: java classpath jess.jar jess.Main Or start an applet console.html Jess> (batch apples.clp) TRUE Jess> (reset) TRUE Jess> (run)
Please enter the apple characteristics: - color red, yellow, green: red - size (large or medium) : large Youve got a Cortland
2 Jess> (exit)
48
CLIPS resources
Official CLIPS website (maintained by Gary Riley): http://www.ghg.net/clips/CLIPS.html CLIPS Documentation:
http://www.ghg.net/clips/download/docum entation
50
http://www.monmouth.com/%7Ekm2580/d lhowto.htm
51
JESS resources
http://herzberg.ca.sandia.gov/jess/ Includes instructions and examples for embedding JESS into a Java program (http://herzberg.ca.sandia.gov/jess/d ocs/61/embedding.html ) and or creating Java GUI from JESS (see http://herzberg.ca.sandia.gov/jess/do cs/61/jessgui.html)
52