Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit 2 AI

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Unit 2

Heuristic Search Techniques


 Search Algorithms
Many traditional search algorithms are used in AI applications. For
complex problems, the traditional algorithms are unable to find the
solutions within some practical time and space limits. Consequently,
many special techniques are developed, using heuristic functions.

The algorithms that use heuristic functions are called heuristic


algorithms.
• Heuristic algorithms are not really intelligent; they appear to be
intelligent because they achieve better performance.
• Heuristic algorithms are more efficient because they take advantage of
feedback from the data to direct the search path.
• Uninformed search algorithms or Brute-force algorithms, search
through the search space all possible candidates for the solution
checking whether each candidate satisfies the problem’s statement.
• Informed search algorithms use heuristic functions that are specific to
the problem, apply them to guide the search through the search space
to try to reduce the amount of time spent in searching.

A good heuristic will make an informed search dramatically outperform


any uninformed search: for example, the Traveling Salesman Problem
(TSP), where the goal is to find is a good solution instead of finding the
best solution. Such techniques help in finding a solution within
reasonable time and space (memory). Some prominent intelligent search
algorithms are stated below:
1. Generate and Test Search
2. Best-first Search
3. Greedy Search
4. A* Search
5. Constraint Search
6. Means-ends analysis

 Heuristics
A heuristic is a method that improves the efficiency of the search
process. Heuristics may not find the best solution every time but
guarantee that they find a good solution in a reasonable time. These are
particularly useful in solving tough and complex problems.

 Heuristic search
To find a solution in proper time rather than a complete solution in
unlimited time we use heuristics. ‘A heuristic function is a function that
maps from problem state descriptions to measures of desirability,
usually represented as numbers’. Heuristic search methods use
knowledge about the problem domain and choose promising operators
first. These heuristic search methods use heuristic functions to evaluate
the next state towards the goal state.

Characteristics of heuristic search


• Heuristics are knowledge about domain, which help search and
reasoning in its domain.
• Heuristic search incorporates domain knowledge to improve efficiency
over blind search.
• Heuristic is a function that, when applied to a state, returns value as
estimated merit of state, with respect to goal.
- Heuristics might (for reasons) underestimate or overestimate the
merit of a state with respect to goal.
- Heuristics that underestimate are desirable and called admissible.
• Heuristic evaluation function estimates likelihood of given state
leading to goal state.
• Heuristic search function estimates cost from current state to goal,
presuming function is efficient.

Example: Travelling salesman


A salesman has to visit a list of cities and he must visit each city only
once. There are different routes between the cities. The problem is to
find the shortest route between the cities so that the salesman visits all
the cities at once.
Suppose there are N cities, then a solution would be to take N! possible
combinations to find the shortest distance to decide the required route.
This is not efficient as with N=10 there are 36,28,800 possible routes.
This is an example of combinatorial explosion.

There are better methods for the solution of such problems: one is
called branch and bound. First, generate all the complete paths and find
the distance of the first complete path. If the next path is shorter, then
save it and proceed this way avoiding the path when its length exceeds
the saved shortest path length, although it is better than the previous
method.

 Generate-And-Test Algorithm
Generate-and-test search algorithm is a very simple algorithm that
guarantees to find a solution if done systematically and there exists a
solution.

Algorithm: Generate-And-Test
1.Generate a possible solution.
2.Test to see if this is the expected solution.
3.If the solution has been found quit else go to step 1.

Potential solutions that need to be generated vary depending on the


kinds of problems. For some problems the possible solutions may be
particular points in the problem space and for some problems, paths
from the start state.

Generate-and-test, like depth-first search, requires that complete


solutions be generated for testing. In its most systematic form, it is only
an exhaustive search of the problem space.
Solutions can also be generated randomly but solution is not guaranteed.
This approach is what is known as British Museum algorithm: finding an
object in the British Museum by wandering randomly.

 Hill Climbing
Hill Climbing is heuristic search used for mathematical optimization
problems in the field of Artificial Intelligence . Given a large set of inputs
and a good heuristic function, it tries to find a sufficiently good solution
to the problem. This solution may not be the global optimal maximum.

In the above definition, mathematical optimization problems implies


that hill climbing solves the problems where we need to maximize or
minimize a given real function by choosing values from the given inputs.
Example-Travelling salesman problem where we need to minimize the
distance traveled by salesman.
‘Heuristic search’ means that this search algorithm may not find the
optimal solution to the problem. However, it will give a good solution in
reasonable time.
A heuristic function is a function that will rank all the possible
alternatives at any branching step in search algorithm based on the
available information. It helps the algorithm to select the best route out
of possible routes.

