informed search algorithms - nus computingkanmy/courses/3243_2010/lecturen… · material sections...

53
Informed search algorithms Chapter 4 CS 3243 - Informed Search 1

Upload: others

Post on 02-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Informed search algorithms

Chapter 4

CS 3243 - Informed Search 1

Page 2: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Material

Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search

(3 5)(3.5)

CS 3243 - Informed Search 2

Page 3: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Outline

Best-first search Greedy best-first search A* search

Heuristics

Local search algorithms

Online search problems

CS 3243 - Informed Search 3

Page 4: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Review: Tree search

A search strategy is defined by picking theA search strategy is defined by picking the order of node expansion

CS 3243 - Informed Search 4

Page 5: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

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 d i bilitdesirability

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

CS 3243 - Informed Search 5

Page 6: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Romania with step costs in kmp

CS 3243 - Informed Search 6

Page 7: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Greedy best-first searchy

Evaluation function f(n) = h(n) (heuristic)Evaluation function f(n) h(n) (heuristic) = estimate of cost from n to goal

e.g., hSLD(n) = straight-line distance from nhto Bucharest

Greedy best-first search expands the node that appears to be closest to goal

CS 3243 - Informed Search 7

that appears to be closest to goal

Page 8: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Greedy best-first search exampley p

CS 3243 - Informed Search 8

Page 9: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Greedy best-first search exampley p

CS 3243 - Informed Search 9

Page 10: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Greedy best-first search exampley p

CS 3243 - Informed Search 10

Page 11: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Greedy best-first search exampley p

Greedy Best-First demo?

CS 3243 - Informed Search 11

Page 12: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Properties of greedy best-first searchProperties of greedy best first search

Complete? No – can get stuck in loops,Complete? No can get stuck in loops, e.g., Iasi Neamt Iasi Neamt …

Time? O(bm) but a good heuristic can give Time? O(b ), but a good heuristic can give dramatic improvement

Space? O(bm): keeps all nodes in memory Space? O(bm): keeps all nodes in memory Optimal? No

CS 3243 - Informed Search 12

Page 13: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

A* search

Idea: avoid expanding paths that are alreadyIdea: 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 h(n) estimated cost from n to goal f(n) = estimated total cost of path through n

to goalCS 3243 - Informed Search 13

to goal

Page 14: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

A* search examplep

CS 3243 - Informed Search 14

Page 15: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

A* search examplep

CS 3243 - Informed Search 15

Page 16: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

A* search examplep

CS 3243 - Informed Search 16

Page 17: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

A* search examplep

CS 3243 - Informed Search 17

Page 18: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

A* search examplep

CS 3243 - Informed Search 18

Page 19: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

A* search examplep

A* demo?

CS 3243 - Informed Search 19

Page 20: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Admissible heuristics

A heuristic h(n) is admissible if for every node n,( ) y ,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

CS 3243 - Informed Search 20

Page 21: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Optimality of A* (proof)p y (p )

Suppose some suboptimal goal G2 has been generated and is in the 2fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G.

f(G2) = g(G2) since h(G2) = 0 (G ) (G) i G i b ti l g(G2) > g(G) since G2 is suboptimal

f(G) = g(G) since h(G) = 0 f(G2) > f(G) from above

CS 3243 - Informed Search 21

Page 22: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Optimality of A* (proof)p y (p )

Suppose some suboptimal goal G2 has been generated and is in the 2fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G.

f(G2) > f(G) from previoush( ) h*( ) i h i d i ibl h(n) ≤ h*(n) since h is admissible

g(n) + h(n) ≤ g(n) + h*(n) f(n) ≤ f(G)

CS 3243 - Informed Search 22

Hence f(G2) > f(n), and A* will never select G2 for expansion

Page 23: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Consistent heuristics A heuristic is consistent if for every node n, every successor n' of n

generated by any action agenerated by any action a,

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

