CIS 488/588 Bruce R. Maxim UM-Dearborn

Slides:



Advertisements
Similar presentations
CHAPTER 13 Inference Techniques. Reasoning in Artificial Intelligence n Knowledge must be processed (reasoned with) n Computer program accesses knowledge.
Advertisements

Production Systems CIS 479/579 Bruce R. Maxim UM-Dearborn.
The Assembly Language Level
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
1 Software Design Introduction  The chapter will address the following questions:  How do you factor a program into manageable program modules that can.
Programming Types of Testing.
Reasoning System.  Reasoning with rules  Forward chaining  Backward chaining  Rule examples  Fuzzy rule systems  Planning.
What is Software Design?  Introduction  Software design consists of two components, modular design and packaging.  Modular design is the decomposition.
Copyright Irwin/McGraw-Hill Software Design Prepared by Kevin C. Dittman for Systems Analysis & Design Methods 4ed by J. L. Whitten & L. D. Bentley.
Rule Based Systems Michael J. Watts
Chapter 12: Expert Systems Design Examples
Expert System Human expert level performance Limited application area Large component of task specific knowledge Knowledge based system Task specific knowledge.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Chapter 2: Algorithm Discovery and Design
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Program Design and Development
1 Chapter 9 Rules and Expert Systems. 2 Chapter 9 Contents (1) l Rules for Knowledge Representation l Rule Based Production Systems l Forward Chaining.
Rules and Expert Systems
Knowledge Acquisition CIS 479/579 Bruce R. Maxim UM-Dearborn.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
EXPERT SYSTEMS Part I.
Artificial Intelligence CSC 361
Chapter 2: Algorithm Discovery and Design
Python quick start guide
Invitation to Computer Science, Java Version, Second Edition.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
 Architecture and Description Of Module Architecture and Description Of Module  KNOWLEDGE BASE KNOWLEDGE BASE  PRODUCTION RULES PRODUCTION RULES 
SE: CHAPTER 7 Writing The Program
A FIRST BOOK OF C++ CHAPTER 6 MODULARITY USING FUNCTIONS.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Forward and Backward Chaining
Automation Testing- QTP Rajesh Charles Batch No: Date: jan
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Advanced Computer Systems
Advanced AI Session 2 Rule Based Expert System
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Control Flow Testing Handouts
F453 Computing Questions and Answers
Chapter 2: Input, Processing, and Output
Topics Introduction to Repetition Structures
GC211Data Structure Lecture2 Sara Alhajjam.
Architecture Components
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Stacks Chapter 4.
Database Performance Tuning and Query Optimization
Knowledge Representation
CIS 488/588 Bruce R. Maxim UM-Dearborn
Chapter 5 - Functions Outline 5.1 Introduction
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Analysis and Understanding
Topics Introduction to File Input and Output
Forward Chaining DFS can supply compatible bindings for forward chaining.
Chapter 6 Intermediate-Code Generation
Java Programming Arrays
CIS 488/588 Bruce R. Maxim UM-Dearborn
CIS 488/588 Bruce R. Maxim UM-Dearborn
CIS 488/588 Bruce R. Maxim UM-Dearborn
Coding Concepts (Basics)
Chapter 11 Database Performance Tuning and Query Optimization
Boolean Expressions to Make Comparisons
Java Programming Loops
Using Decision Structures
Basic Concepts of Algorithm
Topics Introduction to File Input and Output
Presentation transcript:

CIS 488/588 Bruce R. Maxim UM-Dearborn Rule-Based Systems CIS 488/588 Bruce R. Maxim UM-Dearborn 11/18/2018

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 11/18/2018

Rule Format Label Rn if condition1 condition2 … then action1 action2 11/18/2018

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 11/18/2018

Generic System Components Global Database content of working memory (WM) Production Rules knowledge-base for the system Inference Engine rule interpreter and control subsystem 11/18/2018

Simple Rule-Based System 11/18/2018

Expert System Architecture 11/18/2018

Inference Engine Rulebase new rule Conflict Execute Match Resolution new fact Factbase 11/18/2018

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.) 11/18/2018

Table vs Graph 11/18/2018

Forward Chaining Procedure Do until problem is solved or no antecedents match Collect 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” 11/18/2018

Forward Chaining 11/18/2018

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 11/18/2018

Backward Chaining Given 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 consult user 11/18/2018

Backward Chaining 11/18/2018

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) 11/18/2018

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 11/18/2018

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 11/18/2018

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 11/18/2018

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 G Until problem is solved 11/18/2018

Inference Net R4 R2 R5 R1 R3 6 mon up MM risk lower discount Fed expans R5 stock 6 mon down R1 decreas reserve short term R3 11/18/2018

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 11/18/2018

And/Or Tree Goal: Acquire TV Steal TV Buy TV and Earn Money Get Job 11/18/2018

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 11/18/2018

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 11/18/2018

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) 11/18/2018

Combining Declarative and Procedural Approaches 11/18/2018

VP Expert Rules !RULES BLOCK RULE 1 IF Married = Yes AND Savings = Ok AND Insurance = Yes THEN Advice = Invest BECAUSE "Rule 1 determines if married should invest"; RULE 3 IF Savings <> Ok OR Insurance = No THEN Advice = Do_Not_Invest CNF 80 BECAUSE "Rule 3 determines automatic 'not invest'"; 11/18/2018

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; 11/18/2018

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 11/18/2018

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) 11/18/2018

Expert Systems First generation Second 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 11/18/2018

RBS Advantages Simplicity Modularity Flexibility Applicability 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 11/18/2018

RBS Disadvantages Expressiveness Power Efficiency Suitability 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 11/18/2018

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 11/18/2018

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) 11/18/2018

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 11/18/2018

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 11/18/2018

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 11/18/2018

Wall Following Behavior If no wall is present and not already following another wall then move forward If wall in front then turn away from it If wall on the side and not in front then move forward to follow the wall If no wall is present and a wall was previously being followed then turn toward the side where the last wall was 11/18/2018

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

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 11/18/2018

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 11/18/2018

Working Memory XML is used to initialize FEAR modules Working memory <Symbol name="sideWall” /> <Symbol name="following" value="false" ground="true" />   </memory> 11/18/2018

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 11/18/2018

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

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 11/18/2018

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) 11/18/2018

Accessor Methods For Boolean values Adding Rules on the Fly void Set(const string& symbol, const bool value); bool Get(const string& symbol) const; Adding Rules on the Fly void AddCondittion(const string& symbol, const bool value); void SetAction(const string& action); 11/18/2018

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/ 11/18/2018

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 11/18/2018

Interpreter - 1 CheckSensorsI( ) ApplyRules( ) 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 11/18/2018

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 11/18/2018

Working Memory Assuming wall appears on one side only reduces number of symbols required Symbol Default Initial sideWall (sensor) frontWall following true false moveForwards turnAway turnTowards 11/18/2018

Rulebase Written in XML format mean IF NOT following AND NOT frontWall AND NOT sideWAll THEN following = false IF frontWall THEN turnAway = true AND moveForwards = false IF 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 11/18/2018

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 11/18/2018

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 11/18/2018

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 11/18/2018