1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 01:29:36 +00:00

Revert "use winning_percentage_wdl in learn"

This reverts commit c964e902c5.

# Conflicts:
#	src/uci.cpp
This commit is contained in:
nodchip 2020-07-06 11:07:46 +09:00
parent 3b535b5ade
commit 85c802d0b9
3 changed files with 8 additions and 59 deletions

View file

@ -116,7 +116,6 @@ bool use_draw_in_training_data_generation = false;
bool use_draw_in_training = false;
bool use_draw_in_validation = false;
bool use_hash_in_training = true;
bool use_wdl = false;
// -----------------------------------
// write phase file
@ -1026,16 +1025,6 @@ double sigmoid(double x)
return 1.0 / (1.0 + std::exp(-x));
}
// A function that converts the evaluation value to the winning rate [0,1]
double winning_percentage_wdl(Value value, int ply)
{
double wdl_w = UCI::win_rate_model( value, ply);
double wdl_l = UCI::win_rate_model(-value, ply);
double wdl_d = 1000.0 - wdl_w - wdl_l;
return (wdl_w + wdl_d / 2.0) / 1000.0;
}
// A function that converts the evaluation value to the winning rate [0,1]
double winning_percentage(double value)
{
@ -1044,18 +1033,6 @@ double winning_percentage(double value)
// = sigmoid(Eval/4*ln(10))
return sigmoid(value / PawnValueEg / 4.0 * log(10.0));
}
// A function that converts the evaluation value to the winning rate [0,1]
double winning_percentage(Value value, int ply)
{
if (use_wdl) {
return winning_percentage_wdl(value, ply);
}
else {
return winning_percentage(value);
}
}
double dsigmoid(double x)
{
// Sigmoid function
@ -1092,8 +1069,8 @@ double calc_grad(Value deep, Value shallow, PackedSfenValue& psv)
// Also, the coefficient of 1/m is unnecessary if you use the update formula that has the automatic gradient adjustment function like Adam and AdaGrad.
// Therefore, it is not necessary to save it in memory.
double p = winning_percentage(deep, psv.gamePly);
double q = winning_percentage(shallow, psv.gamePly);
double p = winning_percentage(deep);
double q = winning_percentage(shallow);
return (q - p) * dsigmoid(double(shallow) / 600.0);
}
#endif
@ -1118,8 +1095,8 @@ double calc_grad(Value deep, Value shallow, const PackedSfenValue& psv)
// = ...
// = q-p.
double p = winning_percentage(deep, psv.gamePly);
double q = winning_percentage(shallow, psv.gamePly);
double p = winning_percentage(deep);
double q = winning_percentage(shallow);
return q - p;
}
@ -1150,8 +1127,8 @@ double calc_grad(Value deep, Value shallow , const PackedSfenValue& psv)
// elmo (WCSC27) method
// Correct with the actual game wins and losses.
const double q = winning_percentage(shallow, psv.gamePly);
const double p = winning_percentage(deep, psv.gamePly);
const double q = winning_percentage(shallow);
const double p = winning_percentage(deep);
// Use 1 as the correction term if the expected win rate is 1, 0 if you lose, and 0.5 if you draw.
// game_result = 1,0,-1 so add 1 and divide by 2.
@ -1173,8 +1150,8 @@ void calc_cross_entropy(Value deep, Value shallow, const PackedSfenValue& psv,
double& cross_entropy_eval, double& cross_entropy_win, double& cross_entropy,
double& entropy_eval, double& entropy_win, double& entropy)
{
const double p /* teacher_winrate */ = winning_percentage(deep, psv.gamePly);
const double q /* eval_winrate */ = winning_percentage(shallow, psv.gamePly);
const double p /* teacher_winrate */ = winning_percentage(deep);
const double q /* eval_winrate */ = winning_percentage(shallow);
const double t = double(psv.game_result + 1) / 2;
constexpr double epsilon = 0.000001;
@ -2943,7 +2920,6 @@ void learn(Position&, istringstream& is)
else if (option == "use_draw_in_training") is >> use_draw_in_training;
else if (option == "use_draw_in_validation") is >> use_draw_in_validation;
else if (option == "use_hash_in_training") is >> use_hash_in_training;
else if (option == "use_wdl") is >> use_wdl;
// Discount rate
else if (option == "discount_rate") is >> discount_rate;

View file

@ -248,32 +248,6 @@ namespace {
uint64_t eval_sum;
} // namespace
namespace UCI{
// The win rate model returns the probability (per mille) of winning given an eval
// and a game-ply. The model fits rather accurately the LTC fishtest statistics.
int win_rate_model(Value v, int ply) {
// The model captures only up to 240 plies, so limit input (and rescale)
double m = std::min(240, ply) / 64.0;
// Coefficients of a 3rd order polynomial fit based on fishtest data
// for two parameters needed to transform eval to the argument of a
// logistic function.
double as[] = {-8.24404295, 64.23892342, -95.73056462, 153.86478679};
double bs[] = {-3.37154371, 28.44489198, -56.67657741, 72.05858751};
double a = (((as[0] * m + as[1]) * m + as[2]) * m) + as[3];
double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3];
// Transform eval to centipawns with limited range
double x = Utility::clamp(double(100 * v) / PawnValueEg, -1000.0, 1000.0);
// Return win rate in per mille (rounded to nearest)
return int(0.5 + 1000 / (1 + std::exp((a - x) / b)));
}
} // namespace UCI
// Make is_ready_cmd() callable from outside. (Because I want to call it from the bench command etc.)
// Note that the phase is not initialized.
void is_ready(bool skipCorruptCheck)

View file

@ -74,7 +74,6 @@ std::string square(Square s);
std::string move(Move m, bool chess960);
std::string pv(const Position& pos, Depth depth, Value alpha, Value beta);
std::string wdl(Value v, int ply);
int win_rate_model(Value v, int ply);
Move to_move(const Position& pos, std::string& str);
// Flag that read the evaluation function. This is set to false when evaldir is changed.