0% found this document useful (0 votes)
22 views58 pages

CS249-Uninformed-Search-2023

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)
22 views58 pages

CS249-Uninformed-Search-2023

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/ 58

CS 249: Artificial Intelligence

Search
Outline
§ Search Problems
§ Search trees and state space graphs
§ Uninformed search
§ Depth-first, Breadth-first, Uniform cost
§ Search graphs
§ Informed search
§ Greedy search, A* search
§ Heuristics, admissibility
§ Local search and optimization
§ Hill-climbing
§ Simulated annealing
§ Genetic algorithms
Disciplines which form the core of AI- inner circle
Fields which draw from these disciplines- outer circle.

Robotics

NLP

Search,
KR & Reasoning,
Expert
Machine Learning,
Systems

Planning

Computer
Vision
Search: Everywhere

Deciding on a sequence of actions


to get to a goal
Planning
§ (a) which block to pick, (b) which to stack, (c) which to unstack, (d) whether
to stack a block or (e) whether to unstack an already stacked block. These
options have to be searched in order to arrive at the right sequence of
actions

C
B
A B C A
Table
Vision
§ A search needs to be carried out to find which point in the image of L
corresponds to which point in R. Naively carried out, this can become an
O(n2) process where n is the number of points in the retinal images.

R L
Two eye
system

World
Robot Path Planning
§ searching amongst the options of moving Left, Right, Up or Down.
Additionally, each movement has an associated cost representing the
relative difficulty of each movement. The search then will have to find the
optimal, i.e., the least cost path.

R O2

O1 Robot
Path

D
Natural Language Processing
§ search among many combinations of parts of speech on the way to
deciphering the meaning. This applies to every level of processing- syntax,
semantics, pragmatics and discourse.

The man would like to play.

Noun PrepositionVerb Noun Verb


Verb
Expert Systems
Search among rules, many of which can apply to a situation:

If-conditions
the infection is primary-bacteremia
AND the site of the culture is one of the sterile sites
AND the suspected portal of entry is the gastrointestinal tract
THEN
there is suggestive evidence (0.7) that infection is bacteroid

(from MYCIN)

MYCIN was an early expert system designed to identify bacteria


causing severe infections, such as bacteremia and meningitis, and
to recommend antibiotics
Is Search Intelligent?
§ IBM’s Deep Blue
§ Beats Chess Master Kasparov in 1997, 2 wins, 1 loss, 3 draws
§ By Feng-Hsiung Hsu, Thomas Anantharaman, and Murray
Campbell
§ Massively parallel, RS/6000 SP Thin P2SC-based system with 30-
nodes, with each node containing a 120 MHz P2SC
microprocessors for a total of 30, enhanced with 480 special
purpose VLSI chess chips
§ Looks ahead at the consequences of its actions
§ Brute force, but simplified search space
§ Evaluates about 200 million positions per second
§ Minimax search

Details From Wikipedia


Is Search Intelligent?
When people express the opinion that human grandmasters do not examine
200,000,000 move sequences per second, I ask them, ``How do you know?'' The
answer is usually that human grandmasters are not *aware* of searching this
number of positions, or *are* aware of searching many fewer. But almost
everything that goes on in our minds we are unaware of. I tend to agree that
grandmasters are not searching the way Deep Blue does, but whatever they are
doing would, if implemented on a computer, seem equally ``blind.'' Suppose most
of their skill comes from an ability to compare the current position against 10,000
positions they've studied. (There is some evidence that this is at least partly true.)
We call their behaviour insightful because they are unaware of the details; the
right position among the 10,000 ``just occurs to them.'' If a computer does it, the
trick will be revealed; we will see how laboriously it checks the 10,000 positions.
Still, if the unconscious version yields intelligent results, and the explicit
algorithmic version yields essentially the same results, then they will be
intelligent, too.
ftp://ftp.cs.yale.edu/pub/mcdermott/papers/deepblue.txt
How Intelligent is Deep Blue?
Drew McDermott, Yale University
Search building blocks
 State Space: Graph of states (Express constraints and
parameters of the problem)
 Operators : Transformations applied to the states

Successor function: for a state x, it returns a set of <action,

successor> ordered pairs, where each action is one of the legal


actions in state x and each successor is a state that can be
reached from x by applying the action
 Start state : S (Search starts from here)