Features of Hill Climbing


1. Variant of generate and test algorithm : It is a variant of generate and
test algorithm. The generate and test algorithm is as follows :
1. Generate a possible solutions.
2. Test to see if this is the expected solution.
3. If the solution has been found quit else go to step 1.
Hence we call Hill climbing as a variant of generate and test algorithm as
it takes the feedback from test procedure. Then this feedback is utilized
by the generator in deciding the next move in search space.

2. Uses the Greedy approach : At any point in state space, the search
moves in that direction only which optimizes the cost of function with
the hope of finding the optimal solution at the end.

Types of Hill Climbing


1. Simple Hill climbing : It examines the neighboring nodes one by one
and selects the first neighboring node which optimizes the current cost
as next node.

Algorithm for Simple Hill climbing :


Step 1 : Evaluate the initial state. If it is a goal state then stop and return
success. Otherwise, make initial state as current state.
Step 2 : Loop until the solution state is found or there are no new
operators present which can be applied to current state.
a) Select a state that has not been yet applied to the current state and
apply it to produce a new state.
b) Perform these to evaluate new state
i. If the current state is a goal state, then stop and return success.
ii. If it is better than the current state, then make it current state and
proceed further.
iii. If it is not better than the current state, then continue in the loop until
a solution is found.
Step 3 : Exit.

2. Steepest-Ascent Hill climbing : It first examines all the neighboring


nodes and then selects the node closest to the solution state as next
node.
Step 1 : Evaluate the initial state. If it is goal state then exit else make the
current state as initial state
Step 2 : Repeat these steps until a solution is found or current state does
not change
i. Let ‘target’ be a state such that any successor of the current state will
be better than it;
ii. for each operator that applies to the current state
a. apply the new operator and create a new state
b. evaluate the new state
c. if this state is goal state then quit else compare with ‘target’
d. if this state is better than ‘target’, set this state as ‘target’
e. if target is better than current state set current state to Target
Step 3 : Exit

3. Stochastic hill climbing : It does not examine all the neighboring


nodes before deciding which node to select .It just selects a neighboring
node at random, and decides (based on the amount of improvement in
that neighbor) whether to move to that neighbor or to examine another.

Figure : State Diagram for Hill Climbing Algorithm

Different regions in the State Space Diagram


1. Local maximum : It is a state which is better than its neighboring state
however there exists a state which is better than it(global maximum).
This state is better because here value of objective function is higher
than its neighbors.
2. Global maximum : It is the best possible state in the state space
diagram. This because at this state, objective function has highest value.
3. Plateua/flat local maximum : It is a flat region of state space where
neighboring states have the same value.
4. Ridge : It is region which is higher than its neighbours but itself has a
slope. It is a special kind of local maximum.
5. Current state : The region of state space diagram where we are
currently present during the search.
6. Shoulder : It is a plateau that has an uphill edge.

Problems in different regions in Hill climbing


Hill climbing cannot reach the optimal/best state(global maximum) if it
enters any of the following regions :

1. Local maximum : At a local maximum all neighboring states have a


values which is worse than than the current state. Since hill climbing
uses greedy approach, it will not move to the worse state and terminate
itself. The process will end even though a better solution may exist.

To overcome local maximum problem : Utilize backtracking technique.


Maintain a list of visited states. If the search reaches an undesirable
state, it can backtrack to the previous configuration and explore a new
path.

2. Plateau : On plateau all neighbors have same value . Hence, it is not


possible to select the best direction.
To overcome plateaus : Make a big jump. Randomly select a state far
away from current state. Chances are that we will land at a non-plateau
region

3. Ridge : Any point on a ridge can look like peak because movement in
all possible directions is downward. Hence the algorithm stops when it
reaches this state.
To overcome Ridge : In this kind of obstacle, use two or more rules
before testing. It implies moving in several directions at once.
 Best First Search (Informed Search)
The idea of Best First Search is to use an evaluation function to decide
which adjacent is most promising and then explore. Best First Search
falls under the category of Heuristic Search or Informed Search.

It is the combination of depth-first search and breadth-first search


algorithms. It uses the heuristic function and search. Best-first search
allows us to take the advantages of both algorithms. With the help of
best-first search, at each step, we can choose the most promising node.

In the best first search algorithm, we expand the node which is closest to
the goal node and the closest cost is estimated by heuristic function, i.e.
f(n)= g(n).
Where, h(n)= estimated cost from node n to the goal.

We use a priority queue to store costs of nodes. So the implementation


