rule-based reasoning

48
UBI 517 Expert Systems 1 Rule-Based Reasoning Introduction

Upload: orestes-kristopher

Post on 01-Jan-2016

142 views

Category:

Documents


0 download

DESCRIPTION

Rule-Based Reasoning. Introduction. Introduction. Rule based systems are going to be discussed with respect to the structure of rules, the two inference methods, Forward and backward reasoning the two basic architectures used to organize rules and perform inferencing. inference networks - PowerPoint PPT Presentation

TRANSCRIPT

UBI 517 Expert Systems 1

Rule-Based Reasoning

Introduction

UBI 517 Expert Systems 2

Introduction

Rule based systems are going to be discussed with respect to the structure of rules, the two inference methods,

• Forward and backward reasoning the two basic architectures used to organize

rules and perform inferencing.• inference networks• pattern matching

UBI 517 Expert Systems 3

What are Rules?

Rules represent knowledge using IF-THEN format

The IF portion of a rule is a condition, (also called a premise or an antecedent), which tests the truth value of set of facts.

If these are found true, the THEN portion of a rule (also called the action, the conclusion or the consequent) is inferred as a new set of facts.

UBI 517 Expert Systems 4

Production Systems and the Rules

The rule based systems are also called production systems.

Simon and Newel developed the production system to model human problem solving.

A production system consists of: An area of memory that is used to track the current

state of the universe under consideration (working memory - database).

A set of production rules :condition - action pairs (knowledge base).

An interpreter (inference engine) recognizes and executes a production whose conditions has been satisfied. This control may be either data driven or goal driven.

UBI 517 Expert Systems 5

Rule-based Inference

Using search techniques and pattern matching, rule based systems automate reasoning methods and provide the logical progression from initial data to the desired conclusion.

Thus the process of problem solving in knowledge based systems is to create a series of inferences that create a “path” between the problem definition and the solution

This series of inferences is progressive in nature and is called an inference chain.

UBI 517 Expert Systems 6

Example

Suppose we are building a knowledge based system for forecasting the weather over the next 12 – 24 hours in Florida during the summer.

RULE 1: IF the ambient temperature is above 900F

THEN the weather is hot.

RULE 2: IF the relative humidity is greater than 65%

THEN the atmosphere is humid

RULE 3: IF the weather is hot and the atmosphere is humid

THEN thunderstorms are likely to develop.

UBI 517 Expert Systems 7

Assume the following facts are true: The ambient temperature is 920F The relative humidity is 70% Rules 1 and 2 are fired and the following new

facts are deduced The atmosphere is humid The weather is hot Which satisfy the premises of the rule 3, causing

a new fact to be derived: Thunderstorms are likely to develop.

UBI 517 Expert Systems 8

A single rule could have been written to reach the same conclusion:

Rule 1-A:IF the ambient temperature is above

900 F andthe atmospheric relative humidity > 65%

THEN thunderstorms are likely to developThere may be other rules that use the facts “The weather

is hot.” and “The atmosphere is humid.”

UBI 517 Expert Systems 9

Rule based systems differ from logic in the following major ideas:1. They are generally non-monotonic2. They accept uncertainty in the deductive

process. Non-monotonic reasoning is the concept by

which derived facts can be retracted when they are no longer true.

UBI 517 Expert Systems 10

The reasoning Process

There are two means of progressing toward conclusions:

1. Start with all the known data and progress to the conclusion (data driven or forward chaining)

2. Select a possible conclusion and prove its validity by looking for supportive evidence (goal driven or backward chaining).

UBI 517 Expert Systems 11

Example

Suppose we have a task of identifying different varieties of fruit.

Knowledge used in identification of fruits can be described through a set of rules.

UBI 517 Expert Systems 12

R01:IF shape = long and color = green or yellow THENfruit = banana

R02:IF shape = round or oblong and diameter > 4 inches THEN fruitclass = vine

R03:IF shape = round and diameter < 4 inches THENfruitclass = tree

R04:IF seedcount = 1 THEN seedclass = stonefruit

R05:IF seedcount > 1 THEN seedclass = multiple

R06:IF fruitclass = vine and color = green THEN fruit=watermelon

R07:IF fruitclass = vine and surface = smooth and color = yellow THEN fruit = honeydew

R08:IF fruitclass = vine and surface = rough and color = tan THEN fruit = cantolope

