Professional Documents
Culture Documents
Ai Mod2 PDF
Ai Mod2 PDF
in
ARTIFICIAL INTELLIGENCE
MODULE 2
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.
Algorithm:
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
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.
A D Goal state
D C
C B
B A
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
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
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.
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
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.
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.
Intermediate
Rule x
Rule y apply rule y
Choose rule x
Result
Apply
Result State y
State x Rule
And to reach its goal, it does not matter whether the robot executes N-N-
E or N-E-N,
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
A H
H G
G F
F E
E D
D C
C B
B A
Operators:
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
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
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
B C D
Step 3:
(3) (5) (1)
B C D
(3) (5)
(4) E F (6)
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)
Simulated Annealing
If the random NO is less than the move is accepted otherwise do nothing.
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.
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.
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.
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.
A* Algorithm Example
Given graph is:
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’.
Here path ‘C’ is discarded because there is no progress going down the path as it is a Blind
alley.
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.
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).
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.
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.
Important attributes:
There are 2 important attributes of significance.
1. Instance
2. Isa
These attributes are important as they support inheritance.
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.
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.