Expert System Implementation

Slides:



Advertisements
Similar presentations
Heuristic Search techniques
Advertisements

Chapter 11 user support. Issues –different types of support at different times –implementation and presentation both important –all need careful design.
© C. Kemke XPS Implementation 1 COMP 4200: Expert Systems Dr. Christel Kemke Department of Computer Science University of Manitoba.
Recursion vs. Iteration The original Lisp language was truly a functional language: –Everything was expressed as functions –No local variables –No iteration.
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
Chapter 7: Introduction to CLIPS
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.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Chapter 9 Describing Process Specifications and Structured Decisions
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
© Franz J. Kurfess ES Implementation 1 CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly.
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.
© Franz J. Kurfess Expert System Design CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
EXPERT SYSTEMS Part I.
© Franz J. Kurfess ES Implementation 1 CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly.
CS 561, Session 25 1 Introduction to CLIPS Overview of CLIPS Facts Rules Rule firing Control techniques Example.
Katanosh Morovat.   This concept is a formal approach for identifying the rules that encapsulate the structure, constraint, and control of the operation.
Chapter 9: Modular Design, Execution Control, and Rule Efficiency Expert Systems: Principles and Programming, Fourth Edition.
Chapter 7: Introduction to CLIPS Expert Systems: Principles and Programming, Fourth Edition.
Software School of Hunan University Database Systems Design Part III Section 5 Design Methodology.
Developing an Algorithm
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
Algorithms & Flowchart
Methodology – Physical Database Design for Relational Databases.
CS62S: Expert Systems Based on: The Engineering of Knowledge-based Systems: Theory and Practice, A. J. Gonzalez and D. D. Dankel.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Rule Based Expert System دكترمحسن كاهاني
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
Mostly adopted from Jason Morris notes (Morris Technical Solutions)
Forward and Backward Chaining
The CLIPS Expert System Shell Dr Nicholas Gibbins
Summary for final exam Agent System..
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Introduction toData structures and Algorithms
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Logical Database Design and the Rational Model
Software Testing.
Algorithms and Problem Solving
Module 11: File Structure
Parsing IV Bottom-up Parsing
Relational Algebra Chapter 4 1.
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Methodology – Physical Database Design for Relational Databases
Chapter 7: Introduction to CLIPS
Component 1 – 2A, B, C Binary Logic
Java Review: Reference Types
Knowledge Representation
4 (c) parsing.
Relational Algebra Chapter 4, Part A
Unit# 9: Computer Program Development
國立臺北科技大學 課程:資料庫系統 fall Chapter 18
Arrays and Linked Lists
Relational Algebra 1.
Chapter 8: Advanced Pattern Matching
Relational Algebra Chapter 4 1.
Higher-Level Testing and Integration Testing
Chapter 6 Intermediate-Code Generation
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Chapter 11 user support.
Algorithms and Problem Solving
Chapter 11 Describing Process Specifications and Structured Decisions
Combinational Circuits
Implementation of Learning Systems
ONTOMERGE Ontology translations by merging ontologies Paper: Ontology Translation on the Semantic Web by Dejing Dou, Drew McDermott and Peishen Qi 2003.
Presentation transcript:

Expert System Implementation

Objectives comprehend the mechanics of pattern matching in rule-based systems basic concepts and techniques Rete algorithm understand the effects of matching and rule formulation on the performance of rule-based systems learn to write rule-based programs and implement systems in an efficient way analyze and evaluate the performance of rule-based programs and systems identify bottlenecks formulate and implement strategies for performance improvements

Overview Implementation of Rule-Based Systems due to their more declarative nature, it can be difficult to evaluate and predict the performance of rule-based systems time to complete a task memory usage disk space usage pattern matching can be used to eliminate unsuitable rules and facts but it can also introduce substantial overhead

Introduction Important Concepts Performance Aspects entities with internal structure data structures, objects, components terms, sentences, graphs diagrams, images concepts, hierarchies Performance Aspects somewhat different from conventional programs less control over the runtime behavior pattern matching can do a lot of the work

