Forward chaining vs backward chaining

Chaining is a method in which we apply logical rules in a sequential manner to our data to derive meaningful conclusions.

Chaining process
Chaining process
  • Input facts are the initial facts provided to the system.

  • The logical base contains rules that the system uses for reasoning.

  • The inference engine performs logical reasoning and makes inferences based on input facts and rules.

  • Derived conclusions are the conclusions that we infer in the inference engine.

  • The final result is the ultimate result obtained from the whole process.

Application of chaining in AI

In artificial intelligence, we derive conclusions by applying a set of predefined rules on data. It is used in expert systems, knowledge-based systems, and inference engines to automate decision-making processes. It enables the system to process and analyze data, apply relevant rules, and derive new information or conclusions.

Types of chaining

There are two types of chaining: forward and backward. In this Answer, we will discuss these types in detail.

Forward chaining

Forward chaining is a bottom-up approach in which we move in a forward direction from collecting facts to finding our final result.

In this approach, we adhere to the following steps:

  1. We first collect the facts used for our task.

  2. We identify the rules and logic that match our data.

  3. We apply the logical rules to our data.

  4. We collect the conclusion and inferences derived from our data.

  5. We deduce a final result of our process.

Forward chaining
Forward chaining

Example

Let's suppose we have to use forward chaining in a medical center. In this specific case, we have the following predefined rules in our inference engine:

Rule 1: If a patient has a fever, they have a viral infection.

Rule 2: If a patient has a cough, they have a respiratory infection.

We adhere to the following steps:

  1. We identify two facts: The patient has a fever and a cough.

  2. We match the patient facts with the rules present in our logical base.

  3. Our rules match the patient's facts. They have a fever, so we infer it is a viral infection. Secondly, they have a cough, so we infer it is a respiratory infection.

  4. We add our conclusions (viral infection) and (respiratory infection) to the derived conclusions.

  5. Our final outcome is that our patient has a viral and respiratory infection.

Example of forward chaining
Example of forward chaining

Backward chaining

Backward chaining is a top-down approach in which we first decide the final outcome we want to achieve and then work in a backward direction to fulfill it.

In this approach, we adhere to the following steps:

  1. We first specify our end goal.

  2. We check if selected rules can be satisfied based on the facts available.

  3. We select the rules that align with conclusions to achieve our goal.

  4. We evaluate the goal based on the available facts and supported premises.

  5. We obtain the facts that help us achieve our end goal.

Backward chaining
Backward chaining

Example

Let's suppose we use backward chaining in a medical center. In this specific case, we have the following predefined rules in our inference engine:

Rule 1: If a patient has a fever, they have a viral infection.

Rule 2: If a patient has a cough, they have a respiratory infection.

We adhere to the following steps:

  1. We start with the final result, which is to diagnose the patient's condition.

  2. We look for rules whose conclusions match the goal: the patient has a viral and respiratory infection.

  3. Rule 1 matches the goal, which is the viral infection, and Rule 2 matches the goal, which is the respiratory infection. Therefore, we must examine its premises (fever and sore throat).

  4. We check if the premises can be satisfied based on the available facts. In this case, the patient has a high fever and cough, so the premises are satisfied.

  5. We conclude the premises are satisfied, and we find the facts that the patient has a fever and cough.

Example of backward chaining
Example of backward chaining

Summary

Forward chaining

Backward chaining

Forward direction

Backward direction

Data driven approach

Goal driven approach

Bottom-up approach

Top-down approach

Uses breadth for search

Uses depth for search

Starting point is the fact

Starting point is the goal

Ending point is the goal

Ending point is the fact

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved