You are on page 1of 33

P a g e | 1 | Module 2 Source : diginotes.

in

ARTIFICIAL INTELLIGENCE
MODULE 2

The above problems can be classified into 3 sets of problems:


Ignorable (Ex. Theorem proving) in which the solution steps can be ignored.
E.g.: for acute angled, triangle we have Pythagoras theorem stating
(Hyp)2 = Base 2+ Altitude)2
So while using this theorem to solve problems need not prove Pythagoras theorem.
Recoverable (8 Puzzle) In this case the solution steps can be undine.
Irrecoverable (chess):In this case the solution steps cannot be undine.

3. Is the universe predictable: supposing that we are playing 8 – puzzle game? In


this game we know exactly what will happen next.
This means that it is possible to plan entire sequence of waves & we know what the
resulting stat will be.
Planning can be used for avoiding the scenario of undoing the move. Though it will
be necessary to back track past these moves are at a time during the planning
process:
In this case a control structure which all are back tracking will be necessary.
Thus planning can be described as problem solving without feedback from the
environment for solving the certain outcome problems, this open – loop approach
(no feedback) will work fine as the result of an action can be predicted perfectly.
This planning can be used to generate a sequence of operators, which guarantee
the solution will be obtained certainly.
 But for uncertain outcome problems, planning can at best generate, a
sequence of operations which has a good probability of leading to a solution.
 For uncertain outcome a process of plan revision has to be allowed for
necessary feedback.
Drawback of planning for uncertain outcome problems:
 Planning does not provide guarantee to actual solution.
 It is often very expensive since the number of solution paths, which need to be
explored increase exponentially with the number of points at which the
outcome cannot be predicted.
Uncertain Outcome problems controlling a robotic arm:
The outcome is uncertain for a variety of reasons. Something might come in
the path of arm while it is moving.
A slight error could cause the arm to knock over a whole stack of things.
The gears of the arm might stick.
4. Is a good solution absoluter or relative?
Consider the problem of answering questions based on a databased of simple
facts:
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 2 | Module 2 Source : diginotes.in

(1) Marcus was a man.


(2) Marcus was a Pompeian.
(3) Marcus was born in 40 AB.
(4) All men are mortal.
(5) All Pompeiians died, which the volcano erupted in 79 AD.
(6) No mortal lives longer than 150 years.
(7) It is now 2017 AD.
Based on the maxims provided, we ask the question “Is Marcus alive?”
This question can be answered in 2 – ways.
1st Method: Justification:
(1) Marcus was a man axiom 1.
(2) All men are mortal axiom 4.
(3) Marcus is mortal axioms 1&4.
(4) Marcus was born in axiom 3 40 AD.
(5) It is now 2017 AD axiom 7
(6) Marcus’s age is 1977 years axioms 3, 7
(7) No Mortal lives longer axiom 6
(8) Marcus is dead axiom 6,3
2ndMethod Justification:
(1) It is now 2017 AD axiom 7
(2) All Pompeiians died in 79 AD. axiom 5
(3) All Pompeiians are cleared statements 1 & 2
(4) Marcus was Pompeian axiom 2
(5) Marcus is dead 3,4
Ex 2: Consider the traveling sale man problem. The goal is to find the shortest rate
by visiting each of the city exactly once.
Following is the table depicting cities to be visited by the salesman and the
respective distances:
Cities Boston New York Miami Dallas SF
Boston - 250 1450 1700 3000
New York 250 - 1200 1500 2900
Miami 1450 1200 - 1600 3300
Dallas 1700 1500 1600 - 1700
SF 3000 2900 3300 1700 -
X X X X X X

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 3 | Module 2 Source : diginotes.in

Example: Water Jug Problem

Consider the following problem:


Water Jug Problem: You are given two jugs, a 4-gallon one and a 3-ga11on one, a
pump which has unlimited water which you can use to fill the jug, and the ground on
which water may be poured. Neither jug has any measuring marking in it. How can
you get exactly 2 gallons of water in the 4-ga11on jug?
State Representation and Initial State - we will represent a state of the problem as a
tuple (x. y) where x represents the amount of water in the 4-gallon jug and y
represents the amount of water in the 4-gallon jug.
Note 0 <= x <= 4, and 0 <= y <= 3.
Our initial state: (0,0)
GoaI predicate -state: (2,y) where 0 <= y <= 3.
Operators - we must define a set of operators that will take us from one state to
another:
1. Fill 4-gal jug (x,y) (4,y)
x<4
2. Fill 3-gal jug (x,y)  (x,3)
y<3
3. Empty 4-gal jug on ground (x,y)  (0,y)
x>0
4. Empty 3-gal jug on ground (x,y)  (x,0)
y>0
5. Pour water from 3-gal jug (x,y) (4, y - {.4 - x))
to fill 4-gai jug 0 <x+y>= 4 and y> 0
6. Pour water from 4-gal jug (x,y)  (x - (3-y), 3)
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 4 | Module 2 Source : diginotes.in
to fill 3-gal-jug 0 <x+y>= 3and x > 0
7. Pour all of water from 3-gal jug (x,y)  (x+y, 0)
Into4-gal jug 0 <x+y<=4andy >= 0
8. Pour all of water from 4-gal jug (x,y)  (0, x+y)
into 3-ga1 jug 0 <x+y<= 3 andx>= 0

Through Graph Search, the following solution is found :


Gals in 4-gal jug Gals in 3-gal jug Rule Applied
0 0
1.fill 4
4 0
6.pour 4 into 3 to
fill
1 3
4.empty 3
1 0
8.pour all of 4
into 3
0 1
1. fill 4
4 1
6.pour into 3
2 3

