Announcements: Homework 1
Announcements: Homework 1
Homework 1:
stanford.ai-class.com To be done individually; due Sunday Review section: Tomorrow 11:00-12:00, Skilling Auditorium
Project 1: Search
cs221.stanford.edu Start early and ask questions You can work in groups of up to 3 people; due Thursday
Contact us
[email protected]
(Slides from Dan Klein, with help from Stuart Russell, Andrew Moore, Teg Grenager, Peter Norvig)
Outline
Problem-solving agents (Book: 3.1)
Problem types and problem formulation
Search trees and state space graphs (3.3) Uninformed search (3.4)
Depth-first, Breadth-first, Uniform cost Search graphs
Agents
act = AgentFn(percept) sensors agent fn
actuators
4
Reflex Agents
Reflex agents:
Choose action based on current state May have memory or a model of the world s current state; use percept Do not consider the future consequences of their actions Act on how the world IS
WWGBAD?
WWGBAD?
Problem types
Fully observable, deterministic
single-belief-state problem
Non-observable
sensorless (conformant) problem
Partially observable/non-deterministic
contingency problem interleave search and execution
Search Problems
A search problem consists of:
A state space
N, 1
A transition model
E, 1
A solution is a sequence of actions (a plan) which transforms the start state to a goal state
Transition Models
Successor function
Successors( ) = {(N, 1, ), (E, 1, )}
Example: Romania
State space:
Cities
Successor function:
Go to adj city with cost = dist
Start state:
Arad
Goal test:
Is state == Bucharest?
Solution?
a b d h p q r c e f
Search Trees
N, 1 E, 1
A search tree:
This is a what if tree of plans and outcomes Start state at the root node Children correspond to successors Nodes contain states, correspond to paths to those states For most problems, we can never actually build the whole tree
Search:
Expand out possible plans Maintain a frontier of unexpanded plans Try to expand as few tree nodes as possible
Important ideas:
Frontier (aka fringe) Expansion Exploration strategy
Detailed pseudocode is in the book!
Each NODE in in the search tree is an entire PATH in the state space.
e r f c a
G
p q
Search Tree
Parent
Depth 5
Action Node
Depth 6
d b a c a p q h q c a e r f
G
e h p q q c a r f
G
p q
[demo: dfs]
a b d
G c e h q r f
p
S
d Search Tiers b a c a p q h q c a e r f
G
e h p q q c a r f
G
p q
[demo: bfs]
Santayana s Warning
Those who cannot remember the past are condemned to repeat it. George Santayana Failure to detect repeated states can cause exponentially more work (why?)
Graph Search
In BFS, for example, we shouldn t bother expanding the circled nodes (why?)
S
d b a c a p q h q c a e r f
G
e h p q q c a r f
G
p q
Graph Search
Very simple fix: never expand a state twice
Costs on Actions
2 b 1 3
START
GOAL
2 c 8 2 d 9 4 h 4 q r 8 2 e f 1 3 2
1 p
15
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.
G 8
c
1
d
2
h
2 1
r f
9
q
15 9
0 e p q 1 16
d b 4 Cost contours a 6 c a
3 11 e 5 h 13 r 7 p q f 8
G 10
h 17 r 11 p q q c a f
G
q 11 c a
Start
Goal
b 0 1
GOAL
AI Lesson
Search Heuristics
Any estimate of how close a state is to a goal Designed for a particular search problem Examples: Manhattan distance, Euclidean distance
10 5 11.2
Heuristics
2 f 5 h=6
h=0 5
h=4
G h=0
A* Search Progress
A
h=2
2 G
h=0
B
h=1
Is A* Optimal?
1 A
h=6
3
h=0
h=7
G 5
Admissible Heuristics
A heuristic h is admissible (optimistic) if:
where
Never overestimate!
366
Properties of A*
Uniform-Cost
b
A*
b
UCS vs A* Contours
Uniform-cost expanded in all directions
Start Goal
A* expands mainly toward the goal, but does hedge its bets to ensure optimality
Start
Goal
Example: 8 Puzzle
What are the states? How many states? What are the actions? What states can I reach from the start state? What should the costs be?
8 Puzzle
Heuristic: Number tiles misplaced Why is it admissible? h(start) = 8 This is a relaxed-problem heuristic:
UCS
Average nodes expanded when optimal path has length 4 steps 8 steps 12 steps
112 TILES 13
6,300 39
8 Puzzle
What if we had an easier 8-puzzle where any tile could slide one step at any time, ignoring other tiles? Total Manhattan distance Why admissible? h(start) = 3 + 1 + 2 + = 18 Relaxed problem:
TILES
MANHATTAN
Average nodes expanded when optimal path has length 4 steps 8 steps 12 steps
13 12
39 25
227 73
Trivial heuristics
Bottom of lattice is the zero heuristic (what does this give us?) Top of lattice is the exact heuristic
Other A* Applications
Path finding / routing problems Resource planning problems Robot motion planning Language analysis Machine translation Speech recognition
Summary: A*
A* uses both backward costs, g(n), and (estimates of) forward costs, h(n) A* is optimal with admissible heuristics Heuristic design is key: often use relaxed problems A* is not the final word in search algorithms (but it does get the final word for today)