Sei sulla pagina 1di 15

Artificial Intelligence 2006 28 Aug.

2006

Trí tuệ nhân tạo (artificial intelligence)

Chapter 4. Informed search


Đặng Xuân Hà
DSE, FIT, HAU1
Office phone: 8276346; Ext.:132
Office location: Room 317, Administration building.
Email: dxha at hau1.edu.vn; dangxuanha at gmail.com
Website: http://www.hau1.edu.vn/it/dxha

Review: Tree search

‰A search strategy is defined by picking the order of


node expansion

28 Aug. 2006 Artificial Intelligence 2006 2

Review: Uninformed tree search


‰ Breath-first search:
¾ Shallowest node first
‰ Depth-first search
¾ Deepest node first
‰ Uniform-cost search
¾ Least-cost node first
‰ Depth-limited search
¾ Depth-first with limited depth
‰ Iterative deepening search
¾ Depth-limited with increasing limit.
28 Aug. 2006 Artificial Intelligence 2006 3

Đặng Xuân Hà <dxha at hau1.edu.vn> 1


Artificial Intelligence 2006 28 Aug. 2006

Review: Exercise
10 A
7
5
B C D
5 20 15
6 25 20

E F
G H I J
10
12
10 15
K L 8

N M O - Initial: A; Goal: I , N
Solution:
(1) ABCDEFGHI - Find seq. for each
(2) ABEKLFCGMN tree search algrithm?:
(3) ACDBGEN (1)BFS; (2)DFS; (3)uniform-cost;
(4) ABEFCGDHI (4)Depth-limited (l=2);
(5) A; ABCD; ABEKLFCGMN (5)Iterative deepening

28 Aug. 2006 Artificial Intelligence 2006 4

Informed search
‰ Best-first search
¾ (Greedy) best-first search
¾ A* search
‰ Heuristics

‰ Local search
¾ Hill
climbing
¾ Simulated annealing
¾ Genetic algorithms

28 Aug. 2006 Artificial Intelligence 2006 5

Best-first search
‰ Idea: use an evaluation function f(n) for each node
¾ estimate of "desirability"
Æ Expand most desirable unexpanded node

‰ Implementation:
Order the nodes in fringe in decreasing order of
desirability

‰ Special cases:
¾ greedy best-first search
¾ A* search

28 Aug. 2006 Artificial Intelligence 2006 6

Đặng Xuân Hà <dxha at hau1.edu.vn> 2


Artificial Intelligence 2006 28 Aug. 2006

Romania with step costs in km

28 Aug. 2006 Artificial Intelligence 2006 7

Greedy best-first search


‰ Evaluation function f(n) = h(n) (heuristic) =
estimate of cost from n to goal
‰ e.g., hSLD(n) = straight-line distance from n to
Bucharest
‰ Greedy best-first search expands the node that
appears to be closest to goal

28 Aug. 2006 Artificial Intelligence 2006 8

Greedy best-first search example

28 Aug. 2006 Artificial Intelligence 2006 9

Đặng Xuân Hà <dxha at hau1.edu.vn> 3


Artificial Intelligence 2006 28 Aug. 2006

Greedy best-first search example

28 Aug. 2006 Artificial Intelligence 2006 10

Greedy best-first search example

28 Aug. 2006 Artificial Intelligence 2006 11

Greedy best-first search example

28 Aug. 2006 Artificial Intelligence 2006 12

Đặng Xuân Hà <dxha at hau1.edu.vn> 4


Artificial Intelligence 2006 28 Aug. 2006

Properties of greedy best-first search


‰ Complete? No – can get stuck in loops, e.g., Iasi Æ
Neamt Æ Iasi Æ Neamt Æ
‰ Time? O(bm), but a good heuristic can give
dramatic improvement
‰ Space? O(bm) -- keeps all nodes in memory
‰ Optimal? No

28 Aug. 2006 Artificial Intelligence 2006 13

A* search (A-star search)


‰ Idea: avoid expanding paths that are already
expensive
‰ Evaluation function f(n) = g(n) + h(n)
¾ g(n) = cost so far to reach n
¾ h(n) = estimated cost from n to goal
‰ f(n) = estimated total cost of path through n to goal

28 Aug. 2006 Artificial Intelligence 2006 14

A* search example

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

28 Aug. 2006 Artificial Intelligence 2006 15

Đặng Xuân Hà <dxha at hau1.edu.vn> 5


