100% found this document useful (1 vote)
496 views

21-22 KR Using Rules-Forward and Backward Reasoning

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
496 views

21-22 KR Using Rules-Forward and Backward Reasoning

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Module 4

Knowledge Representation
Using Rules
Representing Knowledge Using Rules
• Procedural vs. Declarative Knowledge
• Logic Programming
• Forward vs. backward reasoning
Introduction
• Humans are best at understanding, reasoning, and interpreting knowledge.
• Human knows things, which is knowledge and as per their knowledge they perform various
actions in the real world. But how machines do all these things comes under knowledge
representation and reasoning.
• One way to represent knowledge is by using rules that express what must happen or what
does happen when certain conditions are met.
Rules : assertions given in implicational form.
Facts : assertions that represent domain specific knowledge.
• Rules are usually expressed in the form of IF . . . THEN . . . statements, such as:
IF A THEN B
• This can be considered to have a similar logical meaning as the following: A→B
A is called the antecedent and B is the consequent in this statement-
IF <antecedent> THEN <consequent>
Rule Based Systems
• A system whose knowledge base is represented as a set of rules and facts is called a Rule
Based System Rule-based systems are based on rules that say what to DO, given various
conditions.
IF <this is the case> THEN <do this>,
• A rule-based system consists of a collection of IF-THEN rules, a collection of facts, and
some interpreter controlling the application of the rules, given the facts.
• When the antecedent part is NULL the Rule becomes a fact.
• Rules are normally represented as Horn Clause.
• A rule is triggered when all the antecedents evaluate to true.
• A rule is fired when the action stated in the consequent part or the inference related to
the consequent part is inferred / taken.
Example Rules
• If it rains today the roads will be wet today
Rains(today) à Wet-road (today)
If Rains(today) Then Wet-road(today)

If Rains (today) and Not-covered (roads)


Then Wet-road (today)

-- Facts are also generated


When the antecedent part is NULL the Rule becomes a fact.
Rule based Systems
• The classic methods of representing knowledge use either rules or logic.
• Rules are often used in rule-based expert systems, and are either specified explicitly by a
knowledge engineer (usually through a process called ‘knowledge acquisition’ from a human
expert), or they are derived from data using a machine learning or data mining algorithm.
• Rules use a logic-based form for reasoning. Logic is the use of symbolic and mathematical
techniques for deductive reasoning,
Rule-based system architecture

Control Scheme (Interpreter)

Condition-Action Rules Database of


Facts
R1: IF hot AND smoky THEN ADD fire
R2: IF alarm_beeps THEN ADD smoky alarm_beeps
R3 IF fire THEN ADD switch_on_sprinklers hot
Inference Machine
• A machine that implements strategies to utilize the knowledge base and derive new
conclusions from it.
• The execute state fires the rules once all its antecedents match.
• Essentially, the function of the execute state can be thought of as searching a path to the
goal in a search space.
Automata of
Inference machine
Conflict
Fact and Rule Base Resolution
R’

Match Execute
Goal Check
Declarative and Procedural Knowledge
• Declarative knowledge involves knowing THAT something is the case –
• that J is the tenth letter of the alphabet,
• that Paris is the capital of France.
• Declarative knowledge is conscious; it can often be verbalized.
• Metalinguistic knowledge, or knowledge about a linguistic form, is declarative
knowledge.

Procedural knowledge involves knowing HOW to do something - ride a bike, for


