You are on page 1of 47

Fundamentals of Artificial

Intelligence
Module Code & Version #

Informed Search
Topic & Structure of The Lesson

• Greedy Best-First Search (GBF)


• A* Search
• Hill Climbing

Module Code and Module Title Title of Slides


Learning Outcomes

• At the end of this topic, You should be able


to:
– Explain Greedy Best-First Search, A* search and
Hill Climbing.
– Identify path for the each informed search
algorithm.

Module Code and Module Title Title of Slides


Key Terms You Must Be Able To
Use
• If you have mastered this topic, you should be able to use
the following terms correctly in your assignments and
exams:
– Greedy Best-First Search
– A*
– Hill Climbing

Module Code and Module Title Title of Slides


Informed Search

• Informed search algorithm contains an array of


knowledge such as how far we are from the goal,
path cost, how to reach to goal node, etc.
• This knowledge helps agents to explore less to the
search space and find more efficiently the goal
node. Thus, it is more useful for large search space.
• Informed search algorithm uses the idea of
heuristic, so it is also called Heuristic Search.

Module Code and Module Title Title of Slides


Heuristic 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.
• However, might not always give the best solution,
but it guaranteed to find a good solution in
reasonable time.

Module Code and Module Title Title of Slides


Heuristic Function

• 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.

Module Code and Module Title Title of Slides


Pure Heuristic Search

• It expands nodes based on their heuristic value


h(n).
• It maintains two lists, OPEN and CLOSED list.
• In the CLOSED list, it places those nodes which
have already expanded and in the OPEN list, it
places nodes which have yet not been expanded.
• On each iteration, each node n with the lowest
heuristic value is expanded and generates all its
successors and n is placed to the closed list.
• The algorithm continues unit a goal state is found.

Module Code and Module Title Title of Slides


Pure Heuristic Search

• In the informed search we will discuss two main


algorithms which are given below:
– Greedy-Best-First Search
– A* Search
– Hill Climbing

Module Code and Module Title Title of Slides


Greedy Best-First Search

• Greedy-Best First search algorithm always selects


the path which appears best at that moment.
• 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, it
can choose the most promising node.

Module Code and Module Title Title of Slides


Greedy Best-First Search

• 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.
• The greedy best first algorithm is implemented by
the priority queue.

Module Code and Module Title Title of Slides


Search Space

S Node h(n)
A 12
B 4
A B C 7
D 3

C D E F E 8
F 2
H 4
H I G I 9
S 13
G 0

Module Code and Module Title Title of Slides


Greedy Best-First Search
1) Open S13 h(A) = 13

Close S

h(A) = 12 h(B) = 4
2) Open B4 A12
Close S13 A B

h(C) = 7 h(D) = 3
h(F) = 2
h(E) = 8
3) Open F2 E8 A12
C D E F
Close S13 B4
h(G) = 0
h(I) = 9
h(H) = 4
4) Open G0 E8 I9 A12
H I G
Close S13 B4 F2

5) Open E8 I9 A12
Close S13 B4 F2 G0
Module Code and Module Title Title of Slides
Greedy Best-First Search
1) Open S13
h(A) = 13

Close S

h(A) = 12 h(B) = 4
2) Open B4 A12

Close S13 A B

h(C) = 7 h(D) = 3
h(F) = 2
h(E) = 8
3) Open F2 E8 A12
C D E F
Close S13 B4
h(I) = 9 h(G) = 0
h(H) = 4
4) Open G0 E8 I9 A12
H I G
Close S13 B4 F2
Path – S, B, F, G

5) Open E8 I9 A12

Close S13 B4 F2 G0
Module Code and Module Title Title of Slides
Search Space

Node h(n)
I 45
I
A 53
C B 40
B
C 42
A
D 57

E F E 44
D F 0

Goal state = F

Module Code and Module Title Title of Slides


Greedy Best-First Search
1) Open I45
h(I) = 45
Close
I
h(C) = 42
2) Open B40 C42 A53
h(B) = 40
C
Close I45 h(A) = 53
B
A
3) Open C42 E44 A53
h(D) = 57
E F
Close I45 B40
D h(E) = 44 h(F) = 0

4) Open F0 E44 A53

Close I45 B40 C42

5) Open E44 A53

Close I45 B40 C42 F0


Module Code and Module Title Title of Slides
Greedy Best-First Search
1) Open I45
h(I) = 45
Close
I
h(C) = 42
2) Open B40 C42 A53
h(B) = 40
C
Close I45 h(A) = 53
B
A
3) Open C42 E44 A53
h(D) = 57
E F
Close I45 B40
D h(E) = 44 h(F) = 0

4) Open F0 E44 A53


Path – I, B, C, F

Close I45 B40 C42

5) Open E44 A53

Close I45 B40 C42 F0


Module Code and Module Title Title of Slides
A* Search

• 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.

Module Code and Module Title Title of Slides


A* Search

• 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).

Module Code and Module Title Title of Slides


Search Space
1
h(S) = 5

