rule-based expert system aziz kustiyo departemen ilmu komputer fmipa ipb 2011

39
Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Upload: irma-hunter

Post on 05-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Rule-Based Expert System

Aziz KustiyoDepartemen Ilmu Komputer FMIPA

IPB2011

Page 2: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Knowledge Representation Techniques (by Barr and Feigenbaum, 1981)

• Object-attribute-value triples• Rules• Semantic network• Frames• Logic

Page 3: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Rule-based Expert Systems• A rule-based expert system is an expert system (see

intro) which works as a production system in which rules encode expert knowledge.

• Most expert systems are rule-based.

• Alternatives are • frame-based - knowledge is associated with the

objects of interest and reasoning consists of confirming expectations for slot values. Such systems often include rules too.

Page 4: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Rule-based Expert Systems• model-based, where the entire system models the real

world, and this deep knowledge is used to e.g. diagnose equipment malfunctions, by comparing model predicted outcomes with actual observed outcomes

• case-based - previous examples (cases) of the task and its solution are stored. To solve a new problem the closest matching case is retrieved, and its solution or an adaptation of it is proposed as the solution to the new problem.

Page 5: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Production rules• A production rule consists of two parts: condition

(antecedent) part and conclusion (action, consequent) part,

• i.e: IF (conditions) THEN (actions)

• Example IF Gauge is OK AND [TEMPERATURE] > 120

THEN Cooling system is in the state of overheating

N. Kasabov, Foundations of Neural Networks, Fuzzy Systems, and Knowledge Engineering, MIT Press, 1996

Page 6: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Advantages of rule-based expert systems

• Natural knowledge representation. – An expert usually explains the problem-solving procedure with such

expressions as this: “In such-and-such situation, I do so-and-so”. – These expressions can be represented quite naturally as IF-THEN

production rules.

• Uniform structure. – Production rules have the uniform IF-THEN structure. – Each rule is an independent piece of knowledge. – The very syntax of production rules enables them to be self-

documented.

Page 7: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Advantages of rule-based expert systems

• Separation of knowledge from its processing. – The structure of a rule-based expert system provides an effective

separation of the knowledge base from the inference engine. – Thus possible to develop different applications using the same

expert system shell. • Dealing with incomplete and uncertain knowledge.

– Most rule-based expert systems are capable of representing and reasoning with incomplete and uncertain knowledge. Example: fuzzy rule based system

Page 8: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Disadvantages of rule-based expert systems

• Opaque relations between rules – Although individual rules are relatively simple and self-documented,

their logical interactions within the large set of rules may be opaque. – Rule-based systems make it difficult to observe how individual rules

serve the overall strategy.

• Ineffective search strategy– Inference engine applies an exhaustive search through all the rules

during each cycle. – Large set of rules (over 100 rules) can be slow, and large rule-based

systems can be unsuitable for real-time applications.

• Inability to learn– Cannot automatically modify its existing rules or add new ones. – Knowledge engineer still responsible for revising / maintaining the

system.

Page 9: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Rules Techniques• Rule is a knowledge structure that relates some

known information to other information that can be concluded or inferred to be known Procedural Knowledge

• IF … THEN …ELSE

• Ex : IF the ball’s color is blue THEN I like the ball

IF Today’s time is after 10 amAND Today is weekdayAND I am at homeOR My boss called and said that I am late for workTHEN I am late for workELSE I am not late for work

Page 10: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Rules Based System• Use rules to encode the knowledge in the system

• General rule syntax :– if <antecedent> then <consequent>

• if I put my hand on a hot iron, • then it will burn

• if I want my car to stop, • then apply pressure to the brake

• Fact (or assertion) : – a statement that something is true

• I put my hand on a hot iron• I want my car to stop

Page 11: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Components of a Rule Based Expert System

• A rule-based expert system contains :

– Set of rules - stored in knowledge base

– Working memory or database of facts

– Rule interpreter - or inference engine

– User interface

– Explanation module

• These five components are essential for any rule based expert system

Page 12: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Basic structure of a rule-based expert system

Inference Engine

Knowledge Base

Rule: IF-THEN

Database

Fact

Explanation Facilities

User Interface

User

Page 13: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Basic Components of a Rule Based Expert System

