Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capping stat bonus at 2000 #3731

Closed

Conversation

snicolet
Copy link
Member

@snicolet snicolet commented Oct 5, 2021

This patch updates the stat_bonus() function (used in the history tables to
help move ordering), keeping the same quadratic for small depths but changing
the values for depth >= 9:

The old bonus formula was increasing from zero at depth 1 to 4100 at depth 14,
then used the strange, small value of 73 for all depths >= 15.

The new bonus formula increases from 0 at depth 1 to 2000 at depth 8, then
keep 2000 for all depths >= 8.

passed STC:
LLR: 2.94 (-2.94,2.94) <-0.50,2.50>
Total: 169624 W: 42875 L: 42454 D: 84295
Ptnml(0-2): 585, 19340, 44557, 19729, 601
https://tests.stockfishchess.org/tests/view/615bd69e9d256038a969b97c

passed LTC:
LLR: 3.07 (-2.94,2.94) <0.50,3.50>
Total: 37336 W: 9456 L: 9191 D: 18689
Ptnml(0-2): 20, 3810, 10747, 4067, 24
https://tests.stockfishchess.org/tests/view/615c75d99d256038a969b9b2

closes #3731

Bench: 6261865

snicolet added a commit to snicolet/Stockfish that referenced this pull request Oct 5, 2021
This patch updates the stat_bonus() function (used in the history tables to
help move ordering), keeping the same quadratic for small depths but changing
the values for depth >= 9:

The old bonus formula was increasing from zero at depth 1 to 4100 at depth 14,
then used the strange, small value of 73 for all depths >= 15.

The new bonus formula increases from 0 at depth 1 to 2000 at depth 8, then
keep 2000 for all depths >= 8.

passed STC:
LLR: 2.94 (-2.94,2.94) <-0.50,2.50>
Total: 169624 W: 42875 L: 42454 D: 84295
Ptnml(0-2): 585, 19340, 44557, 19729, 601
https://tests.stockfishchess.org/tests/view/615bd69e9d256038a969b97c

passed LTC:
LLR: 3.07 (-2.94,2.94) <0.50,3.50>
Total: 37336 W: 9456 L: 9191 D: 18689
Ptnml(0-2): 20, 3810, 10747, 4067, 24
https://tests.stockfishchess.org/tests/view/615c75d99d256038a969b9b2

closes official-stockfish/Stockfish#3731

Bench: 6261865
@mstembera
Copy link
Contributor

Congrats! One multiply could be removed with

 return std::min((6  * d + 229) * d - 215 , 2000);

@Vizvezdenec
Copy link
Contributor

Congrats!
I propose testless removal of this https://github.com/official-stockfish/Stockfish/blob/master/src/search.cpp#L1711
and making it bonus1 : stat_bonus(depth) instead - since bonus1 now is always >= stat_bonus(depth) with this patch.

@silversolver1
Copy link

silversolver1 commented Oct 6, 2021

isn't this about equivalent to:

  int stat_bonus(Depth d) {
    return d > 7 ? 2000 : 6 * d * d + 229 * d - 215;
  }

as value of d=8 is 2001 (and all values larger will be pushed to 2000 anyways). no real point in doing the calculations and the comparison every time (only necessary for values 0 to 7 or 1 to 7)

or to use mstembera's calculation which is indeed a bit shorter

  int stat_bonus(Depth d) {
    return d > 7 ? 2000 : (6 * d + 229) * d - 215;
  }

edit: d > 8 should maintain bench (untested but basically means depth 9 or above would be automatic 2000 without having to obtain a number for comparison while depth 1 to 8 would be calculated as normal, including d = 8, 2001)

@snicolet
Copy link
Member Author

snicolet commented Oct 6, 2021

@vondele I can squash the change proposed by @Vizvezdenec in the PR, if you wish. That is, instead of

bonus2 = bestValue > beta + PawnValueMg ? bonus1                                 // larger bonus
                                        : std::min(bonus1, stat_bonus(depth));   // smaller bonus

we would use this expression, which would keep the same bench:

bonus2 = bestValue > beta + PawnValueMg ? bonus1               // larger bonus
                                        : stat_bonus(depth);   // smaller bonus

@vondele
Copy link
Member

vondele commented Oct 6, 2021

@snicolet yes please squash the change. I won't be able to commit patches before tonight.

This patch updates the stat_bonus() function (used in the history tables to
help move ordering), keeping the same quadratic for small depths but changing
the values for depth >= 9:

The old bonus formula was increasing from zero at depth 1 to 4100 at depth 14,
then used the strange, small value of 73 for all depths >= 15.

The new bonus formula increases from 0 at depth 1 to 2000 at depth 8, then
keep 2000 for all depths >= 8.

passed STC:
LLR: 2.94 (-2.94,2.94) <-0.50,2.50>
Total: 169624 W: 42875 L: 42454 D: 84295
Ptnml(0-2): 585, 19340, 44557, 19729, 601
https://tests.stockfishchess.org/tests/view/615bd69e9d256038a969b97c

