Inference Engine
Inference Engine
It is important to understand about inference engine before learning about forward and backward chaining. An
inference engine is a system which applies logical reasoning to draw conclusions and solve a problem based on
given facts.
It consists of algorithms that bring useful info from the knowledge base and use it to conclude new facts to the user's
issues. The inference engine uses two mechanisms, forward and backward chaining, in order to extract data from the
knowledge base.
Let us now discuss both of them one by one.
Forward Chaining
Forward chaining is a data-driven reasoning approach used by inference engines. It starts with given facts and
applies rules to derive new conclusions or facts from them. The engine keeps applying the rules until it reaches a
conclusion or cannot apply any more rules. It is based on logical prediction methodology. One of its examples is the
prediction of trends in the stock market.
Characteristics
It is a bottom-up approach.
It starts with the initial state and progresses toward the end state to reach a conclusion.
Rules:
1. If a person is a coder, it means he enrolled in a college.
2. If a person is enrolled in a college and studies computer science, it means he learned DSA.
Now, we will use forward chaining to derive a conclusion based on given facts and rules.
Step 1: If a person is a coder, it means he enrolled in a college.
FOL: ∀x (coder(x) → Enrolled_IN(x, college))
Step 2: If a person is enrolled in a college and studied computer science, it means he learned DSA.
FOL: ∀x,y (Enrolled_In(x, college) ∧ studies(x, computer science) → Learned_DSA(x))
It is suited for expert systems where an application needs more control and monitoring.
It should be applied when there is a very few numbers of initial states available.
Disadvantages
Below are a few cons of forward chaining in AI.
The inference engine generates information without knowing which data is more relevant and useful to reach
the final result.
The inference engine may fire many unnecessary rules to reach the goal state.
The user may need to enter a lot of information to reach the goal state.
It is a goal-driven approach, as we start from the goal state and reach the initial state.
Rules:
1. If a person is a coder, it means they enrolled in a college.
2. If a person is enrolled in a college and studies computer science, it means they learned DSA.
Now, we will use backward chaining to check whether Sohail learns DSA or not.
Step 1: If a person is enrolled in a college and studies computer science, it means they learned DSA. (Rule 1)
FOL: ∀x,y (Enrolled_In(x, college) ∧ studies(x, computer_science) → Learned(x, DSA))
Now, we need to check if Sohail is enrolled in a college and studies computer science.
Step 2: If a person is a coder, it means they enrolled in a college. (Rule 2)
FOL: ∀x (coder(x) → Enrolled_In(x, college))
From the above, we can conclude that Sohail is enrolled in a college (from Rule 1) and studies computer science.
Therefore, using the backward chaining, we can conclude that Sohail learned DSA.
Advantages
Below are a few pros of backward chaining in AI.
In backward chaining, the process terminates once the fact is verified.
It only considers the relevant part of the data and eliminates unnecessary information.
It only tests for the required rules and neglects the others.
In forward chaining, the decision is In backward chaining, the process starts from
taken based on given data. the goal state and reaches the initial state.
Its only goal is to reach a conclusion. Its goal is to validate the facts.
It operates in the forward direction It operates in the backward direction (goal state
(initial state to goal state). to initial state).
It may include multiple ASK questions Backward chaining includes fewer ASK
from the information source. questions compared to forward chaining.