0
 Goal state : {G} - Search terminates here

 Cost : Effort involved in using an operator

 Optimal path : Least cost path


Examples (8 – puzzle)

4 3 6 1 2 3

2 1 8 4 5 6

7 5 7 8

S G

Tile movement represented as the movement of the blank space.


Operators:
L : Blank moves left
R : Blank moves right
U : Blank moves up C(L) = C(R) = C(U) = C(D) = 1
D : Blank moves down
8-Puzzle: Successor Function

8 2 7 SUCC(state)  subset of states

3 4 The successor function is knowledge


about the 8-puzzle game, but it does
5 1 6 not tell us which outcome to use

8 2 8 2 7 8 2 7
3 4 7 3 4 6 3 4
5 1 6 5 1 5 1 6

Search is about the


exploration of alternatives
State Space Graphs
§ State space graph: A
mathematical a G
representation of a b c
search problem
e
§ For every search problem, d f
there’s a corresponding
S h
state space graph
§ The successor function is p r
represented by arcs q

§ This can be large or


infinite, so we won’t
create it in memory
Solution to the Search Problem

§ A solution is a path connecting the initial


node to a goal node (any one)
G

I
Solution to the Search Problem
§ A solution is a path connecting the initial
node to a goal node (any one)
§ The cost of a path is the sum of the arc
costs along this path
§ An optimal solution is a solution path of
minimum cost
I
§ There might be
no solution !
G
8-Puzzle: Successor Function

8 2 7 SUCC(state)  subset of states

3 4 The successor function is knowledge


about the 8-puzzle game, but it does
5 1 6 not tell us which outcome to use

8 2 8 2 7 8 2 7
3 4 7 3 4 6 3 4
5 1 6 5 1 5 1 6

Search is about the


exploration of alternatives
How big is the state space of the (n 2 -1)-
puzzle?

§ 8-puzzle  9! = 362,880 states


§ 15-puzzle  16! ~ 2.09 x 1013 states
§ 24-puzzle  25! ~ 1025 states

Only half of these states are reachable


from any given state !

we don’t know in advance !


8-Queens Problem
Place 8 queens in a chessboard so that no two
queens are in the same row, column, or diagonal

A solution Not a solution


Formulation #1
§ States: all arrangements of 0, 1, 2, ...,
8 queens on the board

§ Initial state: 0 queens on the board

§ Successor function: each of the


successors is obtained by adding one
queen in an empty square

§ Arc cost: irrelevant

§ Goal test: 8 queens are on the board,


with no queens attacking each other

 ~ 64x63x...x57 ~ 3x1014 states


Formulation #2
§ States: all arrangements of k = 0, 1,
2, ..., 8 queens in the k leftmost
columns with no two queens attacking
each other

§ Initial state: 0 queens on the board

§ Successor function: each successor


is obtained by adding one queen in any
square that is not attacked by any
queen already in the board, in the
leftmost empty column

§ Arc cost: irrelevant

 2,057 states § Goal test: 8 queens are on the board


Representation of nodes
§ State: the state in the state space

§ Parent: node in the search tree that generated the node

§ Action: action applied to the parent to generate the node

§ Path-cost: cost of the path from the initial state to the


node

§ Depth: # steps along the path from the initial state


General Tree Search

§ Important ideas:
§ Frontier (aka fringe)
§ Expansion
§ Exploration strategy
§ Main question: which frontier nodes to explore?
(search strategy)
Implementation: general tree search

§ Implemented as a queue

§ MAKE-QUEUE (element, …): creates a queue with


given elements
§ EMPTY?(queue): returns true only if there are no
more elements in the queue
§ FIRST (queue): return the first element in the queue
§ REMOVE-FRONT (queue): returns FIRST (queue)
and removes from the queue
§ INSERT (element, queue): inserts an element into the
queue and returns the resulting queue
§ INSERT-ALL (elements, queue): inserts a set of
elements into the queue and returns the resulting
queue
Implementation: general tree search
Uninformed vs. informed search

§ Uninformed search (or, blind search)


§ Uses only the information available in the problem
definition
Search through the space of possible solutions
§ Uses no knowledge about which path is likely to
be best
§ E.g. BFS, DFS, uniform cost etc.
§ Informed search (or, heuristic search)
§ Knows whether a non-goal state is more promising
§ E.g. Greedy search, A* Search etc.
Breadth First Search
a G
Strategy: expand
b c
shallowest node first
e
Implementation: d f
Fringe is a FIFO S h
queue p q r

