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

ai DFS Unit 1

The document discusses various uninformed and informed search strategies in artificial intelligence, focusing on Depth-First Search (DFS) and local search methods like hill-climbing and simulated annealing. It highlights the strengths and weaknesses of these algorithms, including their memory usage and ability to escape local optima. Additionally, it introduces optimization techniques for continuous functions, such as gradient descent.

Uploaded by

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

ai DFS Unit 1

The document discusses various uninformed and informed search strategies in artificial intelligence, focusing on Depth-First Search (DFS) and local search methods like hill-climbing and simulated annealing. It highlights the strengths and weaknesses of these algorithms, including their memory usage and ability to escape local optima. Additionally, it introduces optimization techniques for continuous functions, such as gradient descent.

Uploaded by

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

Uninformed/Blind Search - Depth-First

Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

Introduction to Artificial Intelligence and Problem Formulations


Uninformed/Blind Search - Depth-First
Search

It can get stuck going down the wrong path.


Depth-first search should be avoided for search trees with large
or infinite maximum depths.

Introduction to Artificial Intelligence and Problem Formulations


DFS (Depth First Search) algorithm
Step 1 -.
1.STACK: H
Step 2 -
1.Print: H
STACK: A
Step 3 -
2.Print: A
2.STACK: B, D
Step 4 -
3.Print: D
2.STACK: B, F
Step 5 -
3.Print: F
2.STACK: B
DFS (Depth First Search) algorithm
Step 6 -
1.Print: B
2.STACK: C
Step 7 -
3.Print: C
2.STACK: E, G
Step 8 -
3.Print: G
2.STACK: E
Step 9 -
3.Print: E
2.STACK:
Output: HADFBCGE
Satisfaction vs.
Optimization
Goal
Optimization
Satisfaction
reach the goal optimize(objective
node Constraint fn) Constraint
satisfaction Optimization

You can go back and forth between the two


problems Typically in the same
complexity class

© Mausam 6
Local search and
optimization
• Local search
– Keep track of single current state
– Move only to neighboring states
– Ignore paths

• Advantages:
– Use very little memory
– Can often find reasonable solutions in large or infinite (continuous)
state spaces.

• “Pure optimization” problems


– All states have an objective function
– Goal is to find state with max (or min) objective value
– Does not quite fit into path-cost/goal-state formulation
– Local search can do quite well on these problems.
7
Hill-climbing (Greedy Local Search)
max version
function HILL-CLIMBING( problem) return a state that is a local maximum
input: problem, a problem
local variables: current, a node.
neighbor, a node.

current  MAKE-NODE(INITIAL-STATE[problem])
loop do
neighbor  a highest valued successor of current
if VALUE [neighbor] ≤ VALUE[current] then return STATE[current]
current  neighbor

min version will reverse inequalities and look for


lowest valued successor
13
Hill-climbing
search
• “a loop that continuously moves towards increasing value”
– terminates when a peak is reached
– Aka greedy local search
• Value can be either
– Objective function value
– Heuristic function value (minimized)

• Hill climbing does not look ahead of the immediate neighbors


• Can randomly choose among the set of best successors
– if multiple have the best value

• “climbing Mount Everest in a thick fog with amnesia”

14
“Landscape” of
search

Hill Climbing gets stuck in local


minima depending on?
15
Hill Climbing
Drawbacks

• Local
maxima

• Plateau
s

• Diagonal
ridges
17
Escaping Shoulders/local Optima
Enforced Hill Climbing
• Perform breadth first search from a local optima
– to find the next state with better h function

• Typically,
– prolonged periods of exhaustive search
– bridged by relatively quick periods of hill-climbing

• Middle ground b/w local and systematic search

© Mausam 2
0
Hill-climbing: stochastic
variations
• Stochastic hill-climbing
– Random selection among the uphill moves.
– The selection probability can vary with the steepness of the uphill move.

• To avoid getting stuck in local minima


– Random-walk hill-climbing
– Random-restart hill-climbing
– Hill-climbing with both

2
1
Hill Climbing with
random walk
When the state-space landscape has local
minima, any search that moves only in the
greedy direction cannot be complete
Random walk, on the other hand, is
asymptotically complete

Idea: Put random walk into greedy


