0% found this document useful (0 votes)
28 views

SET394 - AI - Lecture 05 - Informed Search and Local Search Algorithms

Uploaded by

k7180566
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

SET394 - AI - Lecture 05 - Informed Search and Local Search Algorithms

Uploaded by

k7180566
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

SET 394 - Fall 2022

Artificial Intelligence
Informed Search Algorithms
Associate Prof. Dr. Ayman Elshenawy

5
Lecture Five
[email protected]
[email protected]

1
Informed Search
• Uses problem/domain specific knowledge beyond
the definition of the problem.
• Can find solutions more efficiently than uninformed
search (blind search).
• Depend on an evaluation function F(n) that:
• Used to estimate how close a node is to the goal.
• Consider the nodes of better f(n) and explore it first.
• Is imprecise, which makes the method a heuristic
(works well in most cases).
• Is often based on empirical observations.
Informed Search Evaluation Function F(n)
• F(n) = g(n) + h(n)
• g(n) is the cost to reach node n from the start node ( exact value).
• h(n) is a heuristic function :
• h(n): estimated cost to reach the goal from the node n.
• h(n1) < h(n2) means it is probably cheaper to get to the goal from n1.
• h(goal) = 0.
• Evaluation function f(n):
• f(n) = g(n): Uniform-cost search. ➔ h(n) = 0
• f(n) = h(n): Greedy best-first search. ➔ g(n) = 0
• f(n) = g(n) + h(n): A* search.
• Example: Straight-Line Distance (SLD) on the map between the two points
f(n)
Start g(n) h(n) Goal
3
Informed Search Algorithms
• Greedy best-first search
• A* search
• Weighted A*
• Beam Search
• Bounded-cost search
• Un-Bounded-cost search
• Simple bound A* search
Greedy best-first search GBFS
• Is an instance of the general TREE-SEARCH or GRAPH-SEARCH
algorithm.
• It uses f(n) = h(n) and ignores the path cost g(n) entirely (h(n)=0).
• Is identical to UNIFORM-COST-SEARCH except that h is used instead
of g.
• A node is selected for expansion based on an evaluation function, f(n).

5
Greedy best-first search GBFS
Find a route from Arad to Bucharest?
hSLD =(Arad)=366

the path via Sibiu and Fagaras to


Bucharest is 32 miles longer than the path
through Rimnicu Vilcea and Pitesti. 6
Greedy best-first search GBFS
• Step 1: Place the starting node into the OPEN list.
• Step 2: If the OPEN list is empty, Stop and return failure.
• 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 4: Expand the node n, and generate the successors of node n.
• Step 5: Check each successor of node n and find whether any node is a goal node or not.
• If any successor node is goal node, then return success and terminate the search.
• Else proceed to Step 6.
• Step 6: For each successor node,
• f(n) is evaluated, and then check if the node has been in either OPEN or CLOSED list.
• If the node has not been in both list, then add it to the OPEN list.
• Step 7: Return to Step 2.
7
Greedy best-first search GBFS
• Travers the following search problem using GBFS.
• Evaluation function f(n)=h(n) , is given in the table.

•Expand the nodes of S and put in the


CLOSED list
•Initialization: Open [A, B], Closed [S]
•Iteration 1: Open [A], Closed [S, B]
•Iteration 2: Open [E, F, A], Closed [S, B]
: Open [E, A], Closed [S, B, F]
•Iteration 3: Open [I, G, E, A], Closed [S, B, F]
: Open [I, E, A], Closed [S, B, F, G]
•The final solution path will be S---> B---->F---> G
8
Greedy best-first search
• Not complete: Advantages:
• Unless m is finite; uncommon in trees. • Can switch between
• May get stuck in an infinite loop. BFS and DFS by
• Not optimal. gaining the
• e.g., Arad→ Sibiu → Rimnicu Virea → Pitesti → Bucharest is shorter!
advantages of both
the algorithms.
• Time complexity: With a good heuristic function, the • Efficient than BFS
complexity can be reduced reaching O(bm). and DFS algorithms.
• Space complexity = O(bm) - keeps all nodes in memory.
9
A* search
• Uniform cost search orders the queue according to the path cost g(n):
• Optimal, complete, but inefficient in time and space.
• Greedy best first search orders the queue using the heuristic cost h(n):
• Not optimal, not complete but efficient (with good heuristic).
• Idea: combine the two strategies or avoid expanding paths that are already
expensive
• Evaluation function f(n) = g(n) + h (n)
• g(n) = cost to reach n ( from the start node to node n)➔ History
• h(n) = estimated cost to reach the goal from the node n ➔ Future
• f(n) measures the total estimated cost from the initial state to the goal state passing through
the current state n.
• The resulting search is both optimal and complete (with certain conditions of h(n))
10
A* search Steps
• Step1: Place the starting node in the OPEN list.
• 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 with the smallest f(n) from the OPEN list, if node n is
goal node, then return success and stop, otherwise
• Step 4: Expand node n:
• Generate all 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 f(n) for n' and place it into 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.
• Step 6: Return to Step 2.
11
A* search example