example. - We may not be able to explain how we do it.
• Procedural knowledge involves implicit learning, which a learner may not be
aware of, and may involve being able to use a particular form to understand or
produce language without necessarily being able to explain it.
Declarative Knowledge
Declarative representation
• Knowledge is specified but the use is not given.
• Need a program that specifies what is to be done to the
knowledge and how.
• Example:
• Logical assertions and Resolution theorem prover
• A different way: Logical assertions can be viewed as a
program, rather than as data to a program.
• Logical assertions = Procedural representations of
knowledge
• Procedural representation
• –The control information that is necessary to use the knowledge is
considered to be embedded in the knowledge itself.
• –Need an interpreter that follows the instructions given in the
knowledge.
• –The real difference between the declarative and the procedural views of
knowledge lines in where control information resides.
Logic Programming (Programming in Prolog)
• Logic Programming is a programming language paradigm on which logical assertions
are viewed as programs.
• PROLOG program (PROgramming LOGic) is described as a series of logical assertions
each of which is a Horn Clause.
• Prolog program = {Horn Clauses}
• Horn clause: clause that has at most one positive literal
• p, ¬pVq, and p ®q are horn clauses.
• The fact that PROLOG programs are composed only of Horn Clauses and not of arbitrary
logical expressions has two important consequences.
• Because of uniform representation a simple & effective interpreter can be written.
• The logic of Horn Clause systems is decidable
• Control structure:
Prolog interpreter = backward reasoning + depth-first with backtracking
Logic(FOL) Vs Prolog
1. In logic, variables are explicitly quantified,
In prolog, Quantification is provided implicitly by the way the variables are
interpreted.
• Variables: begin with UPPERCASE letter
• Constants: begin with lowercase letters or number
2. In logic, there are explicit symbols for and( Ù) or (Ú).
In Prolog, there is an explicit symbol for AND (,) , OR (;)
disjunction must be represented as a list of alternative statements
3. In logic, “p implies q” is written as p ®q ,
In Prolog “p implies q” is written as q :- p.
Representation in logic: Representation in PROLOG:
"x: pet(x) Ù small(x) ® apartmentpet(x) apartmentpet(X) :- pet(X) , small(X).
pet(X) :- cat(X).
"x : cat(x) Ú dog(x) ® pet(x)
pet(X) :- dog(X).
"x : poodle(x) ® dog(x) Ù small(x) dog(X) :- poodle(X).
poodle(fluffy) small(X) :- poodle(X).
poodle(fluffy).

• An apartment pet is a pet that is small


• Dog is a pet
• Cat is a pet
Forward vs. Backward
Reasoning
Introduction to Expert System
• An expert system is a computer application that uses rules, approaches, and facts to
provide solutions to complex problems. Ex: MYCIN and DENDRAL
• Basic components: user interface, inference engine, and knowledge base.
• User interface - users to interact with the expert system and domain-specific knowledge
is stored in the knowledge base.
• Inference engine - logical rules are applied to the knowledge base to get new
information or make a decision. The backward and forward chaining techniques are used
by the inference engine as strategies for proposing solutions or deducing information in
the expert system.

MYCIN used backward chaining technique to diagnose


bacterial infections and to recommend antibiotics, with
the dosage adjusted for patient's body weight .

DENDRAL employs forward chaining to establish the


structure of chemicals
Forward and Backward Reasoning
• In AI, the purpose of the search is to find the path through a problem space.
• There are two ways to pursue such a search - forward and backward reasoning.
• forward reasoning starts with the initial data towards the goal.
• backward reasoning -to determine the initial facts and information with the help
of the given results.

Forward: Reason forward from the initial states


Backward: Reason backward from the goal states
Definition of Forward Reasoning
• The solution of a problem generally includes the initial data and facts in order to arrive at the
solution - These unknown facts and information is used to deduce the result.
• Ex: Diagnosing a patient - the doctor checks the symptoms and medical condition of the
body - symptoms are analysed and compared against the predetermined symptoms – then
provides the medicines
• Forward chaining – the inference rules are applied to existing data to extract additional data
until an endpoint (goal) is achieved.
• Here, the inference engine starts by evaluating existing facts, derivations, and conditions
before deducing new information. An endpoint (goal) is achieved through the manipulation
of knowledge that exists in the knowledge base.

Forward chaining can be


