AI Mod2
AI Mod2
AI Mod2
Informed Search Informed search algorithms in AI use domain expertise. Problem information is
accessible in an informed search, which can guide the search. As a result, informed search strategies
are more likely to discover a solution than uninformed ones.
The informed search algorithm is more useful for large search space. Informed search algorithm
uses the idea of heuristic, so it is also called Heuristic search.
Heuristic search is another name for informed search. A heuristic is a method that, while not always
guaranteed to find the best solution, is guaranteed to find a decent solution in a reasonable amount
of time. An informed search can answer many complex problems that would be impossible to
handle otherwise.
Heuristic is a technique which makes our search algorithm more efficient. Some heuristics help to
guide a search process without sacrificing any claim to completeness and some sacrificing it.
Heuristic is a problem specific knowledge that decreases expected search efforts. It is a technique
which sometimes works but not always. Heuristic search algorithm uses information about the
problem to help directing the path through the search space.
These searches uses some functions that estimate the cost from the current state to the goal
presuming that such function is efficient. A heuristic function is a function that maps from problem
state descriptions to measure of desirability usually represented as number.
The purpose of heuristic function is to guide the search process in the most profitable directions by
suggesting which path to follow first when more than is available. Generally heuristic incorporates
domain knowledge to improve efficiency over blind search.
In AI heuristic has a general meaning and also a more specialized technical meaning. Generally a
term heuristic is used for any advice that is effective but is not guaranteed to work in every case.
For example in case of travelling sales man (TSP) problem we are using a heuristic to calculate the
nearest neighbour. Heuristic is a method that provides a better guess about the correct choice to
make at any junction that would be achieved by random guessing.
This technique is useful in solving though problems which could not be solved in any other way.
Solutions take an infinite time to compute.
Heuristics function: Heuristic is a function which is used in Informed Search, and it finds the most
promising path. It takes the current state of the agent as its input and produces the estimation of how
close agent is from the goal. The heuristic method, however, might not always give the best solution,
but it guaranteed to find a good solution in reasonable time. Heuristic function estimates how close
a state is to the goal. It is represented by h(n), and it calculates the cost of an optimal path between
the pair of states. The value of the heuristic function is always positive.
Advantages
Best first search can switch between BFS and DFS by gaining the advantages of
both the algos.
This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
It can behave as an unguided depth-first search in the worst case scenario.
It can get stuck in a loop as DFS.
This algorithm is not optimal.
Example:
Consider the below search problem, and we will traverse it using greedy best-first search. At each
iteration, each node is expanded using evaluation function f(n)=h(n) , which is given in the below
table.
Greedy Search - The closest node to the target node is expanded in greedy search algo-rithms in
AI. A heuristic function, h, determines the closeness factor (x). h(x) is a distance estimate between
one node and the end or target node. The closer the node is to the endpoint, the smaller the h(x)
value. When the greedy search looks for the best route to the target node, it will select nodes with
the lowest possible values. This algorithm is implemented through the priority queue. It is not an
optimal algorithm. It can get stuck in loops.
For example, imagine a simple game where the goal is to reach a specific location on a board. The
player can move in any direction but walls are blocking some paths. In a greedy search approach,
the player would always choose the direction that brings them closer to the goal, without
considering the potential obstacles or the fact that some paths may lead to dead ends.
If the chosen path leads to a dead end or a loop, the algorithm will keep moving back and forth
between the same nodes, without ever exploring other options. This can result in an infinite loop
where the algorithm keeps repeating the same steps and fails to find a solution.
A* Search - A* Tree Search, known as A* Search, combines the strengths of uniform-cost search
and greedy search. To find the best path from the starting state to the desired state, the A* search
algorithm investigates all potential paths in a graph or grid. The algorithm calculates the cost of
each potential move at each stage using the following two criteria:
How much it costs to reach the present node ?
The approximate cost from the present node to the goal.
Heuristic search
Heuristic:
- It is a "rule of thumb" used to help guide search
-It is a technique that improves the efficiency of search process, possibly by sacrificing claims of
completeness.
- It is involving or serving as an aid to learning, discovery, or problem-solving by xperimental and
especially trial-and-error methods.
Heuristic Function:
-It is a function applied to a state in a search space to indicate a likelihood of success if that state is
selected
-It is a function that maps from problem state descriptions to measures of desirability usually
represented by numbers
– Heuristic function is problem specific.
A heuristic function is used to determine the estimated cost and estimate the distance between the
current node and the desired state. The acceptable nature of this heuristic function ensures that it
never over estimates the actual cost of achieving the goal.
The path with the lowest overall cost is chosen after an A* search examines each potential route
based on the sum of the actual cost and the estimated cost (i.e., the cost so far and the estimated
cost-to-go). By doing this, the algorithm is guaranteed to always investigate the most promising
path first, which is most likely to lead to the desired state.
Conclusion
Search algorithms in AI are algorithms that aid in the resolution of search issues. A search
issue comprises the search space, start, and goal state.
These algorithms are essential because they aid in solving AI problems and support other
systems, such as neural networks and manufacturing systems.
Search algorithms in artificial intelligence define the problem (initial state, target state, state
space, space cost, etc.) and then perform search operations to find the best solution to the
given problem.
Search algorithms in artificial intelligence are classified into two types: informed algorithms
and uninformed algorithms. Breadth-first, depth-first, and uniform-cost algorithms are
examples of informed algorithms. Greedy, A* tree and A* graph algorithms are examples of
uninformed algorithms.
Vehicle routing, nurse scheduling, record retrieval, and industrial processes are some of AI's
most common uses of search algorithms.
In this example, the cost is measured strictly using the heuristic value. In other words, how close it
is to the target.
C has the lowest
cost of 6. Therefore, the search will continue like so
U has the lowest cost compared to M and R, so the search will continue by exploring U. Finally, S
has a heuristic value of 0 since that is the target node:
The total cost for the path (P -> C -> U -> S) evaluates to 11. The potential problem with a greedy
best-first search is revealed by the path (P -> R -> E -> S) having a cost of 10, which is lower than
(P -> C -> U -> S). Greedy best-first search ignored this path because it does not consider the edge
weights.
Algorithm
The Greedy Best-First Search algorithm aims to find the path from a given start node to a goal node
in a graph. Here are the general steps of the algorithm −
Initialize an empty priority queue.
Enqueue the start node into the priority queue.
Create an empty set to track visited nodes.
While the priority queue is not empty − Dequeue the highest-priority node from the queue.
If the dequeued node is the goal node, the algorithm terminates, and the path is found.
Otherwise, mark the dequeued node as visited.
Enqueue all unvisited neighboring nodes of the dequeued node into the priority queue.
If the priority queue becomes empty before reaching the goal node, no path exists. calling
the greedyBestFirstSearch function.
Example:
Consider the below search problem, and we will traverse it using greedy best-first search. At each
iteration, each node is expanded using evaluation function f(n)=h(n) , which is given in the below
table.
Let us see how this works for route-finding problems in Romania; we use the straight line distance
heuristic, which we will call hSLD . If the goal is Bucharest, we need to know the straight line
distances to Bucharest, which are shown in Figure.
In this search example, we are using two lists which are OPEN and CLOSED Lists. Following are
the iteration for traversing the above example.
Time Complexity: The worst case time complexity of Greedy best first search is O(bm).
Space Complexity: The worst case space complexity of Greedy best first search is O(bm). Where,
m is the maximum depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space is finite.
Optimal: Greedy best first search algorithm is not optimal.
Greedy best first search
Concept:
Step 1: Traverse the root node
Step 2: Traverse any neighbor of the root node, that is maintaining a least distance from the
root node and insert them in ascending order into the queue.
Step 3: Traverse any neighbor of neighbor of the root node, that is maintaining a least
distance fromthe root node and insert them in ascending order into the queue
Step 4: This process will continue until we are getting the goal node
Algorithm:
Step 1: Place the starting node or root node into the queue.
Step 2: If the queue is empty, then stop and return failure.
Step 3: If the first element of the queue is our goal node, then stop and return success.
Step 4: Else, remove the first element from the queue. Expand it and compute the estimated
goal distancefor each child. Place the children in the queue in ascending order to the goal
distance. Step 5: Go to step-3
Implementation:
Step 1: Consider the node A as our root node. So the first element of the queue is A which is not our
goal node, so remove it from the queue and find its neighbor that are to inserted in ascending order.
A
Step 2: The neighbors of A are B and C. They will be inserted into the queue in ascending order.
BCA
Step 3: Now B is on the FRONT end of the queue. So calculate the neighbours of B that are
maintaining a least distance from the roof.
FEDCB
Step 4:Now the node F is on the FRONT end of the queue. But as it has no further children, so
remove it from the queue and proceed further.
EDCB
Step 5:Now E is the FRONT end. So the children of E are J and K. Insert them into the queue in
ascending order.
KJDCE
Step 6:Now K is on the FRONT end and as it has no further children, so remove it and proceed
further
JDCK
Step7:Also, J has no corresponding children. So remove it and proceed further.
DCJ
Step 8:Now D is on the FRONT end and calculates the children of D and put it into the queue.
ICD
Step9:Now I is the FRONT node and it has no children. So proceed further after removing this node
from the queue.
CI
Step 10:Now C is the FRONT node .So calculate the neighbours of C that are to be inserted in
ascending order into the queue.
GHC
Step 11:Now remove G from the queue and calculate its neighbour that is to insert in ascending
order into the queue.
MLHG
Step12:Now M is the FRONT node of the queue which is our goal node. So stop here and exit.
LHM
Advantage:
It is more efficient than that of BFS and DFS.
Time complexity of Best first search is much less than Breadth first search.
The Best first search allows us to switch between paths by gaining the benefits of both breadth
first and depth first search. Because, depth first is good because a solution can be found without
computing all nodes and Breadth first search is good because it does not get trapped in dead ends.
Disadvantages:
Sometimes, it covers more distance than our consideration.
A* search is the most commonly known form of best-first search. It uses heuristic function h(n),
and cost to reach the node n from the start state g(n). It has combined features of UCS and greedy
best-first search, by which it solve the problem efficiently. A* search algorithm finds the shortest
path through the search space using the heuristic function. This search algorithm expands less
search tree and provides optimal result faster. A* algorithm is similar to UCS except that it uses
g(n)+h(n) instead of g(n).
In A* search algorithm, we use search heuristic as well as the cost to reach the node. It evaluates
nodes by combining g(n), the cost to reach the node, and h(n), the cost to get from the node to the
goal:
At each point in the search space, only those node is expanded which have the lowest value of f(n),
and the algorithm terminates when the goal node is found.
Algorithm of A* search:
Solution:
Initialization: {(S, 5)}
Iteration1: {(S--> A, 4), (S-->G, 10)}
Iteration2: {(S--> A-->C, 4), (S--> A-->B, 7), (S-->G, 10)}
Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration4: will give the final result, as S--->A--->C--->G it provides the optimal path with cost 6.
Points to remember:
A* algorithm returns the path which occurred first, and it does not search for all remaining paths.
The efficiency of A* algorithm depends on the quality of heuristic.
A* algorithm expands all nodes which satisfy the condition f(n)
Complete: A* algorithm is complete as long as: Branching factor is finite. Cost at every action is
fixed.
Optimal: A* search algorithm is optimal if it follows below two conditions:
Admissible: the first condition requires for optimality is that h(n) should be an admissible heuristic
for A* tree search. An admissible heuristic is optimistic in nature.
Consistency: Second required condition is consistency for only A* graph-search.
If the heuristic function is admissible, then A* tree search will always find the least cost path.
Time Complexity: The time complexity of A* search algorithm depends on heuristic function, and
the number of nodes expanded is exponential to the depth of solution d. So the time complexity is
O(b^d), where b is the branching factor.
Space Complexity: The space complexity of A* search algorithm is O(b^d)
Heuristic Search
A heuristic is a technique that is used to solve a problem faster than the classic methods. These
techniques are used to find the approximate solution of a problem when classical methods do not.
Heuristics are said to be the problem-solving techniques that result in practical and quick solutions.
Heuristics are strategies that are derived from past experience with similar problems. Heuristics use
practical methods and shortcuts used to produce the solutions that may or may not be optimal, but
those solutions are sufficient in a given limited timeframe.
History of heuristics
Psychologists Daniel Kahneman and Amos Tversky have developed the study of Heuristics in
human decision-making in the 1970s and 1980s. However, this concept was first introduced by the
Nobel Laureate Herbert A. Simon, whose primary object of research was problem-solving.
Why do we need heuristics?
Heuristics are used in situations in which there is the requirement of a short-term solution. On
facing complex situations with limited resources and time, Heuristics can help the companies to
make quick decisions by shortcuts and approximated calculations. Most of the heuristic methods
involve mental shortcuts to make decisions on past experiences.
The heuristic method might not always provide us the finest solution, but it is assured that it helps
us find a good solution in a reasonable time.Based on context, there can be different heuristic
methods that correlate with the problem's scope. The most common heuristic methods are -trial and
error, guesswork, the process of elimination, historical data analysis. These methods involve simply
available information that is not particular to the problem but is most appropriate. They can include
representative, affect, and availability heuristics. Each heuristic type plays a role in decision-
making.
Availability heuristic
Availability heuristic is said to be the judgment that people make regarding the likelihood of an
event based on information that quickly comes into mind. On making decisions, people typically
rely on the past knowledge or experience of an event. It allows a person to judge a situation based
on the examples of similar situations that come to mind.
Representative heuristic
It occurs when we evaluate an event's probability on the basis of its similarity with another event.
Example: We can understand the representative heuristic by the example of product packaging, as
consumers tend to associate the products quality with the external packaging of a product. If a
company packages its products that remind you of a high quality and well-known product, then
consumers will relate that product as having the same quality as the branded product.
So, instead of evaluating the product based on its quality, customers correlate the products quality
based on the similarity in packaging.
Affect heuristic
It is based on the negative and positive feelings that are linked with a certain stimulus. It includes
quick feelings that are based on past beliefs. Its theory is one's emotional response to a stimulus that
can affect the decisions taken by an individual.
When people take a little time to evaluate a situation carefully, they might base their decisions
based on their emotional response.
Example: The affect heuristic can be understood by the example of advertisements. Advertisements
can influence the emotions of consumers, so it affects the purchasing decision of a consumer. The
most common examples of advertisements are the ads of fast food. When fast-food companies run
the advertisement, they hope to obtain a positive emotional response that pushes you to positively
view their products.
If someone carefully analyzes the benefits and risks of consuming fast food, they might decide that
fast food is unhealthy. But people rarely take time to evaluate everything they see and generally
make decisions based on their automatic emotional response. So, Fast food companies present
advertisements that rely on such type of Affect heuristic for generating a positive emotional
response which results in sales.
Examples of heuristics in everyday life
Some of the real-life examples of heuristics that people use as a way to solve a problem:
Common sense: It is a heuristic that is used to solve a problem based on the observation of an individual.
Rule of thumb: In heuristics, we also use a term rule of thumb. This heuristic allows an
individual to make an approximation without doing an exhaustive search.
Working backward: It lets an individual solve a problem by assuming that the problem is
already being solved by them and working backward in their minds to see how much a
solution has been reached.
Availability heuristic: It allows a person to judge a situation based on the examples of
similar situations that come to mind.
Familiarity heuristic: It allows a person to approach a problem on the fact that an
individual is familiar with the same situation, so one should act similarly as he/she acted in
the same situation before.
Educated guess: It allows a person to reach a conclusion without doing an exhaustive
search. Using it, a person considers what they have observed in the past and applies that
history to the situation where there is not any definite answer has decided yet.
Limitation of heuristics
Along with the benefits, heuristic also has some limitations.
Although heuristics speed up our decision-making process and also help us to solve
problems, they can also introduce errors just because something has worked accurately in
the past, so it does not mean that it will work again.
It will hard to find alternative solutions or ideas if we always rely on the existing solutions
or heuristics.
Conclusion
That's all about the article. Hence, in this article, we have discussed the heuristic techniques that are
the problem-solving techniques that result in a quick and practical solution. We have also discussed
some algorithms and examples, as well as the limitation of heuristics.