Reasoning Systems Reasoning Systems Chapter 4 Chapter 4 Dr Ahmed - - PowerPoint PPT Presentation

reasoning systems reasoning systems
SMART_READER_LITE
LIVE PREVIEW

Reasoning Systems Reasoning Systems Chapter 4 Chapter 4 Dr Ahmed - - PowerPoint PPT Presentation

Reasoning Systems Reasoning Systems Chapter 4 Chapter 4 Dr Ahmed Rafea Rafea Dr Ahmed Introduction Introduction In this chapter we will explore how the various In this chapter we will explore how the various knowledge


slide-1
SLIDE 1

Reasoning Systems Reasoning Systems

Chapter 4 Chapter 4

Dr Ahmed Dr Ahmed Rafea Rafea

slide-2
SLIDE 2

Introduction Introduction

  • In this chapter we will explore how the various

In this chapter we will explore how the various knowledge representations can be used for knowledge representations can be used for reasoning reasoning

  • We will explore :

We will explore :

  • Reasoning with rules

Reasoning with rules

  • Forward chaining

Forward chaining

  • Backward chaining

Backward chaining

  • Fuzzy rule systems

Fuzzy rule systems

slide-3
SLIDE 3

Reasoning with Rules Reasoning with Rules-

  • 1

1

If

If-

  • then rules became the most popular form of declarative

then rules became the most popular form of declarative knowledge representation used in AI applications knowledge representation used in AI applications

A knowledge

A knowledge-

  • based system is the common term to describe a rule

based system is the common term to describe a rule-

  • based processing system. It consists of three major elements: a

based processing system. It consists of three major elements: a knowledge base, a working memory (database), and an inference knowledge base, a working memory (database), and an inference engine, which contains the reasoning logic used to process the r engine, which contains the reasoning logic used to process the rules ules

  • r data
  • r data

Given the following rule:

Given the following rule:

If num_wheels = 4 and motor = yes

If num_wheels = 4 and motor = yes

then vehicleTypt = automobile then vehicleTypt = automobile

This rule has two antecedent clause joined by a conjunction (If

This rule has two antecedent clause joined by a conjunction (If num_wheels = 4 and motor = yes ) and a single consequent clause num_wheels = 4 and motor = yes ) and a single consequent clause (then vehicleType = automobile). The rule states a relationshi (then vehicleType = automobile). The rule states a relationship p between clauses and depending on the situation, we can generate between clauses and depending on the situation, we can generate new information or prove the truth of the assertion. new information or prove the truth of the assertion.

For example, if we know that the a vehicle has 4 wheels and a mo

For example, if we know that the a vehicle has 4 wheels and a motor, tor, we can conclude that the vehicleType is an automobile and add th we can conclude that the vehicleType is an automobile and add that at fact to our knowledge base. fact to our knowledge base.

slide-4
SLIDE 4

Reasoning with Rules Reasoning with Rules-

  • 2

2

A rule whose antecedent clauses are all true is said to be trigg

A rule whose antecedent clauses are all true is said to be triggered ered

  • r ready to fire. We fire a rule by asserting the consequent cla
  • r ready to fire. We fire a rule by asserting the consequent clause

use and adding it as a fact to our working memory and adding it as a fact to our working memory

Most rule

Most rule-

  • based systems allow rules to have labels or names such

based systems allow rules to have labels or names such as Rule1: or Automobile: as Rule1: or Automobile:

For example:

For example:

Rule1: If

Rule1: If num_wheels num_wheels = 4 and motor = yes = 4 and motor = yes

then then vehicleTypt vehicleTypt = automobile = automobile

Another enhancement to rule syntax is the addition of a certaint

Another enhancement to rule syntax is the addition of a certainty y

  • factor. This enables us to have a large knowledge base because
  • factor. This enables us to have a large knowledge base because

we cant write rules that applied 100% of the time with 100% we cant write rules that applied 100% of the time with 100%

  • confidence. For example:
  • confidence. For example:

Rule1: if (

Rule1: if (weather_forecast weather_forecast = rain) and ( = rain) and (weather_probability weather_probability > 80%) > 80%)

