1. Production Systems
◼ Represent knowledge in terms of multiple rules that
specify what should be or should not be concluded in
different situations.
◼ A rule-based system consists of IF-THEN rules, facts,
and an interpreter
◼ Rules are popular for a number of reasons:
Modular nature
◼ easy to encapsulate knowledge and expand the expert system by
incremental development
Explanation facilities
◼ By keeping track of which rules have fired, an explanation facility can
present the chain of reasoning that led to a certain conclusion.
Similarity to the human cognitive process
1
SEEM 5750
2. Post production systems
◼ Production systems were first used in symbolic logic by Post who
originated the name.
◼ The basic idea of Post was that any mathematical or logic system is
simply a set of rules specifying how to change one string of symbols
into another set of symbols.
◼ Given an input string, the antecedent, a production rule could
produce a new string, the consequent.
2
SEEM 5750
3. Post production systems
◼ A production rule could be:
Antecedent →Consequent person
has fever → take aspirin
◼ In terms of the IF-THEN notation as:
IF person has fever THEN take aspirin
◼ The production rules can also have multiple antecedents
person has fever AND
fever is greater than 102 → see doctor
3
SEEM 5750
4. Post production systems
◼ A Post production system consists of a group of production rules
(1) car won't start → check battery
(2) car won't start → check gas
(3) check batteryAND batterybad →replace battery
(4) check gas AND no gas → fill gas tank
4
SEEM 5750
5. Post production systems
◼ The rules could have been written in any order
(4) check gas AND no gas → fill gas tank
(2) car won't start → check gas
(1) car won't start → check battery
(3) check batteryAND battery bad →replace battery
◼ The basic limitation is lack of a control strategy to guide the application of
the rules
◼ Therefore, although they were useful in laying part of the foundation of
expert systems, they are not adequate.
5
SEEM 5750
6. Rule-based Systems
◼ Consider the problem of deciding to cross a street
◼ The productions for the two rules are
the light is red -> stop
the light is green -> go
◼ An equivalent pseudo code IF-THEN format as:
Rule: Red_light IF
IF
the light is red
THEN
stop
Rule: Green_light IF
IF
The light is green
THEN
go
6
SEEM 5750
7. Rule-based Systems
◼ Each rule is identified by a name. Following the name is the IF part
of the rule
◼ Between the IF and THEN part of the rule is called by various
names such as the antecedent, conditional part, pattern part, or
left-hand-side (LHS)
◼ The individual condition:
the light is green
is called a conditional element or a pattern
7
SEEM 5750
8. Rule-based Systems
8
SEEM 5750
◼ The following are some examples of rules from the classic
systems:
MYCIN system for diagnosis of meningitis and bacteremia (bacterial
infections)
IF
The site of the culture is blood, and
The identity of the organism is not known with certainty, and
The stain of the organism is gramneg, and
The morphology of the organism is rod, and The patient has been
seriously burned
THEN
There is weakly suggestive evidence (.4) that
the identity of the organism is pseudomonas
9. Rule-based Systems
9
SEEM 5750
XCON/Rl for configuring DEC VAX computer systems
IF
The current context is assigning devices to Unibus modules and
There is an unassigned dual-port disk drive and
The type of controller it requires is known and
There are two such controllers, neither of which has any devices assigned to it,
and
The number of devices that these controllers can support is known
THEN
Assign the disk drive to each of the controllers, and
Note that the two controllers have been associated and each supports one drive
10. Rule Inference
◼ Two general methods of inferencing used
forward chaining
backward chaining
◼ Other methods used
means-ends analysis, problem reduction, backtracking, plan-generate-
test, hierarchical planning and the least commitment principle, and
constraint handling
◼ Forward chaining is reasoning from facts to the conclusions resulting
from those facts
◼ Backward chaining involves reasoning in reverse from a hypothesis,
a potential conclusionto be proved, to the facts that support the
hypothesis
10
SEEM 5750
11. Rule Inference
◼ CLIPS is designed for forward chaining, PROLOG performs
backward chaining
◼ The choice of inference engine depends on the type of problem
Diagnostic problems are better solved with backward chaining
Prognosis, monitoring, and control are better done by forward chaining
◼ A rule whose patterns are all satisfied is said to be activated or
instantiated.
◼ Multiple activatedrules may be on the agenda at the same time, the
inference engine must then select one rule for firing
11
SEEM 5750
12. Rule Inference
◼ Following the THEN part of a rule is a list of actions to be executed
when the rule fires
the consequent or right-hand side (RHS)
◼ The inference engine operates in recognize-act cycles will
repeatedly execute a group of tasks until certain criteria cause
execution to cease
12
SEEM 5750
13. Rule Inference
◼ Conflict resolution, act, match, and check for halt:
WHILE not done
Conflict Resolution: If there are activations, then select the one with highest
priority, else done.
Act: Sequentially perform the actions on the RHS of the selected activation.
Re-move the activation that has just fired from the agenda.
Match: Update the agenda by checking if the LHS of any rules are satisfied. If so,
activate them. Remove activations if the LHS of their rules are no longer satisfied.
Check for Halt: If a halt action is performed or break command given, then done.
END-WHILE
Accept a new user command
13
SEEM 5750
28. KBS architecture (1)
⚫ The typical architecture of an KBS is often
described as follows:
user
interface
inference
engine
knowledge base
29. KBS architecture (1)
⚫ The inference engine and knowledge
base are separated because:
◼ the reasoning mechanism needs to be as
stable as possible;
◼ the knowledge base must be able to grow
and change, as knowledge is added;
◼ this arrangement enables the system to be
built from, or converted to, a shell.
30. KBS architecture (2)
⚫ It is reasonable to produce a richer,
more elaborate, description of the typical
KBS.
⚫ A more elaborate description, which still
includes the components that are to be
found in almost any real-world system,
would look like this:
33. KBS architecture (2)
◼ The system holds a collection of general
principles which can potentially be applied to
any problem - these are stored in the
knowledge base.
◼ The system also holds a collection of specific
details that apply to the current problem
(including details of how the current
reasoning process is progressing) - these are
held in working memory.
◼ Both these sorts of information are processed
by the inference engine.
35. KBS architecture (2)
⚫ Any practical expert system needs an
explanatory facility. It is essential that an
expert system should be able to explain
its reasoning. This is because:
⚫ it gives the user confidence in the
system;
⚫ it makes it easier to debug the system.
37. KBS architecture (2)
⚫ It is not unreasonable to include an
expert interface & a knowledge base
editor, since any practical KBS is going
to need a mechanism for efficiently
building and modifying the knowledge
base.
41. Rule-based reasoning
⚫ One can often represent the expertise
that someone uses to do an expert task
as rules.
⚫ A rule means a structure which has an if
component and a then component.
⚫ This is actually a very old idea indeed -
42. Rule-based reasoning: rules
⚫ examples:
if - the leaves are dry, brittle and
discoloured
then - the plant has been attacked by red
spider mite
if - the customer closes the account
then - delete the customer from the
database
43. Rule-based reasoning: rules
⚫ The statement, or set of statements,
after the word if represents some pattern
which you may observe.
⚫ The statement, or set of statements,
after the word then represents some
conclusion that you can draw, or some
action that you should take.
44. Rule-based reasoning: rules
⚫ A rule-based system, therefore, either
◼ identifies a pattern and draws
conclusions about what it means,
or
◼ identifies a pattern and advises what
should be done about it,
or
◼ identifies a pattern and takes
appropriate action.
45. Rule-based reasoning: rules
• The essence of a rule-based reasoning system is
that it goes through a series of cycles.
• In each cycle, it attempts to pick an appropriate rule
from its collection of rules, depending on the
present circumstances, and to use it as described
above.
• Because using a rule produces new information, it's
possible for each new cycle to take the reasoning
process further than the cycle before. This is rather
like a human following a chain of ideas in order to
come to a conclusion.
46. Terminology
⚫ A rule as described above is often
referred to as a production rule.
⚫ A set of production rules, together with
software that can reason with them, is
known as a production system.
47. Terminology
⚫ There are several different terms for the statements
that come after the word if, and those that come after
the word then.
◼ The statements after if may be called the
conditions, those after then may be called the
conclusions.
◼ The statements after if may be called the premises,
those after then may be called the actions.
◼ The statements after if may be called the
antecedents, those after then may be called the
consequents.
49. Terminology
⚫ If a production system chooses a
particular rule, because the conditions
match the current state of affairs, and
puts the conclusions into effect, this is
known as firing the rule.
50. Terminology
⚫ In a production system, the rules are
stored together, in an area called the
rulebase.
51. Conditional branching
⚫ Is a production rule the same as a
conditional branching statement?
⚫ A production rule looks similar to the
if (statement to be evaluated) then (action)
pattern which is a familiar feature of all
conventional programming languages.
53. Conditional branching
{ int magic;
int guess;
magic = rand( );
printf(“guess the magic number: ”);
scanf(“%d”, &guess);
if (guess == magic) printf(“** Right **”);
else {
printf(“Wrong, ”);
if (guess > magic) printf(“too high”);
else printf(“too low”);
}
}
54. Conditional branching vs. production rules
⚫ However, the similarity is misleading.
There is a radical difference between a
production system and a piece of
conventional software.
◼ In a conventional program, the
if...then... structure is an integral part
of the code, and represents a point
where the execution can branch in
one of two (or more) directions.
55. Conditional branching vs. production rules
◼ In a production system, the if...then...
rules are gathered together in a rule
base, and the controlling part of the
system has some way of choosing a
rule from this knowledge base which
is appropriate to the current
circumstances, and then using it.
56. Reasoning with production rules
⚫ The statements forming the conditions,
or the conclusions, in such rules, may
be structures, following some syntactic
convention (such as three items
enclosed in brackets).
57. Reasoning with production rules
⚫ Very often, these structures will include
variables - such variables can, of
course, be given a particular value, and
variables with the same name in the
same rule will share the same value.
58. Reasoning with production rules
⚫ For example (assuming words beginning
with capital letters are variables, and
other words are constants):
if [Person, age, Number] &
[Person, employment, none] &
[Number, greater_than, 18] &
[Number, less_than, 65]
then [Person, can_claim,
unemployment_benefit].
59. Reasoning with production rules
rule
memory Inference
engine
working
memory
⚫ Architecture of a typical production
system:
observed data
fire
modify
select
output
60. Reasoning with production rules
⚫ Architecture of a typical production
system:
rule
memory
interpreter
working
memory
New information
fire
modify
select
output
61. Reasoning with production rules
⚫ Architecture of a typical production
system:
rule
memory
interpreter
working
memory
New information
fire
modify
select
output
62. Reasoning with production rules
⚫ Architecture of a typical production
system:
rule
memory
Inference
engine
executes
actions
working
memory
New information
fire
modify
select
output
63. Reasoning with production rules
⚫ Architecture of a typical production
system:
rule
memory
Inference
engine
executes
actions
working
memory
New information
fire
modify
select
output
64. Reasoning with production rules
⚫ Architecture of a typical production
system:
rule
memory
interpreter
working
memory
New information
fire
modify
select
output
65. Reasoning with production rules
⚫ Architecture of a typical production
system:
rule
memory
Inference
engine
executes
actions
working
memory
New information
fire
modify
select
output
66. Reasoning with production rules
⚫ Architecture of a typical production
system:
rule
memory
Inference
engine
executes
actions
working
memory
New information
fire
modify
select
output
67. Architecture of a typical production system
⚫ Has a working memory.
◼ Holds items of data. Their presence, or
their absence, causes the inference
engine to trigger certain rules.
◼ e.g. W.M. contains [john, age, 29] &
[john, employment, none]
◼ The system decides: does this match
any rules in the rulebase? If so, choose
the rule.
68. Architecture of a typical production system
⚫ has an inference engine. Behaviour of
the inference engine :
◼ the system is started by putting a
suitable data item into working memory.
◼ recognise-act cycle: when data in the
working memory matches the conditions
of one of the rules in the system, the rule
fires (i.e.is brought into action).
69. Advantages of production systems
... at first glance
⚫ The principle advantage of production
rules is notational convenience - it’s
easy to express suitable pieces of
knowledge in this way.
⚫ The principle disadvantage of production
rules is their restricted power of
expression - many useful pieces of
knowledge don’t fit this pattern.
70. Advantages of production systems
... at first glance
⚫ This would seem to be a purely declarative
form of knowledge representation. One
gathers pieces of knowledge about a
particular subject, and puts them into a
rulebase. One doesn't bother about when or
how or in which sequence the rules are used;
the production system can deal with that.
⚫ When one wishes to expand the knowledge,
one just adds more rules at the end of the
rulebase.
71. Advantages of production systems
... at first glance
⚫ The rules themselves are very easy to
understand, and for someone (who is expert
in the specific subject the system is
concerned with) to criticise and improve.
72. Advantages of production systems
... at first glance
⚫ It's fairly straightforward to implement a
production system interpreter. Following the
development of the Rete Matching
Algorithm, and other improvements, quite
efficient interpreters are now available.
73. Advantages of production systems
... at first glance
⚫ However, it isn't that simple. See
"advantages reconsidered" later on.
74. Operation of a production system in
more detail
⚫ The recognise-act cycle (forward-chaining):
Halt
yes
no
Produce some output
Put the right-hand side
of the rule into effect,
using the information
from working memory
Halt
Pick rules on the
basis of what's in
working memory
Set the cycle going
Put the word "start"
in working memory
Use conflict resolution
strategy to cut this
down to one rule.
Has
the rule
got the
command
"halt" at
the
end?
no
Any
rules
eligible
to fire
?
yes
Information
sources & recipients
the
user
working
memory
75. Operation of a production system
in more detail
⚫ The recognise-act cycle (forward-chaining):
Halt
yes
no
Producesomeoutput
Put theright-handside
of theruleintoeffect,
usingtheinformation
from workingmemory
Halt
Pick rules on the
basis of what's in
working memory
Set thecyclegoing
Put theword "start"
inworking memory
Use conflict resolution
strategytocut this
down toone rule.
Has
therule
got the
command
"halt"at
the
end?
Any
rules
eligible
tofire
?
no
yes
Information
sources&recipients
the
user
working
memory
76. Operation of a production system
in more detail
⚫ The recognise-act cycle (forward-chaining):
Halt
yes
no
Producesomeoutput
Put theright-handside
of theruleintoeffect,
usingtheinformation
from workingmemory
Pick rules on the
basis of what's in
working memory
Set thecyclegoing
Put theword "start"
inworking memory
Use conflict resolution
strategytocut this
down toone rule.
Has
therule
got the
command
"halt"at
the
end?
eligible
tofire
?
Halt
no
Any
rules
yes
Information
sources&recipients
the working
user memory
77. Operation of a production system
in more detail
⚫ The recognise-act cycle (forward-chaining):
Halt
yes
n
o
Producesomeoutput
Put theright-handside
of theruleintoeffect,
usingtheinformation
fromworkingmemory
Pick rules on the
basis of what's in
workingmemory
Put theword "start"
inworkingmemory
Set thecyclegoing
Useconflict resolution
strategytocut this
down toonerule.
Has
therule
got the
comman
d "halt"at
the
end?
Any
rules
eligible
tofire
?
Halt
no
yes
Information
sources&recipients
the
user
working
memory
78. Operation of a production system
in more detail
⚫ The recognise-act cycle (forward-chaining):
Halt
yes
Producesomeoutput
Put theright-handside
of theruleintoeffect,
usingtheinformation
from workingmemory
Use conflict resolution
strategytocut this
down toone rule.
command
"halt"at
the
end?
Halt
no
Any
rules
eligible
tofire
?
yes
Put theword "start"
inworking memory
Set thecyclegoing
Pickruleson the
basisof what's in
no working memory
Has Information
therule sources&recipients
got the
the working
user memory
79. Operation of a production system
in more detail
⚫ The recognise-act cycle (forward-chaining):
Halt
yes
Producesomeoutput
Put theright-handside
of theruleintoeffect,
usingtheinformation
from workingmemory
krules ont
isof what'
rkingmem
got the
command
"halt"at
the
end?
Halt
no
Any
he rules
sin eligible
ory tofire
?
yes
Use conflict resolution
strategytocut this
down toone rule.
Put theword "start"
inworking memory
Set thecyclegoing
Pic
bas
no wo
Has Information
therule sources&recipients
the
user
working
memory
80. Operation of a production system
in more detail
⚫ The recognise-act cycle (forward-chaining):
no
Has
therule
got the
command
"halt"at
the
end?
yes
Halt
Put theword "start" Halt
inworking memory
no
Set thecyclegoing
Any
Pickrulesonthe rules
basisof what'sin eligible
working memory tofire
?
yes
Use conflict resolution
strategytocut this
down toone rule.
Put theright-handside
of theruleintoeffect,
usingtheinformation
Producesomeoutput
from workingmemory
Information
sources&recipients
the working
user memory
81. Operation of a production system
in more detail
⚫ The recognise-act cycle (forward-chaining):
Halt
yes
no
Has
therule
got the
Producesomeoutput
Put theright-handside
of the rule into effect,
using the information
from workingmemory
Pick rules on the
basis of what's in
working memory
Put theword "start"
inworking memory
Set thecyclegoing
Use conflict resolution
strategytocut this
down toone rule.
command
"halt"at
the
end?
rules
eligible
tofire
?
Halt
no
Any
yes
Information
sources&recipients
the
user
working
memory
83. The recognise-act cycle
⚫ conflict resolution strategy: if more than
one rule matches working memory
contents, this decides which one is to
fire. Alternatively, the rule base could be
designed so there's never any conflict
(but usually isn't).
84. The recognise-act cycle
⚫ Applying the rule will probably modify
the contents of working memory. Then
the system continues with the
recognise-act cycle.
⚫ The system stops when
◼ the rules stop firing, or
◼ a rule fires which specifically tells the
system to halt.
85. Conflict resolution strategies
⚫ Choice of c.r.s. can make a big
difference to system performance.
⚫ Three favourite strategies:
◼ Refractoriness: don't allow a rule to fire
twice on same data.
◼ Recency: take the data which arrived in
working memory most recently, and find a
rule that uses this data.
◼ Specificity: use the most specific rule (the
one with the most conditions attached).
86. Conflict resolution strategies
⚫ However, in recent years the fashion (in
expert system shells) has been for very
simple CRSs, coupled with a reluctance
to mention the problem to the potential
system builder.
⚫ Simple strategies:
◼ Give each rule a priority number. If a choice
has to be made, choose the rule with the
highest number.
◼ If a choice has to be made, choose the rule
that comes first in the rule base.
87. Advantages of production systems
reconsidered.
⚫ Because of the effect of conflict
resolution strategies, rules interact and
the order of rules matters.
◼ One must go beyond the declarative
meaning of the rules and consider when
(under which circumstances) they will fire.
◼ One cannot properly understand a rule
simply by reading it in isolation; one must
consider the related rules, the meta-rules,
and the conflict resolution strategy as well.
88. Advantages of production systems
reconsidered.
⚫ For the same reason, attempting to
expand a production system by simply
adding more rules at the end is
dangerous.
◼ Unexpected rule interactions are liable
to happen.
◼ The need to consider all these
possible rule interactions makes large
rule-based systems unwieldy and hard
to update.
89. Advantages of production systems
reconsidered.
⚫ Although non-computer-specialists find it
easy to grasp the meaning of individual
rules, they don't find it easy to grasp
these issues concerned with
interactions.
90. Advantages of production systems
reconsidered.
⚫ Although efficient rule interpreters are
available, one may still need to engage
in meta-level programming in order to
achieve a production system that shows
acceptable performance on a large
rulebase.