Transposition Table

From Chessprogramming wiki
Jump to:navigation,search

Home *Search * Transposition Table

ATransposition Table,
first used inGreenblatt's programMac Hack VI[1][2][3], is a database that stores results of previously performed searches. It is a way to greatly reduce the search space of achess tree with little negative impact. Chess programs, during theirbrute-force search, encounter the samepositions again and again, but from different sequences ofmoves, which is called atransposition. Transposition (andrefutation) tables are techniques derived fromdynamic programming[4], a term coined byRichard E. Bellman in the 1950s, when programming meant planning and dynamic programming was conceived to optimally plan multistage processes[5] .

Contents

How it works

When the search encounters atransposition, it is beneficial to 'remember' what was determined the last time the position was examined, rather than redoing the entire search again. For this reason, chess programs have a transposition table, which is a largehash table storing information about positions previously searched, how deeply they were searched, and what we concluded about them. Even if thedepth (draft) of the related transposition table entry is not big enough, or does not contain the right bound for a cutoff, abest (or good enough) move from a previous search can improvemove ordering, and save search time. This is especially true inside aniterative deepening framework, where one gains valuable table hits from previous iterations.

Hash functions

Hash functions convert chess positions into an almost unique, scalar signature, allowing fast index calculation as well as space-saving verification of stored positions.

Both, the more common Zobrist hashing as well BCH hashing use fast hash functions, to provide hash keys or signatures as a kind ofGödel number of chess positions, today typically64-bit wide. They areupdated incrementally duringmake andunmake move by either own-inverseexclusive or or by addition versus subtraction.

Address Calculation

The index is not based on the entire hash key because this is usually a 64-bit number, and with current hardware limitations, no hash table can be large enough to accommodate it. Therefore calculating the address or index requires a signaturemodulo a number of entries, for the power of two sized tables, the lower part of the hash key, masked by an 'and'-instruction accordantly.

What Information is Stored

Typically, the following information is stored as determined by thesearch[6] :

PV-Node, Score isExact
All-Node, Score isUpper Bound
Cut-Node, Score isLower Bound
  • Age is used to determine when to overwrite entries from searching previous positions during thegame of chess

Table Entry Types

In analpha-beta search, we usually do not find the exact value of a position. But we are happy to know that the value is either too low or too high for us to be concerned with searching any further. If we have the exact value, of course, we store that in the transposition table. But if the value of our position is either high enough to set the lower bound, or low enough to set the upper bound, it is good to store that information also. So each entry in the transposition table is identified with thetype of node, often referred to asexact,lower- orupper bound.

Using the Transposition Table

Transposition Tables are an integral part of an engine's search. It is used in both search heuristics and move ordering.

Transposition Table Cutoffs

Depth, value, and bound information can be used to produce cutoffs and reduce redudant computation. In more advanced engines transposition table cutoffs are not performed on PV-Nodes.

A cutoff can be performed when the depth of entry is greater (or equal) to the depth of the current node and one of the following criteria is satisfied:

Hash Move

Main Article:Hash Move

Best move/Refutation move information from the transposition table is the most important part of move ordering. They are first in order and can be searched before other moves are generated. When the hash move fails high, generating other moves is not necessary. InStockfish, 75% of cutoffs produced in a position with hash moves are caused by the hash move.

Singular Extensions

Restricted SE is only attempted on a position where a TT entry exist, they entry has a valid TT move, the entry has a high enough depth, and the entry has exact or lowerbound bounds.

Collisions

Thesurjective mapping from chess positions to a signature and an, even more, denser index range impliescollisions, different positions share the same entries, for two different reasons, hopefully, rare ambiguous keys (type-1 errors), or regularly ambiguous indices (type-2 errors).

Cardinalities

The typical cardinalities of positions and signatures inside the search reflect the likelihood of collisions:

Cardinalities of positions and signatures #
Upper bound for the number of reachablechess positions[8] 1e46
Different64 bit keys 1.84e19
Some number of distinct nodes searched per game,
assuming 100 moves times 1e8 nodes per move
1e10
Different32 bit keys 4.29e9
Some arbitrary table size in the number of entries 1e8

Index Collisions

Index collisions or type-2 errors[9][10], where different hash keys index same entries, happen regularly. They require detection, realized by storing the signature as part of the hash entry, to check whether a stored entry matches the position while probing. Especially with the power of two entry tables, many programmers choose to trade-off space for accuracy and only store that part of the hash key not already considered as an index, or even less.

Key Collisions

Key collisions or type-1 errors are inherent in using signatures with far fewer bits than required to encode all reachable chess positions. A key collision occurs when two different positions map the same hash key or signature[11][12]. When storing only a partial key, the chance of a collision greatly increases. To accept only hits wherestored moves arepseudo-legal decreases the chance of type-1 errors. On his computer chess page[13],Ken Regan broached on chess engine bugs, anomalies and hash collisions, and mentions aShredder 9.1 game where a key collision might have caused a strange move[14][15].