HILL CLIMBING:
It is another form of Generate-and-Test in which feedback from the test procedure is
used to help the generator to decide which direction to move the search space.
Hill Climbing is often used when a good Heuristic function is available for evaluating
states but when no other useful knowledge is available.
The Hill Climbing can terminate whenever the Goal state is reached. Also it makes a
sense to terminate Hill Climbing when there is no reasonable alternative state to
move to.

Simple Hill Climbing:

Algorithm:

1. Evaluate the initial state.


If it is also a goal state then
Return it and Quit.
else
Continue with the initial state as the current state.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 5 | Module 2 Source : diginotes.in

2. Loop until a solution is found or until there are no new operators left to be
applied on the current state:

a) Select an operator that has not yet been applied to the current state and
apply it to produce a new state.
b) Evaluate the new state

i. If it is a goal state then


Return it and Quit.
ii. If it is not a goal state but it is better than the current state then
make it as current state.
iii. If it is not better than the current state then continue in the loop.

Example: Let us define a heuristic function h(x) = +1 for all the Blocks in the
support structure. If the Block is correctly placed(positioned) otherwise -1 for all the
Blocks in the support structure.

Let the initial state be

A D Goal state
D C
C B
B A

Consider the initial State:


x=1 The value of h(x) will be since B is strongly
A placed
D h(x)= -1 -1 -1 -1
B C D E
C
B +1 +1 -1 -1 -1 -1
C D A B C D

Correctly
Placed
h(x) = h(1) = -6

x=2
D
-6+0+1+1+1
C A B C D
B A
h(2)= -3 (better)
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 6 | Module 2 Source : diginotes.in

x=3 -3+0+1+1
C h(3) = -2+1 = -1
B A D

x=4 h(4) = 0+0+0+0 =0


B A D C

B A D C

x=5

B h(5) = +1 = 0+1
A D C A B

x=6
h(6) = 0+1+1+1 = +3
D
A B C D
C
B A

x=7

D
h(7)= +1 +1 +1 +0 +1+1+1
C C D B A B C D
B
A = +6

Algorithm: Steepest Ascent Hill Climbing

1. Evaluate the initial state :


If it is the goal state then return it & Quit, otherwise continue with the initial
state as the current state.

2. Loop until a solution is found or a complete iteration produces no change to


current state.
a.) Let succ be a state such that any possible successor of the current stte will
be better than succ.
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 7 | Module 2 Source : diginotes.in

b.) For each operator that applies to the current state do:
i) Apply the operator & generate new state.
ii) Evaluate the new state if it is a goal state, then return it & quit.
If it is not a goal state, then compare it to succ.
If it is better the set succ to this new state.
If it is not better leave succ as it is.
c.) If the succ s better than the current state, then set current state to succ.
Both basic & steepest Ascent Hill Climbing may fail to find a solution.
This will happen if the program reaches either a local maximum,
A plateau or a ridge.

A local maximum: It is a state which is better than all its neighbours but it is not
better than some other states farther away. They are called as foothills.

Local maximum global maximum

Far away

A Plateau (A flat surface is called the Plateau): It is the flat area of the search space
in which a wholes set of neighbouring state have the same value. On a Plateau it is
not possible to determine the best direction to move by making a local comparisons.

Maximum

Plateau

A Ridge: It is a special kind of local maximum. It is an area of search space which is


higher than surrounding areas and it itself has a slope but the orientation of the high
region compared to the set of available moves & the direction in which they move
makes it impossible to traverse a ridge by single move.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 8 | Module 2 Source : diginotes.in

 It looks only one step ahead & no further measures to be taken for dealing
with a problem of a local maximum , a plateau & a ridge.
 Backtracking to some earlier node & try to go In a different direction which
may be promising later.
 Make a big jump in some direction & try to get a new section of search space.

Is the solution a state or path?


Let us consider the problem of finding a consistent interpretation for the
following sentence:
“The bank president ate a dish of pasta salad with fork”.
 Many interpretation can be given for the statement since in English “Bank”
indicates bank of river or financial institution.
But only one of these entity has a president
 The word “dish” is the object of the verb “eat”. It is possible that dish was
catch. But dog food generally does not contain dog.
 The watering problem; the solution is a state of the world pasta problem is a
problem who is solution is a path to a state.

What is the role of the knowledge?


Consider the problem of playing chess assuming that unlimited compulsion
power is available. Then to know “How much of Knowledge would be required
to develop a perfect program fro playing chess. What is required is just the
rules for determining the legal moves & some simple control mechanism which
implements an appropriate search procedure. And for speeding up the
execution of the program, a good strategy & a tactics could help in the search.

Problem 2: Consider the problem of scanning daily newspapers to decide


which set of people are supporting the BJP party or Congress party in some
upcoming election.
Assuming again that unlimited power is available, then how much knowledge
is required by a computer which is trying to solve this problem?
The solution should have knowledge do the following
1. The name of the candidates of each part.
2. But if somebody wants that the taxes be lowered then they may vote for BJP
3. If someone wants to improve education for minorities then they may be voting
congress & so on.
These 2 problem of chess & politics illustrate the differences between the
problem for which a lot of knowledge is important only to constraint the search
for a solution and the search for a solution and the problem for which a lot of
knowledge is required even to be able to recognize a solution.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 9 | Module 2 Source : diginotes.in

Does the task require Interaction with a person?


Now a days many programs are being written which require intermediate
interaction with people, both to provide additional input to the program & to
provide additional reassurance to the user .
 Consider the problem of proving mathematical theorems.
(i) All we want to know that there is a proof.
(ii) The program is capable of finding a proof by itself and a theorem may be
very difficult to prove& the program does not know where to start. At the moment
people are still better at doing the high level strategy which is required for a proof.
So the computer might like to be able to ask for an advice.
Ex: Sometimes in a geometry drawing an additional line is suggested by someone to
of proof in all easy way.