• The knowledge base:– Contains the domain knowledge useful for problem solving. – In a rule-based expert system, knowledge is represented as a set

of rules. – Each rule specifies a relation, recommendation, directive, strategy

or heuristic and has the IF (condition) THEN (action) structure. – When the condition part of a rule is satisfied, the rule is said to

fire and the action part is executed

• The database:– Includes a set of facts used to match against the IF (condition)

parts of rules stored in the knowledge base

Page 14: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Basic Components of a Rule Based Expert System

• The inference engine:– Carries out the reasoning – Links the rules given in the knowledge base with the facts

provided in the database

• The explanation facilities:– Enable the user to ask the expert system how a particular

conclusion is reached and why a specific fact is needed. – An expert system must be able to explain its reasoning and

justify its advice, analysis or conclusion.

• The user interface:– Means of communication between a user seeking a solution to

the problem and an expert system.

Page 15: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Additional Components

• In addition to the essential components there can be:

• External databases – Many Expert System shells have ODBC capabilities

• External Progams

• Developer Interface– Includes

• Knowledge base editors• Debugging Aids

Page 16: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Additional structure of a rule-based expert system

User

ExternalDatabase External Program

Inference Engine

Knowledge Base

Rule: IF-THEN

Database

Fact

Explanation Facilities

User Interface DeveloperInterface

Expert System

Expert

Knowledge Engineer

Page 17: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Rule-based system operation

Q : Ball’s color ?

A : Red

IF Ball’s Color is Red THEN I Like the Ball

IF I Like the BallTHEN I Will buy the Ball

IF Ball’s Color is Red THEN I Like the Ball

IF I Like the BallTHEN I Will buy the Ball

Ball’s Color is Red

I Like the Ball

I Will Buy the Ball

Ball’s Color is Red

I Like the Ball

I Will Buy the Ball

Knowledge Base

Working Memory

Page 18: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Inferencing Strategies

Two strategies:

– Forward chaining data driven

– Backward chaining goal driven

Page 19: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Forward Chaining - Data Driven• Forward chaining:

– Is data driven reasoning - the reasoning starts from the known data and proceeds forward with that data

– Start with a set of facts ( i.e. assertions)– Match conditions of rules against items in database– When rule is fired, add consequent to database– Continue until no rules left to fire

Page 20: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Inference Engine cycles via a match-fire procedure

Knowledge Base

Database

Fact: A is x

Match Fire

Fact: B is y

Rule: IF A is x THEN B is y

Page 21: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

E

Database

A B C D

X

Match Fire

Knowledge Base

X & B &E Y

ZY & D

LC

L & M

A X

N

E

Forward chaining

E

X

Database

A B C D

Match Fire

Knowledge Base

X & B & E Y

ZY & D

LC

L & M

A X

N

L

Cycle One

Page 22: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Match Fire

Knowledge Base

Database

A C D E

Y

B

LX

X & B &E Y

ZY & D

LC

L & M

A X

N

Match Fire

Knowledge Base

Database

A C D E

L

B

X

X & B &E Y

ZY & D

LC

L & M

A X

N

Forward chainingCycle Two Cycle Three

Y Z

Page 23: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Forward chaining Example

Rule 1If patient has sore throatAnd suspect a bacterial InfectionThen patient has strep throat

Rule 2If patient temperature > 100Then patient has a fever

Rule 3If patient has been sick over one monthAnd patient has a feverThen we suspect a bacterial Infection

Page 24: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Forward chaining Example

Cycle 1: Rule 2 true -> conclude Patient has a fever

patient temperature = 102patient been sick for two monthspatient has sore throat

Database

patient has a fever

bacterial infection

patient has strep throat

Cycle 3: Rule 1 true -> conclude patient has strep throat

Cycle 2: Rule 3 true -> conclude bacterial infection

Page 25: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Backward Chaining – Goal Driven• In contrast backward chaining:

– goal driven, try to prove a specific goal– Work backwards from a conclusion and try to reach a

set of conditions which establish that conclusion. – Start with a goal and use this to establish a set of

sub-goals.– continue until goal is proved (or disproved), or no

more matches

Page 26: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Backward chaining

• Backward chaining is the goal-driven reasoning.

• In backward chaining, an expert system has the goal (a hypothetical solution) and the inference engine attempts to find the evidence to prove it.

