Skip to content

Commit

Permalink
Tweak nnue scaling to keep more material
Browse files Browse the repository at this point in the history
Current master uses a constant scale factor of 5/4 = 1.25 for the output
of the NNUE network, for compatibility with search and classical evaluation.
We modify this scale factor to make it dependent on the phase of the game,
going from about 1.5 in the opening to 1.0 for pure pawn endgames.

This helps Stockfish to avoid exchanges of pieces (heavy pieces in particular)
when she has the advantage, keeping more material on the board when attacking.

Passed STC:
LLR: 2.95 (-2.94,2.94) {-0.25,1.25}
Total: 14744 W: 1771 L: 1599 D: 11374
Ptnml(0-2): 87, 1184, 4664, 1344, 93
https://tests.stockfishchess.org/tests/view/5f6fb0a63b22d6afa506904f

Passed LTC:
LLR: 2.95 (-2.94,2.94) {0.25,1.25}
Total: 8912 W: 512 L: 393 D: 8007
Ptnml(0-2): 7, 344, 3637, 459, 9
https://tests.stockfishchess.org/tests/view/5f6fcf533b22d6afa5069066

closes official-stockfish#3154

Bench: 3943952
  • Loading branch information
snicolet authored and vondele committed Sep 27, 2020
1 parent f66c381 commit 1dbd2a1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,10 @@ Value Eval::evaluate(const Position& pos) {
else
{
// Scale and shift NNUE for compatibility with search and classical evaluation
auto adjusted_NNUE = [&](){ return NNUE::evaluate(pos) * 5 / 4 + Tempo; };
auto adjusted_NNUE = [&](){
int mat = pos.non_pawn_material();
return NNUE::evaluate(pos) * (1024 + mat / 32) / 1024 + Tempo;
};

// If there is PSQ imbalance use classical eval, with small probability if it is small
Value psq = Value(abs(eg_value(pos.psq_score())));
Expand All @@ -1037,7 +1040,7 @@ Value Eval::evaluate(const Position& pos) {
// small probability if the classical eval is less than the threshold.
if ( largePsq
&& (abs(v) * 16 < NNUEThreshold2 * r50
|| ( pos.opposite_bishops()
|| ( pos.opposite_bishops()
&& abs(v) * 16 < (NNUEThreshold1 + pos.non_pawn_material() / 64) * r50
&& !(pos.this_thread()->nodes & 0xB))))
v = adjusted_NNUE();
Expand Down

0 comments on commit 1dbd2a1

Please sign in to comment.