Artificial Intelligence A Modern Approach Chapter 3 Problem Solving by Search

Problem Solving Agent

There are some issues can not draw the solution through a separate action, action sequences needed to reach the goal, you need to use search method.

Search : Finding the sequence of actions to achieve the goal of
free information search : In addition to the problem definition algorithm does not have any other information.
Search information : the use of a given knowledge guide to find the solution more effectively.
Formal problem : the process of determining what actions and states to consider the given target under.
Abstract : removing the details of the process is referred to as abstract. If the solution in every action easier than the original problem in the execution, then this abstraction is useful.

Formal problem

One problem formalization of the five components of the following composition

  • First rotation state
    in Romania problem, the initial state is In (Arad)
  • Description of possible actions
  • Given a state s, ACTIONS (s) return operation can be performed in a set state s. He said status read these s are available.
    In Romania problem, consider the state of In (Arad), can be applied to mobile :( {Go (Sibiu), Go (Timisoara), Go (Zerind)})
  • Metastasis model (description of each action)
    by a function RESULT (s, a) Description: After the operation reached a state in the execution state s.
  • Objective test
    to determine whether a given state is the goal state.
    In Romania problem, the target state is a singleton set {In (Bucharest)}
  • Path dissipation
    function dissipating bit value assigned for each path, i.e., edge-weighted. S actions come from a state s 'by a single step dissipation c (s, a, s' ) represents

It can be seen from the initial state transition model and action on the issue of the definition of the state space , ie the set of all states reachable from the initial state.

Examples of questions
Toy question: Slider problem, the eight queens problem, Knuth
real-world problems: TSP, VLSI wiring, robot navigation, automatic assembly

Vacuum cleaner problem (toy problems)
states: Agent position is determined by the location and the dust, the state of the world there are n * 2 ^ n, there are n positions, but there is no dust or
initial action: Any state can be designed to the initial state
action: there are three actions: left, right, suck
metastasis model: the left can no longer be left, the far right can not be the right
target test: detecting the position of all is clean
path consumption: path dissipation value of 1, and therefore the entire path of dissipation value is the number of steps in path

Search by solving (tree search, map search)

Romanian state space from Arad to FIG follows :( Bucuresti)

Edge (open end point table): at any given point in time, be extended set of all leaf nodes;
Exploration sets (closed form): record each node has been extended through.
General tree search and map search informal description of the algorithm:

Tree search
tree search has redundant paths

(Frontier: generated not expand; closed: has been extended)

Map search
to avoid redundant paths to explore ways to keep in mind once walked the streets. FIG search elements in the tree search algorithm adds a parameter: Exploration set (closed form): has been extended through the records for each node. The newly generated node if the node has been generated in a match, then that is focused on the edge or set in exploration, it will be discarded and not added to the edge set.

The figure is showing a search process in Romania question:

Figure search just three steps to reach the goal:

A features map search: FIG edge into the state space and the search area has been unexplored areas, thus starting from the initial state to any unexplored path of a state node are forced through the edges.

Search algorithms based
a solution is an action, the search algorithm takes into account various possible sequence of actions
n.STATE: state corresponds to the state space
n.PARENT: generating junction of the search tree node
n.ACTION: parent node generates the when the node actions taken
n.PATH-cOST: the cost, usually with g (n) represents, refers to the path from the initial state to the consumption of the node

queue

  • FIFO queue: FIFO
  • LIFO queue: stack, LIFO
  • Priority Queue: a function of calculating the highest priority, the highest priority lists team squad

Problem solving performance of the algorithm
to evaluate the performance standards

  • Completeness : Are guaranteed to find solution
  • 最优性:找到的解是否最优
  • 时间复杂度:找到解需要多少时间
  • 空间复杂度:在执行搜索过程中需要多少内存

复杂度的表达

  • b:分支引子 任何节点的最多后继数
  • d:深度 目标节点的最浅深度 根节点到目标节点的步数
  • m:状态空间中任何路径的最大长度

评价搜索有效性—搜索代价,通常由时间复杂度和空间复杂度决定

无信息搜索策略(盲目搜索)

无信息搜索(盲目搜索):除了问题定义中提供的状态信息外没有任何附加信息的搜索。
当搜索空间较大并且不知道解所在深度时,迭代加深的深度优先搜索是首选的无信息搜索方法。

宽度优先搜索(广度优先搜索)(BFS)