used in planning, monitoring,
controlling, and interpreting
applications.
Examples of forward chaining
A is the starting point. A
A->B represents a fact. A->B
This fact is used to achieve a decision B.
B
Ex:
• Tom is running (A)
• If a person is running, he will sweat (A->B)
• Therefore, Tom is sweating. (B)
Forward chaining
Advantages
• It can be used to draw multiple conclusions.
• It provides a good basis for arriving at conclusions.
• It’s more flexible than backward chaining because it does not have a limitation on
the data derived from it.
Disadvantages
• The process of forward chaining may be time-consuming. It may take a lot of time
to eliminate and synchronize available data.
• Unlike backward chaining, the explanation of facts or observations for this type of
chaining is not very clear.
Definition of Backward Reasoning
• In backward reasoning, the goal is analyzed in order to deduce the rules, initial facts and
data.
• Ex: the patient is experiencing a problem in his body - on the basis of which the doctor is
going to prove the symptoms.
• Backward chaining is a concept in AI that involves backtracking from the endpoint or goal
to steps that led to the endpoint. This type of chaining starts from the goal and moves
backward to comprehend the steps that were taken to attain this goal.
Example
B is the goal or endpoint, that is used as the starting point for backward
tracking.
B
A is the initial state.
A->B
A->B is a fact that must be asserted to arrive at the endpoint B.
A
Ex:
• Tom is sweating (B).
• If a person is running, he will sweat (A->B).
• Tom is running (A).
Ex: MYCIN
• The KB of MYCIN comprises many antecedent-consequent rules, that enable the system to
recognize various causes of (bacterial) infections.
• This system is suitable for patients who have a bacterial infection, but don’t know the specific
infection.
• The system will gather information relating to symptoms and history of the patient. It will then
analyze this information to establish the bacterial infection.
• Sequence:
• The patient has a bacterial infection.
• The patient is vomiting.
• The patient is also experiencing diarrhea and severe stomach upset.
• Therefore, the patient has typhoid (salmonella bacterial infection).
• The MYCIN expert system uses the information collected from the patient to recommend
suitable treatment.
• The recommended treatment corresponds to the identified bacterial infection. In this case
the system may recommend the use of ciprofloxacin.
Backward Reasoning
Advantages
• The result is already known, which makes it easy to deduce inferences.
• It’s a quicker method of reasoning because the endpoint is available.
• The correct solutions can be derived effectively if pre-determined rules are met
by the inference engine.
Disadvantages
• The process of reasoning can only start if the endpoint is known.
• It doesn’t deduce multiple solutions or answers.
• It only derives data that is needed, which makes it less flexible than forward
chaining.
Steps that are followed in the backward reasoning

• The system chooses a goal state and reasons in the backward direction.
• Steps:
• Firstly, the goal state and the rules are selected where the goal state reside in
the THEN part as the conclusion.
• From the IF part of the selected rule, the subgoals are made to be satisfied for
the goal state to be true.
• Set initial conditions important to satisfy all the subgoals.
• Verify whether the provided initial state matches with the established states.
If it fulfils the condition then the goal is the solution otherwise other goal
state is selected.
Key Differences Between Forward and Backward Reasoning

BASIS FOR COMPARISON FORWARD REASONING BACKWARD REASONING

Basic Data-driven Goal driven

Begins with New Data and facts Uncertain conclusion (results)

Objective is to find the Conclusion that must follow Facts to support the conclusions

Type of approach opportunistic approach because Conservative -a specific goal can


it could produce different results only have certain predetermined
initial data
Flow Incipient to consequence Consequence to incipient
(antecedent to consequent )
Factors that influence whether to choose forward or
backward reasoning
• Are there more possible start states or goal states? We would like to go from
smaller set of states to larger set of states.
• In which direction is the branching factor (the average number of nodes that can
be reached directly from a single node) greater? We would like to proceed in the
direction with the lower branching factor.
• Will the program be asked to justify its reasoning process to the user? It so, it is
important to proceed in the direction that corresponds more closely with the way
user will think.
• What kind of event is going to trigger a problem-solving episode? If it is the
arrival of a new fact , forward reasoning should be used. If it a query to which
response is desired, use backward reasoning

You might also like