is a variation of BFS, we just need to change Queue to Priority Queue.

 OR-graph
It is sometimes important to search graphs so that duplicate paths
will not be pursued.An algorithm to do this will operate by searching
a directed graph in which each node represents a point in problem
space.

Each node will contain:


– Description of problem state it represents
– Indication of how promising it is
– Parent link that points back to the best node from which it came
– List of nodes that were generated from it
• Parent link will make it possible to recover the path to the goal once
the goal is found.
• The list of successors will make it possible, if a better path is found to
an already existing node, to propagate the improvement down to its
successors.
• This is called OR-graph, since each of its branhes represents an
alternative problem solving path. We need two lists of nodes:

– OPEN – nodes that have been generated and have had the
heuristic function applied to them but which have not yet been
examined. OPEN is actually a priority queue in which the elements with
the highest priority are those with the most promising value of the
heuristic function.

– CLOSED- nodes that have already been examined. We need to keep


these nodes in memory if we want to search a graph rather than a tree,
since whenver a new node is generated, we need to check whether it
has been generated before.

Best first search algorithm:


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 the best node on OPEN
b. Generate its successors
c. For each successor do:
i. If it has not been generated before, evaluate it, add
it to OPEN, and record its parent.
ii. 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
successors that this node may already have.

 A* Algorithm
• BFS is a simplification of A* Algorithm
• Presented by Hart et al
• Algorithm uses:
– f’: Heuristic function that estimates the merits of each node we
generate. This is sum of two components, g and h’ and f’ represents an
estimate of the cost of getting from the initial state to a goal state along
with the path that generated the current node.
– g : The function g is a measure of the cost of getting from initial
state to the current node.
– h’ : The function h’ is an estimate of the additional cost of getting
from the current node to a goal state.
– OPEN
– CLOSED
Algorithm :
1. Start with OPEN containing only initial node. Set that node’s g value
to 0, its h’ value to whatever it is, and its f’ value to h’+0 or h’. Set
CLOSED to empty list.
2. Until a goal node is found, repeat the following procedure:
If there are no nodes on OPEN, report failure.
Otherwise pick the node on OPEN with the lowest f’ value. Call it
BESTNODE. Remove it from OPEN. Place it in CLOSED. See if the
BESTNODE is a goal state. If so exit and report a solution.
Otherwise, generate the successors of BESTNODE but do not set the
BESTNODE to point to them yet.
For each of the SUCCESSOR, do the following:
a. Set SUCCESSOR to point back to BESTNODE. These backwards
links will make it possible to recover the path once a solution is
found.
b. Compute g(SUCCESSOR) = g(BESTNODE) + the cost of
getting from BESTNODE to SUCCESSOR
c. See if SUCCESSOR is the same as any node on OPEN. If so
call the node OLD.
d. If SUCCESSOR was not on OPEN, see if it is on CLOSED. If so,
call the node on CLOSED OLD and add OLD to the list of
BESTNODE’s successors.
e. If SUCCESSOR was not already on either OPEN or CLOSED,
then put it on OPEN and add it to the list of BESTNODE’s
successors. Compute
f’(SUCCESSOR) = g(SUCCESSOR) + h’(SUCCESSOR)

 PROBLEM REDUCTION
When a problem can be divided into a set of sub problems, where each
sub problem can be solved separately and a combination of these will be
a solution, AND-OR graphs or AND - OR trees are used for representing
the solution.

 AND-OR graphs
AND-OR graph (or tree) is useful for representing the solution of
problems that can be solved by decomposing them into a set of smaller
problems, all of which must then be solved.One AND arc may point to
any number of successor nodes, all of which must be solved in order for
the arc to point to a solution.
In order to find solution in an AND-OR graph, we need an algorithm
similar to bfs but with the ability to handle the AND arcs appropriately.
Notice that it may be necessary to get to more than one solution state
since each arm of an AND arc must lead to its own solution node.

FUTILITY is chosen to correspond to a threshold such than any solution


with a cost above it is too expensive to be practical, even if it could ever
be found.

Algorithm : Problem Reduction


I. Initialize the graph to the starting node.
II. Loop until the starting node is labeled SOLVED or until its cost goes
above FUTILITY:
a. Traverse the graph, starting at the initial node and following the
current best path, and accumulate the set of nodes that are on
that path and have not yet been expanded or labeled as solved.
b. Pick one of these nodes and expand it. If there are no successors,
assign FUTILITY as the value of this node. Otherwise, add its
successors to the graph and for each of them compute f’. If f’ of
any node is 0, mark that node as SOLVED.
c. Change the f’ estimate of the newly expanded node to reflect the
new information provided by its successors. Propagate this
change backward through the graph. This propagation of revised
cost estimates back up the tree was not necessary in the BFS
algorithm because only unexpanded nodes were examined. But
now expanded nodes must be reexamined so that the best
current path can be selected.

 AO* Algorithm