d e p
Search
b c e h r q
Tiers
a a h r p q f

p q f q c G

q c G a

a
Depth First Search
a G
Strategy: expand b c
deepest node first
e
d f
Implementation:
Frontier is a LIFO S h

stack p r
q

d e p

b c e h r q

a a h r p q f

p q f q c G

q c G a

a
Comparisons

§ When will BFS outperform DFS?

§ When will DFS outperform BFS?


Search Algorithm Properties
§ Complete? Guaranteed to find a solution if one exists?
§ Optimal? Guaranteed to find the least cost path?
§ Time complexity? How long it takes to find a solution?
§ Space complexity? How much memory required to
perform search?
Variables:
n Number of states in the problem
b The average branching factor B
(the average number of successors)
C* Cost of least cost solution
s Depth of the shallowest solution
m Max depth of the search tree
BFS
Algorithm Complete Optimal Time Space
DFS w/ Path
Y N O(bm+1) O(bm)
Checking

BFS Y N* O(bs+1) O(bs+1)

1 node
b
… b nodes
s tiers
b2 nodes

bs nodes

bm nodes
BFS
§ When complete?
§ Shallowest goal node is at d, a finite depth
§ Will eventually find after expanding all the
shallower nodes
§ b (branching factor) should be finite

§ When optimal? (when all step costs are equal)


§ If path cost is a non-decreasing function of the depth
of the node
Why BFS hard?
§ Huge requirement of time and space !

§ Time? b+b2+b3+… +bs + b(bs-1) = O(bs+1)


Space? O(bs+1) (keeps every node in
memory)

§ Space is the bigger problem (more than time)


Why BFS hard?
Assuming b=10, 10,000 nodes/sec, 1000 bytes/node

Depth of Nodes to
Solution Expand Time Memory

2 1100 .11 seconds 1 megabytes

4 111,100 11 seconds 106 megabytes

8 109 28 hours 1 terabytes

12 1013 35 years 10 petabytes

14 1015 3,523 years 1 exabyte

Un-informed search is not good for problems having exponential


complexity
DFS
Algorithm Complete Optimal Time Space
DFS Depth First N N N N O(B LMAX)
Infinite O(LMAX)
Infinite
Search

START a

GOAL

§ Infinite paths make DFS incomplete…


§ How can we fix this? (checking of cycles!)
DFS
§ Can make wrong choice and can go down infinite length
§ Alternative choice would lead to a solution near the root
§ Not optimal!
S

d e p

b c e h r q

a a h r p q f

p q f q c G

q c a
G

a
DFS
§ With cycle checking and graph search (avoid repeated state and
redundant state), DFS is complete
§ d: finite
1 node
b
… b nodes
b2 nodes
m tiers

bm nodes

Algorithm Complete Optimal Time Space


DFS w/ Path
Y N O(bm+1) O(bm)
Checking

§ When is DFS optimal? (iterative deepening search)


DFS with Backtracking
§ Generate only one successor
§ Each partially expanded node remembers which
successor to explore next
§ Undo modification when going back to generate
next successor
§ Space =O(m)
§ Techniques are suitable for problems with large
state descriptions (robotic path assembly)
Costs on Actions
a GOAL
2 2
b c
3
2
1 8
2 e
3 d
f
9 8 2
START h
1 4 1

p 4 r
15
q

Notice that BFS finds the shortest path in terms of number of transitions. It
does not find the least-cost path.
We will quickly cover an algorithm which does find the least-cost path.
Uniform Cost Search
BFS: all step costs are equal 2 a G
b c
UCS: optimal with any step costs 1 8 2
2 e
Expand cheapest node first: 3 d f
9 2
S h 8
Frontier is a priority queue 1
1 p
q
r
What about zero-cost action? 15
S 0

d 3 e 9 p 1

b 4 c e 5 h 17 r 11 q 16
11
Cost a 6 a h 13 r 7 p q f
contours
p q f 8 q c G

q 11 c G 10 a

a
Uniform Cost Search
§ Zero-cost action: leads back to the same state (infinite
loop!)
§ Cost must be greater than some small positive constant
§ Sufficient for optimality and guarantees completeness
§ Cost always increases as we proceed
§ Algorithm always expands nodes in order of increasing
path cost

