Ai Chapter 3
Ai Chapter 3
Chapter-3
3. Knowledge Representation using rules
Representing Knowledge Using Rules
We discuss the use of rules to encode knowledge. This is particularly
important issue, since rule based reasoning systems played very important rule
in the evolution in AI.
We have been assuming that search control knowledge was maintained
completely, separately from the rules themselves. Consider a set of rules to
represent both knowledge about relationships in the world, as well as
knowledge about, how to solve problems using the content of rules.
The real difference between the Declarative & Procedural views of the
knowledge lies in where control information takes place.
Now consider trying to extract from this knowledge base the answer to the
question
y : person (y)
Here, we want to bind y to a particular value for which person is true. Our
knowledge base justifies any of the following answers:
y= Marcus y= Caesar y= Cleopatra
Because there is more than one value that satisfies the predicate, but only one
value is needed, the answer to the question will depend on the order in which
2 సర్ సి ఆర్ రెడ్డి కాలేజ్ ఆఫ్ ఇంజనీరంగ్, ఏలూరు Sree
Database Management Systems-Chapter-3 (1-22) Dept. of Computer Science & Engineering
the assertions are examined during the search for a response. If we view the
assertions as declarative, then they do not themselves say anything about how
they will be examined. If we view them as procedural then they do.
Inheritable knowledge :
1. Facts : which represents statements about specific objects.
2. Rules : which represents statements about clauses of objects.
Fact is poodle (fluffy)
Rule is dog (x) :- poodle (x)
The first two of these différences araise naturally from the fact. That
PROLOG programs are actually set of Horn clauses that have been transformed
as follows :
If the Horn clause contains no negative literals, then leave it as it is.
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.
Problem :
Find a value of x, that satisfies the predicate apratment (x)
Apartment (x) :- pet (x), small (x)
Pet (x) :- cat (x)
Here cat (x) does not contain rules and also does not contain fact. So we go to
the backward . we take another rule for pet (x) (i.e., there exist another rule for
pet (x) )
Pet (x) :- dog (x)
Poodle (fluffy) ,
Small (x) is true
Pet (x) and small (x) is true, so , therefore
Apartment (x) is true.
x is fluffy.
Forward Reasoning:
Consider the initial state as the root of the tree. Generate the next level of
the tree by finding all the rules whose left sides match the root node and using
their right side to create new configurations. Generate the next level by taking
each node generated at the previous level and applying it to all of the rules,
whose leftsides matched continue until a configuration that matches the goal
state is generated. Ex : Water Jug Problem, 8- Puzzle.
Backward Reasoning:
Consider the goal state as the root of the tree. Generate the next level of
the tree by finding all the rules, whose right sides match the root node and using
their left side to create new configuration. Generate the next level, by taking
each node generated at the previous level and applying it to all the rules, whose
right sides matched continue, untill a configuration that matches the initial state
is generated. Ex : Predicate Logic, PROLOG
Bidirectional Search:
5 సర్ సి ఆర్ రెడ్డి కాలేజ్ ఆఫ్ ఇంజనీరంగ్, ఏలూరు Sree
Database Management Systems-Chapter-3 (1-22) Dept. of Computer Science & Engineering
We can also search both forward and backward simultaneously, until two
paths meet somewhere in between. This strategy is called Bidirectional Search.
Ex : Medical Diagnosis.
In more complex cases the matching process may permit transformations in
the patterns in order to achieve an equality match. The transformation may be a
simple change of some variables to constants, or ti may amount to ignoring
some components during the match operation. For example, a pattern matching
variable such as ?x may be used to permit successful matching between the two
patterns (a b (c d ) e) and (a b ?x e) by binding ?x to (c, d). Such matching are
usually restricted in some way, however, as is the case with the unification of
two classes where only consistent bindings are permitted. Thus, two patterns
such as ( a b (c d) e f) and (a b ?x e ?x) would not match since ?x could not be
bound to two different constants.
In subsequent chapters we will see examples of many problems where exact
matches are inappropriate, and some form of partial matching is more
meaningful. Typically in such cases, one is interested in finding a best match
between pairs of structures. This will be the case in object classification
problems, for example, when object descriptions are subject to corruption by
noise or distortion. In such cases, a measure of the degree of match may also be
required.
Other types of partial matching may require finding a match between certain
key elements while ignoring all other elements in the pattern. For example, a
human language input unit should be flexible enough to recognize any of the
following three statements as expressing a choice of preference for the low-
calorie food item
I prefer the low-calorie choice.
I want the low-calorie item
The low-calorie one please.
7 సర్ సి ఆర్ రెడ్డి కాలేజ్ ఆఫ్ ఇంజనీరంగ్, ఏలూరు Sree
Database Management Systems-Chapter-3 (1-22) Dept. of Computer Science & Engineering
Finally, some problems may obviate the need for a form of fuzzy matching
where an entity’s degree of membership in one or more classes is appropriate.
Some classification problems will apply here if the boundaries between the
classes are not distinct, and an object may belong to more than one class.
Fig 8.1 illustrates the general match process where an input description is
being compared with other descriptions. As stressed earlier, their term object is
used here in a general sense. It does not necessarily imply physical objects. All
objects will be represented in some formalism such a s a vector of attribute
values, prepositional logic or FOPL statements, rules, frame-like structures, or
other scheme. Transformations, if required, may involve simple instantiations or
unifications among clauses or more complex operations such as transforming a
two-dimensional scene to a description in some formal language. Once the
descriptions have been transformed into the same schema, the matching process
is performed element-by-element using a relational or other test (like equality or
ranking). The test results may then be combined in some way to provide an
overall measure of similarity. The choice of measure will depend on the match
criteria and representation scheme employed.
The output of the matcher is a description of the match. It may be a simple yes
or no response or a list of variable bindings, or as complicated as a detailed
annotation of the similarities and differences between the matched objects.
`
To summarize then, matching may be exact, used with or without pattern
variables, partial, or fuzzy, and any matching algorithm will be based on such
factors as Choice of representation scheme for the objects being matched,
Criteria for matching (exact, partial, fuzzy, and so on),
Choice of measure required to perform the match in accordance with the
chosen criteria, and
Type of match description required for output.
Matching:
It is a process of extracting the rules that can be applied at a given point from
the entire collection of rules. It requires some kind of matching between current
state and preconditions of the rules or current state to the next state. Some of the
matching techniques are
1. Indexing:
One way to select applicable rules is to do a simple search, through all the
rules, comparing each ones preconditions to the current state and extracting all
the ones that match. But there are two problems in the simple solution.
It is necessary to use a large number of rules, scanning through all of
them at every step of the search.
It is not always immediately obvious whether a rule’s preconditions are
satisfied by a particular state.
Some times there are easy ways to deal with the first of these problems.
Instead of searching through the rules, use the current state as an index into the
rules and select the matching ones immediately. Ex: Water Jug Problem.
Some times, indexing cannot be helpful, even when taking the larger set of
rules stated high level predicates. Finally despite, some limitations of this
approach. Indexing is very important in the efficient of Rule Based System.
description rules are matched against many elements in the state description
simultaneously.
One efficient way in many to many match algorithms is called
RETE which gains efficiency from the three major sources.
1. Temporal nature of data. Rules usually do not alter the state descriptions
radically, instead a rule will typically add one or two elements or perhaps delete
one or two, but most of the state descriptions remain the same.
2. Structural similarity in rules. Different rules share a large no. of
preconditions. For ex: consider rules for identifying the wild animals. One rule
concludes
1. Jaguar (x) mammal (x), feline (x), carnivorous (x), has-spots (x)
2. Tiger (x) mammal (x), feline (x), carnivorous (x), has-stripes (x)
If we match the two rules independently, we will repeat a lot of
work unnecessarily. RETE stores the rules, so that they store structures in
memory.
3. Persistence of variable binding consistency. While the entire individual
preconditions of a rule might be met. There may be variable binding conflicts
that prevent the rule from firing. Fortunately it is not necessary to compute
binding consistency from scratch. Every time, a new condition is satisfied.
RETE remembers its previous calculations and is able to merge new binding
information efficiently.
Ex: son (x, y) ^ son (y, z) grandparent(x, z)
4. Conflict Resolution:
The result of the matching process is a list of rules, whose
antecedents have matched the current state description along with whatever
10 సర్ సి ఆర్ రెడ్డి కాలేజ్ ఆఫ్ ఇంజనీరంగ్, ఏలూరు Sree
Database Management Systems-Chapter-3 (1-22) Dept. of Computer Science & Engineering
variables binding were generated by the matching process. It is the job of the
search method to decide on the orders, in which rules will be applied. But
sometimes, it is useful to incorporate, some of the decision making into the
matching process. This phase of matching process is called the conflict
resolution.
The match between the two can then be evaluated by how well they
correspond and how much push-and-pull distortion is needed to obtain
the best correspondence
Use the number of rigid pieces connected with springs. This pieces can
correspond to low level areas such as pixels or even larger area segments
To model any restrictions such as the relative positions of body parts,
nonlinear cost functions of piece displacements can be used
The costs can correspond to different spring tensions which reflect the
constraints
For example, the cost of displacing some pieces might be zero for no
displacement, one unit for single increment displacements in any one of
the permissible directions, two units for two position displacements and
infinite cost for displacements of more than two increments. Other pieces
would be assigned higher costs for unit and larger position displacements
when stronger constraints were applicable
The matching problem is to find a least cost location and distortion
pattern for the reference sheet with regard to the sensed picture
Attempting to compare each component of some reference to each
primitive part of a sensed picture is a combinatorially explosive problem
In using the template-spring reference image and heuristic methods to
compare against different segments of the sensed picture, the search and
match process can be made tractable
Any matching metric used in the least cost comparison would need to
take into account the sum of the distortion costs Cd , the sum of the costs
for reference and sensed component dissimilarities Cc , and the sum of
penalty costs for missing components Cm . Thus, the total cost is given
by Ct = Cd + Cc + Cm
12 సర్ సి ఆర్ రెడ్డి కాలేజ్ ఆఫ్ ఇంజనీరంగ్, ఏలూరు Sree
Database Management Systems-Chapter-3 (1-22) Dept. of Computer Science & Engineering
In such cases the two structures are matched to isolate the differences in order
that they may be reduced or transformed. Once again, partial matching
techniques are appropriate
In visual application, an industrial part may be described using a graph
structure where the set of nodes correspond to rectangular or cylindrical
block subparts
The arc in the graph correspond to positional relations between the
subparts
Labels for rectangular block nodes contain length, width and height,
while labels for cylindrical block nodes, where location can be above, to
the right of, behind, inside and so on
Graphs such as this are called attributed relational graphs (ATRs). Such a
graph G is defined as a sextuple G = (N, B, A, Gn, Gb)
Where N = { n1, n2, . . ., nk}is a set of nodes, A = {a n1, an2, . . . , ank}
is an alphabet of node attributes, B = { b1, b2, . . . , bm}is a set of
directed branches (b = (ni, nj)), and Gn and Gb are functions for
generating node and branch attributes respectively
When the representations are graph structures like ARGs, a similarity
measure may be computed as the total cost of transforming one graph into
the other
For example, the similarity of two ARGs may be determined with the
following steps:
Decompose the ARGs into basic subgraphs, each having a depth of one
Compute the minimum cost to transform either basic ARG into the other
one subgraph-by-subgraph
Compute the total transformation cost from the sum of the subgraph costs
An ARG may be transformed by the three basic operations of node or branch
deletions, insertions, or substitutions, where each operation is given a cost based
on computation time or other factors
Match:
During the match portion of the cycle, the conditions in the LHS of the
rules in the knowledge base are matched against the contents of working
memory to determine which rules have their LHS conditions satisfied
with consistent bindings to working memory terms.
Rules which are found to be applicable are put in a conflict set
Select:
From the conflict set, one of the rules is selected to execute. The selection
strategy may depend on recency of useage, specificity of the rule or other
criteria
Execute:
15 సర్ సి ఆర్ రెడ్డి కాలేజ్ ఆఫ్ ఇంజనీరంగ్, ఏలూరు Sree
Database Management Systems-Chapter-3 (1-22) Dept. of Computer Science & Engineering
The rule selected from the conflict set is executed by carrying the action
or conclusion part of the rule, the RHS of the rule. This may involve an
I/O operation, adding, removing or changing clauses in working memory
or simply causing a halt
The above cycle is repeated until no rules are put in the conflict set or
until a stopping condition is reached
2. Many rules in a knowledge base will have the same conditions occurring in
their LHS. This is just another way in which unnecessary matching can arise.
Repeating testing of the same conditions in those rules could be avoided by
grouping rules which share the same conditions and linking them to their
common terms. It would then be possible to perform a single set of tests for all
the applicable rules shown in Fig below
16 సర్ సి ఆర్ రెడ్డి కాలేజ్ ఆఫ్ ఇంజనీరంగ్, ఏలూరు Sree
Database Management Systems-Chapter-3 (1-22) Dept. of Computer Science & Engineering
Overview of LISP:
Lisp is one of the oldest (developed in 1958) and prominent language created
by the Dr. John MaCarthy, who coined the term ‘Artificial Intelligence’.
17 సర్ సి ఆర్ రెడ్డి కాలేజ్ ఆఫ్ ఇంజనీరంగ్, ఏలూరు Sree
Database Management Systems-Chapter-3 (1-22) Dept. of Computer Science & Engineering
Although it is not used much these days, the language is both flexible and
extendable.
It was originally developed for Lambda Calculus computation, and since its
inception it has evolved a lot. The language introduced many ideas in computer
science, such as recursion, dynamic typing, higher-order functions, automatic
storage management, self hosting compiler and tree data structure.
Advantages
Fast and efficient in coding as it is supported by compilers instead of
interpreters.
Automatic memory manager was invented for LISP, therefore, it has
a garbage collection.
LISP offers specific control over systems resulting to their maximum use.
Disadvantages
Overview of PROLOG:
The first PROLOG program was written in Marseille, France, in the early
1970s as part of a project in natural language processing.
It’s a declarative language with formal logic. AI developers value it for its
pre-designed search mechanism, no determinism, backtracking mechanism,
recursive nature, high level abstraction and pattern matching.
Prolog is well suited for problems involving structured objects and relations
between them. For instance, in Prolog, it is easier to express spatial relationships
between object, like green triangle is behind the blue one. It is also simple to
state a general rule – if object A is closer to the person than object B, and B is
closer than C, then A should be closer than C.
Advantages
Prolog has a built-in list handling essential in representing tree-based data
structures.
Efficient for fast prototyping for AI programs to be released modules
frequently.
Allows database creation simultaneous with running of the program.
Disadvantages
Despite prolog old age, it has not been fully standardized in that some features
differ in implementation making the work of the developer cumbersome.