Pattern Matching determines if two or more complex entities (patterns) are compatible with each other patterns can be (almost) anything that has a structure pictures: person drawings: diagrams of systems expressions: words,sentences of a language, strings graphs are often used as the underlying representation the structure of the graphs must be compatible usually either identical, or one is a sub-graph of the other the individual parts must be compatible nodes must have identical or compatible values variables are very valuable links must indicate compatible relationships compatibility may be dependent on the domain or task

Pattern MatchingExample Bucky and Satchel Satchel likesBucky Pattern MatchingExample images Do both images refer to the same individual? Do they have other commonalities? test ????? Bucky Bucky likes fish Bucky Bucky likes fish

Pattern Matching Example shapes ????? ?? ????? ??

Pattern Matching Examples constants and variables “Hans” “Franz” “Josef” ? “Joseph” first_name “Joseph” last_name ? “Joseph”

Pattern Matching Examples terms composed of constants, variables, functions father(X) ? “Joseph” father(X) ? father(Y) father(X) mother(X) father(father(X)) grandfather(X) ??

Unification formal specification for finding substitutions that make logical expressions identical the unification algorithm takes two sentences and returns a unifier for them (if one exists) Unify(p,q) =  if Subst(,p) = Subst(,q) if there is more than one such substitution, the most general unifier is returned used in logic programming, automated theorem proving possibly complex operation

Pattern Matching in Rule-Based Systems used to match rules with appropriate facts in working memory rules for which facts can be found are satisfied the combination of a rule with the facts that satisfy it is used to form activation records one of the activation records is selected for execution

Simplistic Rule-Based Pattern Matching go through the list of rules, and check the antecedent (LHS) of each rule against the facts in working memory create an activation record for each rule with a matching set of facts repeat after each rule firing very inefficient the actual performance depends on the formulation of the rules and the contents of the working memory

Rete Algorithm in most cases, the set of rules in a rule-based system is relatively constant the facts (contents of working memory) change frequently most of the contents of working memory, however, don’t change every time optimization of the matching algorithm remember previous results change only those matches that rely on facts that changed the Rete algorithm performs an improved matching of rules and facts invented by Charles Forgy in the early 80s basis for many rule-based expert system shells

Rete Network the name comes from the latin word rete stands for net consists of a network of interconnected nodes each node represents one or more tests on the LHS of a rule input nodes are at the top, output nodes at the bottom pattern nodes have one input, and check the names of facts join nodes have two inputs, and combine facts terminal node at the bottom of the network represent individual rules a rule is satisfied if there is a combination of facts that passes all the test nodes from the top to the output node at the bottom that represents the rule the Rete network effectively is the working memory for a rule-based system

Rete Network Example 1 (deftemplate x (slot a)) ?= y (deftemplate x (slot a)) (deftemplate y (slot b)) (defrule example-1 (x (a ?v1)) (y (b ?v1)) ==> ) ?v1 ?v1 Left.0.a ?= Right.b ?v1 = ?v1 example-1

Rete Left and Right Memories left (alpha) memory contains the left input of a join node right (beta) memory contains the right input of a join node notation: Left.p.q ?= Right.r compare the contents of slot q in fact p from the left memory with slot r in the fact from the right memory (deftemplate x (slot a)) (deftemplate y (slot b)) (defrule example-1 (x (a ?v1)) (y (b ?v1)) ==> ) ?= x ?= y ?v1 ?v1 Left.0.a ?= Right.b ?v1 = ?v1 example-1

Running the Network ?v1 ?v1 ?v1 = ?v1 example-1 only facts x and y are considered all facts where x.a == y.b pass the join network all {x, y} tuples are fowarded to the next node compare the contents of slot q in fact p from the left memory with slot r in the fact from the right memory (deftemplate x (slot a)) (deftemplate y (slot b)) (defrule example-1 (x (a ?v1)) (y (b ?v1)) ==> ) ?= x ?= y ?v1 ?v1 Left.0.a ?= Right.b ?v1 = ?v1 example-1