Then ( Then (chance_of_rain chance_of_rain = high) with CF:90 = high) with CF:90

slide-5
SLIDE 5

Reasoning with Rules Reasoning with Rules-

  • 3

3

Many rule

Many rule-

  • based systems allow functions to be called from the

based systems allow functions to be called from the antecedent clauses. These functions are called sensors. When antecedent clauses. These functions are called sensors. When functions are allowed in the consequent, they are called effecto functions are allowed in the consequent, they are called effectors rs

Rule:2 if

Rule:2 if sensor(mailArrived sensor(mailArrived) then ) then affector(processMail affector(processMail) )

The main problem in rule

The main problem in rule-

  • based systems is as the number of

based systems is as the number of rules grows, the if rules grows, the if-

  • then rules lose their effectiveness from a

then rules lose their effectiveness from a readability perspective . Also as more complex information readability perspective . Also as more complex information comes in, or as things change in the real world, rules that may comes in, or as things change in the real world, rules that may have been true before become false. have been true before become false.

The problem of dealing with changes is called non

The problem of dealing with changes is called non-

  • monotonic

monotonic reasoning reasoning

Most reasoning systems, such as predicate logic, are monotonic,

Most reasoning systems, such as predicate logic, are monotonic, they add information but do not retract information from the they add information but do not retract information from the knowledge base knowledge base

slide-6
SLIDE 6

Reasoning with Rules Reasoning with Rules-

  • 4

4

  • This is a an example for a rule

This is a an example for a rule-base system. It include nine rules base system. It include nine rules Vehicle Rule Base: Vehicle Rule Base: Bicycle: if Bicycle: if vehicleType vehicleType = cycle = cycle And And num_wheels num_wheels = 2 = 2 And motor = no And motor = no Then vehicle = Bicycle Then vehicle = Bicycle Tricycle: if Tricycle: if vehicleType vehicleType = cycle = cycle And And num_wheels num_wheels = 3 = 3 And motor = no And motor = no Then vehicle = Tricycle Then vehicle = Tricycle Motorcycle: if Motorcycle: if vehicleType vehicleType = cycle = cycle And And num_wheels num_wheels = 2 = 2 And motor = yes And motor = yes Then vehicle = Motorcycle Then vehicle = Motorcycle Sportscar Sportscar: if : if vehicleType vehicleType = automobile = automobile And size = small And size = small And And num_doors num_doors = 2 = 2 Then vehicle = Then vehicle = Sportscar Sportscar

slide-7
SLIDE 7

Reasoning with Rules Reasoning with Rules-

  • 5

5

Sedan: if Sedan: if vehicleType vehicleType = automobile = automobile And size = small And size = small And And num_doors num_doors = 4 = 4 Then vehicle = Sedan Then vehicle = Sedan MiniVan MiniVan: if : if vehicleType vehicleType = automobile = automobile And size = medium And size = medium And And num_doors num_doors = 3 = 3 Then vehicle = Then vehicle = MiniVan MiniVan SUV: if SUV: if vehicleType vehicleType = automobile = automobile And size = large And size = large And And num_doors num_doors = 4 = 4 Then vehicle = Then vehicle = Sports_utility_vehicle Sports_utility_vehicle Cycle: if Cycle: if num_wheels num_wheels < 4 < 4 Then Then vehicleType vehicleType = Cycle = Cycle Automobile: if Automobile: if num_wheels num_wheels = 4 = 4 And motor = yes And motor = yes Then Then vehicleType vehicleType = automobile = automobile

slide-8
SLIDE 8

Forward chaining Forward chaining-

  • 1

1

  • Forward chaining is a reasoning process in which a set of rules

Forward chaining is a reasoning process in which a set of rules is is used to derive new facts from an initial set of data. used to derive new facts from an initial set of data.

  • The forward chaining cycle:

The forward chaining cycle:

1. 1.

load the rule base into the inference engine and load any facts load the rule base into the inference engine and load any facts from the from the knowledge base into the working memory knowledge base into the working memory

2. 2.

add any additional data into the working memory add any additional data into the working memory

3. 3.