R09:IF fruitclass = tree and color = orange and seedclass = stonefruit THEN fruit = apricot

R10:IF fruitclass = tree and color = orange and seedclass = multiple THEN fruit = orange

R11:IF fruitclass = tree color = red and seedclass = stonefruit THEN fruit = cherry

R12:IF fruitclass = tree and color = orange and seedclass = stonefruit THEN fruit = peach

UBI 517 Expert Systems 13

R13:IF fruitclass = tree and color = red or yellow or green and

seedclass = multiple THEN fruit = apple

R14:IF fruitclass = tree and color = purple and

seedclass = stonefruit THEN fruit = plum

The knowledge expressed in rules can be pictorially represented by a graph

The graphical format clearly details the connections that exist between the rules via the parameters. AND parameters OR parameters Intermediate parameters

Generally these facts can be derived through the application of some rules rather than being requested directly from the user.

UBI 517 Expert Systems 14

Graphical Representation

UBI 517 Expert Systems 15

Data driven reasoning vs goal driven reasoning

Data driven reasoning is ideally suitable for problem domains involving synthesis such as design, configuration, planning, scheduling. In these cases many but equally acceptable

solutions exist. Goal driven reasoning is ideally suited for

diagnostic problems. In these cases there are small number of

conclusions that can be drawn.

UBI 517 Expert Systems 16

Conflict Resolution

The patterns in working memory are matched against the conditions of the production rules this produces a subset of the productions called the conflict set whose conditions match the patterns in working memory. One of the productions in the conflict set is then selected (conflict resolution) and the production is fired. That is, the action of the rule is performed changing the contents of working memory. After the selected production rule is fired the control cycle repeats with the modified working memory. The process terminates when no rule conditions are matched by the contents of working memory.

UBI 517 Expert Systems 17

Forward Reasoning Inference Process

Step3:Execution

Knowledge

Facts

Ste2:Conflict ResolutionStep1:

Match

Applicable

rules

Selected

rules

New rules

Rules

Facts

New Facts

UBI 517 Expert Systems 18

Forward Reasoning

Rule interpretation in forward reasoning involves the repetition of the basic steps:1. Matching: Find all rules whose premises are true and

mark them as being applicable

2. Conflict Resolution: If more than one rule applies then select the rule with the highest priority (those whose premises have been satisfied).

3. Action: Execute the action of the lowest numbered applicable rule. If none applies then halt.

4. Reset: Reset the applicability of all rules and return to step 1.

UBI 517 Expert Systems 19

Example

Assume the database contains the following facts:

  Diameter = 1 inch  Shape = round Seedcount = 1 Color = red

UBI 517 Expert Systems 20

Trace of Rule Based Forward Reasoning

Execution Cycle Applicable rules Selected rules Derived facts

1 3,4 3 Fruitclass = tree

2 3, 4 4 Seedclass = stonefruit

3 3, 4, 11 11 Fruit = cherry

4 3, 4, 11 - -

UBI 517 Expert Systems 21

Backward Reasoning

Backward reasoning corresponds very closely to depth first search.

The system starts with an empty database of known facts.

A list of goals (or conclusions) is provided for which the system attempts to derive values.

For fruit identification problem initially: Known fact Base: ( ) Goals: (fruit)

UBI 517 Expert Systems 22

Steps in Backward Reasoning

Form a stack initially composed of all the top level goals defined in the system.

Consider the first goal from the stack. Gather all rules capable f satisfying this goal.

For each of these rules:1. If all premises are satisfied, then execute this rule to

derive its conclusion. Remove this goal from the stack and go to step to 2.

2. If any premise of a rule is not satisfied, look for rules that derive the specified value for the parameter used in this premise. If any can be found, consider it as a subgoal and put it on top of the stack, return to step 2.

UBI 517 Expert Systems 23

Steps in Backward Reasoning

3. If step above can’t find a rule to derive the specified value, then query the user for its value and add it to the database. If the premise is satisfied continue with the next premise, if not consider the next rule.

If all rules that can satisfy the current goal have been attempted and all have failed, then this goal remains undetermined. Remove it from the stack and return to step 2. If the stack is empty, announce completion and halt.

UBI 517 Expert Systems 24

Example- Fruit Identification Problem

Suppose that the fruit we are trying to identify is cherry.

The top level goal: fruit Step2: Gather all rules that can derive this

