Skip to content

Commit

Permalink
corr-hist-depth-based-alpha (#197)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
connormcmonigle authored Nov 24, 2024
1 parent b04754b commit 9d8b602
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions include/search/eval_correction_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)];

Expand All @@ -71,6 +71,18 @@ template <typename... Ts>

template <std::size_t N>
struct composite_eval_correction_history {
static constexpr depth_type lookup_table_size = 32;

static constexpr std::array<score_type, lookup_table_size> alpha_lookup_table = [] {
std::array<score_type, lookup_table_size> result{};
for (depth_type depth{1}; depth < lookup_table_size; ++depth) {
const double alpha_value = 1.0 - 1.0 / (1.0 + static_cast<double>(depth) / 8.0);
result[depth] = static_cast<depth_type>(16.0 * alpha_value);
}

return result;
}();

std::array<eval_correction_history, N> histories_{};

[[nodiscard]] constexpr score_type correction_for(const composite_feature_hash<N>& composite_hash) const noexcept {
Expand All @@ -84,13 +96,16 @@ struct composite_eval_correction_history {
return result;
}

constexpr void update(const composite_feature_hash<N>& composite_hash, const bound_type& bound, const score_type& error) noexcept {
constexpr void update(const composite_feature_hash<N>& 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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/search/search_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ pv_search_result_t<is_root> 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);
Expand Down

0 comments on commit 9d8b602

Please sign in to comment.