Now there may be 2 types of problems.


1. Solitary (done by self or alone) : in this case the computer is given a
problem description & it produces an answer with no intermediate
communication & with no demand for an explanation of the reasoning process.
2. Conversational: In this case there is an intermediate communication between
a person and the computer either to provide additional assistance to the
computer or to provide additional information to the user or both.

Problem classification: By seeing all the problems that have been discussed
so far, it is clear that there are several broad classes into which the problems fall.
Each of these classes can be associated with generic control strategy which is
appropriate for solving the problem.
Ex: Consider the generic problem of classification. The basic task here is to
examine the input & take a decision as to which set of known classes the input is
an instance.
Ex: mechanical device faults, Medical diagnosis.

Production System Characteristics:


 As we know that the production systems are a good way to describe the
operation which can be performed in a search for finding solutions to a
problem.

Questions to be answered here are:


1. Can the production systems, like problems, be described by a set of
characteristics which shed some light on how can they be implemented easily.
2. If the characteristics are there for a production system, then what relationships
are there between problem types and the types of production systems best
suited to solving the problems?
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 10 | Module 2 Source : diginotes.in

The answer to the first question is “yes”.


Consider the following definition of classes of production systems, there are 4
types of production systems.
1. Monotonic Production System:
This is a production system in which application of a rule never prevents
the later application of another rule which could also have been applied
at the time the first rule was selected.

Intermediate
Rule x
Rule y apply rule y
Choose rule x
Result

2. Non-Monotonic Production System:


This is a production system which is not like Monotonic production
system, i.e. application of a rule will prevent later application of another
rule which could have been selected in the first place.

3. A Partially Commutative production System:


It is a production system with the property that if the application of a
particular sequence of rules transform state ‘x’ into state ‘y’ then any
permutation of those rules which is allowable (i.e. each rule’s
precondition are satisfied when it is applied) also transforms state ‘x’ into
state ‘y’.

Apply
Result State y
State x Rule

4. A Commutative Production System:


It is a production system which is both monotonic and partially
commutative.

Now to answer 2nd Question


 Which asks whether there is an interesting relationship between classes of
Production systems and classes of problems.

 For any solvable problem, there exists an infinite number of production


systems which describe ways to find solutions.
We have following representation of production systems
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 11 | Module 2 Source : diginotes.in

Monotomic Non Monotomic


Partially Theorem proving Robot Navigation
commutative
Non Partially Chemical System Bridge
commutative

 Partially commutative, Monotomic production system are useful for solving


ignorable problems and such problems can be solved without the ability to
backtrack to previous states when it is discovered that an incorrect path has
been followed. Further such systems are good for problems where things do
not change, new things get created.

 Non-Monotonic, Partially Commutative systems are useful for solving


problems in which changes occur but such changes can be reserved and is
such problems the order of operations is not critical.

Example: Suppose that a Robot has the following operators


Go North(N), go South(S)
Go East(E), go West(W)

And to reach its goal, it does not matter whether the robot executes N-N-
E or N-E-N,

The non-Partially commutative Production Systems are useful for many


problems in which irreversible changes occur.

Example: Production of a desired chemical compound.


The order in which the operators are applied may cause irreversible
changes. The order in which the operators are applied can be very
important in determining the final output.
Ex: add z
x Y O/p nothing happens
add stable compound
add
z Y another stable output no effect
add compound x

Non Partially Commutative Production Systems are less likely to produce


the same node many times in the search process.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 12 | Module 2 Source : diginotes.in

Example: Game of chess where one cant loose.

Partially Commutative Production System:


8-puzzle blocks world problem can be considered depending on how the
operators are chosen.

Heuristic Search Techniques:

Generate and test, Hill climbing, Best first search, Problem Reduction,
Constraint Satisfaction, Means-ends Analysis
Generate-and Test:
Algorithm: Generate-and-Test
1. Generate a possible solution, (for some problems it means generating
particular point in the problem space for others, it means generating a
path from a start state).
2. Test to see if this is actually a solution by comparing the chosen point or
end point of chosen path to the set of chosen path to the set of
acceptable goal states.
3. If the solution has been found, Quit, otherwise return to step1

It is a depth-first search procedure since the complete solution must be


generated before they can be tested. It is also known as British Museum
Algorithm
The simplest way of implementing systematic Generate-and-Test is to
implement Depth-first-Search tree with Backtracking.
 Apply two or more rules before testing.
 So that process can move in several directions at once.
 This is particularly a good state for dealing with ridges.

Consider the Blocks World Problem

A H
H G
G F
F E
E D
D C
C B
B A

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 13 | Module 2 Source : diginotes.in
Initial state Goal state

Operators:

1. Pick up one Block and put it on table.


2. Pick up one Bock and put it on another Block.
Now suppose we design the following Heuristic function
Local: h(x): Add one point for every Block which is resting on the Block
Which it is supposed to be resting on.
Subtract one point for every Block that is sitting on the wrong block.

In this case goal state has a score of ‘8’ for this Heuristic function.
(So defined) 1+1+1+1+1+1+1+1=8
A B C D E F G H

And the initial state has a score of 4 i.e. -1+1+1+1+1+1+1-1=4


B C D E F G H A

Now there is only one move from initial state i.e.


H
G
F
E
D
C
A B
Move block A on top of table, now the score of Heuristic function will be
+1-1+1+1+1+1+1+1=6
A B C D E F G H

And this move will be accepted by Hill Climbing Algorithm as there is an


improvement in the Heuristic function value.