Artificial Intelligence 2006 28 Aug. 2006

A* search example

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

28 Aug. 2006 Artificial Intelligence 2006 16

A* search example

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

28 Aug. 2006 Artificial Intelligence 2006 17

A* search example

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

28 Aug. 2006 Artificial Intelligence 2006 18

Đặng Xuân Hà <dxha at hau1.edu.vn> 6


Artificial Intelligence 2006 28 Aug. 2006

A* search example

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

28 Aug. 2006 Artificial Intelligence 2006 19

A* search example

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

28 Aug. 2006 Artificial Intelligence 2006 20

Admissible heuristics
‰ A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal
state from n.
‰ An admissible heuristic never overestimates the cost to
reach the goal, i.e., it is optimistic
‰ Example: hSLD(n) (never overestimates the actual road
distance)
‰ Theorem: If h(n) is admissible, A* using TREE-SEARCH
is optimal

28 Aug. 2006 Artificial Intelligence 2006 21

Đặng Xuân Hà <dxha at hau1.edu.vn> 7


Artificial Intelligence 2006 28 Aug. 2006

Consistent heuristics
‰ A heuristic is consistent if for every node n, every successor n' of n
generated by any action a,

h(n) ≤ c(n,a,n') + h(n')

‰ If h is consistent, we have
f(n') = g(n') + h(n')
= g(n) + c(n,a,n') + h(n')
≥ g(n) + h(n) triangle inequality
= f(n)
‰ i.e., f(n) is non-decreasing along any path.
‰ Theorem: If h(n) is consistent, A* using GRAPH-SEARCH is optimal

28 Aug. 2006 Artificial Intelligence 2006 22

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

28 Aug. 2006 Artificial Intelligence 2006 23

Properties of A*
‰ Complete? Yes (unless there are infinitely many
nodes with f ≤ f(G) )
‰ Time? Exponential
‰ Space? Keeps all nodes in memory
‰ Optimal? Yes

28 Aug. 2006 Artificial Intelligence 2006 24

Đặng Xuân Hà <dxha at hau1.edu.vn> 8


Artificial Intelligence 2006 28 Aug. 2006

Admissible heuristics
E.g., for the 8-puzzle:
‰ h1(n) = number of misplaced tiles
‰ h2(n) = total Manhattan distance
(i.e., no. of squares from desired location of each tile)

‰ h1(S) = ? 8
‰ h2(S) = ? 3+1+2+2+2+3+3+2 = 18

28 Aug. 2006 Artificial Intelligence 2006 25

Dominance
‰ If h2(n) ≥ h1(n) for all n (both admissible)
‰ then h2 dominates h1
‰ h2 is better for search

‰ Typical search costs (average number of nodes expanded):

d=12: IDS = 3,644,035 nodes


A*(h1) = 227 nodes
A*(h2) = 73 nodes
d=24 : IDS = too many nodes
A*(h1) = 39,135 nodes
A*(h2) = 1,641 nodes

28 Aug. 2006 Artificial Intelligence 2006 26

Relaxed problems
‰ A problem with fewer restrictions on the actions is called a
relaxed problem
‰ The cost of an optimal solution to a relaxed problem is an
admissible heuristic for the original problem
‰ If the rules of the 8-puzzle are relaxed so that a tile can
move anywhere, then h1(n) gives the shortest solution
‰ If the rules are relaxed so that a tile can move to any
adjacent square, then h2(n) gives the shortest solution

28 Aug. 2006 Artificial Intelligence 2006 27

Đặng Xuân Hà <dxha at hau1.edu.vn> 9


Artificial Intelligence 2006 28 Aug. 2006

Local search algorithms


‰ In many optimization problems, the path to the goal is
irrelevant; the goal state itself is the solution

‰ State space = set of "complete" configurations


‰ Find configuration satisfying constraints, e.g., n-queens

‰ In such cases, we can use local search algorithms: keep a


single "current" state, try to improve it

28 Aug. 2006 Artificial Intelligence 2006 28

Example: n-queens
‰ Put n queens on an n × n board with no two queens
on the same row, column, or diagonal
‰ Move queens to reduce conflicts

28 Aug. 2006 Artificial Intelligence 2006 29

Hill-climbing search
‰ "Like climbing Everest in thick fog with amnesia"

28 Aug. 2006 Artificial Intelligence 2006 30

Đặng Xuân Hà <dxha at hau1.edu.vn> 10


Artificial Intelligence 2006 28 Aug. 2006

Hill-climbing search
‰ "Like climbing Everest in thick fog with amnesia"

28 Aug. 2006 Artificial Intelligence 2006 31

Hill-climbing search
‰ Problem: depending on initial state, can get stuck in
local maxima

28 Aug. 2006 Artificial Intelligence 2006 32

Hill-climbing search: 8-queens problem

‰ h = number of pairs of queens


that are attacking each other,
either directly or indirectly
‰ successor function: move a
single queen to another square
in the same column
‰ h = 17 for the above state

28 Aug. 2006 Artificial Intelligence 2006 33

Đặng Xuân Hà <dxha at hau1.edu.vn> 11


Artificial Intelligence 2006 28 Aug. 2006

Drawbacks of hill climbing

‰ Ridge = sequence of local maxima difficult for greedy


algorithms to navigate
‰ Plateaux = an area of the state space where the evaluation
function is flat.
‰ Gets stuck 86% of the time.
28 Aug. 2006 Artificial Intelligence 2006 34

Hill-climbing search: 8-queens problem

‰A local minimum with h = 1: no better


successors
28 Aug. 2006 Artificial Intelligence 2006 35

Hill-climbing variations
‰ Stochastic hill-climbing
¾ Random selection among the uphill moves.
¾ The selection probability can vary with the steepness of the
uphill move.
‰ First-choice hill-climbing
¾ cfr. stochastic hill climbing by generating successors
randomly until a better one is found.
‰ Random-restart hill-climbing
¾ Tries to avoid getting stuck in local maxima.

28 Aug. 2006 Artificial Intelligence 2006 36

Đặng Xuân Hà <dxha at hau1.edu.vn> 12


Artificial Intelligence 2006 28 Aug. 2006

Simulated annealing search

local minimum

global minimum

gradually decrease shaking to make sure the ball


escape from local minima and fall into the global minimum

28 Aug. 2006 Artificial Intelligence 2006 37

Simulated annealing search


‰ Idea: escape local maxima by allowing some "bad" moves
but gradually decrease their frequency
‰ Implement:
¾ Randomly select a move instead of selecting best move
¾ Accept a bad move with probability less than 1 (p<1)
¾ p decreases by time

28 Aug. 2006 Artificial Intelligence 2006 38

Properties of simulated annealing search


‰ One can prove: If T decreases slowly enough, then
simulated annealing search will find a global optimum
with probability approaching 1

‰ Widely used in VLSI layout, airline scheduling, etc

28 Aug. 2006 Artificial Intelligence 2006 39

Đặng Xuân Hà <dxha at hau1.edu.vn> 13


Artificial Intelligence 2006 28 Aug. 2006

Local beam search


‰ Keep track of k states rather than just one in hill climbing
‰ 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.
‰ Comparison to random restart hill climbing:
¾ Information is shared among k search threads: If one state
generated good successor, but others did not Æ “come here, the
grass is greener!”

28 Aug. 2006 Artificial Intelligence 2006 40

Genetic algorithms
‰ Variant of local beam search with sexual recombination.

28 Aug. 2006 Artificial Intelligence 2006 41

Genetic algorithms
‰ A successor state is generated by combining two parent states

‰ Start with k randomly generated states (population)

‰ A state is represented as a string over a finite alphabet (often a string


of 0s and 1s)

‰ Evaluation function (fitness function). Higher values for better


states.

‰ Produce the next generation of states by selection, crossover, and


mutation

28 Aug. 2006 Artificial Intelligence 2006 42

Đặng Xuân Hà <dxha at hau1.edu.vn> 14


Artificial Intelligence 2006 28 Aug. 2006

Genetic algorithms

‰ Fitness function: number of non-attacking pairs of queens (min = 0,


max = 8 × 7/2 = 28)
‰ 24/(24+23+20+11) = 31%
‰ 23/(24+23+20+11) = 29% etc
28 Aug. 2006 Artificial Intelligence 2006 43

Genetic algorithms

28 Aug. 2006 Artificial Intelligence 2006 44

References
‰ Slides provided by Prof. Russell at http://aima.cs.berkeley.edu/
‰ AIMA chapter 4

28 Aug. 2006 Artificial Intelligence 2006 45

Đặng Xuân Hà <dxha at hau1.edu.vn> 15

Potrebbero piacerti anche