match the rules against the data in the working memory and deter match the rules against the data in the working memory and determine mine which rules are triggered, meaning that all of their antecedent which rules are triggered, meaning that all of their antecedent clauses are clauses are

  • true. This set is called conflict set
  • true. This set is called conflict set

4. 4.

use the conflict resolution procedure to select a single rule fr use the conflict resolution procedure to select a single rule from the conflict

  • m the conflict

set set

5. 5.

fire the selected rule by evaluating the consequent clause; eith fire the selected rule by evaluating the consequent clause; either update the er update the working memory if it is a fact working memory if it is a fact-

  • generating rule, or call the effector procedure,

generating rule, or call the effector procedure, if it is an action rule. This is referred to as the act step if it is an action rule. This is referred to as the act step

6. 6.

repeat steps 3,4, and 5 until the conflict set is empty repeat steps 3,4, and 5 until the conflict set is empty

slide-9
SLIDE 9

Forward chaining Forward chaining-

  • 2

2

The match phase can take an enormous amount of processing

The match phase can take an enormous amount of processing

  • time. Thus, we would like to only test those rules whose
  • time. Thus, we would like to only test those rules whose

antecedent clauses refer to facts that have been updated by the antecedent clauses refer to facts that have been updated by the prior rule’s firing. This job is done by the “ prior rule’s firing. This job is done by the “Rete Rete” algorithm ” algorithm

In the conflict resolution step we have to make wise decisions i

In the conflict resolution step we have to make wise decisions in n selecting which rule to be fires. We can: selecting which rule to be fires. We can:

Select the first rule in the conflict set

Select the first rule in the conflict set

Select the rule with the highest number of antecedent clauses

Select the rule with the highest number of antecedent clauses

Select the rule that refers to the data that has changed most re

Select the rule that refers to the data that has changed most recently cently

When there is a tie, select a rule randomly

When there is a tie, select a rule randomly

Assign priorities to the rules, and select the one with the high

Assign priorities to the rules, and select the one with the highest priority. est priority. This reduces the number of rules that have to be searched and te This reduces the number of rules that have to be searched and tested in sted in the match phase the match phase

slide-10
SLIDE 10

A Forward Chaining Example A Forward Chaining Example-

  • 1

1

  • we load our vehicles rule base into the inference engine and def

we load our vehicles rule base into the inference engine and define a set of initial ine a set of initial values for variables in the working memory as follows: values for variables in the working memory as follows:

  • Num_wheels

Num_wheels = 4 = 4

  • Motor = yes

Motor = yes

  • Num_doors

Num_doors = 3 = 3

  • Size = medium

Size = medium

  • next we do a match phase to examine the antecedent clauses of ea

next we do a match phase to examine the antecedent clauses of each rule to determine ch rule to determine which ones can be triggered. We have no value for which ones can be triggered. We have no value for vehicleType vehicleType so the first seven rules so the first seven rules are not triggered. The last two rules require values for are not triggered. The last two rules require values for num_wheels num_wheels and motor, so they and motor, so they are candidates. The are candidates. The num_wheel num_wheel is 4 and motor is yes are both true so the Automobile is 4 and motor is yes are both true so the Automobile rule is triggered rule is triggered

  • conflict resolution is easy. We select a single rule and fire it

conflict resolution is easy. We select a single rule and fire it in the act cycle. Firing the in the act cycle. Firing the Automobile rule gives us the following working memory: Automobile rule gives us the following working memory:

  • Num_wheels

Num_wheels = 4 = 4

  • Motor = yes

Motor = yes

  • Num_doors

Num_doors = 3 = 3

  • Size = medium

Size = medium

  • vehicleType

vehicleType = automobile = automobile

slide-11
SLIDE 11

A Forward Chaining Example A Forward Chaining Example-

  • 2

2

  • now we are ready for our next

now we are ready for our next inferencing inferencing cycle. We do match against the

  • cycle. We do match against the

rules to determine which one to be fires. Now that the rules to determine which one to be fires. Now that the vehicleType vehicleType has a has a value the first seven rules are candidates value the first seven rules are candidates

  • Only single rule will have all of its antecedent clauses satisfi

Only single rule will have all of its antecedent clauses satisfied, the ed, the MiniVan MiniVan: :

  • rule. So we fire the
  • rule. So we fire the MiniVan