• First, the knowledge base is searched to find rules that might have the desired solution.

• Such rules must have the goal in their THEN (action) parts.

• If such a rule is found and its IF (condition) part matches data in the database, then the rule is fired and the goal is proved.

• However, this is rarely the case.

Page 27: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Backward chaining

• Thus the inference engine puts aside the rule it is working with (the rule is said to stack)

• And sets up a new goal, a subgoal, to prove the IF part of this rule

• The knowledge base is searched again for rules that can prove the subgoal

• The inference engine repeats the process of stacking the rules until no rules are found in the knowledge base to prove the current subgoal

Page 28: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Backward Chaining – Example 1

Goal: Z

Knowledge Base

Pass 1

Database

B C D EA

Z

X & B & E Y

LC

L & M

A X

N

ZY & D

Knowledge Base

Sub-Goal: Y

A B C D E

Y

?

X & B & E YZY & D

LC

L & M

A X

N

Pass 2

Database

Sub-Goal: X

Knowledge Base

A B C D E

X

?

LC

L & M N

X & B & E YZY & D

A X

Pass 3

Database

Page 29: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Backward Chaining – Example 1

Goal: Z

Knowledge Base

A C D E

ZY

B

X

Match Fire

X & B &E YZY & D

LCL & M

A X

N

Pass 6Database

Match FireKnowledge Base

A B C D E

X

Sub-Goal: X

Pass 4

X & B &E Y

ZY & D

LC

L & M

A X

N

Database

Sub-Goal: Y

Match FireKnowledge Base

A C D E

YX

B

X & B &E Y

LCL & M

A X

N

ZY & D

Pass 5Database

Page 30: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Backward Chaining - Example 2 Rule 1

If patient has sore throatAnd suspect a bacterial InfectionThen patient has strep throat

Rule 2If patient temperature > 100Then patient has a fever

Rule 3If patient has been sick over one

monthAnd patient has a feverThen we suspect a bacterial

Infection

Start with same set of facts:patient temperature = 102

patient has been sick for two months

patient has sore throat

But now start with goal

Patient has a strep throat

And try to prove this given the rules and the facts.

Page 31: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Example 2 : Backward Chaining

Strep throat?

Sore throat

bacterial infection

fever

Temp>100

Sick >One month

Page 32: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Choosing between forward and backward chaining?

• If an expert first needs to gather some information and then tries to infer from it whatever can be inferred, choose the forward chaining inference engine.

• However, if your expert begins with a hypothetical solution and then attempts to find facts to prove it, choose the backward chaining inference engine.

Page 33: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Forward Chaining - Evaluation

• Advantages:– Works well when problem naturally begins by

gathering information– Planning, control, monitoring

• Disadvantages:– Difficult to recognise if some evidence is more

important than others– May ask un-related questions

Page 34: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Backward Chaining - Evaluation

• Advantages:– Remains focussed on a goal– Produces a series of questions that are relevant – Good for diagnosis

• Disadvantages:– Will continue to follow a line of reasoning even

when it should switch.

Page 35: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Meta-Knowledge• Meta-knowledge can be simply defined as knowledge about

knowledge.

• Meta-knowledge is knowledge about the use and control of domain knowledge in an expert system.

• In rule-based expert systems, meta-knowledge is represented by meta-rules.

• A meta-rule determines a strategy for the use of task-specific rules in the expert system.

• Example meta-rule:IF the computer will not bootAND the electrical system is operating normallyTHEN use rules concerning the bios

Page 36: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Meta-rules

Page 37: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Forward Chaining - Summary

• Present to future• Antecedent to consequent

– Antecedent determine search

• Data driven• Work forward to find what solutions follow from

facts• No explanation available• Uses:

– Planning, monitoring, control

Page 38: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

Backward Chaining - Summary• Present to past• Consequent to antecedent

– Consequent determine search

• Goal driven• Work backwards to find facts that support

hypothesis.• Explanation available• Uses:

– Diagnosis

Page 39: Rule-Based Expert System Aziz Kustiyo Departemen Ilmu Komputer FMIPA IPB 2011

pustaka

• Yeni Herdiyeni. 2006. Materi kuliah Representasi pengetahuan dan Sistem Inferensia

• Materi lain dari berbagai sumber