a) 概念:先扩展根结点,接着扩展根结点的所有后继,每次总是扩展深度最浅的结点,然后再扩展它们的后继。
b) 评价:

  • 完备的(分支因子b有限时);
  • 最优的(如果路径代价是基于结点深度的非递减函数,比如step cost保持是1,则是最优的);
  • 时间复杂度
    如果目标检测是在选择扩展的结点时:O(b^d)
    如果选择要扩展的结点在结点生成时才检测,那么目标结点到之前深度d时已经被扩展,此时为O(b^(d+1))
  • 空间复杂度 O(b^d) ,有 O(b^(d-1) )个结点在搜索集中,O(b^d)个结点在边缘集中。

默认:Time and space complexity is 1+b+…+b^d =O(b^d)

  • 使用FIFO队列实现

一个简单二叉搜索树的搜索过程:

一致代价搜索(Uniform-cost Search)

每一步的行动代价都相等时,BFS是最优的。因为它总是选择先扩展深度最浅但是未扩展的结点。
a) 概念:扩展的是路径消耗g(n)最小的结点n(g(n)指从初始状态到该结点的路径消耗 )。
这可以通过将边缘结点按路径代价g值进行排序的队列来实现
b) 评价:

  • 完备的(如果每一步代价都大于等于某个小的正值常数);
  • 最优的;
  • 时间复杂度和空间复杂度在最坏情况均比宽度优先搜索大(因为可能搜索一些对结果无用的树,一致代价搜索可能会检查目标深度所有结点看谁的代价小,在这种情况下一致搜索在深度d无意义地做了更多的工作)。

c)特点(和BFS的区别)

  • 将边缘结点按路径代价g值进行排序的队列来实现
  • 目标检测应用于结点被选择拓展时,而不是在结点生成的时候
  • 如果边缘中的节点有更好的路径到达该节点,则会引入一个测试

例子:考虑下图(初始状态S,目标状态G)

树搜索

图搜索

深度优先搜索(DFS)

a) 概念:总是扩展搜索树的当前边缘结点集(叶节点)中最深的结点。
b) 评价:

  • 完备性:避免冗余路径和重复状态的图搜索,在有限空间中是完备的,但树搜索的DFS则不完备,有可能陷入死循环中。在无限状态空间中,则均可能陷入死循环中
  • 最优性:无论基于图搜索还是树搜索的DF算法都不是最优的
  • 时间复杂度O(b^m)受限于状态空间的规模(可能是无限的);
    m:叶子结点的最大深度
    b:分支因子
    d:目标结点的最浅深度
  • 空间复杂度O(bm)(只需要存储一条从根结点到叶结点的路径,以及该路径上每个结点的所有未扩展的兄弟结点);

c) 变形——回溯搜索:空间复杂度O(m)(每次只产生一个后继而不是生成所有后继,每个被部分扩展的结点要记住下一个要生成的结点);
d)使用LIFO队列实现(栈)

深度受限搜索(Depth Limited Search:DLS)

a) 概念:在深度优先搜索基础上设置界限l来避免无限状态空间深度优先搜索失败的问题(深度为l被当作没有后继对待)。
b) 评价:

  • 完备的(l大于d)|不完备的(l小于d,则最浅的目标结点搜索不到);
  • 不是最优的
  • 时间复杂度O(b^l);
  • 空间复杂度O(bl);
    深度优先搜索可以看作是特殊的深度受限搜索,其深度l=∞
    深度受限搜索可以通过修改一般的树搜索或图搜索算法来实现。

迭代加深的深度优先搜索(Iterative Deepening Search:IDS)

定义:不断地增大深度限制,不断执行深度受限搜索。当深度界限达到d,即最浅的目标结点所在深度时,就能找到目标。
性能:

  • 完备性:分支引子b有限时完备
  • 最优性:路径代价是节点深度的非递减函数时最优
  • 空间复杂度:O(bd)
    d: the depth of the shallowest goal node

问题:当深度为3时,有多少个结点被生成?

双向搜索(Bidirectional search)

定义:同时运行两个搜索,一个从初始状态向前搜索,另一个从目标状态向后搜索,目标检测是检查两个方向的边缘结点集是否相交,如果交集不为空就找到了解。
理由是b(d/2)+b(d/2)要比b^d小很多。
性能:

  • 完备性:分支引子有限时完备
  • 最优性:不一定是最优的
  • 时空复杂度:O(b^(d/2))

