Document 7802624

Download Report

Transcript Document 7802624

Production Systems
Productions systems are rule based forward chaining
systems.
They are based on forward chained reasoning, but are
extended to be a kind of programming language systems.
Systems exist that can handle several thousand rules
efficiently.
What is Production Systems
Algorithmic ,procedural (C,FORTRAN)
Applicative,functional
(LISP)
Logic programming (PROLOG)
Object oriented (Smalltalk,Java,Simula)
Hybrid systems (KEE,NEXPERT,ART)
Forward chained
Rule based
Symbolic
Rules comunicate only through Working Memory
When is Production Systems used
•When the knowledge is present on the form
situation-action
•When the program control is very complex, i.e. no
algorithm
•When the program is expected to be heavily extended
and modified over a long period
Evidence
Forward and Backward chaining
Hypothesis
Narrow and deep
Good applications for BC
Facts
Conclusions
Broad and shallow
Good applications for FC
Incremental forward chaining
%% rule '9.3'
american(X) and weapon(Y) and
sells(X,Y,Z) and hostile(Z) => criminal(X).
%% rule '9.6'
missile(X) and owns(nono,X)
=> sells(west,X,nono).
%% rule '9.7'
missile(X)
=> weapon(X).
%% rule '9.8'
enemy(X,america)
=> hostile(X).
%% facts
t=> owns(nono,m1).
% 9.4
t=> missile(m1).
% 9.5
t=> american(west).
% 9.9
t=> enemy(nono,america). % 9.10
Derivations:
+ owns(nono,m1)
+ missile(m1)
+ sells(west,m1,nono)
+ weapon(m1)
+ american(west)
+ enemy(nono,america)
+ hostile(nono)
+ criminal(west)
rule '9.3'
if american(X) and weapon(Y)
and
sells(X,Y,Z) and hostile(Z)
then criminal(X).
Forward chaining
Proxy format
rule '9.6'
if missile(X) and owns(nono,X)
then sells(west,X,nono).
rule '9.7'
if missile(X)
then weapon(X).
Derivations
rule '9.8'
if enemy(X,america)
then hostile(X)
*** 9.6 ==> sells(west,m1,nono) ***
*** 9.7 ==> weapon(m1) ***
*** 9.8 ==> hostile(nono) ***
facts
owns(nono,m1) and % 9.4
missile(m1) and
% 9.5
american(west) and % 9.9
enemy(nono,america). % 9.10
*** 9.3 ==> criminal(west) ***
*** Time 0 ms
Production Systems
Forward Chained
All communictations via Working Memory (WM).
1. [Matching] Find all the rules whose premise are satisfied
2. [Conflict Resolution] If more than one rule apply, select
the one with the highest priority
3. [Execution] Execute(fire) the rule selected. The
execution will change the WM.
4. Then start again from top.
Efficiency considerations 1
Forward reasoning can be done in levels.
Every new fact must be derived from at least 1 fact in the
previous level.
This is true because inference mechanism that does not
require a new fact from level t-1 could have been done at
in level t-1 already.
Efficiency considerations 2
With suitable indexing, it is easy to identify all the
rules that can be triggered by a new fact.
Typically, there are many more rules than facts in a
production system rule base.
Rules
Facts
Efficiency considerations 3
Forward chaining gives a lot of irrelevant facts. One
way to avoid this is to simulate backward chaining.
This means that goals and subgoals are explicitly represented
and used to control the reasoning.
Another way is to restrict forward chaining to a subset of rules.
Efficiency considerations 4
(according to AIMA)
A method is to rewrite the rule set using information about
the goal so that only relevant variable bindings –
those belonging to a magic set – are considered during forward inference. For
instance, if the goal is criminal(west), the rule that concludes criminal(X) is
prefixed with an extra conjunct
magic(X) and american(X) and weapon(X) and
sells(X,Y,Z) and hostile(Z) => criminal(X)
which avoids redundant inferences if west is in the magic set.
Efficiency considerations 5
There may be 300 mill americans but only 5(?)
hostile nations.
It may be smart to reorder the condition sequence of
the rules in increasing ”plurality” .
not
american(X) and weapon(X) and
sells(X,Y,Z) and hostile(Z) => criminal(X)
but
hostile(Z) and sells(X,Y,Z) and weapon(X) and
american(X) => criminal(X)
Facts searching for rules
Rules searching for facts
FACTS
RULES
Facts searching for rules
FACTS
RULES
The Rete(*) algorithm
Efficient algorithm to match facts against (patterns) of rules to
determine which rules have all its conditions fullfilled
This algortithm preprocesses the set of rules
in the knowledge base to construct a set of dataflow
network in which each rule is a literal from the rule premise.
Variable bindings flow through the network and are filtered
out when they fail to match a literal. …
At any given point, the state of a rete network captures all
the partial matches of the rules, avoiding a great deal of
recomputation.
(*) pronounced as ”treaty”.
Means ”net” in Latin
Production systems and applications
System
Application
R1
XCON (configuration of VAX computers)
OPS-5
Several applicatons
CLIPS
Severl applications, used by NASA
ACT
Cognitive architecture
SOAR
Cognitive architecture with learning
PRAGMA
BusTUC ( natural language interpretation)
PROXY
Education
Production system PROXY
PROlog implementationof produXion sYstem
All communictations via Working Memory (WM).
1.
[Matching] Find the first rule whose premise are satisfied
2.
[Conflict Resolution] The first has highest priority
3.
[Execution] Execute(fire) the rule selected. The execution will
change the WM. Then start from top.
Conflict Resolution Strategies
Menu
”LEX” strategy
•First found
Refraction
•Least recently used
(don’t fire twice in sequence)
•Most recently used
•Antecedent ordered
Recency
(the newest fact has priority)
•Consequent ordered
•Most complex first
Specificity
(the rule that matches most facts)
•Simplest first
•Rule priority
•User defined
Arbitrary choice
The logic of Proxy
”Imperative logic”
Indicative Logic
If Conditions then Conclusions
Productions
If Conditions then Actions
Imperative Logic
If Conditions then cause Conclusions
PROXY
implementation outline
proxy:repeat,
% repeat until
Alternative for
not epoch.
% epoch fails
negative conclusions
epoch :-
epoch :-
( if P then Q ),
% find a rule
( if P then not Q ),
P,
% check that P is true
P,
not Q,
% and not Q is true
Q,
assert Q.
% put Q into KB
retract Q.
Proxy’s Refraction Rule
Refraction (from refrain)
Proxy requires that all the conditions and not all the
conclusions are true when a rule fires. Then all the
conclusions will be made true by the imperative logic, so the
same rule will not fire the next time.
The method is not particularly efficient, but suffices for
small to medium rule bases (< 1000 rules).
CLIPS
C Language Implementation of production Systems
Example of rule format
(defrule become-adult
(child harry)
(birthday
harry August-15)
(age harry 17)
(date today August-15)
=>
(assert (adult harry))
(retract (child harry))
(retract (age harry 17))
(assert (age harry 18))
(print t “harry is now an adult”))
OPS-5
with example of rules for goal based reasoning
English version
IF there is a goal for monkey to be on some physical object
and the object is at a particular location
and the monkey is at some location holding something
THEN establish a goal for the monkey to hold nothing.
(p On::Phys-Object:Holds
(goal ^status active ^type on ôbject-name <o1>)
(phys-object ^name <o1> ^at <p>)
(monkey ^at <p> ^holds <> nil)
-->
(make goal ^status active ^type on ^object-name nil))
Pragma
Pragma is a production system for translating the natural language
queries (in the form of an intermediate meaning representation language
TQL) to a database query.
At present, there are 1329 rules. In average, 10 rules are fired.
The time used is negligable.
Example of Pragma rule (to be shown),
Purpose:
If time requested is before 430 (today) (" half past four" ) and
time now is after requested time + 1200
then change time requested to 1200 + time requested and
change day to tomorrow.
Pragma rule example
rule defaulttomorrowafternoon
if srel/Rel/time/Four/_,
not
not
not
not
not
not
not
not
_ isa midnight,
_ isa morning,
_ isa prenoon,
_ isa afternoon,
_ isa evening,
_ isa night,
_ isa date,
_ isa weekday,
{Four < 0430, Sixteen is Four + 1200)},
queryitem(timenow(NOW)),
{NOW > Sixteen}
queryitem(today(TODAY)),
queryitem(todaysdate(TODATE)),
{ daysucc(TODAY,TOMORROW)},
{ add_days(TODATE,1,TODATE1)},
then
Sixteen isa clock,
not Four isa clock,
srel/Prep/time/Sixteen/D,
not srel/Prep/time/Four/D,
queryitem(atday(TOMORROW)),
queryitem(atdate(TODATE1)),
message(
‘I assume you mean routes
for tomorrow').