MiniVan rule and add the new information that vehicle = rule and add the new information that vehicle = MiniVan MiniVan to the working memory to the working memory

  • Num_wheels

Num_wheels = 4 = 4

  • Motor = yes

Motor = yes

  • Num_doors

Num_doors = 3 = 3

  • Size = medium

Size = medium

  • vehicleType

vehicleType = automobile = automobile

  • Vehicle =

Vehicle = MiniVan MiniVan

  • We match again to find that the only rule that is triggered is t

We match again to find that the only rule that is triggered is the he MiniVan MiniVan: :

  • rule. However because it has already fired we don’t add it to th
  • rule. However because it has already fired we don’t add it to the conflict set

e conflict set

slide-12
SLIDE 12

Backward Chaining Backward Chaining

  • In backward chaining a consequence is evaluated and then we go

In backward chaining a consequence is evaluated and then we go backward through the rule. It uses rules to answer questions abo backward through the rule. It uses rules to answer questions about ut whether a clause is true or not. whether a clause is true or not.

  • The backward chaining cycle:

The backward chaining cycle:

1. 1.

load the rule base into the inference engine and load any facts load the rule base into the inference engine and load any facts from the from the knowledge base into the working memory knowledge base into the working memory

2. 2.

Add any additional data into the working memory Add any additional data into the working memory

3. 3.

specify a goal variable for the inference engine to find specify a goal variable for the inference engine to find

4. 4.

find the set of rules that refer to the goal variable in a conse find the set of rules that refer to the goal variable in a consequent clause. Put quent clause. Put each rule on the goal stack each rule on the goal stack

5. 5.

if the goal stack is empty, halt if the goal stack is empty, halt

6. 6.

take the top rule off the goal stack. take the top rule off the goal stack.

7. 7.

try to prove that the rule is true by testing all the antecedent try to prove that the rule is true by testing all the antecedent clauses to see if clauses to see if they are true, as follows: they are true, as follows:

  • If the clause is true, go on to the next antecedent clause

If the clause is true, go on to the next antecedent clause

  • If the clause is false, pop the rule off the stack and go to ste

If the clause is false, pop the rule off the stack and go to step 5 p 5

  • If the truth value is unknown, go to step 4

If the truth value is unknown, go to step 4

  • If all antecedent clauses are true, fire the rule, pop the rule

If all antecedent clauses are true, fire the rule, pop the rule off the stack, and go to

  • ff the stack, and go to

step5 step5

slide-13
SLIDE 13

A Backward Chaining Example A Backward Chaining Example-

  • 1

1

  • This is the rule that must be satisfied:

This is the rule that must be satisfied:

  • MiniVan

MiniVan: if : if vehicleType vehicleType = automobile = automobile

And size = medium And size = medium And And num_doors num_doors = 3 = 3 Then vehicle = Then vehicle = MiniVan MiniVan

  • we start with an empty working memory and we check to see if ve

we start with an empty working memory and we check to see if vehicle = hicle = MiniVan MiniVan is already true. If not, then all the antecedent clauses of the is already true. If not, then all the antecedent clauses of the MiniVan MiniVan rule: must be true to conclude that the vehicle is rule: must be true to conclude that the vehicle is MiniVan

  • MiniVan. So we test if the

. So we test if the vehicleType vehicleType = automobile is true. The = automobile is true. The vehicleType vehicleType has no value, so we look has no value, so we look for a rule that has the for a rule that has the vehicleType vehicleType = automobile, and we find the = automobile, and we find the Automobile: rule below: Automobile: rule below:

  • Automobile: if

Automobile: if num_wheels num_wheels = 4 = 4 And motor = yes And motor = yes then then vehicleType vehicleType = automobile = automobile

  • This is backward chaining, we started with the

This is backward chaining, we started with the MiniVan MiniVan: rule, and, in the : rule, and, in the course of proving that true, we chained to another rule, the Aut course of proving that true, we chained to another rule, the Automobile: rule

  • mobile: rule
slide-14
SLIDE 14

A Backward Chaining Example A Backward Chaining Example-

  • 2

2

Focused now on the Automobile: rule we need to know if

