Forward chaining and backward chaining are two approaches for reasoning using rules in an expert system. Forward chaining applies rules to existing facts to infer new facts, proceeding iteratively until no more rules can fire. Backward chaining starts with a goal or hypothesis and works backwards from the conclusion of rules to find facts that support the goal. The appropriate approach depends on factors like whether the problem is data-driven or goal-driven, the size and relationships of the rule set and facts, and performance requirements. Both techniques have tradeoffs and combining them may provide the best solution in some cases.
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
FORWARD CHAINING AND BACKWARD CHAINING SYSTEMS IN ARTIFICIAL INTELIGENCE
1. FORWARD CHAINING AND BACKWARD CHAINING SYSTEMS IN
ARTIFICIAL INTELIGENCE
BY
Johnleonard Onwuzuruigbo
INTRODUCTION
The inference engine is a computerprogram designedto produce
reasoning on rules. In order to produce reasoning, it should be based on
logic.With logic,the engine is able to generate new information from the
knowledge contained in the rule base and data to be processed.The engine
has two ways to run: batch or conversational. In batch, the expert system
has all the necessary data to process from the beginning. For the user, the
program works as a classicalprogram:he provides data and receives
results immediately. Reasoning is invisible. The conversational method
becomes necessary when the developer knows he cannot ask the user
for all the necessary data at the start, the problem being too complex.The
software must "invent" the way to solve the problem, request the missing
data from the user, gradually approaching the goal as quickly as possible.
The result gives the impressionof a dialogue led by an expert. To guide a
dialogue, the engine may have several levels of sophistication: "forward
chaining" and "backward chaining".
Forward Chaining System
The standard definition of a forward-chaining
system states that the system operates by
repeating the following sequence of operations
as shown in the diagram.
Examine the rules to find one who's IF
part is satisfied by the current contents of
Working Memory.
Fire the rule by adding to Working
Memory the facts that are specified in the
rules THEN part.
(The THEN part may perform other actions as
well, but that can also be ignored for now.)
This control cycle continues until no rules have satisfied IF parts.
2. An inference engine using forward chaining searches the inference rules
until it finds one where the IF clause is known to be true. When found it can
conclude,or infer, the THEN clause, resulting in the addition of new
information to its dataset. In other words, it starts with some facts and
applies rules to find all possible conclusions.Therefore,forward chaining
system is also known as Data Driven system.
In a ForwardChainingsystem:
Process of moving from the “if” patterns to the “then “patterns.
Wheneveran “if” pattern is observed to match a Fact: the antecedentis
satisfied.
Wheneverthe entire “if” patterns of a rule are satisfied ---> the rule is
triggered.
A triggered rule establishes a new Fact ---> it is fired
Example of a Forwardchainingsystem process
Rules
R1: IF hot AND smoky THEN ADD fire
R2: IF alarm_beeps THEN ADD smoky
R3: If fire THEN ADD switch_on_sprinklers
Facts
F1: alarm_beeps [Given]
F2: hot [Given]
F3: smoky [from F1 by R2]
F4: fire [from F2, F4 by R1]
F5: switch_on_sprinklers [from F4 by R3]
In a forward chaining system:Facts are held in a working memory
Condition-action, rules representactions to take when specifiedfacts occur
in working memory. Typically the actions involve adding or deleting facts
from working memory.
Properties of forward chaining System
i. Note that all rules which can fire do fire.
ii. Set of rules that can fire is known as conflict set.
iii. Decisionabout which rule to fire — conflictresolution.
BackwardChainingSystem
3. Backward-chaining systems try to satisfy
the goals in the goal stack. They do this by
finding rules that can conclude the
information needed by the goal, and trying
to make the If parts of those rules
satisfied.
1. Check the conclusions of the rules to
find all rules that can satisfy the top goal
on the stack.
2. Processthese rules one at a time:
a. Evaluate the conditions in the rules IF
part one at a time:
If the condition is currently unknown
(if there is not enough information
currently known to determine whether the condition is satisfied)push
a goal to make that condition known, and recursively invoke the
system.
If the condition is known to be unsatisfied then the system continues
with the loop at Step 2.
If it was not possibleto determine whether the condition was satisfied
then system continues with the loop at Step 2.
b. If all the conditions in the selectedrule are satisfied,add to Working
Memory the facts specifiedin the THEN part of the rule, pop the goal off
the stack, and return from this invocation of the system.
The system terminates with success when the goal stack is empty.
In a Backward chaining system
Form a hypothesis.
Use the antecedent-consequentrules to work backward towards
hypothesis-supporting Facts.
An inference engine using backward chaining would search the inference
rules until it finds one which has a THEN clause that matches a desired
goal. If the IF clause of that inference rule is not known to be true, then it is
added to the list of goals (in orderfor goal to be confirmed it must also
provide data that confirms this new rule). In other words, this approach
starts with the desired conclusionand works backward to find supporting
facts. Therefore,it is also known as Goal-Driven System.
4. In a Backward chaining system:Same rules/facts may be processed
differently,using backward chaining interpreter.
Backward chaining means reasoning from goals back to facts. The idea is
that this focusesthe search.
Checking hypothesis
“Should I switch the sprinklers on?”
Example of Backwardchainingsystem
Hypothesis (“Should I switch the sprinklers on?”)
Rules:
R1: IF hot AND smoky THEN fire
R2: IF alarm_beeps THEN smoky
R3: If fire THEN switch_on_sprinklers
Facts:
F1: hot
F2: alarm_beeps
Goal:
Switch on sprinklers
Comparisonbetween Forward and backward Chain system
i. The exploration of knowledge has differentmechanisms in forward
and backward chaining. Backward chaining is more focusedand tries
to avoid exploring unnecessary paths of reasoning. Forward chaining,
on the other hand is like an exhaustive search (Forward chaining goes
to the extreme to get the all rules fired).
ii. Backward chaining systems are good for diagnostic and classification
tasks, but they are not good for planning, design,process monitoring,
and quite a few other tasks. Forward chaining systems can handle all
these tasks.
iii. Forward chaining system, includes writing rules to manage sub goals.
Whereas,backward chaining systems automatically manage sub
goals .
iv.Lots of output Hypothesis + Lots of data up front => Use Forward
Chaining Fewer output Hypothesis + Must query for data=>
5. v. In backward chaining, the search is goal directed,so rules can be
applied that are necessaryto achieve the goal. But in forward chaining
the whole process is not directed towards goal, so when to stop the
rules in not known.
vi.If the facts that has to be established lead to a large number of
conclusion, but the number of ways to reach that particular conclusion
is small, then there is more information out rather than information in,
then backward chaining should be used.On the other hand, if the
number of ways to reach a particular conclusion is large, but the
number of conclusions likely to be reach using the facts is small, then
forward chaining is preferred.
Finally
The only way to know how a rule will behave is to profile it and understand
the business case. Many people make the mistake of thinking a rule engine
will magically solve their problems. Writing high performance rules is not
easy or intuitive. The bestway to build efficientapplications using rule
engines is to take the time to learn how each approach works and use
both techniques. Although it increases the learning curve, the choice
between forward and backward chaining isn't something that can be
summed up in 2-3 sentences.It's crucial to considerthe intent of the rule,
size of the dataset and performancerequirements.