Now after this step there are 3 possible moves as shown below
A
H G G
G F F
F E E
E D D
D H C C
C A B A H B
B
(a) (b) (c)
h=4 h=4 h=4

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 14 | Module 2 Source : diginotes.in

All the 3 states (a),(b) and (c) shown above will have a score of 4 and the process
has reached a local Maximum which is not a Global Maximum (with h=8).
The Hill Climbing process will Halt because all these possible sates have scores
lower than the current state ‘6’ where the score is ‘4’.
And the current state appears to be better than any of its successors.
The design of Heuristic function was incorrect.
Now we modify the Heuristic function

Global:
For each block that has correct support structure(i.e. the complete
structure below it is exactly as it should be) add one point for every Block in
the support structure.
For each Block that has an incorrect support structure, subtract one point for
every Block in the existing support structure

Simulated Annealing: It is a variation 3 of hill climbing in which some downhill


moves may be made at the beginning the process
It tries to lower the chances of getting caught at a local maximum a plateau or a
ridge.
In this case an objective function is used in place of Heuristic function.
In this case an effort is made to minimize the value of objective function (unlike the
Heuristic function)

Physical process of Annealing: The physical substances such as metals are


molten (i.e. raised to high energy levels) then gradually cooled until some solid state
is reached.
The goal of this process is to produce a minimal-energy final state.
The probability of transition to a higher energy state is given by
𝒑 = 𝒆−∆𝑬/𝒌𝑻
Where ∆𝐸 is the positive change in the energy level, T is the temperature and k is
the Boltzmann’s constant.
Thus, in the physical valley descending which occurs during Annealing, the
probability of a large uphill move is lower than the probability of a small one.
Also, the probability that an uphill move will be made, decreases as the temperature
decreases.
The rate at which the system is cooled is called the Annealing Scheduling (If cooling
occurs too rapidly, stable regions of high energy will form.) Therefore, a local, but
not global minimum is reached.
But if a slower schedule is used then a crystalline structure corresponding to the
global minimum, is likely to develop.
𝒑′ = 𝒆−∆𝑬/𝑻
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 15 | Module 2 Source : diginotes.in

Algorithm: Simulated Annealing


1.Evalulate the Initial state. If it’s an abo a goal state then return it and quit otherwise
continue with it as initial state as current state.
2.Initialize BEST-SO-FAR to the current state.
3.Initialize T according to the Annealing schedule.
4.Loop until a solution is found or until there are no new operators left to be applied
to the current state.
a. Select an operator that has not yet been applied to the current state and apply it
to produce a new state.
b. Evaluate the new state. Compute ∆𝐸 = (value of current) − (value of new state)
 If the new state is a goal state then return it and quit.
 If it is not a goal state but it is better than the current state then make it. Also
set BEST-SO-FAR to this new state.
 If it is not better than the current state with probability p as defined above.
(This is generally implemented by invoking a random number generator to
produce a number in the range

Algorithm: Best-First Search


1. Start with OPEN containing just the initial state
2. Until a goal is found or there are no nodes left on OPEN do:
a. Pick up the best node on OPEN.
b. Generate its successor.
c. For each successor do:
 If it has not been generated before, evaluate it, add it to OPEN and
record its parent.
 If it has been generated before, change the parent if this new path
is better than the previous one. In that case update the cost of
getting to this node and to any successor that this node may
already have
Step 1: A Step 2:
a

B C D
Step 3:
(3) (5) (1)

B C D

(3) (5)

(4) E F (6)

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 16 | Module 2 Source : diginotes.in

Step 4: Step 5:

B D B C D
C

(5)
G H E F
G H E F

(6) (5)
(6) (5) (4) (6)
I J

(2) (1)

The 𝑨∗ Algorithm: The best first search algorithm is a simplification of an algorithm


called 𝐴∗ .
This algorithm uses same notations 𝑓 ′ , 𝑔 and ℎ′ functions as well as the lists OPEN
and CLOSED.
Algorithm: 𝐴∗ 𝑓 ′ = 𝑔 + ℎ′
1.Start with OPEN containing only the initial node. Set that node’s ‘g’ value to ∅
and ℎ′ value to whatever it is and 𝑓 ′ = ℎ′ + ∅. Set CLOSED to the empty list.
2. Until the goal node is found repeat the following procedure:
If there are no nodes on OPEN then report failure.
Otherwise, pick the node on OPEN with the lowest 𝑓 ′ value.
Call it BESTNODE and remove it from OPEN. Place it on CLOSED. See if
BESTNODE is a good node, if so, exit and report a solution (either the BESTNODE
if all we want is the node or the path that has been created between the initial state
and BESTNODE if we are interested in the path).
Otherwise, generate the successor of the BESTNODE but do not set the
BESTNODE to point them yet (see weather if any of them has already been
generated).
For each successor do the following things:
a. Set successor to point back to BESTNODE. These backward links will make it
possible to recover the path once the solution is found.
b. Compute g(SUCCESSOR) = g(BESTNODE) +
cost of getting from BESTNODE to SUCCESSOR. See if SUCCESSOR is the
same as any node on OPEN (i.e. it has already been generated but not
processed). If so then call the node OLD.
Since this node already exists in the graph we can throw the SUCCESSOR
away add OLD to it.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 17 | Module 2 Source : diginotes.in

Simulated Annealing
If the random NO is less than the move is accepted otherwise do nothing.

Revise T as necessary according to the annealing schedule.

5) Return BEST-SO-FAR as the answer


a) The initial value should be used as temparature 'T'.
b) Then it has to be decided when the temperature has to be reduced.
c) The amount by which the temperature has to be reduced each time it is
changed.
d) When to quit.
The Simulated Annealing is used to solve problem in which the number of
moves from a given state is very large.

