0% found this document useful (0 votes)
20 views36 pages

Lecture-12 c0W

Uploaded by

Kanav Arora
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)
20 views36 pages

Lecture-12 c0W

Uploaded by

Kanav Arora
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/ 36

Artificial Intelligence

CS 165A

 Informed Search (Ch. 3)

1
Practical note about search algorithms
• The computer can’t “see” the search graph like we can
– No “bird’s eye view” – make relevant information explicit!
• What information should you keep for a node in the search tree?
– State
 (1 2 0)

– Parent node (or perhaps complete ancestry)


 Node #3 (or, nodes 0, 2, 5, 11, 14)

– Depth of the node


 d=4

– Path cost up to (and including) the node


 g(node) = 12

– Operator that produced this node


 Operator #1

2
Avoiding repeated states
• It may be beneficial to explicitly avoid repeated states,
especially where there are loops in the state graph and/or
reversible operators
– Search space can be very significantly pruned
• How to deal with repeated states:
– Do not return to state we just came from (parent node)
– Do not create paths with cycles (ancestor nodes)
– Do not generate any state that was ever generated before (graph
search)
• But there is a cost
– Have to keep track (in memory) of every state generated
– The path might not be optimal

3
Graph Search vs Tree Search
• Tree Search
– We might repeat some states
– But we do not need to remember states

• Graph Search
- We remember all the states that have been explored
- But we do not repeat some states

4
Search as problem-solving
• We have defined the problem
– Data
 States, initial state(s), goal test/state(s), path cost function

– Operations
 State transitions

– Control – Search to find paths from initial states to goal states


 Build up a search tree whose nodes and arcs correspond to
nodes and arcs in the state space graph
 Solution: “Best” path through the state space

5
Best-First Search
function BEST-FIRST-SEARCH(problem, EVAL-FN) returns a solution or
failure
QUEUING-FN  a function that orders nodes by EVAL-FN
return GENERAL-SEARCH(problem, QUEUING-FN)

But what evaluation function to use?

6
Uniform Cost Search
• Similar to breadth-first search, but always expands the
lowest-cost node, as measured by the path cost function,
g(n)
– g(n) is (actual) cost of getting to node n
– Breadth-first search is actually a special case of uniform cost
search, where g(n) = DEPTH(n)
– If the path cost is monotonically increasing, uniform cost search
will find the optimal solution

function UNIFORM-COST-SEARCH(problem) returns a solution or failure


return GENERAL-SEARCH(problem, ENQUEUE-IN-COST-ORDER)

7
Example

A
2 8 6

B C E
2
12 1
4
D
1
F

Try breadth-first and uniform cost

8
Uniform-Cost Search
C = optimal cost
• Complete? Yes if ε = minimum step cost > 0

• Optimal? If minimum step cost > 0

• Time complexity? Exponential: O( b└C/ε┘ )

• Space complexity? Exponential: O( b└C/ε┘ )

Same as breadth-first if all edge costs are equal

9
Greedy Best-First Search
• Uses a heuristic function, h(n), as the EVAL-FN
• h(n) estimates the cost of the best path from state n to a goal state
– h(goal) = 0
• Greedy search – always expand the node that appears to be the closest
to the goal (i.e., with the smallest h)
– Instant gratification, hence “greedy”

function GREEDY-SEARCH(problem, h) returns a solution or failure


return BEST-FIRST-SEARCH(problem, h)

• Greedy search often performs well


– It doesn’t always find the best solution
– It may get stuck
– It depends on the particular h function
10
Romania (cont.)

11
“A” Search
• Uniform-cost search minimizes g(n) (“past” cost)

• Greedy search minimizes h(n) (“expected” or “future” cost)

• “A Search” combines the two:


– Minimize f (n) = g(n) + h(n)
– Accounts for the “past” and the “future”
– Estimates the cheapest solution (complete path) through node n

12
A* Search
• “A* Search” is A Search with an admissible h
– h is optimistic – it never overestimates the cost to the goal
 h(n)  true cost to reach the goal

– So f (n) never overestimates the actual cost of the best solution


passing through node n

function A*-SEARCH(problem, h) returns a solution or failure


return BEST-FIRST-SEARCH(problem, f )

13
A* Example

f(n) = g(n) + h(n) 14


A* Example
f = 0 + 366 = 366 Arad

f = 75 + 374 = 449 Zerind 140 + 253 = 393 Sibiu 118+329=447 Timisoara

291+380=671 Oradea 280+366=506 Arad 239+178=417 Fagaras 220+193=413 Rimnicu Vilcea

15
Optimality of A*
• A* expands nodes in order of increasing f value
• Gradually adds "f-contours" of nodes
• Contour i has all nodes with f=fi, where fi < fi+1

Optimality of A*
• Optimality of A*
• Let OPT be the optimal path cost.
– All non-goal nodes on this path have f ≤ OPT.
 Positive costs on edges

– The goal node on this path has f = OPT.


• A* search does not stop until an f-value of OPT is reached.
– All other goal nodes have an f cost higher than OPT.
• All non-goal nodes on the optimal path are eventually
expanded.
– The optimal goal node is eventually placed on the priority queue,
and reaches the front of the queue.

17
A* Search
• Optimal? Yes

• Complete? Yes

• Time complexity? Exponential; better under some


conditions
• Space complexity? Exponential; keeps all nodes in
memory

18
A* Works for Multiple Goals

R
5 1

A B

1 1

C D

1 10

G1 G2

19
Efficiency of A*