5 S 6
h(D) = 6
h(A) = 7
9 6
A 2
D
3 h(B) = 3 2
h(C) = 4
9 1
B
2
C E h(E) = 5
2
G1 5 7
7
h(G1) = 0 8
F G3
G2
h(F) = 6
h(G3) = 0
h(G2) = 0

Module Code and Module Title Title of Slides


A* Search
h(S) = 5

S
5 6
9

h(A) = 7
A f(A) = 12 h(B) = 3 B f(B) = 12
h(D) = 6 D f(D) = 12

2 2
3 9

f(E) = 13
f(G) = 14 f(C) = 12
h(B) = 3 B h(G1) = 0 G1 h(C) = 4
C h(E) = 5 E
f(B) = 11
5 7 7
1
h(G3) = 0
h(C) = 4 C f(C) = 13
h(G2) = 0 G2 F h(F) = 6 G3 f(G3) = 15

f(G2) = 13 f(F) = 21

Visited: S(5), A(12), B(11), D(12), C(12), E(13), G2(13)

Module Code and Module Title Title of Slides


A* Search
h(S) = 5

S
5 6
9

h(A) = 7
A f(A) = 12 h(B) = 3 B f(B) = 12
h(D) = 6 D f(D) = 12

2 2
3 9

f(C) = 12 f(E) = 13
f(G) = 14
h(B) = 3 B h(G1) = 0 G1 h(C) = 4
C h(E) = 5 E
f(B) = 11
5 7 7
1
h(G3) = 0
h(C) = 6 C f(C) = 13
h(G2) = 0 G2 F h(F) = 6 G3 f(G3) = 15

f(G2) = 13 f(F) = 21

Path: S. D. C. G2

Module Code and Module Title Title of Slides


Search Space

Module Code and Module Title Title of Slides


A* Search
h(S) = 5

S
1 10

h(G) = 0
h(A) = 3

A f(A) = 4
G f(G) = 10

2 1

h(B) = 4 h(C) = 2

f(B) = 7
B C f(C) = 4

3 4
h(D) = 6 h(G) = 0

D G
f(D) = 11 f(G) = 6

Visited: S(5), A(4), C(4), G(6)

Module Code and Module Title Title of Slides


A* Search
h(S) = 5

S
1 10

h(G) = 0
h(A) = 3

A f(A) = 4
G f(G) = 10

2 1

h(B) = 4 h(C) = 2

f(B) = 7
B C f(C) = 4

3 4
h(D) = 6 h(G) = 0

D G
f(D) = 11 f(G) = 6

Path: S, A, C, G

Module Code and Module Title Title of Slides


Hill Climbing

• Hill climbing algorithm is a local search algorithm


which continuously moves in the direction of
increasing elevation/value to find the peak of the
mountain or best solution to the problem.
• It terminates when it reaches a peak value where
no neighbor has a higher value.

Module Code and Module Title Title of Slides


Hill Climbing

• This algorithm works on the following steps in


order to find an optimal solution.
– It tries to define the current state as the state of starting
or the initial state.
– It generalizes the solution to the current state and tries to
find an optimal solution. The solution obtained may not
be the best.
– It compares the solution which is generated to the final
state also known as the goal state.
– It will check whether the final state is achieved or not. If
not achieved, it will try to find another solution.

Module Code and Module Title Title of Slides


State Space for Hill Climbing

Module Code and Module Title Title of Slides


Hill Climbing

• Local Maximum: Local maximum is a state which is better


than its neighbor states, but there is also another state
which is higher than it.
• Global Maximum: Global maximum is the best possible state
of state space landscape. It has the highest value of objective
function.
• Current state: It is a state in a landscape diagram where an
agent is currently present.
• Flat local maximum: It is a flat space in the landscape where
all the neighbor states of current states have the same value.
• Shoulder: It is a plateau region which has an uphill edge.

Module Code and Module Title Title of Slides


Simple Hill Climbing

• Simple hill climbing is the simplest way to


implement a hill climbing algorithm.
• It only evaluates the neighbor node state at a time
and selects the first one which optimizes current
cost and set it as a current state.
• It only checks it's one successor state, and if it
finds better than the current state, then move else
be in the same state.

Module Code and Module Title Title of Slides


Simple Hill Climbing
h(A) = 27

h(B) = 29 h(C) = 30
h(D) = 31
B C D

h(G) = 37 h(H) = 39
h(E) = 33 h(F) = 35 h(I) = 34 h(J) = 36

E F G H I J

h(K) = 40

Module Code and Module Title Title of Slides


Simple Hill Climbing
h(A) = 27

h(B) = 29 h(C) = 30
h(D) = 31
B C D

h(G) = 37 h(H) = 39
h(E) = 33 h(F) = 35 h(I) = 34 h(J) = 36

E F G H I J

h(K) = 40

Module Code and Module Title Title of Slides


Simple Hill Climbing