Bits Required

During theWCCC 1989 WorkshopNew Directions in Game-Tree Search,James Gillogly, author ofTech, discussed transposition table collisions[16] . He produced the following table using theBirthday Paradox, where the columns are the number of positions stored and the rows are the probability of collision. The entries are the number of bits of combined address and check hash required to reduce the probability of collision to the desired amount.

Number of Positions: 105 106 107 108 109 1010
Collision
probability:
.01 39 46 53 59 66 73
.001 43 49 56 63 69 76
.0001 46 53 59 66 73 79
.00001 49 56 63 69 76 83

During the discussion,David Slate andKen Thompson pointed out that the Birthday Paradox does not apply to most programs, since the hash table will fill up and not all previous positions will be in the table; thus these figures must be regarded as an upper bound on the number of bits required for safety[17]. The dangers of transposition table collisions were further studied byRobert Hyatt andAnthony Cozzie as published in their 2005 paperHash Collisions Effect[18]. They gave a surprising answer to the question “Is it really worth all the effort to absolutely minimize signature collisions?”, and concluded that 64-bit signatures are more than sufficient.

Replacement Strategies

Because there are a limited number of entries in a transposition table, and because in modern chess programs, they can fill up very quickly, it is necessary to have a scheme by which the program can decide which entries would be most valuable to keep, i.e. a replacement scheme[19] . Replacement schemes are used to solve an index collision when a program attempts to store a position in a table slot that already has a different entry in it. There are two opposing considerations to replacement schemes:

  • Entries that were searched to a high depth save more work per table hit than those searched to a low depth.
  • Entries that are closer to the leaves of the tree are more likely to be searched multiple times, making the table hits of them higher. Also, entries that were searched recently are more likely to be searched again.
  • Most well-performing replacement strategies use a mix of these considerations.

Always Replace

This replacement strategy is very simple, placing all emphasis on the second consideration. Any old entries are replaced immediately when a new entry is stored[20].

Priority by Searched Nodes Count

This replacement strategy uses the number of nodes searched spent to obtain an entry, as replacement priority.

Priority by Move Ordering Position

This replacement strategy uses the position of entry move inmove ordering list as replacement priority. The main idea is that if the best move was not considered as a good cut-off candidate by the move-ordering algorithm, storing it in TT should provide better help for the search.

Depth-Preferred

This replacement strategy puts all emphasis on the first consideration. The only criterion in deciding whether to overwrite an entry is whether the new entry has a higher depth than the old entry.

Two-tier System

This strategy, devised byKen Thompson andJoe Condon[21] , uses two tables, side by side. For each table slot, there is a depth-preferred and an always-replace entry[22] .

Bucket Systems

This family of strategies is similar to the two-tier system, but any number of tiers (known as "buckets") can be used (typically the number is based on the size of a cache line). The difference is that the buckets are not specific to one consideration, but rather the new entry overwrites the entry in the bucket with the lowest depth[23] .

Aging

Aging considers searches for different chess positions during gameplay. While early implementations and programs relying onroot pre-processing to guide search andevaluation were obligated to clear the hash table between root positions, most todays programs do not, profit from entries of previous searches. Nevertheless, to avoid persistence of old entries which may no longer occur from the current root, aging is used to likely replace those entries by new ones, even if their draft and flags would otherwise protect them. To implement aging, one often stores and compares the currenthalfmove clock as age, likely modulo some power two constant, depending on how many bits are used to store it inside an entry[24][25].

TT and Parallel Search

Aglobal transposition table, shared by multiplethreads orprocesses is essential for effectiveparallel search algorithms on modern multi-core CPUs, and might be accessedlock-less, as proposed byRobert Hyatt andTim Mann[26] .

Further Hash Tables

Besides storing the best move and scores of the search trees, furtherhash tables are often used to cache other features.

Maximizing Transpositions

See also

Publications

1967 ...

1970 ...

1980 ...

1990 ...

2000 ...

2010 ...

Forum Posts

1990 ...

1995 ...

1996

1997

Re: Hash functions for use with a transition table byRonald de Man,rgcc, March 7, 1997 »BCH Hashing

1998

Re: Using too-shallow mate scores from the hash table byDavid Eppstein,CCC, July 06, 1998
Re: Using too-shallow mate scores from the hash table byDon Dailey,CCC, July 07, 1998

1999

2000 ...

2001

2002

2003

2004

2005 ...

Re: Mate scores in the hash table byBruce Moreland,Winboard Forum, September 04, 2005
Re: Mate scores in the hash table byJosué Forte,Winboard Forum, September 04, 2005

2007

2008

2009

2010 ...

2011

2012

2013

2014

2015 ...