Rete Network Example 2 shares some facts with Example 1 (deftemplate x (slot a)) (deftemplate y (slot b)) (deftemplate z (slot c)) (defrule example-2 (x (a ?v2)) (y (b ?v2)) (z) ==> ) ?= x ?= y ?= z ?v2 ?v2 Left.0.a ?= Right.b ?v2 = ?v2 ?v2 example-2

Rete Network Example 2 with Assert additional fact asserted (deftemplate x (slot a)) (deftemplate y (slot b)) (deftemplate z (slot c)) (defrule example-2 (x (a ?v2)) (y (b ?v2)) (z) ==> ) (assert (z (c 17)) ?= x ?= y ?= z ?v2 ?v2 17 Left.0.a ?= Right.b ?v2 = ?v2 ?v2 ?v2 = 17 example-2

Assert and Retract with Rete asserting additional facts imposes some more constraints on the network retracting facts indicates that some previously computed activation records are not valid anymore, and should be discarded in addition to the actual facts, tags are sent through the networks ADD to add facts (i.e. for assert) REMOVE to remove facts (i.e. for retract) CLEAR to flush the network memories (i.e. for reset) UPDATE to populate the join nodes of newly added rules

Rete Network Optimization networks with shared facts can be combined (deftemplate x (slot a)) (deftemplate y (slot b)) (deftemplate z (slot c)) (defrule example-1 (x (a ?v1)) (y (b ?v1)) ==> ) (defrule example-2 (x (a ?v2)) (y (b ?v2)) (z) ?= x ?= y ?= z Left.0.a ?= Right.b example-1 example-2

Further Optimizations sophisticated data structures to optimize the network hash table to presort the tokens before running the join node tests fine-tuning via parameters frequently trade-off between memory usage and time

Special Cases for Pattern Matching additional enhancements of the Rete network can be used to implement specific methods backward chaining requires a signal indicating to the network that a particular fact is needed not conditional element indicates the absence of a fact requires special join nodes and special fields in the tokens passing through the network test conditional element uses a special join node that ignores its right input the result of the function is passed on

Rule Formulation Pattern Order General vs. Specific Rules Simple vs. Complex Rules Loading and Saving Facts

Pattern Order since Rete saves information about rules and facts, it can be critical to order patterns in the right way otherwise a potentially huge number of partial matches can be generated

Guidelines for Pattern Matches try to formulate your rule such that the number of matches is low full and partial matches try to limit the number of old partial matches removing those also is time-consuming in general, the state of the system should be reasonably stable matches assertion, retraction, modification of facts

Guidelines for Pattern Ordering most specific patterns first smallest number of matching facts largest number of variable bindings to constrain other facts patterns matching volatile facts go last facts that are changing frequently should be used by patterns late in the LHS smallest number of changes in partial matches may cause a dilemma with the above guideline patterns matching the fewest facts first reduces the number of partial matches

Multifield Variables multifield wildcards and multifield variables are very powerful, but possible very inefficient should only be used when needed limit their number in a single slot of a pattern

Test Conditional Element the test conditional element should be placed as close to the top of the rule as possible reduces the number of partial matches evaluation of expressions during pattern matching is usually more efficient

General vs. Specific Rules some knowledge can be expressed through many specific, or a few general rules specific rules generate a top-heavy Rete network with many pattern nodes and fewer join nodes general rules offer better opportunities for sharing pattern and join nodes it usually is easier to write an inefficient general rule than an inefficient specific rule

Simple vs. Complex Rules simple rules are sometimes elegant, but not necessarily efficient storing temporary facts can be very helpful especially in recursive or repetitive programs

Summary ES Implementation for rule-based systems, an efficient method for pattern matching between the rule antecedents and suitable facts is very critical matching every rule against all possible facts repeatedly is very inefficient the Rete algorithm is used in many expert system shells it constructs a network from the facts and rules in the knowledge base since certain aspects of the knowledge base are quite static, repeated matching operations can be avoided a few strategies can be used by programmers to achieve better performance most specific patterns first, patterns with volatile facts last careful use of multifield variables, general rules use of the test conditional element, built-in pattern constraints loading and saving of facts