Thus, first goal node always yields the optimal solution!


§ Guided by path costs rather than depths
§ Complexity can’t be characterized by d and b
Uniform Cost Search
Algorithm Complete Optimal Time Space
DFS w/ Path
Y N O(bm+1) O(bm)
Checking

BFS Y N O(bs+1) O(bs)


UCS Y* Y O(bC*/) O(bC*/)

b

* UCS can fail if
C*/ tiers actions can get
arbitrarily cheap
Depth-limited search

§ Problem of unbounded trees


§ depth-first search with depth limit L, i.e., nodes at
depth L treated to have no successors
Depth limited search

§ Incomplete if L<d (d: depth of the solution)


§ Time complexity =O (bL)
§ Space complexity = O (bL)
§ For L=∞, depth-limited search=depth-first search
Choice of L is important !!
§ Route-finding problem
§ For 20 cities, L=19 is a possible choice (if there is any feasible solution)

§ But, with 9 (a, better depth limit) steps can be reached!


§ Diameter of search space (not possible to predict until we solve the
problem)
Iterative Deepening Search
§ General strategy often used in combination
with DFS
§ Finds best depth limit
§ Combines benefits of both BFS and DFS
§ Like DFS, memory is modest: O(bd)
§ Like BFS, complete when b is finite
§ Like B F S , o p t i m a l w h e n p a t h c o s t i s a n
increasing function of the depth of a node
Iterative Deepening
Iterative deepening uses DFS as a subroutine:
b
1. Do a DFS which only searches for paths of …
length 1 or less.
2. If “1” failed, do a DFS which only searches paths
of length 2 or less.
3. If “2” failed, do a DFS which only searches paths
of length 3 or less.
….and so on.

Algorithm Complete Optimal Time Space


DFS w/ Path
Y N O(bm+1) O(bm)
Checking

BFS Y N* O(bs+1) O(bs)


ID Y N* O(bs+1) O(bs)
Iterative deepening search l =0
Iterative deepening search l =1
Iterative deepening search l =2
Iterative deepening search l =3
Iterative deepening search
Iterative deepening search
§ Number of nodes generated in a depth-limited search to depth d
with branching factor b:
NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd

§ Number of nodes generated in an iterative deepening search to


depth d with branching factor b:
NIDS = d b1 + (d-1) b2 + … + 3bd-2 +2bd-1 + 1bd

§ For b = 10, d = 5,
§ NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
§ NIDS = 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450
§ NBFS =10+100+1,000+10,000+100,000+999,990=1,111,100

§ Overhead = (123,450 - 111,111)/111,111 = 11% (approx.)


Properties of iterative deepening search

§ Complete? Yes
§ Time? d b1 + (d-1)b2 + … + bd = O(bd)
§ Space? O(bd)
§ Optimal? Yes, if step cost = 1
§ Wasteful as states generated multiple times
§ Not very costly
§ With the same branching factor at each level, most of the nodes
are at the bottom
§ Upper level nodes don’t cost much
When to use what?

§ Depth-First Search:
§ Many solutions exist
§ Know (or have a good estimate of) the depth of solution

§ Breadth-First Search:
§ Some solutions are known to be shallow

§ Uniform-Cost Search:
§ Actions have varying costs
§ Least cost solution is the required
This is the only uninformed search that worries about costs

§ Iterative-Deepening Search:
§ Large search space and depth of the solution is not known
Bi-directional search

§ Alternate searching from the start state toward the goal and from
the goal state toward the start
§ Stop when the frontiers intersect
§ Works well only when there are unique start and goal states and
when actions are reversible
§ Can lead to finding a solution more quickly
Bi-directional search
§ Motivation: bd/2 + bd/2 < bd
§ E.g. if solution depth =6 and each direction runs BFS
§ Worst case: two searches meet when each has expanded all the
nodes at 3
§ For b=10,
b+b2 +b3 = 10+100+1000=1110 *2=2220

b2 +b3 +b4+ b5 +b6 +b7= 111,111,00


§ One tree kept in memory to check membership
§ Space complexity = O(bd/2 )
§ Time complexity = O(bd/2 )
Bi-directional search
§ Complete
§ If b is finite
§ If both directions use BFS (check why not
DFS?)

§ Optimal
§ If step costs are all identical
§ If both directions use BFS

You might also like