From d6b6360ff5dcdffa141f50d0a81d0be7c6324c71 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ste=CC=81phane=20Nicolet?= Date: Sun, 9 Oct 2022 00:27:26 +0200 Subject: [PATCH] Tweak the formula for NNUE complexity MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Joint work by Ofek Shochat and Stéphane Nicolet. passed STC: LLR: 2.95 (-2.94,2.94) <0.00,2.00> Total: 93288 W: 24996 L: 24601 D: 43691 Ptnml(0-2): 371, 10263, 24989, 10642, 379 https://tests.stockfishchess.org/tests/view/63448f4f4bc7650f07541987 passed LTC: LLR: 2.94 (-2.94,2.94) <0.50,2.50> Total: 84168 W: 22771 L: 22377 D: 39020 Ptnml(0-2): 47, 8181, 25234, 8575, 47 https://tests.stockfishchess.org/tests/view/6345186d4bc7650f07542fbd ================ It seems there are two effects with this patch: effect A : If Stockfish is winning at root, we have optimism > 0 for all leaves in the search tree where Stockfish is to move. There, if (psq - nnue) > 0 (ie if the advantage is more materialistic than positional), then the product D = optimism * (psq - nnue) will be positive, nnueComplexity will increase, and the eval will increase from SF point of view. So the effect A is that if Stockfish is winning at root, she will slightly favor in the search tree (in other words, search more) the positions where she can convert her advantage via materialist means. effect B : If Stockfish is losing at root, we have optimism > 0 for all leaves in the search tree where the opponent is to move. There, if (psq - nnue) < 0 (ie if the opponent advantage is more positional than materialistic), then the product D = optimism * (psq-nnue) will be negative, nnueComplexity will decrease, and the eval will decrease from the opponent point of view. So the effect B is that Stockfish will slightly favor in the search tree (search more) the branches where she can defend by slowly reducing the opponent positional advantage. ================= closes https://github.com/official-stockfish/Stockfish/pull/4195 bench: 4673898 --- src/evaluate.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 85700bcc..d5844593 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -1051,25 +1051,33 @@ make_v: Value Eval::evaluate(const Position& pos, int* complexity) { Value v; - Color stm = pos.side_to_move(); Value psq = pos.psq_eg_stm(); // We use the much less accurate but faster Classical eval when the NNUE // option is set to false. Otherwise we use the NNUE eval unless the - // PSQ advantage is decisive and several pieces remain (~3 Elo) + // PSQ advantage is decisive and several pieces remain. (~3 Elo) bool useClassical = !useNNUE || (pos.count() > 7 && abs(psq) > 1760); + if (useClassical) v = Evaluation(pos).value(); else { int nnueComplexity; int scale = 1064 + 106 * pos.non_pawn_material() / 5120; + + Color stm = pos.side_to_move(); Value optimism = pos.this_thread()->optimism[stm]; Value nnue = NNUE::evaluate(pos, true, &nnueComplexity); + // Blend nnue complexity with (semi)classical complexity - nnueComplexity = (104 * nnueComplexity + 131 * abs(nnue - psq)) / 256; - if (complexity) // Return hybrid NNUE complexity to caller + nnueComplexity = ( 416 * nnueComplexity + + 424 * abs(psq - nnue) + + (optimism > 0 ? int(optimism) * int(psq - nnue) : 0) + ) / 1024; + + // Return hybrid NNUE complexity to caller + if (complexity) *complexity = nnueComplexity; optimism = optimism * (269 + nnueComplexity) / 256; -- 2.39.2