The algorithm for performing a heuristic search of an AND - OR graph is
given below. Unlike A* algorithm which used two lists OPEN and CLOSED,
the AO* algorithm uses a single structure G.

G represents the part of the search graph generated so far. Each node in
G points down to its immediate successors and up to its immediate
predecessors, and also has with it the value of h' cost of a path from
itself to a set of solution nodes. The cost of getting from the start nodes
to the current node "g" is not stored as in the A* algorithm.

This is because it is not possible to compute a single such value since


there may be many paths to the same state. In AO* algorithm serves as
the estimate of goodness of a node.

AO* ALGORITHM:
1. Let G consists only to the node representing the initial state call this
node INIT. Compute h' (INIT).
2. Until INIT is labeled SOLVED or hi (INIT) becomes greater than
FUTILITY, repeat the following procedure :
(I) Trace the marked arcs from INIT and select an unbounded node
NODE.
(II) Generate the successors of NODE . if there are no successors then
assign FUTILITY as h' (NODE). This means that NODE is not solvable. If
there are successors then for each one called SUCCESSOR, that is not
also an ancestor of NODE do the following :
(a) add SUCCESSOR to graph G
(b) if successor is not a terminal node, mark it solved and assign
zero to its h ' value.
(c) If successor is not a terminal node, compute it h' value.
(III) propagate the newly discovered information up the graph by doing
the following . let S be a set of nodes that have been marked SOLVED.
Initialize S to NODE. Until S is empty repeat the following procedure:
(a) select a node from S call if CURRENT and remove it from S.
(b) compute h' of each of the arcs emerging from CURRENT ,
Assign minimum h' to CURRENT.
(c) Mark the minimum cost path a s the best out of CURRENT.
(d) Mark CURRENT SOLVED if all of the nodes connected to it
through the new marked are have been labeled SOLVED.
(e) If CURRENT has been marked SOLVED or its h ' has just
changed, its new status must be propagate backwards up the
graph .hence all the ancestors of CURRENT are added to S.

AO* Search Procedure.


1. Place the start node on open.
2. Using the search tree, compute the most promising solution tree TP .
3. Select node n that is both on open and a part of tp, remove n from
open and place it no closed.
4. If n is a goal node, label n as solved. If the start node is solved, exit
with success where tp is the solution tree, remove all nodes from open
with a solved ancestor.
5. If n is not solvable node, label n as unsolvable. If the start node is
labeled as unsolvable, exit with failure. Remove all nodes from
open ,with unsolvable ancestors.
6. Otherwise, expand node n generating all of its successor compute the
cost of for each newly generated node and place all such nodes on open.
7. Go back to step(2)
Note: AO* will always find minimum cost solution.

 CONSTRAINT SATISFACTION:-
Many problems in AI can be considered as problems of constraint
satisfaction, in which the goal state satisfies a given set of constraint.
constraint satisfaction problems can be solved by using any of the search
strategies. The general form of the constraint satisfaction procedure is
as follows:

Until a complete solution is found or until all paths have led to lead ends,
do
1. select an unexpanded node of the search graph.
2. Apply the constraint inference rules to the selected node to generate
all possible new constraints.
3. If the set of constraints contains a contradiction, then report that this
path is a dead end.
4. If the set of constraints describes a complete solution then report
success.
5. If neither a constraint nor a complete solution has been found then
apply the rules to generate new partial solutions. Insert these partial
solutions into the search graph.

Example: consider the crypt arithmetic problems.


SEND
+ MORE
----------
MONEY
----------
CONSTRAINTS:-
1. no two digit can be assigned to same letter.
2. only single digit number can be assign to a letter.
1. no two letters can be assigned same digit.
2. Assumption can be made at various levels such that they do not
contradict each other.
3. The problem can be decomposed into secured constraints. A
constraint satisfaction approach may be used.
4. Any of search techniques may be used.
5. Backtracking may be performed as applicable us applied search
techniques.
6. Rule of arithmetic may be followed

Initial state of problem.


D=?
E=?
Y=?
N=?
R=?
O=?
S=?
M=?
C1=?
C2=?
C1 ,C 2, C3 stands for the carry variables respectively.

Goal State: the digits to the letters must be assigned in such a manner so
that the sum is satisfied.

You might also like