• Find a route from Arad to Bucharest using A* search Algorithm?


A* search Example (2)
• Traverse the given graph using the A* algorithm.
The heuristic value of all states is given in the below
table.
•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)}
•Iteration 4 will give the result, as
S--->A--->C--->G
it provides the optimal path with cost 6.
A* search
• Advantages:
• The best algorithm than other search algorithms, it can solve very complex problems.
• Optimal and complete for some conditions.
• Returns the path which occurred first, and it does not search for all remaining paths.
• Expands all nodes which satisfy the condition f(n).
• Disadvantages:
• Its efficiency depends on the quality of heuristics.
• Has some complexity issues.
• The main drawback of A* is memory requirement as it keeps all generated nodes in the
memory, so it is not practical for various large-scale problems.

14
A* search Optimality conditions
• Optimal: A* algorithm is optimal if its heuristic achieves the following two conditions:
• Admissible: h(n) should be an admissible heuristic for A* tree search.
• For every node n if h(n) ≤ h*(n), h(n) never overestimates the true cost h*(n). Hence, f(n) never
overestimates the true cost to the goal through node n.
• An admissible heuristic is optimistic in nature.
• Consistency: A heuristic h(n) is consistent if, for every node n and every successor n’ of
n generated by an action a, we have:

• Complete: if branching factor (m) is finite and the cost at every action is fixed.
• Time and space complexity: not straightforward!
• Number of nodes explored depends on the difference between h and h* (true cost).
• If h = h*, A* expands only the nodes on the optimal solution path(s).
• If h = 0, A* consumes as much (time/space) resources as UCS. 15

admissible heuristic is one that never overestimates the cost to reach a goal
A* search
• Finally:
• A* search is complete, cost-optimal, and optimally
efficient among all such algorithms.
• Unfortunately, it does not mean that A* is the answer
to all our searching needs.

16
Inadmissible heuristics and weighted A*
• A* is efficient, but it expands a lot of nodes.
• We can explore fewer nodes (less time and space)
if we are willing to accept solutions.
• If we allow A* search to use an inadmissible
heuristic
• A detour index of 1.3 means that if two cities are
distance by 10 miles straight-line distance, a good
estimate of the best path between them is 13 miles
(detour index ranges between 1.2 and 1.6).
• Weighted A* search where we weight the heuristic
value more heavily,
f (n)= g(n)+W h(n), for some W > 1.
• In general, if the optimal solution costs C* , a
weighted A* search will find a solution that costs
somewhere between C* and WC*. 17
Inadmissible heuristics

• Bounded-cost search, we look for a solution whose cost is less than


some constant C*.
• Unbounded-cost search, we accept a solution of any cost, if we can
find it quickly.

18
Simple Memory Bounded A*
• The main issue with A* is its use of memory
• Like A*, but when memory is full, delete the worst node,(largef(n) ).
• If there is a tie (equal f-values) we first delete the oldest nodes first.
• simple-MBA* finds the optimal reachable solution given the memory
constraint.
• Time can still be exponential.
• Beam search limits the size of the frontier.
• The easiest approach is to keep only the k nodes with the best f-scores,
discarding any other expanded nodes.
Simple Memory-bounded A* (SMA*)
(Example with 3-node memory)
Search space Progress of SMA*. Each node is labeled with its current f-cost. Values in
parentheses show the value of the best forgotten descendant.

A
f = g+h 13[15]
A A A
12 12
A 13
G
0+12=12
13
10 8
B G B B G
10+5=15 8+5=13 15
18 H
10 10 8 16
15 13