2016

2017

2018

2019

2020 ...

2021

2022

2023

2024

External Links

References

  1. Richard Greenblatt,Donald Eastlake,Stephen D. Crocker (1967).The Greenblatt Chess Program. Proceedings of the AfiPs Fall Joint Computer Conference, Vol. 31, pp. 801-810. Reprinted (1988) inComputer Chess Compendium,pdf fromThe Computer History Museum or aspdf or ps fromDSpace atMIT
  2. Albert Zobrist (1970).A New Hashing Method with Application for Game Playing. Technical Report #88, Computer Science Department, The University of Wisconsin, Madison, WI, USA. Reprinted (1990) inICCA Journal, Vol. 13, No. 2,pdf
  3. Re: Berliner vs. Botvinnik Some interesting points, post 8 byBradley C. Kuszmaul,rgcc, November 06, 1996 » Transposition Table inMac Hack
  4. Algorithms that use dynamic programming from Wikipedia
  5. Sanjoy Dasgupta,Christos H. Papadimitriou,Umesh Vazirani (2006).Algorithms.McGraw-Hill, ISBN: 978-0073523408,amazon, Chapter 6, Dynamic programming
  6. Dennis Breuker,Jos Uiterwijk,Jaap van den Herik (1997).Information in Transposition Tables.Advances in Computer Chess 8
  7. MTD(f)- and somePVS-implementations store distinctupper andlower bound scores, rather than one score with flags
  8. Shirish Chinchalkar (1996).An Upper Bound for the Number of Reachable Positions.ICCA Journal, Vol. 19, No. 3
  9. Albert Zobrist (1970).A New Hashing Method with Application for Game Playing. Technical Report #88, Computer Science Department, The University of Wisconsin, Madison, WI, USA. Reprinted (1990) inICCA Journal, Vol. 13, No. 2,pdf
  10. Collision probability byDennis Breuker,rgcc, April 15, 1996
  11. TT Key Collisions, Workarounds? byClemens Pruell,CCC, August 16, 2011
  12. how to measure frequency of hash collisions byDaniel Shawul,CCC, June 16, 2012
  13. Computer Chess - Hash Collisions in Chess Engines, and What They May Mean... byKenneth W. Regan
  14. Pablo Lafuente vs Shredder (Computer) (2005) fromchessgames.com
  15. Current tournaments – Sanjin, Biel, Argentina, Israel,ChessBase News, July 21, 2005
  16. James Gillogly (1989).Transposition Table Collisions.Workshop on New Directions in Game-Tree Search
  17. James Gillogly (1989).New Directions in Game-Tree Search - First Workshop Session.ICCA Journal, Vol. 12, No. 2
  18. Robert Hyatt,Anthony Cozzie (2005).The Effect of Hash Signature Collisions in a Chess Program.ICGA Journal, Vol. 28, No. 3
  19. Dennis Breuker,Jos Uiterwijk,Jaap van den Herik (1994).Replacement Schemes for Transposition Tables.ICCA Journal, Vol. 17, No. 4
  20. Re: Transposition table usage in quiescent search? byRobert Hyatt,CCC, March 06, 2013
  21. Joe Condon,Ken Thompson (1983).BELLE Chess Hardware.Advances in Computer Chess 3
  22. Dennis Breuker,Jos Uiterwijk,Jaap van den Herik (1996).Replacement Schemes and Two-Level Tables.ICCA Journal, Vol. 19, No. 3
  23. Don Beal,Martin C. Smith (1996).Multiple Probes of Transposition Tables.ICCA Journal, Vol. 19, No. 4
  24. Transposition Age Tutorial byDennis Sceviour,CCC, January 25, 2016
  25. Hashtable aging byMartin Fierz,CCC, April 25, 2016
  26. Robert Hyatt andTim Mann (2002).A lock-less transposition table implementation for parallel search chess engines.ICGA Journal, Vol. 25, No. 1
  27. Re: About random numbers and hashing bySven Reichard,CCC, December 05, 2001
  28. Transposition-driven scheduling - Wikipedia
  29. Transposition driven scheduling byDaniel Shawul,CCC, April 04, 2013
  30. Re. Fail low after fail high byMarcel van Kervinck,CCC, April 05, 2015 »Fail-Low,Fail-High
  31. John Romein,Henri Bal,Jonathan Schaeffer,Aske Plaat (2002).A Performance Analysis of Transposition-Table-Driven Scheduling in Distributed Search. IEEE Transactions on Parallel and Distributed Systems, Vol. 13, No. 5, pp. 447–459.pdf
  32. David E. Welsh,Boris Baczynskyj (1985).Computer Chess II. William C Brown Publications, ISBN-13: 978-0697099112

Up one Level

Retrieved from "https://www.chessprogramming.org/index.php?title=Transposition_Table&oldid=27124"
Categories: