From 1a6c22c5114c6ae9f916a69e0446b6c9eb864d72 Mon Sep 17 00:00:00 2001 From: Gahtan Nahdi <155860115+gahtan-syarif@users.noreply.github.com> Date: Fri, 15 Mar 2024 16:50:27 +0700 Subject: [PATCH] Evaluation adjustment for different eval types Gives different eval scaling parameters for the three different types of evaluation (bignet, smallnet, psqtOnly). Passed STC: https://tests.stockfishchess.org/tests/view/65f4b0020ec64f0526c4a3bd LLR: 2.96 (-2.94,2.94) <0.00,2.00> Total: 168064 W: 43507 L: 42987 D: 81570 Ptnml(0-2): 662, 19871, 42445, 20393, 661 Passed LTC: https://tests.stockfishchess.org/tests/view/65f6be1a0ec64f0526c4c361 LLR: 2.94 (-2.94,2.94) <0.50,2.50> Total: 162564 W: 41188 L: 40604 D: 80772 Ptnml(0-2): 120, 18112, 44216, 18732, 102 closes https://github.com/official-stockfish/Stockfish/pull/5122 Bench: 2113576 --- src/evaluate.cpp | 37 +++++++++++++++++++++++++------------ src/evaluate.h | 2 +- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index c7adf50946f..3d1643fbd54 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -52,22 +52,35 @@ Value Eval::evaluate(const Eval::NNUE::Networks& networks, const Position& pos, int simpleEval = simple_eval(pos, pos.side_to_move()); bool smallNet = std::abs(simpleEval) > SmallNetThreshold; bool psqtOnly = std::abs(simpleEval) > PsqtOnlyThreshold; - - int nnueComplexity; + int nnueComplexity; + int v; Value nnue = smallNet ? networks.small.evaluate(pos, true, &nnueComplexity, psqtOnly) : networks.big.evaluate(pos, true, &nnueComplexity, false); - // Blend optimism and eval with nnue complexity and material imbalance - optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / 524; - nnue -= nnue * (nnueComplexity + std::abs(simpleEval - nnue)) / 31950; - - int npm = pos.non_pawn_material() / 64; - int v = (nnue * (927 + npm + 9 * pos.count()) + optimism * (159 + npm)) / 1000; - - // Damp down the evaluation linearly when shuffling - int shuffling = pos.rule50_count(); - v = v * (195 - shuffling) / 228; + const auto adjustEval = [&](int optDiv, int nnueDiv, int pawnCountConstant, int pawnCountMul, + int npmConstant, int evalDiv, int shufflingConstant, + int shufflingDiv) { + // Blend optimism and eval with nnue complexity and material imbalance + optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / optDiv; + nnue -= nnue * (nnueComplexity + std::abs(simpleEval - nnue)) / nnueDiv; + + int npm = pos.non_pawn_material() / 64; + v = (nnue * (npm + pawnCountConstant + pawnCountMul * pos.count()) + + optimism * (npmConstant + npm)) + / evalDiv; + + // Damp down the evaluation linearly when shuffling + int shuffling = pos.rule50_count(); + v = v * (shufflingConstant - shuffling) / shufflingDiv; + }; + + if (!smallNet) + adjustEval(513, 32395, 919, 11, 145, 1036, 178, 204); + else if (psqtOnly) + adjustEval(517, 32857, 908, 7, 155, 1019, 224, 238); + else + adjustEval(499, 32793, 903, 9, 147, 1067, 208, 211); // Guarantee evaluation does not hit the tablebase range v = std::clamp(v, VALUE_TB_LOSS_IN_MAX_PLY + 1, VALUE_TB_WIN_IN_MAX_PLY - 1); diff --git a/src/evaluate.h b/src/evaluate.h index bd11e0c1675..29dff40d05b 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -29,7 +29,7 @@ class Position; namespace Eval { -constexpr inline int SmallNetThreshold = 1136, PsqtOnlyThreshold = 2656; +constexpr inline int SmallNetThreshold = 1050, PsqtOnlyThreshold = 2500; // The default net name MUST follow the format nn-[SHA256 first 12 digits].nnue // for the build process (profile-build and fishtest) to work. Do not change the