ai unit 2 notes
ai unit 2 notes
II-YEAR-AI&DS -2021 R
SUB CODE: AL3391
SUB NAME: Artificial Intelligence
UNIT II
PROBLEM SOLVING
Heuristic search strategies – heuristic functions. Local search and optimization
problems – local search in continuous space – search with non-deterministic
actions – search in partially observable environments – online search agents and
unknown environments
1
UNIT II
What is Heuristics?
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.
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
2
Direct Heuristic Search techniques in AI
It includes Blind Search, Uninformed Search, and Blind control strategy. These search
techniques are not always possible as they require much memory and time. These techniques
search the complete space for a solution and use the arbitrary ordering of operations.
The examples of Direct Heuristic search techniques include Breadth-First Search (BFS) and
Depth First Search (DFS).
It includes Informed Search, Heuristic Search, and Heuristic control strategy. These techniques
are helpful when they are applied properly to the right types of tasks. They usually require
domain-specific information.
The examples of Weak Heuristic search techniques include Best First Search (BFS) and A*.
Before describing certain heuristic techniques, let's see some of the techniques listed below:
o Bidirectional Search
o A* search
o Simulated Annealing
o Hill Climbing
o Best First search
o Beam search
It is a technique for optimizing the mathematical problems. Hill Climbing is widely used when a
good heuristic is available.
It terminates when it reaches a peak value where no neighbor has a higher value. Traveling-
salesman Problem is one of the widely discussed examples of the Hill climbing algorithm, in
which we need to minimize the distance traveled by the salesman.
It is also called greedy local search as it only looks to its good immediate neighbor state and
not beyond that. The steps of a simple hill-climbing algorithm are listed below:
3
Step 1: Evaluate the initial state. If it is the goal state, then return success and Stop.
Step 2: Loop Until a solution is found or there is no new operator left to apply.
Else if it is better than the current state, then assign a new state as a current state.
Else if not better than the current state, then return to step2.
Step 5: Exit.
This algorithm always chooses the path which appears best at that moment. It is the combination
of depth-first search and breadth-first search algorithms. It lets us to take the benefit of both
algorithms. It uses the heuristic function and search. With the help of the best-first search, at
each step, we can choose the most promising node.
Step 3: Remove the node n from the OPEN list, which has the lowest value of h(n), and places it
in the CLOSED list.
Step 5: Check each successor of node n, and find whether any node is a goal node or not. If any
successor node is the goal node, then return success and stop the search, else continue to next
step.
Step 6: For each successor node, the algorithm checks for evaluation function f(n) and then
check if the node has been in either OPEN or CLOSED list. If the node has not been in both lists,
then add it to the OPEN list.
4
A* Search Algorithm
A* search is the most commonly known form of best-first search. It uses the 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.
It finds the shortest path through the search space using the heuristic function. This search
algorithm expands fewer search tree and gives optimal results faster.
Algorithm of A* search:
Step 2: Check if the OPEN list is empty or not. If the list is empty, then return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value of the evaluation
function (g+h). If node n is the goal node, then return success and stop, otherwise.
Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each
successor n', check whether n' is already in the OPEN or CLOSED list. If not, then compute the
evaluation function for n' and place it into the Open list.
Step 5: Else, if node n' is already in OPEN and CLOSED, then it should be attached to the back
pointer which reflects the lowest g(n') value.
Some of the real-life examples of heuristics that people use as a way to solve a problem:
o Common sense: It is a heuristic that is used to solve a problem based on the observation
of an individual.
o 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.
o 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.
5
o Availability heuristic: It allows a person to judge a situation based on the examples of
similar situations that come to mind.
Types of heuristics
There are various types of heuristics, including the availability heuristic, affect heuristic
and representative heuristic.
Each heuristic type plays a role in decision-making. Let's discuss about the Availability
heuristic, affect heuristic, and Representative heuristic.
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.
6
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.
Limitation of heuristics
o 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.
o It will hard to find alternative solutions or ideas if we always rely on the existing
solutions or heuristics.
7
h(n)=Number of tiles out of position.
So, there is total of three tiles out of position i.e., 6,5 and 4. Do not count the empty tile present
in the goal state).
i.e. h(n)=3. Now, we require to minimize the value of h(n) =0.
We can construct a state-space tree to minimize the h(n) value to 0, as shown below:
It is seen from the above state space tree that the goal state is minimized from h(n)=3 to
h(n)=0.
However, we can create and use several heuristic functions as per the reqirement. It is
also clear from the above example that a heuristic function h(n) can be defined as the
information required to solve a given problem more efficiently.
The information can be related to the nature of the state, cost of transforming from
one state to another, goal node characterstics, etc., which is expressed as a heuristic
function.
8
2. Local Search Algorithms and Optimization Problem:
The informed and uninformed search expands the nodes systematically in two ways:
Which leads to a solution state required to reach the goal node. But beyond these “classical
search algorithms," we have some “local search algorithms” where the path cost does not
matters, and only focus on solution-state needed to reach the goal node.
A local search algorithm completes its task by traversing on a single current node rather than multiple
paths and following the neighbors of that node generally.
Although local search algorithms are not systematic, still they have the following two
advantages:
Local search algorithms use a very little or constant amount of memory as they operate
only on a single path.
Most often, they find a reasonable solution in large or infinite state spaces where
the classical or systematic algorithms do not work.
Working of a Local search algorithm
Consider the below state-space landscape having both:
The local search algorithm explores the above landscape by finding the following two points:
Global Minimum: If the elevation corresponds to the cost, then the task is to find
the lowest valley, which is known as Global Minimum.
Global Maxima: If the elevation corresponds to an objective function, then it finds
the highest peak which is called as Global Maxima. It is the highest point in the
valley.
9
We will understand the working of these points better in Hill-climbing search.
Hill-climbing Search
Simulated Annealing
Local Beam Search
Global Maximum: It is the highest point on the hill, which is the goal state.
Local Maximum: It is the peak higher than all other peaks but lower than the
global maximum.
Flat local maximum: It is the flat area over the hill where it has no uphill or downhill.
It is a saturated point of the hill.
Shoulder: It is also a flat area where the summit is possible.
Current state: It is the current position of the person.
10
Types of Hill climbing search algorithm
There are following types of hill-climbing search:
11
Random-restart hill climbing
Random-restart algorithm is based on try and try strategy. It iteratively searches the node and
selects the best one at each step until the goal is not found.
The success depends most commonly on the shape of the hill. If there are few plateaus, local
maxima, and ridges, it becomes easy to reach the destination.
Local Maxima: It is that peak of the mountain which is highest than all its neighboring
states but lower than the global maxima. It is not the goal peak because there is another peak higher
than it.
Plateau: It is a flat surface area where no uphill exists. It becomes difficult for the
climber to decide that in which direction he should move to reach the goal point.
Sometimes, the person gets lost in the flat area.
Ridges: It is a challenging problem where the person finds two or more local maxima of
the same height commonly. It becomes difficult for the person to navigate the right point
and stuck to that point itself.
12
Simulated Annealing
Simulated annealing is similar to the hill climbing algorithm. It works on the current
situation. It picks a random move instead of picking the best move.
If the move leads to the improvement of the current situation, it is always accepted as a step
towards the solution state, else it accepts the move having a probability less than 1.
This search technique was first used in 1980 to solve VLSI layout problems.
It is also applied for factory scheduling and other large optimization tasks.
Local Beam Search
o Local beam search is quite different from random-restart search.
o It keeps track of k states instead of just one.
o It selects k randomly generated states, and expand them at each step.
o If any state is a goal state, the search stops with success.
o Else it selects the best k successors from the complete list and repeats the same process.
o In random-restart search where each search process runs independently, but in local beam
search, the necessary information is shared between the parallel search processes.
Disadvantages of Local Beam search
This search can suffer from a lack of diversity among the k states.
It is an expensive version of hill climbing search.
13
14
15
4. Search with non-deterministic actions:
16
17
5. Search in partial observable environments:
18
19
20
6. Online Search Agents and Unknown Environments:
6.1.offline search and online search
6.2.online search problem
6.3.Online search agent
6.4.Online local search
21
22
An online depth first exploration agent:
This agent stores it map in a table ,result[s,a],that records the state resulting from
executing action a in state s.
To explore map, the difficulties come when the agent has tried all the action in a
state s.
To avoid dead end,
The algorithm keep another table that lists, for each state, parent state, to which
the agent has not yet backtracked.
If the agent has run out of the state to which it can backtrack then its search is
complete.
It keeps just one current state in memory, and it can do random walk to explore the
environment.
A RANDOM WALK simply select one of the available actions from the current
state.
This process will continue until it find goal or complete its exploration.
Advantage
That space is finite and safely explorable.
Disadvantage
The process can be very slow
An environment in which a random walk will take exponentially many steps to find the goal.
23
24
Online local search:
ke depth-first search, hill-climbing search has the property of locality in its node expansions
25