K40
Initial State: A27
h(B) > h(A)
E33
Current State: B29
h(E) > h(B)
B29
Current State: E33
h(K) > h(E) A27
Current State: K40 = GOAL, STOP!

Module Code and Module Title Title of Slides


Simple Hill Climbing
h(A) = 27

h(B) = 29 h(C) = 30
h(D) = 31
B C D

h(G) = 37 h(H) = 39
h(E) = 33 h(F) = 35 h(I) = 34 h(J) = 36

E F G H I J

h(K) = 40

Path: A, B, E, K

Module Code and Module Title Title of Slides


Simple Hill Climbing
h(A) = 27

h(B) = 29 h(C) = 30
h(D) = 31
B C D

h(G) = 37 h(H) = 39
h(E) = 33 h(F) = 35 h(I) = 34 h(J) = 36

E F G H I J
K40

E33 h(K) = 40
Local Maxima =
drawback of Hill K
Climbing
B29

A27

Module Code and Module Title Title of Slides


Simple Hill Climbing Algorithm

• Step 1: Evaluate the initial state, if it is goal state then return


success and Stop.
• Step 2: Loop Until a solution is found or there is no new
operator left to apply.
• Step 3: Select and apply an operator to the current state.
• Step 4: Check new state:
– If it is goal state, then return success and quit.
– Else if it is better than the current state then assign new
state as a current state.
– Else if not better than the current state, then return to
step2.
• Step 5: Exit.

Module Code and Module Title Title of Slides


Steepest Hill Climbing

• The steepest-Ascent algorithm is a variation of


simple hill climbing algorithm.
• This algorithm examines all the neighboring nodes
of the current state and selects one neighbor node
which is closest to the goal state.
• This algorithm consumes more time as it searches
for multiple neighbors.

Module Code and Module Title Title of Slides


Steepest Hill Climbing
h(A) = 27

h(B) = 29 h(C) = 30
h(D) = 31
B C D

h(G) = 37 h(H) = 39
h(E) = 33 h(F) = 35 h(I) = 34 h(J) = 36

E F G H I J

h(K) = 40

Module Code and Module Title Title of Slides


Steepest Hill Climbing
h(A) = 27

h(B) = 29 h(C) = 30
h(D) = 31
B C D

h(I) = 34 h(J) = 36

I J

h(K) = 40

Module Code and Module Title Title of Slides


Steepest Hill Climbing

K40

Initial State: A27


Compare all the decedents of A
J36
h(D) > h(C)>h(B)
Current State: D31 I34
Compare all the decedents of D
h(J) > h(I) D31
Current State: J36
C30
Compare all the decedents of J
h(K) > h(J) B29

Current State: K40 = GOAL, STOP! A27

Module Code and Module Title Title of Slides


Steepest Hill Climbing Algorithm
• Step 1: Evaluate the initial state, if it is goal state then return success
and stop, else make current state as initial state.
• Step 2: Loop until a solution is found or the current state does not
change.
– Let SUCC be a state such that any successor of the current state
will be better than it.
– For each operator that applies to the current state:
• Apply the new operator and generate a new state.
• Evaluate the new state.
• If it is goal state, then return it and quit, else compare it to
the SUCC.
• If it is better than SUCC, then set new state as SUCC.
• If the SUCC is better than the current state, then set current
state to SUCC.
• Step 5: Exit.

Module Code and Module Title Title of Slides


Problems with Hill Climbing
• Local Maximum: A local maximum is a peak state in the landscape
which is better than each of its neighboring states, but there is
another state also present which is higher than the local maximum.
• Solution: Backtracking technique can be a solution of the local
maximum in state space landscape. Create a list of the promising
path so that the algorithm can backtrack the search space and
explore other paths as well.

Module Code and Module Title Title of Slides


Problems with Hill Climbing
• Plateau: A plateau is the flat area of the search space in which all the
neighbor states of the current state contains the same value,
because of this algorithm does not find any best direction to move.
A hill-climbing search might be lost in the plateau area.
• Solution: The solution for the plateau is to take big steps or very
little steps while searching, to solve the problem. Randomly select a
state which is far away from the current state so it is possible that
the algorithm could find non-plateau region.

Module Code and Module Title Title of Slides


Problems with Hill Climbing
• Ridges: A ridge is a special form of the local maximum. It has an
area which is higher than its surrounding areas, but itself has a
slope, and cannot be reached in a single move.
• Solution: With the use of bidirectional search, or by moving in
different directions, we can improve this problem.

Module Code and Module Title Title of Slides


Summary of Main Teaching Points

• Best-first search algorithm always selects the path which


appears best at that moment.
• A* search algorithm finds the shortest path through the
search space using the heuristic function.
• Hill climbing algorithm is a local search algorithm which
continuously moves in the direction of increasing
elevation/value to find the peak of the mountain or best
solution to the problem.

Module Code and Module Title Title of Slides


Question and Answer Session

Q&A

Module Code and Module Title Title of Slides


What we will cover next

• Neural Network

Module Code and Module Title Title of Slides

You might also like