A* is optimally efficient for any particular h(n)


That is, no other optimal algorithm is guaranteed to expand
fewer nodes with the same h(n). Why?

Need to find good h(n) PLUS

Computing h(n) is fast

20
The cost of being informed
• Typical performance of informed search methods is much
better than uninformed methods
– Assuming reasonable heuristics exist

• However, there is a tradeoff involved


– Evaluating the desirability of a node (h) can be non-trivial
 E.g., theorem proving

How much closer to the theorem are we if we apply this


rule?
– Cost of evaluation (heuristic) can be high
 It can be a difficult search problem itself

21
Cost tradeoff

Overall cost

Cost Cost of evaluating nodes


(control strategy)

Cost of expanding nodes


(rule application)

“Informedness”

There may be different optima for computation and memory

22
Graph Search vs Tree Search
• Tree Search
– We might repeat some states
– But we do not need to remember states

• Graph Search
- We remember all the states that have been explored
- But we do not repeat some states

23
Avoiding Repeated States using A* Search
• Is GRAPH-SEARCH optimal with A*?
Try with TREE-SEARCH and
B
GRAPH-SEARCH
1 h=5 1
A C D
4 4
h=5 h=1 h=0
7
E

h=0

Graph Search
Step 1: Expand A; Among B, C, E, Choose C
Step 2: Expand C; Among B, E, D, Choose B
Step 3: Expand B (C has been explored, stop); Among D, E,
Choose E. (you are not going to select C again) 24
Avoiding Repeated States using A* Search
• Is GRAPH-SEARCH optimal with A*?
Try with TREE-SEARCH and
B
GRAPH-SEARCH
1 h=5 1
A C D
4 4
h=5 h=1 h=0
7
E

h=0

Solution 1: Remember the shortest paths so far: Need


extra bookkeeping
Solution 2: Ensure that the first path to a node is the best!
25
Graph Search
A

Z S T

O A F R

26
Consistency (Monotonicity) of heuristic h
• A heuristic is consistent (or monotonic) provided
– for any node n, for any successor n’ generated by action a with
cost c(n,a,n’)
c(n,a,n’)
 h(n) ≤ c(n,a,n’) + h(n’) n n’
– akin to triangle inequality. h(n’)
– guarantees admissibility (proof?). h(n)
g
– values of f(n) along any path are non-decreasing (proof?).
 Contours of constant f in the state space

– Whenever A* selects a node n’ for expansion, the optimal path to


that node has been found
• GRAPH-SEARCH using consistent h(n) is optimal.
• Note that h(n) = 0 is consistent and admissible.

27
Consistent heuristic is admissible
• Let h(x) be a consistent heuristic and c(x,y) be the
corresponding step cost.
• Consistent heuristic: h(x)≤c(x,y)+h(y)
• Proof…

28
Memory Bounded Search
• Memory, not computation, is usually the limiting factor in
search problems
– Certainly true for A* search
• Why? What takes up memory in A* search?

• IDA* and SMA* are designed to conserve memory

29
Iterative Deepening A* (IDA*)
• IDA* is an optimal, memory-bounded, heuristic search
algorithm
– Requires space proportional to the longest path that it explores
– Space estimate: O(bd)
• Similar to Iterative Deepening Search
– Uses f-cost limit rather than depth-limit
– In IDS, depth-limit is incremented after each round
– In IDA*, f-cost limit is updated after each round
 Limit based on the smallest f-cost of a pruned node from the
previous iteration

30
Simplified Memory-Bounded A* (SMA*)
• IDA* only keeps around the current f-cost limit
– Can check the current path for repeated states, but future paths may
repeat states already expanded
– Inefficient for small ε step costs
• SMA* uses more memory to keep track of repeated states
– Up to the limit of allocated memory
– Nodes with high f-cost are dropped from the queue when memory
is filled (“forgotten nodes”)
• Optimality and completeness depends on how much
memory is available with respect to the optimal solution
– SMA* is complete and optimal if there is any reachable solution
given the current memory limit

31
Heuristics
• What’s a heuristic for
– Driving distance (or time) from city A to city B ?
– 8-puzzle problem ?
– M&C ?
– Robot navigation ?
– Reaching the summit ?
• Admissible heuristic
– Does not overestimate the cost to reach the goal
– “Optimistic”
• Are the above heuristics admissible? Consistent?

32
8-Puzzle

33
Comparing and combining heuristics
• Heuristics generated by considering relaxed versions of a problem.
• Heuristic h1 for 8-puzzle
– Number of out-of-order tiles
• Heuristic h2 for 8-puzzle
– Sum of Manhattan distances of each tile
• h2 dominates h1 provided h2(n) ≥ h1(n).
– h2 will likely prune more than h1.
• max(h1,h2 , .. ,hn) is
– admissible if each hi is
– consistent if each hi is
• Cost of sub-problems and pattern databases
– Cost for 4 specific tiles
– Can these be added for disjoint sets of tiles?

34
Effective Branching Factor
• Though informed search methods may have poor worst-
case performance, they often do quite well if the heuristic
is good
– Even if there is a huge branching factor

• One way to quantify the effectiveness of the heuristic: the


effective branching factor, b*
– N: total number of nodes expanded
– d: solution depth
– N = 1 + b* + (b*)2 + … + (b*)d

• For a good heuristic, b* is close to 1

35
Example: 8-puzzle problem

Averaged over 100 trials each at different solution lengths

Ave. # of nodes expanded

Solution length

36

You might also like