BEST-FIRST SEARCH:

OR Graph:
 Depth first search is good because it allows a solution to be found without all
competing branches that need to be expanded.
 Breadth first search is good because it does not get trapped or dead.
 End path-
a) Both ideologies can be combined to follow a single path at a time but
switch the path whenever some competing path looks more promising
than the current state.

b) At each step of the BEST FIRST SEARCH, most promising nodes of the
nodes generated so far is selected.
c) This is done by applying appropriate Heuristic function to each of them
for BEST-FIRST SEARCH Algorithm we need
2 lists of nodes.
OPEN:
 Nodes that have been generated and have the Heuristic
function applied to them but which have not been examined.
 OPEN actually priority queue in which the element with
highest priority are these which have most promising value of
the Heuristic function.

CLOSED:
 Nodes that have already been examined (i.e. successors have
been generated).
 We need to keep these nodes in the memory if we want to
search a graph rather than a tree, because whenever a new
node is generated, it has already been generated before.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 18 | Module 2 Source : diginotes.in

Further, a Heuristic function is needed which evaluates the goodness of each


node that is generated.
Let this Heuristic function be called as f'=g+h'

Where 'g' is the measure of the cost of getting from the initial state to the current
node.

The function h' is an estimate of the additional cost of getting from the current
node to the good state.

List of BESTNODE successors.


 Now we must decide whether OLD's parent link should be reset to point to
point to BESTNODE.
 It should be if the path we have just found to SUCCESSOR is cheaper than
current best path to OLD(since SUCCESSOR and OLD are same node).
 So see whether it is cheaper to get OLD via its current parent or to
SUCCESSOR via BESTNODE by comparing their 'g' value.
 If OLD is cheaper(or just as cheap) then we do nothing.
 If SUCCESSOR is cheaper, then reset OLD's parent link to point to
BESTNODE, record the new cheaper path in g(OLD),and update f'(OLD).

d). If SUCCESSOR was not an OPEN, see if it is on CLOSED, if so,


call the node m CLOSED OLD and add OLD to the list of BESTNODE's
SUCCESSORs.

 Check to see if the new path or the OLD path is better just as in step 2(c), and
set the parent link and g and f' values approximately. If we have just found a
better path to OLD, we must propagate the improvement to OLD's
SUCCESSORs.

 OLD points to its SUCCESSORs, Each successor’s intern points to its


successors and so on until each branch terminates with a node which either is
still on OPEN or as no successors.

 So to propagate new cost downwards to a DEPTH_FIRST traversal of tree


