0% found this document useful (0 votes)
4 views

FwdandBwd Chain

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

FwdandBwd Chain

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Rule Based Systems

 a set of facts - which are used in a working


memory of a system.
 a set of rules - must be there encompassing
the possible actions to be taken.
 the condition - must be used which is
determining whether a solution is found or
there is no solution at all.
Rule Based Systems

 the rules are used to represent the


knowledge.
 the knowledge can be represented in the
form of IF-THEN rules.
 The rules are made of two parts.
 The IF part (left hand side or LHS) is
called the condition (antecedent)
 THEN (right hand side or RHS) part is
called the action (consequent).
Forward chaining technique

 Initial facts are inputs from the user to be set


into the database (working memory);
 Check LHS of the production rules;
 If the logical condition part of a rule (IF part)
matches, then the rule "fires";
 Execute RHS actions;
 Retract old conditions/facts;
 Input new conditions/facts;
 Do other input-output actions, unifications etc.
 Repeat until no other rules fire.
Matching in forward chaining
 Consider the following simple unifications.
1) likes (murat,x)
likes (murat,pizza)
Unification= {x|pizza}

2) likes (murat,x)
likes (y,pizza)
Unification= {x|pizza, y|murat}

3) likes (murat,x)
likes (x,pizza)
Unification= {fail}
Forward Chaining
 The simple example of the forward chaining
is given below:
 R1: IF A=5 AND B=7 THEN C=10
 R2: IF C=10 AND D=12 THEN E=15
 R3: IF E=15 THEN F=18
 The following facts are present: A=5, B=7,
and D=12
 Use forward chaining to reach the goal F .
Forward Chaining
 Let’s see an example (knowledge base) with a
forward chaining:

 R1: IF X is human THEN X is mammal


 R2: IF X is a mammal THEN X is a life form
 R3: IF X is a life form THEN X is mortal
 Fact: Murat is human.
 Goal: Is Murat a mortal?
Forward Chaining

 RETE algorithm is a pattern matching


algorithm.
 R1: IF A OR B THEN C
 R2: IF D AND E AND F THEN G
 R3: IF C AND G THEN H
 The following facts are presented: B, D, E, F.
 Goal: prove H.
Forward Chaining
Forward Chaining

Advantages and disadvantages of forward


 Forward chaining has the capability of
providing a lot of data from the available few
initial data or facts;
 Forward chaining is a very popular technique
for implementation to expert systems, and
systems using production rules in the
knowledge base.
Backward Chaining
 Backward chaining works in reverse to
forward chaining.
 Starts from the goal and tries to find data to
prove its goal.
 Also called a goal-driven reasoning.
 Search of THEN parts of the given rules.
 if the rule is found and its IF part (condition)
matches the data in the database, then the rule
is executed (fired).
Backward Chaining
 Consider the following rules:
R1: IF A AND B THEN C
R2: IF C THEN E
R3: IF A AND E THEN H
Facts: A, B Goal: Prove H
R3 -> A,E
R2 ->A,E,C
R1 -> A,B,E,C
Backward Chaining Algorithm
 The backward chaining algorithm can be represented
in the following form:
1) The rule that matches the goal is selected.
 IF the condition (IF part) is empty, ask the user for
information.
ELSE
WHILE not end, AND we have the selected rules
DO
Add the conditions of the rules
IF the condition is not met,
THEN put the condition as a goal
to solve
END WHILE.
Backward Chaining
 Take a look at the following rules:
R1: IF customer has the priority
THEN customer gets discount for 20%
R2: IF customer makes a purchase for more than
$200
THEN customer has priority
R3: IF customer is a member of the fan club
THEN customer has priority
 Fact(s) given:
 Customer makes a purchase for more than $200.
 Goal: Will the customer get 20% discount?
Backward Chaining
 Advantages:
 Backward chaining is an excellent tool for
specific types of problems such as diagnosing
and debugging.
 Compare to forward chaining, few data are
asked, but many rules are searched.
Forward and Backward Chaining
Example
The law says that it is a crime for an American
to sell weapons to hostile nations. The country
Nono, an enemy of America, has some missiles,
and all of its missiles were sold to it by Colonel
West, who is American. Prove that Col. West is
a criminal.
Forward and Backward Chaining
Example
Forward and Backward Chaining
Example
Forward and Backward Chaining
Example
Forward Chaining
Example
Forward Chaining
Example
Forward Chaining
Backward Chaining
Backward Chaining
Backward Chaining
Backward Chaining

You might also like