C D H I
20+5=25 16+2=18 A A A
15[15] 15[24] 20[24]
20+0=20 24+0=24
10 10 A 8
8 8 15
E F J K G B B
15 20[]
24[]
30+5=35 30+0=30 24+0=24 24+5=29
B G
I D
Algorithm can tell you when best solution 15 24 C 25
24
 20
found within memory constraint is optimal
or not.
Local search algorithms
• In previous search we wanted to find paths through the search
space, such as a path from Arad to Bucharest.
• But sometimes we care only about the final state, not the path to
get there.
• For example,
• In the 8-queens problem, we care only about finding a valid final
configuration of 8 queens (because if you know the configuration, it is
trivial to reconstruct the steps that created it).
• This is also true for many important applications such as
• Integrated-circuit design, Factory floor layout, Job shop scheduling,
Automatic programming, Telecommunications network optimization,
Local search algorithms
• Operate by searching from a start state to neighboring states:
• Not keeping track of the paths
• Not Keeping the set of states that have been reached.
• That means they are not systematic—they might never explore a portion
of the search space where a solution resides.
• Advantages:
• Use very little memory;
• Can find reasonable solutions in large or infinite state spaces .
• Can solve optimization problems (find the best state according to an objective
function).
Local search algorithms

• Each point (state) in the landscape has an


“elevation,” defined by the value of the
objective function.
• If elevation corresponds to an objective
function, then the aim is to find the highest
peak (a global maximum) and we call the
process hill climbing.
• If elevation corresponds to cost, then the aim
is to find the lowest valley a global
minimum—and we call it gradient descent.
Local search algorithms
• Hill-climbing search.
• Gradient descent search.
• Local beam search.
• Genetic algorithms search.
• It keeps track of one current state.
• On each iteration moves to the neighboring state with highest value
Hill • It terminates when it reaches a “peak” where no neighbor has a
Climbing higher value.
• Does not look beyond the immediate neighbors of the current state.
Search • Note that one way to use hill-climbing search is to use the negative
of a heuristic cost function as the objective function; that will climb
locally to the state with smallest heuristic distance to the goal.
Example: n-queens
• Goal: Put n queens on an n × n board with no two queens on the same row, column,
or diagonal.
• Neighbor: move one queen to another row
• Search: go from one neighbor to the next…
Example: Hill-climbing, 8-queens
h = # of pairs of queens that are attacking
each other, either directly or indirectly
(cost) h=17 for this state

Each number indicates h


if we move a queen in its 12 (boxed) = best h among all
column to that square neighors; select one randomly
Algorithm design considerations
• How do you represent your problem?
• What is a “complete state”?
• What is your objective function?
• How do you measure cost or value of a state?
• Stand on your head: cost = −value, value = −cost
• What is a “neighbor” of a state?
• Or, what is a “step” from one state to another?
• How can you compute a neighbor or a step?
• Are there any constraints you can exploit?
Local beam search
• Keep track of k states rather than just
one.
• Start with k randomly generated
states.
• At each iteration, all the successors of
all k states are generated.
• If any one is a goal state, stop; else
select the k best successors from the
complete list and repeat.
Genetic algorithms (Darwin!!)
• A state = a string over a finite alphabet (an individual)
• A successor state is generated by combining two
parent states
• Start with k randomly generated states (a population)
• Fitness function (= our heuristic objective function).
• Higher fitness values for better states.
• Select individuals for next generation based on fitness
• P(individual in next gen.) = individual fitness/total
population fitness
• Crossover fit parents to yield next generation (offspring)
• Mutate the offspring randomly with some low
probability
Example: N-Queens
Each “individual” is a vector of each queen’s row

Crossover :
Resulting individuals after cross-over
fitness = #non-attacking queens

probability of being
in next generation =
fitness/(_i fitness_i)

• Fitness function: #non-attacking queen pairs How to convert a fitness


• min = 0, max = 8 × 7/2 = 28 value into a probability of
being in the next generation.
• i fitness_i = 24+23+20+11 = 78
• P(pick child_1 for next gen.) = fitness_1/(_i fitness_i) = 24/78 = 31%
• P(pick child_2 for next gen.) = fitness_2/(_i fitness_i) = 23/78 = 29%; etc
The End ☺

33

You might also like