goal Rules 1, 6, 7, 8, 9, 10, 11, 12, 13 and 14

Execution starts with rule1

UBI 517 Expert Systems 25

Example- Fruit Identification Problem

R1: IFshape = long and color = green or yellow THEN

fruit = banana

There is no value for shape in database

The inference mechanism asks the user:

What is the value for shape?

We respond with a value of round which is added to the database.

Known Fact Base: ( (shape = round) )

Based on closed-world assumption rule1 fails. Execution proceeds torule6.

UBI 517 Expert Systems 26

Example- Fruit Identification Problem

R6: IF fruitclass = vine and color = green THEN

fruit = watermelon

R2 and R3 are capable of deriving values for fruitclass. Add this subgoal to the stack

Goals: ( (fruitclass)

(fruit) )R2: IF shape = round and

diameter > 4 inches THEN fruitclass = vineR3: IF shape = round or oblong and

diameter < 4 inches THEN fruitclass = tree

UBI 517 Expert Systems 27

Example- Fruit Identification Problem

Shape = round (from the database)What is the value for the diameter? (queered)

Known Fact Base:( (shape = round)(diameter = 1)

R2 failsR3 derives

(fruitclass = tree) )

UBI 517 Expert Systems 28

Example- Fruit Identification Problem

R7 and R8 failFruitclass = vine

What is the value for color?Respond :red

R9 and R10 fail

R9: IF fruitclass = tree and color = orange and seedclass = stonefruit

THEN fruit = apricot

UBI 517 Expert Systems 29

Example- Fruit Identification Problem

What is the value for seedcount?Respond :1

R11: IF fruitclass = tree and color = red and seedclass = stonefruit

THEN fruit = cherry

Seedclass= ?

R4: IF seedcount = 1 THEN seedclass = stonefruit

UBI 517 Expert Systems 30

Example- Fruit Identification Problem

All premises of R11 are satisfied. R11 is fired and cherry is concluded for the fruit. Known Fact Base:

( ( shape = round)( diameter = 1)( fruitclass = tree)( color = red)( seedcount = 1)( seedclass = stonefruit)( fruit = cherry) )

UBI 517 Expert Systems 31

Rule Based Architectures

There are two basic structures to the knowledge contained within a rule based system:

1. inference networks and2. pattern matching systems.

UBI 517 Expert Systems 32

Inference Networks

Inference network can be represented as a graph in which the nodes represent the parameters that are facts.

Each fact can serve as an antecedent or consequent of a rule.

The rules are represented by the interconnections between the various nodes. This knowledge is used by the inference process to propagate results throughout the network.

UBI 517 Expert Systems 33

Sample Inference Networks

All interconnections between the nodes are known prior to execution Searching to Match facts with premises is minimized Implementation of the inference engine and explanation is

simplified

amb-temp rel-hum

temp-cond hum-cond

storm

R1 R2

UBI 517 Expert Systems 34

Pattern Matching Systems

Pattern matching systems use extensive searches to match and execute the rules, deriving new facts.

Relationships between rules and facts are formed at run-time based on the patterns that match the facts.

A pattern matching system depends on matching the premises of a rule to existing facts to determine which rules have their premises satisfied by the facts and can, therefore execute.

The premises of a rule are patterns. These patterns are satisfied when a search through the database of facts discovers any facts that match them.

UBI 517 Expert Systems 35

Pattern Matching Systems

The typical features included within pattern matching systems are classified as one of the following five types:

1. Pattern connectives – AND, OR2. Wildcard - ? $

Consider the following house example(type color number_of_stories square_footage)(contemporary brown 2 2835)(contemporary ? ? ?sq_footage) ;;a contemporary house with certain square footage, but don’t care about its color or number of stories.

(contemporary $ ?sq_footage) ;; $ represents one or more fields.

UBI 517 Expert Systems 36

Example

CLIPS>(deftemplate person (slot name) (slot eyes) (slot hair))

