Chapter 6 MP

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 30

Module II

Chapter 6
Representing knowledge
using rules
• Rules are the basis for the search programs.

• Rules represent both knowledge about


relationships in the world as well as
knowledge about how to solve problems using
the content of the rules.
I. Procedural versus declarative
knowledge
• A declarative representation is one in which knowledge is
specified, but the use to which that knowledge is to be put
is not given.

• Declarative representation must be augmented with a


program that specifies what is to be done to the knowledge
and how.

• The logical assertions can be viewed as program rather


than data to a program. Reasoning paths define the
possible execution paths of the program. i.e., logical
assertions' can be viewed as procedural representations of
knowledge
A procedural representation is one in which the control
information that is necessary to use the knowledge is
considered to be embedded in the knowledge itself.

Procedural representation is augmented with an


interpreter that follows the instructions given in the
knowledge.

The real difference between declarative and the


procedural views of knowledge lies in where control
information resides.

The distinction between the 2 forms is very fuzzy and a


controversy deciding which framework is better.
II. Logic programming
• Logic programming is a programming language paradigm in
which logical assertions are viewed as programs.
• Ex: PROLOG

• A PROLOG program is a series of logical assertions, each of


which is a Horn clause.

• Horn clause is clause that has at most one positive literal.

• Ex: p, ~pVq
• PROLOG programs are composed only of Horn Clauses.
Therefore,
1. Simple and efficient interpreter can be written.
2. Logic of Horn Clause system is decidable.

The differences between logic and PROLOG representations are:-


1. In logic variables are explicitly quantified, in PROLOG
quantification is provided implicitly by the way the variables
are interpreted.
2. In logic there is explicit symbol for and () and or(V), in
PROLOG, there is an explicit symbol for and(,) but none for or.
3. In logic, implications of the form “p implies q” is written as p-
>q. In PROLOG it is written “backward” as q:-p. The PROLOG
interpreter works backward from a goal, this form causes every
rule to begin with a component that must be matched. The
first component is called head of the rule.
PROLOG programs are a set of Horn clauses that have been
transformed as follows:
1. If the Horn clause contains no negative literals leave it as it is.
2. Otherwise, rewrite the Horn clause as an implication, combining
all of the negative literals into the antecedent of the implication
and leaving the single positive literal as the consequent.
For example, the PROLOG clause
P(x) : - Q (x, y)
Is equivalent to the logic expression
x:  y: Q(x,y) -> P(x)

Key difference between logic and PROLOG representation:


PROLOG interpreter has a fixed control strategy, therefore assertions in
PROLOG define a particular search path to an answer to any
question.
Logical assertions define only the set of answers that they justify, they
say nothing about how to choose among the answers if there are
more than one.
PROLOG control strategy:
1. Begin with a problem statement, which is viewed as a
goal to be proved.
2. Consider the facts that can prove the goal directly,
also consider any rule whose head matches the goal.
3. Invoke a standard unification procedure to decide
whether a rule/fact can be applied to the current
problem.
4. Reason backward from the goal until a path is found.
5. Consider paths using Depth first strategy and
backtracking.
6. If the goal has more than one conjunctive part, prove
the parts in the order in which they appear.
Pros and cons of PROLOG:

Advantage is that programmer only need to specify rules and


facts.
Disadvantage is that search control is fixed as depth-first with
backtracking.
Difficult to apply domain knowledge to constrain a search.
PROLOG does allow for rudimentary control of search through
a non-logical operator called cut.
A cut can be inserted into a rule to specify a point that may
not be backtracked over.
PROLOG programs must be composed of restricted set of
logical operators, hence a limitation of the expressiveness
of the language.
It is possible to build PROLOG compilers that produce very
efficient code.
III. Forward versus Backward Reasoning
Search procedure through a problem space.

2 directions in which a search could proceed:


Forward, from the start states.
Backward, from the goal states.

Reason forward from the initial states. Begin by building a tree


of move of sequences that might be solutions by starting
with the initial configuration at the root of the tree.

Reason backward from the goal states. Begin by building a