Focused now on the Automobile: rule we need to know if num_wheels num_wheels = 4. we look in the working memory and see that it = 4. we look in the working memory and see that it has no value. We look for a rule that has the has no value. We look for a rule that has the num_wheels num_wheels = 4 as = 4 as a consequent. There are none. So we ask the user to provide an a consequent. There are none. So we ask the user to provide an

  • answer. And he says that there are four wheels on the vehicle.
  • answer. And he says that there are four wheels on the vehicle.

The first antecedent rule is true, so we move to the second The first antecedent rule is true, so we move to the second clause, motor = yes. clause, motor = yes.

we check the working memory, and the motor has no value. We

we check the working memory, and the motor has no value. We again ask the user to provide a value. The user answers that the again ask the user to provide a value. The user answers that the vehicle has a motor. Now that both clauses are true, we proved vehicle has a motor. Now that both clauses are true, we proved that the Automobile rule is true, and we set the that the Automobile rule is true, and we set the vehicleType vehicleType=automobile. =automobile.

slide-15
SLIDE 15

A Backward Chaining Example A Backward Chaining Example-

  • 3

3

  • Our working memory now contains the following fact:

Our working memory now contains the following fact:

  • Num_wheels

Num_wheels = 4 = 4

  • motor = yes

motor = yes

  • VehicleType

VehicleType = automobile = automobile

  • back to our original rule. We know the first antecedent clause

back to our original rule. We know the first antecedent clause is true. We is true. We need next to find values for the size and need next to find values for the size and num_doors num_doors. Using the same . Using the same procedure, we end up asking the user for these values. And he in procedure, we end up asking the user for these values. And he indicates that dicates that the size=medium and the size=medium and num_doors num_doors=3. all the antecedent clauses have been =3. all the antecedent clauses have been satisfied, so we can conclude that the vehicle is a satisfied, so we can conclude that the vehicle is a MiniVan

  • MiniVan. Our final memory

. Our final memory contains: contains:

  • Num_wheels

Num_wheels = 4 = 4

  • motor = yes

motor = yes

  • VehicleType

VehicleType = automobile = automobile

  • Size = medium

Size = medium

  • Num_doors

Num_doors = 3 = 3

  • Vehicle =

Vehicle = MiniVan MiniVan

slide-16
SLIDE 16

Fuzzy Rule System Fuzzy Rule System-

  • 1

1

  • Fuzzy logic has provided an alternative to Boolean

Fuzzy logic has provided an alternative to Boolean logic logic-

  • based system.

based system.

  • It is not just probability in a different guise. Probability

It is not just probability in a different guise. Probability theory deals with the likelihood that an event will occur theory deals with the likelihood that an event will occur

Tomorrow there is a 50% chance that it will rain,

Tomorrow there is a 50% chance that it will rain,

  • While fuzzy logic deals with the degree to which an

While fuzzy logic deals with the degree to which an event will occur, event will occur,

Tomorrow it will rain hard

Tomorrow it will rain hard

  • Unlike Boolean logic, fuzzy logic deals with truth values

Unlike Boolean logic, fuzzy logic deals with truth values which range continuously from 0.0 to 1.0. Therefore, which range continuously from 0.0 to 1.0. Therefore, something could be half true (0.5) or very likely true something could be half true (0.5) or very likely true (0.9) (0.9)

slide-17
SLIDE 17

Fuzzy Rule System Fuzzy Rule System-

  • 2

2

This is a fuzzy rule to control the speed of the motor of a fan:

This is a fuzzy rule to control the speed of the motor of a fan:

Motor Fuzzy Rule Base

Motor Fuzzy Rule Base

SlowRule SlowRule: if temp is cold : if temp is cold And humidity is pleasant And humidity is pleasant Then motor is slow Then motor is slow MediumRule MediumRule: if temp is medium : if temp is medium And humidity is comfortable And humidity is comfortable Then motor is medium Then motor is medium FastRule FastRule: if temp is hot : if temp is hot And humidity is sticky And humidity is sticky Then motor is fast Then motor is fast VeryFastRule VeryFastRule: if temp is very hot : if temp is very hot And humidity is very sticky And humidity is very sticky Then motor is very fast Then motor is very fast