(defrule find-blue-eyes (person (name ?name)

(eyes blue)) (printout t ?name " has

blue eyes." crlf))

(deffacts people (person (name Jane) (eyes blue) (hair red) ) (person (name Jack) (eyes blue) (hair black) ) (person (name Jeff) (eyes green) (hair brown) ) )

when run Jack has blue eyesJane has blue eyes.

UBI 517 Expert Systems 37

Pattern Matching Systems

3. Field constraints(ranch ~red ? ?sq_footage)(contemporary gray|white ? ?sq_footage)

4. Mathematical operators(defrule subtraction

(numbers ?x ?y) (bind ?answer (- ?x ?y))

(fprintout t “the answer is “ ?answer crlf))

5. Test feature(if ((A = B) x y ))

UBI 517 Expert Systems 38

Example

(defrule big-obj(width ?obj ?w)(length ?obj ?l)(height ?obj ?h)(or

(test (> ?w 50))(test (> ?l 50))(test (> ?h 50)))

(fprintout t ?obj “is large object.” crlf))

UBI 517 Expert Systems 39

Evaluation of the Architectures

Rule based systems that use pattern matchers are flexible and powerful.

They are more applicable for domains where the possible solutions are either unbound or large in numbers, such as design, planning and synthesis.

The use of search to find applicable rules makes pattern matchers inefficient.

Some knowledge based systems (XCON) and shells (OPS5, KEE, CLIPS) are based on pattern matching architectures

UBI 517 Expert Systems 40

Evaluation of the Architectures

Inference networks are useful for domains where the number of different alternative solutions is limited (classification, diagnostic type of problems).

Easier to implement Less powerful because all the relations need to

be known beforehand. Allow explanation of solution easily.

UBI 517 Expert Systems 41

Disadvantages of Rule Based Systems

Major problems with rule based systems are:

1. infinite chaining,2. addition of new, contradictory knowledge,3. modification of existing rules.

UBI 517 Expert Systems 42

Infinite Chaining

Results from the myth“If the system does not work properly, all you need to do is to add more rules.”

R23: IF anemia-risk(?person)THEN anemis-risk(son(?person))

R24: IF anemia-risk(father(?person))THEN anemia-risk(?person)

UBI 517 Expert Systems 43

Addition of New, Contradictory Knowledge

In rule based systems it is possible to introduce new knowledge to fix some problem in the knowledge base, which in turn introduces a contradiction.

R107: IF it is rainingTHEN not(weather is sunny)

R109: IF location is FloridaTHEN not(weather is cloudy)

R24: IF time of day is late afternoonTHEN weather is sunny or

weather is cloudyFACTS:time of day is late afternoon

location is Florida

Conclusion is that the Weather is sunny.

UBI 517 Expert Systems 44

Addition of New, Contradictory Knowledge

R107: IF it is rainingTHEN not(weather is sunny)

R109: IF location is FloridaTHEN not(weather is cloudy)

R96: IF time of day is late afternoonTHEN weather is sunny or

weather is cloudyR120: IF time of day is late afternoon and

location is FloridaTHEN it is raining

FACTS:time of day is late afternoonlocation is Florida

UBI 517 Expert Systems 45

Modifications to Existing Rules

R302: IF organism = strep or

organism = gonorrhea

THEN prescription = penicillin

Some people are allergic to penicillin

R302: IF organism = strep ororganism = gonorrhea

THEN indicated-drug = penicillinR342: IF indicated-drug = penicillin and

unknown(allergy-to = penicillin)THEN ask(allergy-to = penicillin)

R367: IF indicated-drug = penicillin andnot (allergy-to = penicillin)

THEN prescription = penicillin

UBI 517 Expert Systems 46

Modifications to Existing Rules Patients may be allergic to other drugs.

R342 and R367 can be generalized as follows

R342: IF indicated-drug = ?drug andunknown(allergy-to = ?drug)

THEN ask(allergy-to = ?drug)R367: IF indicated-drug = ?drug and

not (allergy-to = ?drug)THEN prescription = ?drug

UBI 517 Expert Systems 47

Disadvantages

Additional disadvantages of rule based systems are:

1. InefficiencyDuring every cycle of inference mechanism each rule is examined to see whether it applies to the current situation

2. OpacityIt is very difficult to examine a developed knowledge base and determine what actions are going to occur when.

3. Coverage of domainSome domains contain numerous variations of inputs which require the storage of tens of thousands of rules.

UBI 517 Expert Systems 48

Advantages of Rule Based Systems

Significant advantages of rule based systems are:

1. Separation of knowledge and control2. Modularity

Each rule is a distinct separate unit of knowledge that can be added, modified or removed independent of the other rules that are present in the knowledge base.

3. UniformityAll knowledge in the system is expressed in exactly the same format.

4. NaturalnessRules are a natural format for expressing knowledge