Top Banner
06/19/22 1 Rule-Based Systems CIS 488/588 Bruce R. Maxim UM-Dearborn
58

Rule-Based Systems

Feb 18, 2016

Download

Documents

kerem

Rule-Based Systems. CIS 488/588 Bruce R. Maxim UM-Dearborn. Rule-Based Systems. Also known as “production systems” or “expert systems” Rule-based systems are one of the most successful AI paradigms Used for synthesis (construction) type systems - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Rule-Based Systems

04/22/23 1

Rule-Based Systems

CIS 488/588Bruce R. MaximUM-Dearborn

Page 2: Rule-Based Systems

04/22/23 2

Rule-Based Systems

• Also known as “production systems” or “expert systems”

• Rule-based systems are one of the most successful AI paradigms

• Used for synthesis (construction) type systems

• Also used for analysis (diagnostic or classification) type systems

Page 3: Rule-Based Systems

04/22/23 3

Rule Format

Label Rn if condition1condition2…

thenaction1action2…

Page 4: Rule-Based Systems

04/22/23 4

Weaknesses of Expert Systems

• Require a lot of detailed knowledge• Restrict knowledge domain• Not all domain knowledge fits rule format• Expert consensus must exist• Knowledge acquisition is time consuming• Truth maintenance is hard to maintain• Forgetting bad facts is hard

Page 5: Rule-Based Systems

04/22/23 5

Generic System Components

• Global Database– content of working memory (WM)

• Production Rules– knowledge-base for the system

• Inference Engine– rule interpreter and control subsystem

Page 6: Rule-Based Systems

04/22/23 6

Simple Rule-Based System

Page 7: Rule-Based Systems

04/22/23 7

Expert System Architecture

Page 8: Rule-Based Systems

04/22/23 8

Inference Engine

Rulebase

Match

Factbase

ExecuteConflictResolution

new rule

new fact

Page 9: Rule-Based Systems

04/22/23 9

Data Structure

• A major concern for the rulebase is the data structure used for internal storage

• If the rules are stored separately from the system in a declarative fashion they must be loaded at run-time and placed in some searchable data structure

• For data driven programs efficient searching is essential and this is a function of the date structure used (lists, trees, hash tables, etc.)

Page 10: Rule-Based Systems

04/22/23 10

Table vs Graph

Page 11: Rule-Based Systems

04/22/23 11

Forward Chaining Procedure

• Do until problem is solved or no antecedents matchCollect the rules whose antecedents

are found in WM.If more than one rule matches

use conflict resolution strategy to eliminate all but one

Do actions indicated in by rule “fired”

Page 12: Rule-Based Systems

04/22/23 12

Forward Chaining

Page 13: Rule-Based Systems

04/22/23 13

Synthesis Systems

• Used to build things• Tend to use forward chaining• Often data driven• Often make use of breadth first search• Tend looks at all facts before

proceeding

Page 14: Rule-Based Systems

04/22/23 14

Backward ChainingGiven goal g as input find the set of rules S that determine g if a set of rules does not equal empty set then loop choose rule R make R’s antecedent the new goal (ng) if new goal is unknown then backchain (ng) else apply rule R until g is solved or S is equal to empty set else consult user

Page 15: Rule-Based Systems

04/22/23 15

Backward Chaining

Page 16: Rule-Based Systems

04/22/23 16

Analysis System

• Commonly used for diagnostic problems or classification problems

• Tend to use backward chaining• Often goal driven• Often depth-first search• Tend to focus on one hypothesis (path)

at a time (easier for humans)

Page 17: Rule-Based Systems

04/22/23 17

Conflict Resolution Strategies

• Physically order the rules– hard to add rules to these systems

• Data ordering– arrange problem elements in priority queue– use rule dealing with highest priority elements

• Specificity or Maximum Specificity– based on number of antecedents matching– choose the one with the most matches

Page 18: Rule-Based Systems

04/22/23 18

Conflict Resolution Strategies

• Recency Ordering– Data (based on order facts added to WM)– Rules (based on rule firings)

• Context Limiting– partition rulebase into disjoint subsets– doing this we can have subsets and we may also

have preconditions• Randomly Selection• Fire All Application Rules

Page 19: Rule-Based Systems

04/22/23 19

Deductive Systems

• Defintion– the rules in an expert system can be

matched using forward or backward chaining

• Sometimes it is desirable to alternate the forward and backward chaining strategies in the same system

Page 20: Rule-Based Systems

04/22/23 20

Hybred Inference Strategy

repeat• let user enter facts into factbase (WM) • select a a goal G based on current

problem state• call bchain(G) to establish GUntil problem is solved

Page 21: Rule-Based Systems

04/22/23 21

Inference Net

R2

R4

R3

R5lowerdiscount

decreasreserve

shortterm

Fedexpans

6 mondown

stock

MM

R1

6 monup

risk

Page 22: Rule-Based Systems

04/22/23 22

Answering Questions

• Most expert systems users insist on being able to request an explanation of how the ES reached its results

• This is often accomplished using traces of the rule matching and firing order

• The rules themselves can be mapped to an “and/or” type decision tree

Page 23: Rule-Based Systems

04/22/23 23

And/Or TreeGoal: Acquire TV

Buy TV

Earn Money

Steal TV

Get Job

and

Page 24: Rule-Based Systems

04/22/23 24

Explanations

• To answer a “how” question identify the immediate sub-goals for the goal in question and report them

• To answer a “why” question identify the super goals for a given goal and report them

Page 25: Rule-Based Systems

04/22/23 25

Disadvantages

• Basic rule-based systems do not:– Learn– Use multi-level reasoning– Use constraint exposing models– Look at problems from multiple

perspectives– Know when to break their own rules– Make use of efficient matching strategies

Page 26: Rule-Based Systems

04/22/23 26

Extensions

• Rule-Based systems often interface with external systems

• Standard declarative rules support sensors (inputs) as symbols and output (effectors) as function calls

• Rules are tested against working memory using assertions (pre-conditions) to determine when they are eligible to fire (requires post processing)

Page 27: Rule-Based Systems

04/22/23 27

Combining Declarative and Procedural Approaches

Page 28: Rule-Based Systems

04/22/23 28

VP Expert Rules!RULES BLOCK

RULE 1IF Married = Yes AND Savings = Ok AND Insurance = YesTHEN Advice = InvestBECAUSE "Rule 1 determines if married should invest";

RULE 3IF Savings <> Ok OR Insurance = NoTHEN Advice = Do_Not_Invest CNF 80BECAUSE "Rule 3 determines automatic 'not invest'";

Page 29: Rule-Based Systems

04/22/23 29

VP Expert Control Block! ACTIONS BLOCK