If h is consistent, we havef(n') = g(n') + h(n')

= g(n) + c(n,a,n') + h(n') ≥ g(n) + h(n) = f(n)

i.e., f(n) is non-decreasing along any path.

Theorem: If h(n) is consistent A* using GRAPH SEARCH is optimal

CS 3243 - Informed Search 23

Theorem: If h(n) is consistent, A* using GRAPH-SEARCH is optimal

Page 24: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Optimality of A*p y

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+1i, i i+1

CS 3243 - Informed Search 24

Page 25: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Properties of A*p

Complete? Yes (unless there are infinitelyComplete? Yes (unless there are infinitely many nodes with f ≤ f(G) )

Time? Exponential Time? Exponential Space? Keeps all nodes in memory

O l? Optimal? Yes

CS 3243 - Informed Search 25

Page 26: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

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)

Average solution depth?

Average branching factor?

h1(S) = ?

CS 3243 - Informed Search 26

1( ) h2(S) = ?

Page 27: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Admissible heuristics

E.g., for the 8-puzzle:h ( ) b f i l d til 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

CS 3243 - Informed Search 27

Page 28: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Dominance

If h2(n) ≥ h1(n) for all n (both admissible)th h d i t hthen h2 dominates h1h2 is better for search

Typical search costs (average number of nodes expanded):

d=12 IDS = 3 644 035 nodes d=12 IDS = 3,644,035 nodesA*(h1) = 227 nodesA*(h2) = 73 nodes

d=24 IDS = too many nodes d=24 IDS = too many nodesA*(h1) = 39,135 nodesA*(h2) = 1,641 nodes

CS 3243 - Informed Search 28

Page 29: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Relaxed problemsp

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 originalproblem is an admissible heuristic for the original problem

If the rules of the 8-puzzle are relaxed so that a tile 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

CS 3243 - Informed Search 29

solution

Page 30: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Beyond Classical Searchy

Local SearchLocal Search

Searching with non determinism Searching with non-determinism Searching with partial observations Online and exploratory search

CS 3243 - Informed Search 30

Page 31: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Local search algorithmsg

In many optimization problems, the path to the l i i l t th l t t it lf i thgoal 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 algorithmskeep a single "current" state, try to improve it

CS 3243 - Informed Search 31

Page 32: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Example: n-queensp q

Put n queens on an n × n board with no Put n queens on an n n board with no two queens on the same row, column, or diagonaldiagonal

CS 3243 - Informed Search 32

Page 33: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Hill-climbing searchg

"Like climbing Everest in thick fog withLike climbing Everest in thick fog with amnesia"

CS 3243 - Informed Search 33

Page 34: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Hill-climbing searchg

Problem: depending on initial state, can getProblem: depending on initial state, can get stuck in local maxima

CS 3243 - Informed Search 34

Page 35: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Hill-climbing search: 8-queens problemg q p

h = number of pairs of queens that are attacking each other, either directly or indirectlyh 17 f th b t t

CS 3243 - Informed Search 35

h = 17 for the above state

Page 36: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Hill-climbing search: 8-queens problemg q p

Hill climbing demo?

A local minimum with h = 1

CS 3243 - Informed Search 36

Page 37: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Simulated annealing searchg

Idea: escape local maxima by allowing some "bad" p y gmoves but gradually decrease their frequency

CS 3243 - Informed Search 37

Page 38: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Properties of simulated annealing searchp g

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

Widely used in VLSI layout, airline scheduling, etc

CS 3243 - Informed Search 38

Page 39: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Local Beam Search

Why keep just one best state?Why keep just one best state?

BestSt tStates(n=4)

Can be used with randomization tooCS 3243 - Informed Search 39

Can be used with randomization too

Page 40: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Genetic algorithmsg

A successor state is generated by combining two parent statesstates

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

CS 3243 - Informed Search 40

crossover, and mutation

Page 41: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Genetic algorithmsg

Fitness function: number of non-attacking pairs of queens (min = 0 max = 8 × 7/2 = 28)(min = 0, max = 8 × 7/2 = 28)

24/(24+23+20+11) = 31% 23/(24+23+20+11) = 29% etc.

CS 3243 - Informed Search 41

3/( 3 0 ) 9% etc

Page 42: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Genetic algorithmsg

CS 3243 - Informed Search 42

Page 43: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Search w/ non-determinism/

Fully observable, deterministic environmentsFully observable, deterministic environments Sensors, precepts no use

Consider erratic actuators Action leads to a set of possible states Action leads to a set of possible states

Plan will not be a set sequence, may have loops contingencies (if then else)contingencies (if-then-else)

CS 3243 - Informed Search 43

Page 44: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

And-Or Search Tree

Q: what does the “LOOP” label mean here? Q: what does the LOOP label mean here?CS 3243 - Informed Search 44

Page 45: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Search w/ partial observations/ p

Conformant problem – no observationsConformant problem no observations Useful! Solutions are independent of initial state Coerce the state space into a subset of possible Coerce the state space into a subset of possible

CS 3243 - Informed Search 45

Page 46: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

CS 3243 - Informed Search 46

Page 47: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

LocalizationInitial State:

After observing NSW:

Q: What about a really big set of initial positions?

CS 3243 - Informed Search 47

Q: What about a really big set of initial positions?

Page 48: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Online search and explorationp

Many problems are offlineMany problems are offline Do search for action and then perform action

Online search interleave search & executionf l bl Necessary for exploration problems

New observations only possible after acting

CS 3243 - Informed Search 48

Page 49: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Exploratory Searchp y

In an unknown state space, how to pick anIn an unknown state space, how to pick an action? Any random action will do but Any random action will do … but

S G

Favor those that allow more exploration of the Favor those that allow more exploration of the search space Graph-search to track of states previously seen Graph search to track of states previously seen

CS 3243 - Informed Search 49

Page 50: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Assessing Online Agents: Competitive Ratio

Actual cost of path

Competitive RatioI

Best possible cost(if agent knew space in advance)

30/20 = 1.5

For cost, lower is better

20

30

CS 3243 - Informed Search 50

20

Page 51: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Exploration problemsp p

Exploration problems: agentExploration problems: agent physically in some part of the state space.space. e.g. solving a maze using an agent with

local wall sensors Sensible to expand states easily

accessible to agent (i.e. local states)g ( ) Local search algorithms apply (e.g.,

hill-climbing)

CS 3243 - Informed Search 51

Page 52: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Assignmentg

Build a game playerg p y Restricted by time per move (5 real-time secs)

Interact with the game driver through the command line Each turn, we will run your program, providing the board

state as input. Your output will be the pair of coordinates indicating the

piece to move and its destination.

CS 3243 - Informed Search 52

Page 53: Informed search algorithms - NUS Computingkanmy/courses/3243_2010/lectureN… · Material Sections 3.5, 4.1Sections 3.5, 4.1 Excludes memory-bounded heuristic search (3 5)(3.5) CS

Homework #1 - Ataxx

Note: we haven’t yet covered all of the ymethods to solve this problem

This week: start thinking about it, discuss among yourselves (remember the Facebook g y (Rule!) Play the game, review past games by others. What heuristics are good to use? What type of search makes sense to use?

CS 3243 - Informed Search 53