slide-18
SLIDE 18

Fuzzy Rule System Fuzzy Rule System-

  • 3

3

Reasoning in fuzzy rule systems is a forward chaining procedure.

Reasoning in fuzzy rule systems is a forward chaining procedure. The initial data values are The initial data values are fuzzified fuzzified, that is, turned into fuzzy , that is, turned into fuzzy values using the membership functions. Instead of the match values using the membership functions. Instead of the match and conflict resolution phase, all rules are evaluated (rule can and conflict resolution phase, all rules are evaluated (rule can be be true to some degree 0.0 to 1.0). true to some degree 0.0 to 1.0).

There are two methods of

There are two methods of inferencing inferencing in fuzzy rule systems, the in fuzzy rule systems, the min min-

  • max approach and the fuzzy additive approach.

max approach and the fuzzy additive approach.

In the min

In the min-

  • max approach the following steps are done:

max approach the following steps are done:

The antecedent truth values are combined using fuzzy logic opera

The antecedent truth values are combined using fuzzy logic operators tors (and), which takes the minimum value of the antecedent clauses. (and), which takes the minimum value of the antecedent clauses.

the consequent fuzzy set is limited to the minimum of the antece

the consequent fuzzy set is limited to the minimum of the antecedent dent truth value or multiplied by the antecedent truth value truth value or multiplied by the antecedent truth value

The output fuzzy set is computed by taking the maximum of the

The output fuzzy set is computed by taking the maximum of the minimized consequent fuzzy set from each rule. minimized consequent fuzzy set from each rule.

slide-19
SLIDE 19

Fuzzy Rule System Fuzzy Rule System-

  • 4

4

In the additive

In the additive approch approch, the following steps are done: , the following steps are done:

  • The antecedent truth values are combined using fuzzy logic opera

The antecedent truth values are combined using fuzzy logic operators (and), tors (and), which takes the minimum value of the antecedent clauses. which takes the minimum value of the antecedent clauses.

  • It limits the consequent fuzzy set as in the

It limits the consequent fuzzy set as in the minmax minmax method. method.

  • The output fuzzy set is computed by adding the consequent fuzzy

The output fuzzy set is computed by adding the consequent fuzzy set from each set from each rule and limiting it to a maximum value of 1.0. This insures th rule and limiting it to a maximum value of 1.0. This insures that all the rules in at all the rules in the fuzzy set can contribute something to the final result set. the fuzzy set can contribute something to the final result set.

The methods for limiting the height of the consequent based on

The methods for limiting the height of the consequent based on the minimum truth value of the antecedents (minimum the minimum truth value of the antecedents (minimum correlation), truncates the consequent fuzzy set to the minimum correlation), truncates the consequent fuzzy set to the minimum

  • f the antecedent’s truth value, while the product correlation,
  • f the antecedent’s truth value, while the product correlation,

maintains the shape of the consequent fuzzy set by scaling it by maintains the shape of the consequent fuzzy set by scaling it by the truth value of the antecedent the truth value of the antecedent

After the fuzzy set is computed using one of the correlation and

After the fuzzy set is computed using one of the correlation and inferencing inferencing techniques, the fuzzy set is techniques, the fuzzy set is defuzzified defuzzified. .

slide-20
SLIDE 20

Fuzzy Rule System Fuzzy Rule System-

  • 5

5

  • There are two techniques for

There are two techniques for defuzzification defuzzification, , centroid centroid and maximum height. and maximum height.

  • In

In centroid centroid defuzzification defuzzification, the center of gravity of the , the center of gravity of the fuzzy set is found by computing a weighted mean of fuzzy set is found by computing a weighted mean of the fuzzy set. This means that half of the area under the the fuzzy set. This means that half of the area under the membership function is above the membership function is above the centroid centroid point, and point, and the other half is below it. the other half is below it.

  • The maximum height finds the center point in the

The maximum height finds the center point in the region with the maximum truth value. Consequently if region with the maximum truth value. Consequently if the fuzzy set came to a plateau, the the fuzzy set came to a plateau, the defuzzified defuzzified value value would be the center of the plateau would be the center of the plateau