Search problems
consist
- a state space: all possilbel states in the world
world state: all info about the state in the world
search state: only info needed for planning
e.g. Pacman pathing / pacman eating dots - successor/result function:
input: action,state
output: successor state,cost - start state: agent exist initially
- goal test: whether ends
一些概念
plan: a path from the start state to the goal state(search problem 的目标)
strategy: state 的考虑/搜索顺序 e.g. DFS,BFS
state space size
fundamental enumerate principle: variable domains‘ size multiply together
如果我们有n个变量,每个变量的domain大小分别为
x
1
,
x
2
,
x
3
,
⋯
x_1,x_2,x_3,\cdots
x1,x2,x3,⋯
那么状态空间的大小
x
1
∗
x
2
∗
⋯
x_1*x_2*\cdots
x1∗x2∗⋯
state space graphs and search trees(搜索问题的图表示)
state space graphs
- node: states
- directed edge: actions,cost
weight: the cost of actions(和边相关)
each state only occurs once
search trees:
node show plans from the root to achieve the node
root node: start state
children: successors
states cans occur many times
search trees are greater or equal size to the state space graphs
很多时候(循环),我们没有办法建立整个搜索树
successor function: only save the states we are working with, and use the successor function to compute new ones(节省存储空间)
注: goal test 很多时候就是一个terminal nodes的集合
搜索图和搜索树都太大而不能全部存储
uninformed search
fringe: the observed but unvisited node
expand: pop a node from the fringe
generate: get neighbors of the popped node
stategy: 先pop什么节点
search algorithm properties:
- completeness: guarantee to find a solution
- optimal: find the lowest cost path
- time complexity: generate nodes
- space complexity:store nodes(size of fringe)
branching factor b , 树的最大深度 m , 最优solution的深度 s
o ( b m ) o(b^m) o(bm)nodes in a tree
depth first search
strategy: expand the deepest node first
implementation: fringe is LIFO stack
property:
- completeness:❌ m can be infinite(循环) 永远找不到解
- optimal:❌ find the depth path
- time complexity: exploring the whole tree o ( b m ) o(b^m) o(bm)才能找到解
- space complexity: o ( b m ) o(bm) o(bm)每层只扩展b个因子
breadth first search
strategy: expand the shallowest node first
implementation: fringe is FIFO stack(queue)
property:
- completeness:✅
- optimal: ✅前提不考虑每次拓展的cost,认为每个edge cost一致
- time complexity: exploring the whole tree o ( b s ) o(b^s) o(bs)
- space complexity: o ( b s ) o(b^s) o(bs)
expand 结束 do the goal test:
time complexity:
o
(
b
s
+
1
)
o(b^{s+1})
o(bs+1)
space complexity:
o
(
b
s
+
1
)
o(b^{s+1})
o(bs+1)
bfs robust but need more storage spaces
iterative deepening:
run a dfs with a depth limited 1,if no solution run a dfs with a depth limited 2
expand more nodes than bfs:
b
,
b
+
b
2
,
b
+
b
2
+
b
3
=
b
d
+
(
d
−
1
)
b
2
+
⋯
=
o
(
b
d
)
b,b+b^2,b+b^2+b^3=bd+(d-1)b^2+\cdots=o(b^d)
b,b+b2,b+b2+b3=bd+(d−1)b2+⋯=o(bd)
save storage space:
o
(
b
d
)
o(bd)
o(bd)
uniform cost search
strategy: expand the lowest cost node first
implementation: fringe is priority queue (heap)
weight : path cost from the start node to the node or backward cost of v
从根节点扩展到该节点的开销
property:
- completeness:✅
- optimal: ✅(前提edge cost 不为负)如果有环就会导致来回走
assume edge costs not negative - time complexity: optimal path costs:
C
∗
C^*
C∗,least arc cost
ϵ
\epsilon
ϵ
o
(
b
C
∗
/
ϵ
)
o(b^{C^*/\epsilon})
o(bC∗/ϵ)
expand 所有比cheapest goal浅的节点 - space complexity: o ( b s ) o(b^s) o(bs) o ( b C ∗ / ϵ ) o(b^{C^*/\epsilon}) o(bC∗/ϵ)
sum up
uninformed search | completeness | optimal | time complexity | space complexity |
---|---|---|---|---|
bfs | ✅ | ✅ | o ( b s ) o(b^s) o(bs) | o ( b s ) o(b^s) o(bs) |
dfs | ❌ | ❌ | o ( b m ) o(b^m) o(bm) | o ( b m ) o(bm) o(bm) |
ucs | ✅ | ✅ | o ( b C ∗ / ϵ ) o(b^{C^*/\epsilon}) o(bC∗/ϵ) | o ( b C ∗ / ϵ ) o(b^{C^*/\epsilon}) o(bC∗/ϵ) |
informed search
我们可以知道一点离目标state多近的信息
Heuristics Function
估计当前state与目标state的距离cost
Heuristics Function
input: state
output: the estimate of the distance between state to the goal state
usually want a lower bound
一般要比真实的少一点
用一个relaxed problem去估计启发式函数
greedy search
description: expand the node with lowest heuristics value
fringe: prioritiy queue (estimate forward value)
property:
- completeness:not guaranteed
- optimal: not guaranteed
主要取决于启发式函数的选择,有可能直接找到路径,也有可能永远找不到
A* search
description: expand the node with lowest total estimated cost
fringe: prioritiy queue (estimate total value)
f
(
n
)
=
g
(
n
)
+
h
(
n
)
f(n)=g(n)+h(n)
f(n)=g(n)+h(n)
property:
3. completeness:✅
4. optimal: ✅
前提,启发式函数要满足一些性质
有点:速度很快,然后可以保证完备和最优
坏的启发式会破坏:
h
(
n
)
=
1
−
g
(
n
)
h(n)=1-g(n)
h(n)=1−g(n)
f
(
n
)
=
1
f(n)=1
f(n)=1
对于边cost不一致的情况,会被破坏掉
Admissiblity and consistency
admissible:
0
≤
h
(
n
)
≤
h
∗
(
n
)
0\leq h(n)\leq h^*(n)
0≤h(n)≤h∗(n)
$ h^*(n)$到达goal state的最小值
theorem: for a given search problem, if the admissibility constraint is satisfied by a heuristic function h, using
A
∗
A^*
A∗ tree search will yield an optimal solution.
proof:
A is the optimal goal state, B is a suboptimal goal state;n(include A) are ansesters of A, we claim that n must be chosen before B
- g ( A ) < g ( B ) g(A)<g(B) g(A)<g(B)
- h ( A ) = h ( B ) = 0 h(A)=h(B)=0 h(A)=h(B)=0
-
f
(
n
)
≤
f
(
A
)
f(n)\leq f(A)
f(n)≤f(A)
f
(
n
)
=
h
(
n
)
+
g
(
n
)
≤
h
∗
(
n
)
+
g
(
n
)
=
g
(
A
)
=
f
(
A
)
f(n)=h(n)+g(n)\leq h^*(n)+g(n)=g(A)=f(A)
f(n)=h(n)+g(n)≤h∗(n)+g(n)=g(A)=f(A)
f ( A ) < f ( B ) → f ( n ) < f ( B ) f(A)<f(B)\rightarrow f(n)<f(B) f(A)<f(B)→f(n)<f(B)
how to design admissible heuristic function
- from a relaxed problem
- from a subproblem
一些不一致的启发式函数也有可能很好用,因为可能减少了计算时间
graph search:
maintain a closed set for expanded nodes to avoid expand twice
closed must be a set, since checking list takes
o
(
n
)
o(n)
o(n) time
completeness: if exists , will be visited
optimality:however, graph search may ruin the optimality of
A
∗
A*
A∗, even the heuristic function is admissibility
e.g.
consistency:
∀
A
,
C
\forall A,C
∀A,C
h
(
A
)
−
h
(
C
)
≤
c
o
s
t
(
A
,
C
)
h(A)-h(C)\leq cost(A,C)
h(A)−h(C)≤cost(A,C)
theorem: for a given search problem, if the consistency constraint is satisfied by a heuristic function h, using
A
∗
A^*
A∗ graph search will yield an optimal solution.
proof:
h
(
n
)
≤
h
(
n
′
)
+
c
o
s
t
(
n
,
n
′
)
h(n)\leq h(n')+cost(n,n')
h(n)≤h(n′)+cost(n,n′)
n
′
n'
n′ is a successor of n
f
(
n
′
)
=
h
(
n
′
)
+
g
(
n
′
)
=
g
(
n
)
+
h
(
n
)
+
c
o
s
t
(
n
,
n
′
)
≥
g
(
n
)
+
h
(
n
)
=
f
(
n
)
f(n')=h(n')+g(n')= g(n)+h(n)+cost(n,n')\geq g(n)+h(n)=f(n)
f(n′)=h(n′)+g(n′)=g(n)+h(n)+cost(n,n′)≥g(n)+h(n)=f(n)
so f(n) is nondecreasing along the path
so whenever a node is removed from the fringe, it’s optimal path has already been found
so we only need to show, optimal solution A will be found before B
h
(
A
)
=
h
(
B
)
=
0
h(A)=h(B)=0
h(A)=h(B)=0
f
(
A
)
<
f
(
B
)
f(A)<f(B)
f(A)<f(B)
Under admissibility and consistency,
h
(
A
)
=
h
(
B
)
=
0
h(A)=h(B)=0
h(A)=h(B)=0
consistency implies adimissiblity
图搜索能保证 ucs的最优性和完备性,因为ucs
h
=
0
h=0
h=0既一致又最优
diminance
dominant:
∀
n
h
a
(
n
)
≥
h
b
(
n
)
\forall n h_a(n)\geq h_b(n)
∀nha(n)≥hb(n)
trivial heuristic: h(n)=0,reduce
A
∗
A^*
A∗ to
U
C
S
UCS
UCS
max of admissible heuristics is admissible
可以写多个一致或可达的启发式函数取max,仍然可以保证一致性可可达性
A
∗
A^*
A∗的computation cost会多一些
bfs不会有cycle问题,因为我们会访问比他们的相邻节点更早,cycle会有更大的cost
图搜索不会破坏完备性,但却会破坏最优性
图搜索对于dfs
可以破掉循环,可以保证完备性
图搜索对于bfs
可以保证最优性和完备性
题目复习
A
∗
A^*
A∗可以保证比 ucs 产生更少的nodes
注意搜索问题性质改变会导致是否能够解改变,搜索图没有办法完全决定能不能求解