集束搜索(Beam Search Algorithm )

集束搜索(Beam Search)是一种优化的启发式搜索算法,适用于解决大搜索空间的问题,以减少时间和空间消耗。通过限制每个深度只保留前m个最优节点(m为集束宽度),在保持效率的同时牺牲了完备性和最优性。算法包括使用启发函数、广度优先策略和节点筛选。在不同宽度下,搜索效果和效率有所变化,对于不准确的启发函数和过大的宽度可能导致无法找到最优解或过度消耗内存。
摘要由CSDN通过智能技术生成

看计算机科学中最重要的32个算法,其中有个是集束搜索(又名定向搜索,Beam Search)——最佳优先搜索算法的优化。使用启发式函数评估它检查的每个节点的能力。不过,集束搜索只能在每个深度中发现前m个最符合条件的节点,m是固定数字——集束的宽度。

泛泛的介绍,不是很能理解清楚,于是有百度又google,写篇东西备忘。先贴维基百科的地址:Beam Search

翻译过来就是:

Beam Search(集束搜索)是一种启发式图搜索算法,通常用在图的解空间比较大的情况下,为了减少搜索所占用的空间和时间,在每一步深度扩展的时候,剪掉一些质量比较差的结点,保留下一些质量较高的结点。这样减少了空间消耗,并提高了时间效率。

算法的工作流程如下:

使用广度优先策略建立搜索树,在树的每一层,按照启发代价对节点进行排序,然后仅留下预先确定的个数(Beam Width-集束宽度)的节点,仅这些节点在下一层次继续扩展,其他节点就被剪掉了。

  • 将初始节点插入到list中,
  • 将给节点出堆,如果该节点是目标节点,则算法结束;
  • 否则扩展该节点,取集束宽度的节点入堆。然后到第二步继续循环。
  • 算法结束的条件是找到最优解或者堆为空。

Objectives

  • To show how the Beam Search Algorithm uses a heuristic function and a given beam width in an attempt to simulate the Breadth-First Search in a memory-efficient way.
  • To emphasize the importance of limiting a graph-search's memory consumption when finding solutions to large problem spaces.
  • To demonstrate the strengths and weaknesses of the Beam Search Algorithm.

Preparation

In order to understand this algorithm, you must be familiar with theconcept of a graph as a group of nodes/vertices and edges connectingthese nodes. It is also helpful to understand the how a search treecan be used to show the progress of a graph search. Additionally,knowledge of the Breadth-FirstSearch Algorithm is required because Beam Search is a modificationof this algorithm.

Beam Search Algorithm

Even though the Breadth-First Search Algorithm is guaranteed tofind the shortest path from a start node to a goal node in anunweighted graph, it is infeasible to use this algorithm on largesearch spaces because its memory consumption is exponential. Thiscauses the algorithm run out of main memory before a solution can befound to most large, nontrivial problems. For this reason, Beam Searchwas developed in an attempt to achieve the optimal solution found bythe Breadth-First Search Algorithm without consuming too muchmemory.

In order to accomplish this goal, Beam Search utilizes a heuristicfunction, h, to estimate the cost to reach the goal from a givennode. It also uses a beam width, B, which specifies the numberof nodes that are stored at each level of the Breadth-FirstSearch. Thus, while the Breadth-First Search stores all the frontiernodes (the nodes connected to the closing vertices) in memory, theBeam Search Algorithm only stores the B nodes with the bestheuristic values at each level of the search. The idea is that theheuristic function will allow the algorithm to select nodes that willlead it to the goal node, and the beam width will cause the algorithmto store only these important nodes in memory and avoid running out ofmemory before finding the goal state.

Instead of the open list used by the Breadth-First SearchAlgorithm, the Beam Search Algorithm uses the BEAM to store thenodes that are to be expanded in the next loop of the algorithm. Ahash table is used to store nodes that have been visited, similar tothe closed list used in the Breadth-First Search. Beam Searchinitially adds the starting node to the BEAM and the hashtable. Then, each time through the main loop of the algorithm, BeamSearch adds all of the nodes connected to the nodes in the BEAMto its SET of successor nodes and then adds the B nodes withthe best heuristic values from the SET to the BEAM andthe hash table. Note that a node that is already in the hashtable is not added to the BEAM because a shorter path tothat node has already been found. This process continues until thegoal node is found, the hash table becomes full (indicatingthat the memory available has been exhausted), or the BEAM isempty after the main loop has completed (indicating a dead end in thesearch).

The Beam Search Algorithm is shown by the pseudocode below. Thispseudocode assumes that the Beam Search is used on an unweighted graphso the variable g is used to keep track of the depth of thesearch, which is the cost of reaching a node at that level.

Pseudocode for the Beam Search Algorithm
<span style="font-size:18px;">/*初始化 */
g = 0;//步数
hash_table = { start };//hash表,用于标记所有已经访问过的节点。类似于visited表
BEAM = { start };//BEAM 一个容量受限的not-visited表,也就是在初始化时,需要指定not-visited表的容量


while(BEAM ≠ ∅){// 循环直到BEAM为空,也就是没有需要考察的节点了
  SET = ∅;// 设置集合为空

  for(each state in BEAM){ //对于BEAM中的每个状态state
    for(each successor of 
  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值