From 9d8b6026251013f23b6b325a6061a49652020413 Mon Sep 17 00:00:00 2001 From: connormcmonigle Date: Sun, 24 Nov 2024 11:03:33 -0800 Subject: [PATCH] corr-hist-depth-based-alpha (#197) Elo | 7.57 +- 4.70 (95%) SPRT | 8.0+0.08s Threads=1 Hash=32MB LLR | 2.96 (-2.94, 2.94) [0.00, 5.00] Games | N: 6288 W: 1638 L: 1501 D: 3149 Penta | [35, 708, 1546, 795, 60] http://chess.grantnet.us/test/38419/ Elo | 5.77 +- 3.84 (95%) SPRT | 40.0+0.40s Threads=1 Hash=64MB LLR | 2.97 (-2.94, 2.94) [0.00, 5.00] Games | N: 8070 W: 1898 L: 1764 D: 4408 Penta | [19, 893, 2077, 1027, 19] http://chess.grantnet.us/test/38420/ bench: 4248816 --- include/search/eval_correction_history.h | 27 ++++++++++++++++++------ src/search/search_worker.cc | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/search/eval_correction_history.h b/include/search/eval_correction_history.h index 5491664..fb9ca82 100644 --- a/include/search/eval_correction_history.h +++ b/include/search/eval_correction_history.h @@ -40,12 +40,12 @@ struct eval_correction_history { return raw_correction / eval_correction_scale; } - constexpr void update(const zobrist::quarter_hash_type& feature_hash, const score_type& error) noexcept { + constexpr void update(const zobrist::quarter_hash_type& feature_hash, const score_type& error, const score_type& alpha) noexcept { constexpr score_type score_correction_limit = 65536; + constexpr score_type filter_divisor = 256; - constexpr score_type filter_alpha = 1; - constexpr score_type filter_c_alpha = 255; - constexpr score_type filter_divisor = filter_alpha + filter_c_alpha; + const score_type filter_alpha = alpha; + const score_type filter_c_alpha = filter_divisor - alpha; auto& correction = data[hash_function(feature_hash)]; @@ -71,6 +71,18 @@ template template struct composite_eval_correction_history { + static constexpr depth_type lookup_table_size = 32; + + static constexpr std::array alpha_lookup_table = [] { + std::array result{}; + for (depth_type depth{1}; depth < lookup_table_size; ++depth) { + const double alpha_value = 1.0 - 1.0 / (1.0 + static_cast(depth) / 8.0); + result[depth] = static_cast(16.0 * alpha_value); + } + + return result; + }(); + std::array histories_{}; [[nodiscard]] constexpr score_type correction_for(const composite_feature_hash& composite_hash) const noexcept { @@ -84,13 +96,16 @@ struct composite_eval_correction_history { return result; } - constexpr void update(const composite_feature_hash& composite_hash, const bound_type& bound, const score_type& error) noexcept { + constexpr void update(const composite_feature_hash& composite_hash, const bound_type& bound, const score_type& error, const depth_type& depth) noexcept { if (bound == bound_type::upper && error >= 0) { return; } if (bound == bound_type::lower && error <= 0) { return; } + constexpr depth_type last_idx = lookup_table_size - 1; + const score_type alpha = alpha_lookup_table[std::min(last_idx, depth)]; + for (std::size_t i(0); i < N; ++i) { const zobrist::quarter_hash_type hash = composite_hash.hash(i); - histories_[i].update(hash, error); + histories_[i].update(hash, error, alpha); } } diff --git a/src/search/search_worker.cc b/src/search/search_worker.cc index b9c706d..b4823ff 100644 --- a/src/search/search_worker.cc +++ b/src/search/search_worker.cc @@ -477,7 +477,7 @@ pv_search_result_t search_worker::pv_search( if (!is_check && best_move.is_quiet()) { const score_type error = best_score - static_value; - internal.correction.us(bd.turn()).update(feature_hash, bound, error); + internal.correction.us(bd.turn()).update(feature_hash, bound, error, depth); } const transposition_table_entry entry(bd.hash(), bound, best_score, best_move, depth, tt_pv);