From 7f1333ccf89c715933ead72e31233510c6f4d146 Mon Sep 17 00:00:00 2001 From: xoto10 Date: Wed, 1 Jun 2022 01:20:27 +0100 Subject: [PATCH] Blend nnue complexity with classical. Following mstembera's test of the complexity value derived from nnue values, this change blends that idea with the old complexity calculation. STC 10+0.1: LLR: 2.95 (-2.94,2.94) <0.00,2.50> Total: 42320 W: 11436 L: 11148 D: 19736 Ptnml(0-2): 209, 4585, 11263, 4915, 188 https://tests.stockfishchess.org/tests/live_elo/6295c9239c8c2fcb2bad7fd9 LTC 60+0.6: LLR: 2.98 (-2.94,2.94) <0.50,3.00> Total: 34600 W: 9393 L: 9125 D: 16082 Ptnml(0-2): 32, 3323, 10319, 3597, 29 https://tests.stockfishchess.org/tests/view/6295fd5d9c8c2fcb2bad88cf closes https://github.com/official-stockfish/Stockfish/pull/4046 Bench 6078140 --- src/evaluate.cpp | 11 ++++++----- src/evaluate.h | 2 +- src/nnue/evaluate_nnue.cpp | 7 +++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 9ed9e8e3..415c18c5 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -1099,15 +1099,16 @@ Value Eval::evaluate(const Position& pos) { // If result of a classical evaluation is much lower than threshold fall back to NNUE if (useNNUE && !useClassical) { - Value nnue = NNUE::evaluate(pos, true); // NNUE - int scale = 1080 + 110 * pos.non_pawn_material() / 5120; + int complexity; + int scale = 1048 + 109 * pos.non_pawn_material() / 5120; Color stm = pos.side_to_move(); Value optimism = pos.this_thread()->optimism[stm]; Value psq = (stm == WHITE ? 1 : -1) * eg_value(pos.psq_score()); - int complexity = (278 * abs(nnue - psq)) / 256; + Value nnue = NNUE::evaluate(pos, true, &complexity); // NNUE - optimism = optimism * (251 + complexity) / 256; - v = (nnue * scale + optimism * (scale - 852)) / 1024; + complexity = (137 * complexity + 137 * abs(nnue - psq)) / 256; + optimism = optimism * (255 + complexity) / 256; + v = (nnue * scale + optimism * (scale - 848)) / 1024; if (pos.is_chess960()) v += fix_FRC(pos); diff --git a/src/evaluate.h b/src/evaluate.h index f67961a9..e79eaea3 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -44,7 +44,7 @@ namespace Eval { namespace NNUE { std::string trace(Position& pos); - Value evaluate(const Position& pos, bool adjusted = false); + Value evaluate(const Position& pos, bool adjusted = false, int* complexity = nullptr); void init(); void verify(); diff --git a/src/nnue/evaluate_nnue.cpp b/src/nnue/evaluate_nnue.cpp index 9ee599f4..eb6ad71f 100644 --- a/src/nnue/evaluate_nnue.cpp +++ b/src/nnue/evaluate_nnue.cpp @@ -137,7 +137,7 @@ namespace Stockfish::Eval::NNUE { } // Evaluation function. Perform differential calculation. - Value evaluate(const Position& pos, bool adjusted) { + Value evaluate(const Position& pos, bool adjusted, int* complexity) { // We manually align the arrays on the stack because with gcc < 9.3 // overaligning stack variables with alignas() doesn't work correctly. @@ -161,9 +161,12 @@ namespace Stockfish::Eval::NNUE { const auto psqt = featureTransformer->transform(pos, transformedFeatures, bucket); const auto positional = network[bucket]->propagate(transformedFeatures); + if (complexity) + *complexity = abs(psqt - positional) / OutputScale; + // Give more value to positional evaluation when adjusted flag is set if (adjusted) - return static_cast(((128 - delta) * psqt + (128 + delta) * positional) / 128 / OutputScale); + return static_cast(((128 - delta) * psqt + (128 + delta) * positional) / (128 * OutputScale)); else return static_cast((psqt + positional) / OutputScale); } -- 2.39.2