难点:如何向后搜索,部分问题可以向后搜索,但有些问题向后搜索会使得分子引子很大。

有信息的搜索策略(启发式搜索)

有信息搜索:使用问题本身的定义之外的特定知识进行搜索
评估函数f(n):代价估计
最佳优先搜索的图搜索的实现与一直代价搜索类似,不过最佳优先是根据f值而不是g值进行优先级队列排队的
启发式函数(heuristic function):h(n) = 结点n到目标结点的最小代价路径的代价估计值。若n是目标结点,则h(n)=0

  • f(n):经过结点n的最小代价解的估计代价(有可能略小于真实代价)
  • g(n):到达此结点已经花费的真实代价
  • h(n):从该结点到目标结点所花代价

Evaluation function f(n)

  • f(n) = g(n) ,Uniform Cost 一直代价搜索
  • f(n) = h(n),Greedy Best-First 贪婪最佳优先搜索
  • f(n) = g(n) + h(n),A*搜索

贪婪最佳优先搜索

定义:在每一步扩展时,都试图扩展离目标最近的结点。只用启发信息,f(n)=h(n)
评价

  • 完备性:不一定能找到解,容易钻进离目标节点近的死胡同。
  • 最优性:不一定是最优的,因为其贪婪地每次都寻找离目标结点最近的结点
  • 时空复杂度:罗马尼亚例子中,直线距离启发式hSLD均很小,O(h),只搜索一条路径;但最坏情况下,O(b^m),m是搜索空间的最大深度

A*搜索:缩小总评估代价

定义:f(n) = g(n) + h(n),每次都选择扩展f(n)最小的结点,在扩展时检测是否到达目标
f(n):经过结点n的最小代价解的估计值
算法与一致代价搜索类似,除了A*使用g+h而不是g
若启发式函数h(n)满足特定条件:A*搜索既是完备的也是最优的

保证最优性的条件:

  • 可采纳性:h(n)是一个可采纳启发式(admissible),从不会高估到达目标的代价。例如直线距离启发式。
  • 一致性(单调性):若对于每一个结点n和通过任一行动a生成的n的每个后继结点n’,从结点n到达目标的代价估计满足:h(n) <= c(n, a, n1) + h(n1),即满足三角不等式,则称h(n)是一致的(Consistent)

A*算法的最优性
A*算法有如下性质:
如果h(n)是可采纳的,那么A*的树搜索版本是最优的;
如果h(n)是一致的,那么么A*的图搜素版本是最优的;

存储受限的启发式搜索

将迭代加深的思想用在启发式算法中。迭代加深A*算法,IDA*算法。
原来的迭代加深算法截断值是搜索深度,现在改为f代价(g+h)。

递归最佳优先搜索(RBFS)

  • 定义:f_limit记录次优路径的f值,如果当前后继节点的f值均大于f_limit就暂缓探索该节点,将其后继节点f的最小值代替该节点的f,转而探索次优节点,并重复以上步骤。
  • 优点:仅用线性内存
  • 缺点:内存使用过少,导致有很多节点被重复扩展,冗余路径也会带来复杂度的指数级增长

内存受限A*(MA*)简化内存受限A*(SMA*)

  • 定义:探索最佳叶子节点直到内存耗尽,丢弃当前f最大节点,并添加新节点。
  • 权衡时空复杂度成为算法探索的最终目的

启发式函数

对于八数码问题的启发式函数有两个常用的,两个启发式函数都没有超过实际的解代价

  • h1=不在位置上的棋子数,最大为8
  • h2=所有棋子到其目标位置的距离合(水平距离+垂直距离),最大值在20左右

启发式的精确度对性能的影响
启发式的设计对有效分支因子的值有影响。
有效分支因子b*: N+1 = 1 + b* + (b*)^2 + … + (b*)^d,所得b*越小算法性能越好;
一般来说启发式使用值更大的函数是更好的。

从松弛问题出发设计可采纳的启发式
松弛问题:减少了行动限制的问题,状态空间是原有状态空间的超图,多了很多边。
意义:一个松弛问题最优解的代价,是原问题的可采纳启发式。
生成:通过去掉经过形式化的原问题的一个或几个条件可以形成松弛问题。
最优松弛问题:可以比较生成的松弛问题的最优解的代价,选择最大的最优解代价的松弛问题。

除此之外还可以通过从子问题除法设计可采纳的启发式和从经验中得到启发式等。

总结

本章介绍了在确定性的、 可观察的、静态的和完全可知的环境下,Agent 可以用来选
择行动的方法。在这种情况下,Agent可以构造行动序列以达到目标;这个过程称为搜索

  1. 在Agent可以开始搜索解之前, 必须对目标和良定义的问题加以形式化。

  2. 一个问题由五个部分组成:初始状态,行动集合,转移模型描述这些行动的结果,目标测试函数和路径代价函数。问题的环境用状态空间表示状态空间中从初始状态到达目标状态的路径是一个解

  3. 搜索算法将状态和行动视为原子:不考虑它们可能包含的内部结构。

  4. 一般的TREE-SEARCH算法会考虑所有的可能来寻找一个解;GRAPH-SEARCH算法则考虑避免冗余路径

  5. 搜索算法的从完备性、最优性、时间复杂度和空间复杂度等方面来评价。复杂度依赖于状态空间中的分支因子b,和最浅的解的深度d。

  6. 无信息搜索方法只能访问问题的定义。 基本算法如下:
    宽度优先搜索总是扩展搜索树中深度最浅的结点。算法是完备的,在单位代价的情况下是最优的,但是具有指数级别的空间复杂度。
    一致代价搜索扩展的是当前路径代价g(n)最小的结点,对于一般性的步骤代价而言算法是最优的。
    深度优先搜索扩展搜索树中深度最深的结点。它既不是完备的也不是最优的,但它具有线性的空间复杂度。
    深度受限搜索在深度优先搜索上加了深度限制。
    迭代加深搜索在不断增加的深度限制上调用深度受限搜索直到找到目标。它是完备的,在单位代价的情况下是最优的, 它的时间复杂度可与宽度优先搜索比较,具备线性的空间复杂度。
    双向搜索可以在很大程度上降低时间复杂度,但是它并不是总是可行的并且可能需要太多的内存空间。

  7. 有信息搜索可能需要访问启发式函数h(n)来估算从n到目标的解代价。

  • 一般的最佳优先搜索算法根据评估函数选择扩展结点。
  • 贪婪最佳优先搜索扩展h(n)最小的结点。它不是最优的,但效率较高。
  • A*搜索扩展 f(n)=g(n)+h(n)最小的结点。如果 h(n)是可采纳的(对于TREE-SEARCH)或是一致的(对于 GRAPH-SEARCH),A*算是完备的也是最优的。它的空间复杂度依然很高。
  • RBFS(递归最佳优先) 和SMA*(简单内存受限A*)是鲁棒的、最优的搜索算法,它们使用有限的内存;只要时间充足,它们能求解 A*算法因为内存不足不能求解的问题。
  1. 启发式搜索算法的性能取决于启发式函数的质量。好的启发式有时可以通过松动间
    题的定义来构造,将子问题的解代价记录在模式数据库中,或者通过对问题类的经验学习得到

9.以下结论成立:
a. When all step costs are equal, g(n) ∝ depth(n)(正比 ), so uniform-cost search reproduces breadth-first search.
(depth(n):d(n),即结点深度)
b. Breadth-first search is best-first search with f (n) = depth(n); depth-first search is best-first search with f (n) = −depth(n); uniform-cost search is best-first search with f (n) = g(n).
c. Uniform-cost search is A ∗ search with h(n) = 0.

(1)当每一步的代价都相等,且到达此结点已经花费的真实代价g(n)正比于结点深度d(n),则宽度优先搜索是一致代价搜索的特殊情况;
(2)当f(n)=d(n)时,宽度优先搜索是最佳优先搜索的一种特殊情况;
(3)当f(n)=-d(n)时,深度优先搜索是最佳优先搜索的一种特殊情况;
(4)当f(n)=g(n)时,一致代价搜索就是最佳优先搜索;
(5)当h(n)=0时,一致代价搜索就是A*算法;

资源分享

实验代码下载:
https://github.com/yyl424525/AI_Homework
人工智能-一种现代方法中文第三版pdf、课件、作业及解答、课后习题答案、实验代码和报告、历年考博题下载:https://download.csdn.net/download/yyl424525/11310392

Guess you like

Origin blog.csdn.net/yyl424525/article/details/95307832