tree of move of sequences that might be solutions by
starting with the goal configuration at the root of the tree.
Same rules can be used both to reason forward
from the initial state and to reason backward
from the goal state.
To reason forward the left sides are matched
against the current state and the right sides are
used to generate new nodes until the goal is
reached.
To reason backward, the right sides are matched
against the current node and the left sides are
used to generate new nodes representing new
goal states to be achieved. This continues until
one of the goal states is matched by an initial
state
4 factors that influence the choice of backward versus
forward reasoning:
1. Are there more possible start states or goal states?
Move from smaller set of states to larger set of states.
2. In which direction is the branching factor greater?
Proceed in the direction of lower branching factor.
3. Will the program be asked to justify its reasoning
process to a user? Proceed in the direction that
corresponds more closely with the way the user
thinks.
4. What kind of event is triggering the problem-solving
episode? If it is the arrival of a new fact, forward
reasoning makes sense. If it is query to which
response is desired, backward reasoning is more
natural
• It is possible to search both from the start state
and backward from the goal simultaneously, until
the paths meet somewhere in between. This is
called bidirectional search.
• In principle, the same set of rules can be used for
both backward and forward reasoning, in practice
there are 2 classes of rules defined according to
the kind of knowledge they encode:
1. Forward rules: encode knowledge about how to
respond to certain input configurations.
2. Backward rules : encode knowledge about how
to achieve particular goals
3.1 Backward-Chaining rule systems
• PROLOG is an example.
• Good for goal-directed problem solving.
• Query system uses backward chaining..
• PROLOG allows rapid indexing of rules for
deducing a fact since rules are in Horn Clauses
and might share same rule head.
3.2 Forward-Chaining rule systems
• Instead of being directed by goals, being
directed by incoming data.
• “Recognize-act cycle”
• Matching is more complex.
• Forward chaining systems implement highly
efficient matchers and supply several
mechanisms for preferring one rule over the
other
3.3 Combining Forward and Backward
reasoning
• Whether it is possible to use the same rules
for forward and backward reasoning depends
on the form of the rules themselves.
• Both the left sides and right sides should
contain pure assertions.
• Rules should be reversible.
IV. Matching
• Extracting rules that can be applied at the given point.
• Matching between current sate and preconditions of
the rules.
4.1 Indexing
Comparing each rule’s precondition with current state
and extracting all the ones that match. This is a tedious
task.
Instead use current state as an index to the rules and
select the matching ones immediately.
Rules cannot be generalized in Indexing.
4.2 Matching with variables
• If preconditions are not exact descriptions of the
problem situations but describe properties that
situations must have.
• To match single condition against single element in a
state description, the unification procedure is
sufficient.
• To match the whole set of rules against the current
state:
-Backward chaining systems uses depth-first
backtracking.
- Forward chaining systems use conflict resolution
strategies.
Ex: RETE match algorithm
4.3 Complex and approximate matching
• When the preconditions of the rule specify
required properties that are not stated
explicitly in the description of the current
state.
• If the rules should be applied if their
preconditions approximately match the
current situation.
Ex: Speech-understanding program.
4.4 Conflict resolution
• The result of matching process is a set of rules whose
antecedent has matched the current state descriptions.
• Search method has to decide on the order in which
these rules will be applied.
• Incorporating some of that decision making into the
matching process is called conflict resolution.
3 basic approaches to the problem of conflict resolution
in a production system:
1. Assign a preference based on the rule that matched.
2. Assign a preference based on the objects that
matched.
3. Assign a preference based on the action that the
matches rule would perform
Preferences based on rules
2 ways:
1. Consider the rules in the order they are specified to the
system. Priority is given to the rules in the order in which they
appear. Ex: PROLOG
2. Give priority to the special case rules over the rules that are
more general.
Matcher has to decide that one rule is more general than
another, in the following way
1. If set of preconditions of one rule contains all the
preconditions of another, then the second rule is more
general than the first.
2. If precondition of one rule is same as another except that
one rule contains variables and another rule contains
constants then the first rule is more general than the
second.
Preferences based on objects
• Order the matches found by the search
mechanism based on the importance of the
objects that are matched.
• Priority matching can also occur as a function
of the matchable objects in the current state
description.
Preferences based on states
Suppose there are several rules waiting to fire,
one way of selecting among them is to fire all
of them temporarily and to examine the
results of each.
Then, using a heuristic function that can
evaluate each of the resulting states, compare
the merits of the results and select the
preferred one.
Throw away(or keep for later) the remaining
ones.
V Control Knowledge
• Intelligent programs require search, search is computationally
intractable unless it is constrained by knowledge about the
world.
• Large knowledge bases contain thousands of rules,
intractability of search is an overriding concern.
• Knowledge about which paths are most likely to lead quickly
to a goal state is often called Search Control Knowledge. It can
take many forms:
1. Knowledge about which states are more preferable to
others.
2. Knowledge about which rule to apply in a given situation
3. Knowledge about the order in which to pursue sub goals
4. Knowledge about useful sequences of rules to apply
• Search control knowledge is called meta
knowledge as it is used to represent
knowledge about knowledge.
• Meta knowledge is represented declaratively
using rules.
• The syntax is:
SOAR and PRODIGY are 2 AI systems that represent
control knowledge using rules.
SOAR is based on a set of hypotheses about
structure of human problem solving.
1. Long term memory is stored as a set of
productions/rules.
2. Short-term memory(working memory) is a
buffer that serves as a storage area for facts
deduced by rules in long-term memory.
3. All problem-solving activity takes place as state
space traversal.
4. All intermediate and final results of problem
solving are remembered (chunked) for future
reference.
• PRODIGY is a general-purpose problem solving
system.
• PRODIGY acquire control rules in a number of
ways:
1. Through hand coding by programmers.
2. Through a static analysis of domain’s
operators.
3. Through looking at traces of its own
problem-solving behavior.
PRODIGY learns from its failures
Issues concerning control rules.
1. Utility problem
System’s problem solving efficiency (measured
in CPU cycles) is worse with control rules
than without them.
2. Complexity of production system interpreter.
Interpreter must know how to apply various
rules and meta rules.

You might also like