mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 19:46:55 +08:00
Merge branch 'master' into master
This commit is contained in:
@@ -1028,24 +1028,10 @@ double sigmoid(double x)
|
||||
// A function that converts the evaluation value to the winning rate [0,1]
|
||||
double winning_percentage(double value)
|
||||
{
|
||||
// In Maxima,
|
||||
// load("C:/maxima-5.44.0/cform.lisp");
|
||||
// PawnValueEg = 206;
|
||||
// cform(1.0 / (1.0 + 10.0 ^ (-value / PawnValueEg / 4.0)));
|
||||
constexpr double PawnValue = PawnValueEg;
|
||||
return 1.0 * pow(pow(10.0, -0.25 * pow(PawnValue, -1) * value) + 1.0, -1);
|
||||
}
|
||||
|
||||
double delta_winning_percentage(double value)
|
||||
{
|
||||
// In Maxima,
|
||||
// load("C:/maxima-5.44.0/cform.lisp");
|
||||
// PawnValueEg = 206;
|
||||
// cform(diff(1.0/(1.0+10.0^(-value/PawnValue/4.0)),value));
|
||||
constexpr double PawnValue = PawnValueEg;
|
||||
return
|
||||
0.5756462732485115 * pow(PawnValue, -1) * pow(10.0, -0.25 * pow(PawnValue, -1) * value) *
|
||||
pow(pow(10.0, -0.25 * pow(PawnValue, -1) * value) + 1.0, -2);
|
||||
// 1/(1+10^(-Eval/4))
|
||||
// = 1/(1+e^(-Eval/4*ln(10))
|
||||
// = sigmoid(Eval/4*ln(10))
|
||||
return sigmoid(value / PawnValueEg / 4.0 * log(10.0));
|
||||
}
|
||||
double dsigmoid(double x)
|
||||
{
|
||||
@@ -1143,7 +1129,6 @@ double calc_grad(Value deep, Value shallow , const PackedSfenValue& psv)
|
||||
|
||||
const double q = winning_percentage(shallow);
|
||||
const double p = winning_percentage(deep);
|
||||
const double dq = delta_winning_percentage(shallow);
|
||||
|
||||
// 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.
|
||||
@@ -1154,9 +1139,7 @@ double calc_grad(Value deep, Value shallow , const PackedSfenValue& psv)
|
||||
|
||||
// Use the actual win rate as a correction term.
|
||||
// This is the idea of elmo (WCSC27), modern O-parts.
|
||||
const double pp = (q - p) * dq / q / (1.0 - q);
|
||||
const double tt = (q - t) * dq / q / (1.0 - q);
|
||||
const double grad = lambda * pp + (1.0 - lambda) * tt;
|
||||
const double grad = lambda * (q - p) + (1.0 - lambda) * (q - t);
|
||||
|
||||
return grad;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user