ACTIONS DISPLAY "Welcome to the Investment Advisor !!“ FIND Advice DISPLAY "The best advice we have for you is to {#Advice}.“ FIND Type SORT Type DISPLAY "Your top two choices are:“ FOR X = 1 to 2 POP Type, One_type DISPLAY “Investment strategy to consider is {#One_type}.“ END;

Page 30: Rule-Based Systems

04/22/23 30

VP Expert Statements! STATEMENTS BLOCK

ASK Married: "Are you married ?";

CHOICES Married: Yes, No;

ASK Bank: "What is the size of your emergency fund ?";

ASK Investment: "Enter your confidence in at least two investments:";

CHOICES Investment: Stocks, Bonds, Money_Market, Futures;

PLURAL : Investment, Type; ! Declares Investment and Type as plural variables

Page 31: Rule-Based Systems

04/22/23 31

Knowledge Acquisition

• RBS require extremely detailed domain-specific knowledge

• Much of the rulebase content consists of “rules of thumb” used by human experts to solve specific problems

• This takes a long time and skillful listening on the part of the knowledge engineer (knowledge acquisition bottleneck)

Page 32: Rule-Based Systems

04/22/23 32

Expert Systems

• First generation– Domain experts encoded knowledge as if..then

rules in some programming language– Very brittle and hard to maintain

• Second generation– Rulebase separated from program code and

written in declarative form– More robust and a little easier to maintain

Page 33: Rule-Based Systems

04/22/23 33

RBS Advantages

• Simplicity– Rule syntax is based on human reasoning

• Modularity– Easy to add and subtract rules

• Flexibility– Easy to add and process symbols in WM

• Applicability– Many problems can be formulated as rules

Page 34: Rule-Based Systems

04/22/23 34

RBS Disadvantages• Expressiveness

– Hard to predict RBS behavior from rules alone• Power

– Rule behavior often restricted to syntax representation • Efficiency

– Matching can be time consuming• Suitability

– Rules don’t work for every problem domain

Page 35: Rule-Based Systems

04/22/23 35

RBS Game Development – 1

• Usually one person is the programmer, knowledge engineer, and domain expert (better to be 3 separate people)

• The knowledge-based system is implemented first and the rules come later in the game development cycle

• Dividing the task in two (code writing and rule offering) makes it easier for one person to handle

Page 36: Rule-Based Systems

04/22/23 36

RBS Game Development – 2

• Dividing the task provides demonstrates some of the advantages of second generation expert systems– Reusability (RBS module can be used in other

programs)– Debugging (when errors occur WM contents can

be captures and the offending rule easily identified and modified)

Page 37: Rule-Based Systems

04/22/23 37

RBS Efficiency

• Hard-coding and compiling may be faster than interpretation for processing linear lists of rules

• Declarative rules do not need to be organized in linear lists, but are limited to simple actions (e.g. setting symbol values)

• Can hardcode problem independent facts in a small database and augment this by dynamic data structures as needed

Page 38: Rule-Based Systems

04/22/23 38

Suitable Problems

• Make sure you have access to sufficient expert knowledge to capture in the rules

• If your code has long strings of if statements, they could be encoded as declarative rules

• RBS work bests when there a several (flexible) rule sequences can be used to reach a goal state

• RBS work well to implement control strategies in deterministic, reactive environments

Page 39: Rule-Based Systems

04/22/23 39

Brutus

• First generation procedural expert system

• Each action is expressed as a C++ if statement

• Using steering behaviors to follow players or stop at their feet

Page 40: Rule-Based Systems

04/22/23 40

Wall Following Behavior

1. If no wall is present and not already following another wall then move forward

2. If wall in front then turn away from it3. If wall on the side and not in front then

move forward to follow the wall4. If no wall is present and a wall was

previously being followed then turn toward the side where the last wall was

Page 41: Rule-Based Systems

04/22/23 41

Note: context variable “following wall” used to distinguish between case 1 and 4.

Page 42: Rule-Based Systems

04/22/23 42

RBS Considerations

• It will take longer to implement than approach used for Brutus or Marvin

• The RBS approach has the potential for reuse in other parts of the game (e.g. motion)

• Forward chaining approach will be used– Good for behavioral simulation in reactive systems– Rule action can be procedural does not need to be

declarative (like in backward chaining)– Declarative conditions can be loaded from a file

Page 43: Rule-Based Systems

04/22/23 43

Rule Simplifications

• Keep number of rules used to a minimum• Assume rules listed in priority order• Later rules assume that earlier rule conditions

are already true• Allow for multiple rule actions on a match

rather than repeating matches for each action on at a time

Page 44: Rule-Based Systems

04/22/23 44

Working Memory

• XML is used to initialize FEAR modules• Working memory

-<memory>  <Symbol name="sideWall” /><Symbol name="following" value="false" ground="true" />  

</memory>

Page 45: Rule-Based Systems

04/22/23 45

Symbols

• There are two types of symbols– Native symbols refer to sensors or effectors

outside the RBS (e.g. “sideWall” )– Internal symbols are used inside the RBS only

(e.g. “following” )• This allows functional extensions to be

handled indirectly• Native symbols are set automatically before

interpreter cycle starts

Page 46: Rule-Based Systems

04/22/23 46

Rulebase -<rulebase> -<Rule>

-<conditions> <Symbol name="following" value="false" /> <Symbol name="frontWall" value="false" /> <Symbol name="sideWall" value="false" /> </conditions> -<actions> <Symbol name="following" value="false" /> </actions> </Rule><rulebase>

Page 47: Rule-Based Systems

04/22/23 47

Interface

• Must allow data to be passed to module at run-time

• This mainly tells the systems the location of the native symbols and how to execute native actions

• Run-time data is synchronized with static declarations

Page 48: Rule-Based Systems

04/22/23 48

Synchronization

• Variables can be registered with the module by passing pointers (first parameter) along with their names (second parameter)SetSensor(&SensorSidewall, “sideWall”);

• Procedural actions are implemented as functors (classes that store functions as a means of implementing callback functions without virtual calls)

Page 49: Rule-Based Systems

04/22/23 49

Accessor Methods

• For Boolean valuesvoid Set(const string& symbol, const bool value);bool Get(const string& symbol) const;

• Adding Rules on the Flyvoid AddCondittion(const string& symbol,

const bool value);void SetAction(const string& action);

Page 50: Rule-Based Systems

04/22/23 50

Implementation

• Reuses containers from the C++ standard template library to store the RB and WM

• Rules are easily edited in the XML file• Interpreter processes the rules using their

positional priorities• The C++ RBS module is available at

http://AiGameDev.com/

Page 51: Rule-Based Systems

04/22/23 51

Data Structures

• Symbols are implemented as integers rather than strings

• A map (similar to hash function) is used to do the translation

• WM can be a simple array with integer symbols used as WM indices

• Effectors and sensors can be stored in two containers associating integer symbols with native functions passed by the interface

Page 52: Rule-Based Systems

04/22/23 52

Interpreter - 1

• CheckSensorsI( )– Calls native functions to get symbols– Done before matching means each function only

called once• ApplyRules( )

– Rule antecedents are checked in order listed using short-circuited evaluation

– Default values are overwritten when rule matches– Default values set if no rules match

Page 53: Rule-Based Systems

04/22/23 53

Interpreter - 2

• CheckEffectors( )– Scans effector symbols in WM– Calls native functions for any true effector symbols– For control situations it is more efficient to check

every effector symbol each iteration rather than on those for rule fires

Page 54: Rule-Based Systems

04/22/23 54

Working Memory

• Assuming wall appears on one side only reduces number of symbols required

Symbol Default InitialsideWall (sensor)frontWall (sensor)following true falsemoveForwards trueturnAway falseturnTowards false

Page 55: Rule-Based Systems

04/22/23 55

Rulebase

• Written in XML format meanIF NOT following AND NOT frontWall AND NOT sideWAll

THEN following = falseIF frontWall

THEN turnAway = true AND moveForwards = falseIF NOT sideWall

THEN turnTowards = true AND moveForwards = false

• Rule order says “look for wall” first so the 2nd and 3rd rules can assume the wall is found

• Use of default values eliminate need for 4th rule

Page 56: Rule-Based Systems

04/22/23 56

Sensors and Effectors

• Coded as member functions in Brain class and passed to RBS as function pointers along with a pointer back to the class

• Sensors placed a 0 degrees and 45 degrees (true value returned it obstacle detected)

• Moving average is computed from values returned to reduce jerkiness resulting from calling Move( ) and Turn( ) directly

Page 57: Rule-Based Systems

04/22/23 57

Evaluation

• Animat slows down near corners to avoid getting lost

• Increasing length of whiskers (sensors) helps animat detect walls – but takes more time

• If animat loses wall, it may go into an endless spin trying to find the wall (use of spin counter to trigger forward motion would help)

• Has problems at the bottom of stairs

Page 58: Rule-Based Systems

04/22/23 58

Stalker

• Uses a combination of simple rules driven by a RBS interpreter to follow walls

• Capable of finding walls when lost to prevent aimless spinning motion