starting at OLD changing each nodes 'g' value (also its f' value) terminating
each branch when we reach either a node with no successors or a node to
which an equivalent or better path already has been found.

 Now check for each node's parent link which points back to its best known
parent.
 As we propagate down to a node, see if its parent points to the node we are
coming from. If so continue the propagation.
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 19 | Module 2 Source : diginotes.in

 If not, then its 'g' value already reflects the better path of which it is a part.
Stop propagation here.
 Possibility here is that the new value of 'g' that is being propagated
downward, and the path we are following may become
Better than the path through the current parent.
Compare the 2 paths.

 If the path through the current parent is still better stop the propagation.
 If the path we are propagating through now, is better, then reset the parent
and continue propagation.
 If SUCCESSOR was not already either OPEN, and add it to the list of
BESTNODE's successors.
Compute f` (SUCCESSOR) = g (SUCCESSOR) + h' (SUCCESSOR)

A* Algorithm
 A* algorithm can be used weather we are interested
in finding a minimal cost overall path or simply any
path as quickly as possible.
 If h’ is the perfect estimator of ‘h’ then A* will
converge immediately to the goal with no search.
 If h’=0 then the search will be controlled by ‘g’.
 If g=0 then the search strategy will be random.
 If g=1 then the search will be breath first search.
 If h’ is neither perfect nor ‘0’ then h’ never overestimates ‘h’and A* algorithm is
guaranteed to find an option solution/path ( as determined by G) to a goal (if
one exists)

Ex1: Assuming that the cost of all the arcs is 1. Initially all nodes except ‘A’
are on OPEN (the figure below shows the situation 2 step later, after B &
E have been expanded) for each node f’ is indicated as the sum of h’ &g.
 In the figure B has lowest f’=4 (h’=3,g=1).
 Suppose it has only one successor ‘E’ which also appears to be 3 moves
away from goal. Now f’(E)=5 also f’(C)=5.
 Suppose algorithm resolves this in favour of the path which is being
followed currently. Next node ‘E’ is expanded.
 Suppose ‘E’ too has single successor ‘F’ which is 3 moves away from goal
but f’(f) =6>f’(C)=5. Thus we expand ‘C’ next.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 20 | Module 2 Source : diginotes.in

 Now by understanding h’(B) some effort has been wasted. ‘B’ is


discovered to be farthest away than what was thought thus we try to find
another path.

Ex2: Now consider a situation shown in figure:


 So node ‘B’ is expanded in the first step.
 In the second step we expand ‘E’ next we
expand ‘F’ & finally we generate ‘G’ for a
solution path of length 4.
 But suppose there is a direct path from ‘D’ to
a solution giving a path length 2.
 We will never find it. This happen because by
overestimating h’(D) we make ‘D’ look so bad that we may find some other
WORSE solution without expanding ‘D’.

A* Algorithm Example
 Given graph is:

 In step 2 f’ value of C is better so expanding ‘C’.

 Node ‘A’ looks better so expanding ‘A’.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 21 | Module 2 Source : diginotes.in

 Node ‘E’ seems to be better as it’s f’ = 16.

 f' = 17 for ‘F’ which is better than the f’ values of B & D, So expanding F.

 Between ‘B’ and ‘D’ (f’=18 for both) lets chose ‘D’.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 22 | Module 2 Source : diginotes.in

 Here path ‘C’ is discarded because there is no progress going down the path as it is a Blind
alley.

 Exploring node ‘E’ seems to be promising as f’=15.

 Now node ‘F’ seems to be more promising amongst all the nodes of OPEN (as f’=16).

 We now see that no other nodes are having f’ value higher than the current node & hence it is
the solution & A* Algorithm stops here.
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 1 | Module 2 Source : diginotes.in
Module 2
Knowledge Representation Issues:
 Representations & Mappings:
For solving the complex problems encountered in AI, large amount of knowledge is needed
also same mechanism for manipulating that knowledge for creating solutions to new
problems.
Consider following entities
Facts: These are the truths in some relevant world and these are the things that need to be
represented.

 Representation of facts in some chosen formalism:


These are the things in which are actually to be manipulate.
How to structure these 2 entities
1. At knowledge level: At this level facts are described.
2. A symbol level: At this level the representation of objects which are defined at knowledge
level, in terms of symbols that can be manipulated by programs.

 Mapping between facts & Representation:

 Key components of the design of any knowledge based program.


Ex: using the mathematical logic as a tool for representation formalism.

Consider the English sentence


 Spot is a dog: This sentence can be represented in logical dog(spot).
 Now to represent the fact all dogs how tails
For all(x) : dog(x) ->hastail(x)
Then using this deductive mechanism of logic we may generate a new representation of
object:
Hastail(spot)

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 2 | Module 2 Source : diginotes.in
 Representation of facts:

Ex: In a program say A=5 so within the program (say changing int A=5;(internal
representation of A) later somewhere in the mid of program we write.
A=A+n where n=10
 A=5+10 => A=15 and finally we print the value of A as 15 (Which is an integer number).

Approaches to Knowledge Representation:


For representing knowledge in a particular domain, a good system possesses the following
4 properties
1. Representational Adequacy:
The ability to represent all kinds of the knowledge which are needed for that
domain.
2. Inferential Adequacy:
It is the ability to manipulate the representational structure in such a way as to
derive new structures corresponding to new knowledge inferred from old.
3. Inferential Efficiency:
It is the ability to incorporate additional knowledge into the knowledge
structure which can be used to focus attention of the inference mechanisms in
the most promising directions.
4. Acquisitional Efficiency:
It is the ability to acquire new information easily.

Simple Relational Knowledge:


Simple way to represent declarative facts is to represent it as a set of relations that
are used in Database systems
Player Height Weight Bats-throws
Hank Aaron 6-0 180 Right-Right
Willie Mays 5-10 170 Right-Right

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 3 | Module 2 Source : diginotes.in
Babe Ruth 6-2 215 Left-Left
Ted Williams 6-3 205 Left-Right

Player_info(‘Hank Aaaron’,’6-0’,180,’Right-Right’)
But with such database, it is not possible to answer a simple question “who is the heaviest
player?”
But if a procedure is provided for finding the heaviest player then the facts given in this
relation will enable the procedure to compute the answer.
Inheritable Knowledge:
One of the most useful forms of interface is Property Interface, in which elements of
specific classes inherit attributes and values from more general classes in which they are
included.
For supporting property Inheritance, the objects must be organized into classes and must
be arranged in generalization hierarchy.
Following figure shows some additional Baseball knowledge instead into a Frame.

Boxed nodes represent objects and values of attributes of objects.


Therefore, the object Baseball player
Is a: Adult Male
Bats: (EQUAL Handed)
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 4 | Module 2 Source : diginotes.in
Height: 6-1
Batting-average: .252

Algorithm: Property Inheritance


To retrieve a value V for attribute A of an instance object O:
1. Find O in the knowledge base.
2. If there is a value present for attribute A, report that value.
3. Otherwise, see if there is a value for the attribute instance. If not then fail.
4. Otherwise, move to the node corresponding to that value and look for a value of the
attribute A; if one is found then report it.
5. Otherwise, do until there is no value for the isa attribute or until an answer is found:
(a) Get the value of the isa attribute and more to that node.
(b) See if there is a value for the attribute A. If there is, report it.
This algorithm can be applied to the example (created above) knowledge base to derive
answers to the following queries:
 Team(Pee-Wee-Reese) =Brooklyn Dodgers
As this attribute had a value stored explicitly stored in the knowledge base.
 Batting-average (Three figure Brown) = .106
Through the instance pitcher we extract the value stored there.
 Height(Pee-Wee-Reese) = 6-1
Through instance fielder and isa Baseball-Player we extract the value stored there.
 Bats (Three-finger Brown) =Right
To get a value for the attribute bats required going up the isa hierarchy to the class
Baseball-Player but we found that was not a value but a rule i.e. Equal to handed i.e.
bats=handed hence follow isa link to class adult-male(handed) is not there further it
follows isa link to class person which has attribute handed and the value is right.

Inferential Knowledge:
Inheritance property is a powerful form of inference but it is not the only useful form
E.g.: use of first order predicate logic for representing additional knowledge about
baseball.
𝐹𝑎𝑖𝑟(𝑥)𝐼𝑛𝐹𝑖𝑒𝑙𝑑
1. ∀𝑥: 𝐵𝑎𝑙𝑙(𝑥)𝐹𝑙𝑦(𝑥) − 𝑐𝑎𝑡𝑐ℎ𝑎𝑏𝑙𝑒(𝑥)𝑂𝑐𝑐𝑢𝑝𝑖𝑒𝑑 𝐵𝑎𝑠𝑒(𝐹𝑖𝑟𝑠𝑡)𝑂𝑐𝑐𝑢𝑝𝑖𝑒𝑑 −
¬[𝐿𝑖𝑛𝑒−𝑑𝑟𝑖𝑣𝑒(𝑥)]𝑉
𝐵𝑎𝑠𝑒(𝑆𝑒𝑐𝑜𝑛𝑑)(𝑜𝑢𝑡𝑠<2) 𝐴𝑡𝑡𝑒𝑚𝑝𝑡𝑒𝑑
− 𝐵𝑡(𝑥) → 𝐼𝑛𝑓𝑖𝑒𝑙𝑑 − 𝑓𝑙𝑦(𝑥)
𝐼𝑛𝑓𝑖𝑒𝑙𝑑
2. ∀𝑥, 𝑦: 𝐵𝑎𝑡𝑡𝑒𝑟(𝑥)𝑏𝑎𝑡𝑡𝑒𝑑(𝑥,𝑦) − 𝐹𝑙𝑦(𝑦) → 𝑂𝑢𝑡(𝑥)
The knowledge represented in above 2 examples is USELESS
Unless there is also an inference procedure that can exploit it.

Procedural Knowledge: The Procedural Knowledge (or Operational Knowledge) specifies


what to do when.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 5 | Module 2 Source : diginotes.in
E.g. Procedural knowledge is represented in the form of a program in a programming
language. The machine uses the knowledge. When it executes the code to perform a task.

Issues in knowledge representation


 Are any attributes of objects so basic that they occur in almost every problem
domain, if so, such attribute must be handled appropriately in each of the
mechanism that is being proposed? If such attribute exist, what are they?
 Are there any important relationships which exist among attribute of objects.
 At what level should knowledge be represented? Is there a good set of primitives
into which all knowledge can be broken down? Is that helpful to use such primitives?
 How should sets of objects be represented?
 Given a large amount of knowledge stored in database, how can relevant parts be
accessed when they are needed?

Important attributes:
There are 2 important attributes of significance.
1. Instance
2. Isa
These attributes are important as they support inheritance.

Relationships among attributes:


These are properties via
 Inverses
 Existence in an Isa hierarchy
 Techniques for reasoning about values
 Single valued attributes

Inverses
Consider the logical representations.
Team (Pee-Wee-Reese,Brooklyn-Dodgers).
Then to represent this in other form of assertions gn, the inverse approach a focus on
single entity and using them in pairs is the norm.
Hence the team information is represented as
 One associated with Pee Wee Reese.
Team = Brooklyn – Dodgers
and one associated with Brooklyn Dodgers. We have,
Team – members = Pee Wee Reese.
Thus an inverse relationship has been established.

An ‘Isa’ hierarchy of attribute:-


When we have attributes and specialization of attributes then we can think of Isa hierarchy.
Ex: Consider the Attribute height.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 6 | Module 2 Source : diginotes.in
It is specialization of one more general attribute called Physical size. Which is a
specialization of physical attribute.
Techniques for reasoning about the values
The reasoning system must reason about values which have not been given explicitly.
There are several kinds of information which can play a role in reasoning such as.
1. Information about the type of value
Ex: The value of height must be a number measured in a unit of length.
2. Constraints on the value in terms of related entities.
Ex: Age of a person cannot be greater than that of his/her parents.
3. Rules for computing the values when it is needed. Also called as if needed rules.
Ex: The way in which value for bats for figure 4.5 in page 83 (textbook) was fetched
through backwards rule.
4. Rules which describe actions that should be taken if a value never becomes known.
These rules are called as forward rules. (or if-added rules)

Single Valued Attributes:


The attributes which takes a unique value are called single-valued attributes.
Ex: A baseball player can have a single height & be a member of a single team only at
one point of time.
For extracting/supporting a single valued attribute, the knowledge representation
system must take several different approaches.
 Introduce an explicit notation for temporal interval.
 Assume that the only temporal interval is of interest is now.
 Provide no explicit support.

Choosing the granularity of representation:


The question of “At what level of detail should the world be represented” or “what
should be our primitives?”
Suppose we are interested in fact John spotted Sue.
This can be represented as
spotted (agent (John), object (Sue))
This representation makes it easy to answer the question.
Who spotted Sue?
But now, suppose we want to know
Did John see Sue?
But with given facts we can’t answer the question and we have to add other facts
such as
spotted (x, y) → saw (x, y)
Ex:
Explain the problem described in page 90 fig 4.10
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 7 | Module 2 Source : diginotes.in
There are several arguments against the use of law-level primitives. As
the simple high level facts may require a low of storage when broken down into primitives.
Take: John punched Mary and Mary punched John.
 Second related problem is that if knowledge is initially presented in a relatively high
level form such as English, then substantial work must be done by the system to
reduce the knowledge into primitive form.
A third problem is that with the use of low level primitives is that in many domains, it is not
at all clear what the primitive should be.
Ex: An attempt to describe the cousin relationship in terms of primitives could produce any
of the following interpretations for the sentence “Mary is Sue’s cousin”
 Mary= daughter (brother(mother(sue)))
 Mary= daughter (sister(mother(sue)))
 Mary= daughter (brother(father(sue)))
 Mary= daughter (sister(father(sue)))
But the general representation should have been.
Mary= child (sibling(parent(sue)))
 In less well structured domains, more problems arise.
Eg: John broke the window. A program will not be able to decide if John’s actions
consisted of the primitive sequence:
1. Pick up a hard object.
2. Hold onto the object while causing it to crash into the window.
(or) the single action.
1. Cause hand (or foot) to move fast and crash into the window.
(or) the single action:
1. Shut the window so hard that the glass breaks.
From the above examples it is clear that choosing the correct grammarlarity of
representation for a particular both of the knowledge is not easy.
 Representating sets of objects
It is important to represent the objects for several reason.
Because there are some properties which are true for the sets the same is not true
for individual members of the set.
Eg: consider the sentence
“There are more sheep than people in Australia”. And “English speakers can be found
all over the world”.
Comparing sheep with people and taking a single English speaker to be found all over
the world.
 Finding the right structures as need
In the problem solving process, localing appropriate knowledge structures which
have been stored in the memory is difficult.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 8 | Module 2 Source : diginotes.in
Eg: Consider the script which describes a typical sequence of events in a restaurant
‘John went to steak and ale last night. He ordered a large rare steak, paid his bill and
left. Now this script is supplied is the computer system and the question is asked.
“Did John eat dinner last night?”
 We can see that no where in the story it is mentioned that john ate dinner. For
a human being it is easy to understand that the person who purchases the
food will eat it but for a system it is very difficult to return an answer as in the
given script nowhere it is mentioned that John had been in a Restaurant. So
system fails to select a right structure.
Thus in order to have access to the right structure for describing a particular situation
it is necessary to solve the following problems.
 How to perform an initial selection of the most appropriate structure?
 How to fill appropriate details from the current situation?
 How to find better structure if the one chosen initially turn not to be
appropriate.
 What to do if none of the available structures is appropriate.
 When to create and remember a new structure.

1. Selecting an Initial structure:


Selection of a candidate knowledge structure to match a particular problem solving
situation is a hard problem.
The important approaches are listed as follows:
 Indicate the structures directly by the significant English words that can be
used for describing them.
Eg: For selecting simple structures such as those representing the meanings of
individual words through, this approach may not be adequate.
 Same word may have different meaning under different context.
The word ‘fly’ has different meaning in each of the following sentences:
 John flew to New York (John rode an aeroplane to go from one place to
another).
 John flew a kite (John held a kite that was flying up in the air).
 John flew down the street (John moved rapidly through the street).
 John flew into a large (indicating John became very angry).
2. Consider each major concept as a pointer to all of the structures (such as the scripts)
in which such structure is involved.
This may produce several sets of prospective structures.
Eg: The concept steak may point to two scripts namely
1) Restaurant,

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 9 | Module 2 Source : diginotes.in
2) Super Market,Similarly concept Bill may point to a Restaurant a shopping script.
Now taking the intersection of these sets to get the structures preferably only one
(to be precise), involving all the words content. But this also leads to a problem.
Eg: John rode his bicycle to Steak and Ale last night.
3) Locate one major clue in the problem description and use it for selecting an initial
structure.
But this method has problems:
a. In some situation, identification of major clue may not be identified.
b. It is difficult to anticipate that which clue is going to be important.
Eg: Ramana Murthy has been admitted to cancer hospital. (The admission is as a
student studing medicine, or as all in patient or as a visitor).
i. In many contexts, the colour of the objects involved is not important.
But when the context is traffic light signal. “The light turned red”
there the colour of light is the most important feature.
ii. Revising the choice when necessary when a candidate knowledge
structure is found an attempt is made to do a detailed match of it to
the problem at hand. The matching process may vary depending on
the representation that is being used. The attribute values may have
to be compared, if the values satisfy the required restrictions as
imposed by the knowledge structure then they are placed in
appropriate place in the structure. If no appropriate values can be
found, then a new structure must be selected. When the process of
instantiating a structure in a particular situation after dose not
proceed smoothly than a variety of thing can be done instead of
abandoning the effort & startover.
 Select the fragments of the current structure which corresponds to the situation and
matches them against the candidate alternatives.
Choose the best match and if the current structure is found to be close to being
approximate then all the efforts build and fit the sub-structure into the structure will
be preserved.
 Make an excuse for the current structures failure and continue to use it.
 Refer to specific stored links between structures to suggest new directions in which
to explore.
 If the knowledge structures are stored in an hierarchy, traverse upwards in it until a
structure is found which is sufficiently general that it does not conflict with the
evidence.
Ex: A similarity net

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in


P a g e | 10 | Module 2 Source : diginotes.in

4) The frame problem:


The whole problem of representing the facts, which change as well as that do not
change is called as the frame problem.
In some domain the only difficult part is representing all the facts.
Ex: In robot world, there may be a table with plant on it under the window.
Suppose we now move the table to centre of the room.
Therefore, there is a chance and it has to be inferred that the plant is now in the
centre of the room but the window is not.
 To support this kind of reasoning, some systems make use of some an explicit set of
axioms called as frame axioms which describe all the things that do not change when
a particular operator is applied in state ‘n’ to produce state ‘n+1’.
Therefore, for robot domain the axiom may be written as
color (x, y, x1) ^ move (x, s1, s2) → color (x, y, s2)
where color (x, y, s1) can be read as if x has colour in state s1and the
operation of moving x is applied in the state to produce state s2, then the colour of x
in S2 is still y.

Now the question arise how is undo the effect changes in the problem state description:
Eg:-
Suppose we wish to undo the effect of moving the table to the center of the
Room.
 There are two ways in which this problem can be solved.
a) Do not modify the initial state description at all. At each node store an indication of
the specific changes that should be node at this node.
Whenever it is necessary to refer to the description of the current problem state,
look at the initial state description also look back through all the nodes on the path
from start state to current state.
Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in
P a g e | 11 | Module 2 Source : diginotes.in
This approach makes back tracking very easy (it makes referring to the state
description complex).
b) Modify the initial state description appropriately and record at each node an
indication of what to do undo the move, if it is required to back track through the
node.
Then whenever it is necessary to back track, check each node along the way &
perform the indicated operation on the state description.

Dr. Satyanarayan Reddy K, Dept. of ISE, CITech, Bangalore Source : diginotes.in

You might also like