Production Systems

CO3301 - Games Development 2
Week 20
Production Systems
Gareth Bellaby
1
Knowledge Representation
There are a variety of knowledge representation
methods.
Most AI is based on symbol manipulation, i.e. a
set of symbols with a set of procedures for
operating on them.
Knowledge is representation and the methods for
manipulating it.
2
Knowledge Representation
•A
set of facts can be represented in a
database. However, a database has very low
inferential capabilities. It might be possible to
use an inference engine (cf. Data Mining).
•
•
Database: static, flat, homogenous, passive.
Knowledge
Base:
flexible,
layered,
heterogeneous, active. This is what is used in
an expert system.
3
Procedural Knowledge
Procedural knowledge is operational, i.e. what to
do when.
Could be directly coded, but such an approach
has low inferential adequacy and low
acquisitional adequacy.
Most common method is production rules.
4
Production Rules
IF
a person has a risk of heart attack
AND
a person has had a previous heart attack
THEN give digitalis
New knowledge is derived
reasoning mechanisms.
using
various
5
Rule-based system
1. If ?x has hair
then ?x is a mammal
2. If ?x is a mammal
and ?x chews cud
then ?x is an goat
3. If ?x is a mammal
and ?x long neck
then ?x is an giraffe
6
Example & Exercises
Gordon has hair and a long neck.
Michael has hair.
Graham is a mammal and chews cud.
Thomas has a long neck.
7
Inference
Deduction is the process of reasoning from
premises to conclusions.
A deductive argument can only bring out what is
already implicit in its premises.
However, it can also give rise to questions.
Questions are requests about facts for which we
currently have no data.
8
Forward and Backward
Chaining
Reasoning carried out by a interpreter.
Two methods:
• forward chaining from assertions
• backward chaining from hypotheses
Rule-based system is a deduction system.
9
Forward Chaining
Gordon has hair => Gordon is a mammal
Gordon has a long neck
we already know that Gordon is a mammal
the animal is a mammal and the animal
has a long neck => Gordon is giraffe
10
Backward Chaining
Gertrude has long neck.
Look for the gaps in our knowledge.
Giraffes have a long neck and are mammals. Gertrude
may be a giraffe.
Is Gertrude a mammal?
Mammals have hair. We need to find out if Gertrude has
hair.
11
Rule Based Systems
AI Interface Standards Committee, 2005 AIISC Report
http://www.igda.org/ai/report-2005/rbs.html
12
Age of Empires III
rule startFishing
inactive
group tcComplete
mininterval 15
{
bool givenFishingBoats = false;
if ( (kbUnitCount(cMyID, cUnitTypeFishingBoat, cUnitStateAlive) > 0) &&
(gWaterExploreMaintain < 0) && (gFishingPlan < 0) )
givenFishingBoats = true; // I have fishing boats, but no fishing or water
// scout plans, so they must have been given to me.
if (givenFishingBoats == false) // Skip these early-outs if we were granted free
// boats.
{
if ( (kbGetCiv() == cCivDutch) && (kbUnitCount(cMyID, cUnitTypeBank,
cUnitStateABQ) < 1) )
return; // Don't burn wood before we have a bank
13
Rule Based Systems and
FSMs
• Obviously some similarity between the two.
• If you have a situation in which all of the states
can lead to all of the other states then a rulebased system is more useful than an FSM.
14
Reasoning and inference
It's possible to store knowledge in such a way
that the structure allows reasoning to occur.
The structure used to store the knowledge
allow the derivation of new facts from those
facts which are explicitly stored.
The mechanism for deriving
depends on the structure.
information
15
Structure of Production
Rules
The order of the production rules is the
primary way of structuring production rules.
Sequential logic.
The rules are examined in order. Later rules
may therefore be ignored.
16
Semantic Nets
Semantic = "meaning"
A semantic net is a set of nodes
(usually items you want to represent
knowledge about) connected by a set
of links. The links are labelled and
represent relations between the
nodes.
17
Human Studies
Derived from human
Quillian, 1969).
studies
(Collins
and
People appear to store information at the most
abstract level. They don't remember that canaries
fly, robins fly, swallows fly, etc. Instead they
remember that birds (in general) fly, and that
canaries, robins and swallows are all types of
birds.
18
Human Response Times
Evidence is the difference in response
time to questions. Subjects took
longer to answer "Can a canary fly?"
than "Can a canary sing?". Singing is
a specific property of (or closely
associated with) canaries, whilst flying
is a general property of being a bird.
19
A Semantic Net Example
animal
isa
bird
can
has
fly
wings
isa
canary
sing
can
20
Frames (slot and filler
structure)
Formally equivalent to semantic nets.
A collection of semantic net nodes
and slots that together describe an
object, act or event.
21
Frames
• frame is a list
• slot is an attribute
A frame is a list of attributes (slots) and associated
values that describe some entity in the world.
Slots can be values, constraints or procedures.
Some Advantages:
• fairly detailed
• inheritance links give a form of default reasoning
22
Frames example
FRAME: bird
a_kind_of: animal
moving_method: fly
active_at: daylight
FRAME: albatross
a_kind_of: bird
colour: black_and_white
size: 115
23
Rule-based system
• One
use of production rules is in expert systems. An
expert system is a specialized problem solving program
designed to work in a single area of human expertise.
• Typically use a production system.
• Geological analysis, for instance
for mining and
drilling, e.g. PROSPECTOR.
• Medical diagnosis, e.g. MYCIN.
24
A MYCIN Rule
If
1. the infection is primary-bacteraemia,
and
2. the site of the culture is a sterile site,
and
3. the suspected portal of entry of the
organism is the gastro-intestinal tract,
then there is suggestive evidence (0.7) that
the identity of the organism is bactericides
25
Expert Systems
Expert systems include:
• Rule base or Knowledge base: using
production rules (the knowledge base). A rule
links conditions to outcomes or actions.
Stores the rules, cases, relationships, etc.
• Working memory.
• Inference engine (the interpreter). Runs the
production rules, checks to see if rule applies,
e.g. decisions about which rule to fire, or
places in the firing of rules into ranked order.
An expert system shell is an inference engine
with an empty knowledge base, e.g. Leonardo.
26
Working memory
• Current state of the system.
• Contents of the working memory are compared
to the rules.
• If a rule matches the working memory then the
rule triggers.
• More than one rule could match the contents of
working memory.
27
Knowledge Acquisition
• Knowledge
is acquired from experts, typically
through interviews, observation of problem
analysis.
• Research still underway into formal methods for
knowledge acquisition.
• Research still underway in to machine learning,
e.g. rule induction or learn by example.
• Less useful for games since direct querying of
an expert less required.
• Difficulties of setting up the expertise for a
computer game.
28
Developing An Expert
System
The single most difficult task is interviewing
the expert:
• differences in language between expert
and researcher
• differences
in intention between expert
and researcher
• have
to convert experience
expertise into facts and rules
and
29
Structures
Rules can be set out as a tree.
Expert systems typically use backwards
chaining with opportunistic forwards
chaining.
30
References
• Any AI book, e.g. Russell & Norvig.
• AI Interface Standards Committee, 2005 AIISC Report
http://www.igda.org/ai/report-2005/rbs.html
• Rabin
, "Promising Game AI Techniques", AI Game
Programming Wisdom 2, 2003.
• "Practical
Logic-Based Planning" , Daniel Wilhelm, AI
Game Programming Wisdom 4, 2008.
•A
Simple Inference Engine for a Rule-Based
Architecture, Mike Christian, AI Game Programming
Wisdom, 2002.
•A
Rule-Based Architecture using Dempster-Shafer
Theory, François Dominic Laramée, AI Game
Programming Wisdom, 2002.
31