hill-climbing
• At each step do one of the two
– Random: Withprob
Greedy: With probp1-p move
move to aneighbor
to the random neighbor 2
2
Hill-climbing with random
restarts
• If at first you don’t succeed, try, try again!
• Different variations
– For each restart: run until termination vs. run for a fixed time
– Run a fixed number of restarts or run indefinitely

• Analysis
– Say each search has probability p of success
• E.g., for 8-queens, p = 0.14 with no sideways moves

– Expected number of restarts?


– Expected number of steps taken?

• If you want to pick one local search algorithm, learn this one!!
23
Hill-climbing with
both
• At each step do one of the three
– Greedy: move to the neighbor with largest value
– Random Walk: move to a random neighbor
– Random Restart: Resample a new current state

24
Simulated
Annealing
• Simulated Annealing = physics inspired twist on random walk
• Basic ideas:
– like hill-climbing identify the quality of the local improvements
– instead of picking the best move, pick one randomly
– say the change in objective function is 
– if  is positive, then move to that state
– otherwise:
• move to this state with probability proportional to 
• thus: worse moves (very large negative ) are executed less often
– however, there is always a chance of escaping from local maxima
– over time, make it less likely to accept locally bad moves
– (Can also make the size of the move random as well, i.e., allow “large” steps in state spac
25
Simulated
annealing
function SIMULATED-ANNEALING( problem, schedule) return a solution state
input: problem, a problem
schedule, a mapping from time to temperature
local variables: current, a node.
next, a node.
T, a “temperature” controlling the prob. of downward steps

current  MAKE-NODE(INITIAL-STATE[problem])
for t  1 to ∞ do
T  schedule[t]
if T = 0 then return current
next  a randomly selected successor of current
∆E  VALUE[next] - VALUE[current]
if ∆E > 0 then current  next
else current  next only with probability e∆E /T
26
Temperatur
eT
• high T: probability of “locally bad” move is higher
• low T: probability of “locally bad” move is lower
• typically, T is decreased as the algorithm runs longer
• i.e., there is a “temperature schedule”

27
Physical Interpretation of Simulated
Annealing
• A Physical Analogy:
• imagine letting a ball roll downhill on the function surface
– this is like hill-climbing (for minimization)
• now imagine shaking the surface, while the ball rolls,
gradually reducing the amount of shaking
– this is like simulated annealing

• Annealing = physical process of cooling a liquid or metal


until particles achieve a certain frozen crystal state
• simulated annealing:
– free variables are like particles
– seek “low energy” (high quality) configuration
– slowly reducing temp. T with particles moving around randomly
28
Simulated Annealing in
Practice
– method proposed in 1983 by IBM researchers for
solving VLSI layout problems (Kirkpatrick et al,
Science, 220:671-680, 1983).
• theoretically will always find the global optimum

– Other applications: Traveling salesman, Graph


partitioning, Graph coloring, Scheduling, Facility
Layout, Image Processing, …

– useful for some problems, but can be very slow


• slowness comes about because T must be decreased
very gradually to retain optimality
29
Local beam
search
• Idea: Keeping only one node in memory is an
extreme reaction to memory problems.

• Keep track of k states instead of one


– Initially: k randomly selected states
– Next: determine all successors of k states
– If any of successors is goal  finished
– Else select k best from successors and
repeat

30
Local Beam Search
(contd)
• Not the same as k random-start searches run in parallel!
• Searches that find good states recruit other searches to
join them

• Problem: quite often, all k states end up on same local


hill
• Idea: Stochastic beam search
– Choose k successors randomly, biased towards good ones

• Observe the close analogy to natural selection!


31
Optimization of Continuous
Functions
• Discretization
– use hill-climbing

• Gradient descent
– make a move in the direction of the gradient
• gradients: closed form or empirical

43
44
Gradient
Descent
Assume we have a continuous function: f(x1,x2,…,xN)
and we want minimize over continuous variables
X1,X2,..,Xn

1. Compute the gradients for all i: f(x1,x2,…,xN) /xi

2. Take a small step downhill in the direction of the


gradient:

xi  xi - λf(x1,x2,…,xN) /xi
3. Repeat.

• How to select λ
– Line search: successively double
– until f starts to increase again
45

You might also like