passed LTC:
LLR: 3.07 (-2.94,2.94) <0.50,3.50>
Total: 37336 W: 9456 L: 9191 D: 18689
Ptnml(0-2): 20, 3810, 10747, 4067, 24
https://tests.stockfishchess.org/tests/view/615c75d99d256038a969b9b2

closes official-stockfish/Stockfish#3731

Bench: 6261865
@snicolet
Copy link
Member Author

snicolet commented Oct 6, 2021

@silversolver1

Thanks for the suggestion. I have measured the speed of these two versions (running two benches at depth 20 in parallel):

version A   :   return std::min((6 * d + 229) * d - 215 , 2000);
version B   :   return d > 7 ? 2000 : (6 * d + 229) * d - 215;

Version B is 0.3% slower than version A.

I suspect that in both cases the time is dominated by the test, instead of the polynomial evaluation. However version A may use an optimized implementation for std::min while version B cannot avoid the branch.

@snicolet snicolet closed this in 54a9899 Oct 6, 2021
proukornew pushed a commit to proukornew/Stockfish that referenced this pull request Oct 8, 2021
This patch updates the stat_bonus() function (used in the history tables to
help move ordering), keeping the same quadratic for small depths but changing
the values for depth >= 9:

The old bonus formula was increasing from zero at depth 1 to 4100 at depth 14,
then used the strange, small value of 73 for all depths >= 15.

The new bonus formula increases from 0 at depth 1 to 2000 at depth 8, then
keeps 2000 for all depths >= 8.

passed STC:
LLR: 2.94 (-2.94,2.94) <-0.50,2.50>
Total: 169624 W: 42875 L: 42454 D: 84295
Ptnml(0-2): 585, 19340, 44557, 19729, 601
https://tests.stockfishchess.org/tests/view/615bd69e9d256038a969b97c

passed LTC:
LLR: 3.07 (-2.94,2.94) <0.50,3.50>
Total: 37336 W: 9456 L: 9191 D: 18689
Ptnml(0-2): 20, 3810, 10747, 4067, 24
https://tests.stockfishchess.org/tests/view/615c75d99d256038a969b9b2

closes official-stockfish#3731

Bench: 6261865
@snicolet snicolet added the to be merged Will be merged shortly label Oct 9, 2021
pb00068 pushed a commit to pb00068/Stockfish that referenced this pull request Dec 15, 2021
Seems that after pull official-stockfish#3731 (Capping stat bonus at 2000) this
heuristic is no more useful.

STC:
https://tests.stockfishchess.org/tests/view/61b8d0e2dffbe89a35815444
LLR: 2.94 (-2.94,2.94) <-2.25,0.25>
Total: 30672 W: 7974 L: 7812 D: 14886
Ptnml(0-2): 106, 3436, 8072, 3634, 88

LTC:
https://tests.stockfishchess.org/tests/view/61b8e90cdffbe89a35815a67
LLR: 2.94 (-2.94,2.94) <-2.25,0.25>
Total: 42448 W: 10884 L: 10751 D: 20813
Ptnml(0-2): 23, 4394, 12267, 4507, 33

bench: 4801890
pb00068 pushed a commit to pb00068/Stockfish that referenced this pull request Dec 15, 2021
Seems that after pull official-stockfish#3731 (Capping stat bonus at 2000) this
heuristic is no more useful.

STC:
https://tests.stockfishchess.org/tests/view/61b8d0e2dffbe89a35815444
LLR: 2.94 (-2.94,2.94) <-2.25,0.25>
Total: 30672 W: 7974 L: 7812 D: 14886
Ptnml(0-2): 106, 3436, 8072, 3634, 88

LTC:
https://tests.stockfishchess.org/tests/view/61b8e90cdffbe89a35815a67
LLR: 2.94 (-2.94,2.94) <-2.25,0.25>
Total: 42448 W: 10884 L: 10751 D: 20813
Ptnml(0-2): 23, 4394, 12267, 4507, 33

bench: 4801890
@pb00068 pb00068 mentioned this pull request Dec 15, 2021
snicolet pushed a commit that referenced this pull request Dec 17, 2021
Seems that after pull request #3731 (Capping stat bonus at 2000) this
heuristic is no longer useful.

STC:
https://tests.stockfishchess.org/tests/view/61b8d0e2dffbe89a35815444
LLR: 2.94 (-2.94,2.94) <-2.25,0.25>
Total: 30672 W: 7974 L: 7812 D: 14886
Ptnml(0-2): 106, 3436, 8072, 3634, 88

LTC:
https://tests.stockfishchess.org/tests/view/61b8e90cdffbe89a35815a67
LLR: 2.94 (-2.94,2.94) <-2.25,0.25>
Total: 42448 W: 10884 L: 10751 D: 20813
Ptnml(0-2): 23, 4394, 12267, 4507, 33

closes #3853

bench: 4474950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to be merged Will be merged shortly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants