Beam Search Introduction

Source: Internet
Author: User
Tags hash
Overview

The traditional breadth-first strategy can find the optimal path, but in the case of very large search space, the memory consumption is exponentially increasing, it is easy to cause memory overflow, so the algorithm of beam search is proposed.
Beam search attempts to optimize (similar to pruning) the searching space on a breadth-first basis to reduce memory consumption. Beam Search Algorithm New Concept in order to achieve the purpose of searching, beam search introduced the concept of heuristic function (H h) to estimate the loss from the current node to the target node.
The heuristic function allows the search algorithm to save only the nodes that reach the target node beam width b b The number of nodes saved by the breadth-first search algorithm for each layer.
You can prevent program memory overflow and speed up your search. The BEAM function is similar to the open list, and the node SET for saving the next round of extensions holds all subsequent nodes in the BEAM and is the input space for the heuristic function. A hash table acts like the close list, which holds all the nodes that have been accessed by the algorithm flow to add the Start node (start) to the beam and hash table to iterate through the beam all subsequent nodes into the set, and empty the beam from set to select b b heuristic function value the optimal node is added to the beam and hash table (there is already a hash table in the node can not be increased) above the process cycle continuous guidance to find the target node or hash table Beam is empty (no solution found) pseudo-code after full or main loop ends

/* Initialization */g = 0;
hash_table = {start};

BEAM = {start};                                   /* Main loop */while (beam≠∅) {//loop until the BEAM contains no nodes SET =∅; The empty set/* Generate the SET nodes */for (each of the BEAM) {for "each success
      or of State) {if (successor = = goal) return G + 1;             SET = set∪{successor};                                  Add successor to SET}} BEAM =∅;

  The empty set g = g + 1; /* Fill the BEAM for the next loop */while ((Set≠∅) and (B > | beam|)) {//set is not empty and the number of nodes in BEAM are less than B State = successor in set with smallest h
    Value                   Set = set \ {state}; The remove state from the SET if (state∉hash_table) {//hash_table if (hash_tabl
      E is full) return∞;   hash_table = hash_table∪{State}; Add state to Hash_table BEAM = beam∪{State};  Add state to BEAM}}}//goal were not found, and BEAM are Empty-beam Search failed to find the goal return∞;
Beam Search Example Description

The sample is a two-line representation of the primary loop execution process.
The first line in two rows shows the nodes (alphabetical order) added to the set
The second line shows the nodes that are added from the set to the beam
After two lines there is a hash table showing its status (hash table is only 7slots, indicating the size of available memory)
Each of the following examples takes a different value for b b and shows only four steps to show the advantages and disadvantages of beam search
Beamsearch Target is a graph that is searched from i-> B.

exmple 1 B = 1, showing the lack of beam search, can not find the solution

Number
LoopSet,beam Hash Table
Beam={i} Hash Table={i}
1 SET={G,J,E,H} Hashtable={i}
1 BEAM={G} Hash Table={i,g}
2 Set={d,g,i} HASHTABLE={I,G}
2 BEAM={D} Hash Table={i,d,g}
3 SET={G} HASHTABLE={I,D,G}
3 beam={} Hash Table={i,d,g}

The beam is empty at this point, causing the search to fail.
So the choice of b b is very important. Exmple 2 b b = 2 search for non-optimal values

Number
LoopSet,beam Hash Table
Beam={i} Hash_table = {, I (null),,,,,}
1 Set={g (i), J (i), E (i), H (i)} Hash_table = {, I (null),,,,,}
1 beam={G (i), J (i)} Hash_table = {, I (null), J (i),,,, G (i)}
2 Set={a (j), D (g), G (J), J (g), E (j), I (g)} Hash_table = {, I (null), J (i),,,, G (i)}
2 Beam={a (J), D (G)} Hash_table = {A (j), I (null), J (i), D (G),,, G (i)}
3 Set={c (a), G (D), J (a)} Hash_table = {A (j), I (null), J (i), D (G),,, G (i)}
3 Beam={c (A)} Hash_table = {A (j), I (NULL), J (i), D (g), C (A), _, G (i)}
4 SET = {B (c) [goal Found-algorithm returns], A (c)} Hash_table = {A (j), I (NULL), J (i), D (g), C (A), _, G (i)}

In this example, beam search has found a path: IJACB, but not the optimal solution (IECB)
show that not every cycle beam can be filled (step 3) Exmple 3 b b = 3, find the optimal value, and the memory does not overflow

Number
LoopSet,beam Hash Table
Beam={i} Hash_table = {, I (null),,,,,}
1 Set={g (i), J (i), E (i), H (i)} Hash_table = {, I (null),,,,,}
1 BEAM = {G (i), J (i), E (i)} Hash_table = {, I (null), J (i),, E (i), _, G (i)}
2 SET = {A (j), C (E), D (g), F (E), G (J), J (E), E (j), H (E), I (e)} Hash_table = {, I (null), J (i),, E (i), _, G (i)}
2 BEAM = {A (J), C (E), D (G)} Hash_table = {A (j), I (null), J (i), C (E), E (i), D (g), G (i)}
3 SET = {B (c) [goal Found-algorithm returns], A (c), C (a), J (a)} Hash_table = {A (j), I (null), J (i), C (E), E (i), D (g), G (i)}

B b=3 Beam Search can find the optimal value, but when B is larger, it causes a free memory overflow (hash table overflow) Exmple 4 b b = 4 memory consumption too much

Number
LoopSet,beam Hash Table
Beam={i} Hash_table = {, I (null),,,,,}
1 Set={g (i), J (i), E (i), H (i)} Hash_table = {, I (null),,,,,}
1 BEAM = {G (i), J (i), E (i), H (i)} Hash_table = {H (i), I (null), J (i),, E (i),, G (i)}
2 SET = {A (j), C (E), D (g), F (E), G (J), J (E), E (h), H (e), I (e)} Hash_table = {H (i), I (null), J (i),, E (i),, G (i)}
2 BEAM = {A (J), C (E), D (G) [Not Enough Memory-algorithm returns]} Hash_table = {H (i), I (null), J (i), A (j), E (i), C (E), G (i)}

The second step caused a memory overflow and the search failed. References

Http://jhave.org/algorithms/graphs/beamsearch/beamsearch.shtml

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.