mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 10:57:43 +00:00
Removed LOSS_FUNCTION_IS_WINNING_PERCENTAGE macro.
This commit is contained in:
+1
-8
@@ -9,11 +9,6 @@
|
|||||||
// Select the objective function
|
// Select the objective function
|
||||||
// ----------------------
|
// ----------------------
|
||||||
|
|
||||||
// The objective function is the sum of squares of the difference in winning percentage
|
|
||||||
// See learner.cpp for more information.
|
|
||||||
|
|
||||||
//#define LOSS_FUNCTION_IS_WINNING_PERCENTAGE
|
|
||||||
|
|
||||||
// Objective function is cross entropy
|
// Objective function is cross entropy
|
||||||
// See learner.cpp for more information.
|
// See learner.cpp for more information.
|
||||||
// So-called ordinary "rag cloth squeezer"
|
// So-called ordinary "rag cloth squeezer"
|
||||||
@@ -126,9 +121,7 @@ typedef float LearnFloatType;
|
|||||||
|
|
||||||
#define LOSS_FUNCTION_IS_ELMO_METHOD
|
#define LOSS_FUNCTION_IS_ELMO_METHOD
|
||||||
|
|
||||||
#if defined(LOSS_FUNCTION_IS_WINNING_PERCENTAGE)
|
#if defined(LOSS_FUNCTION_IS_CROSS_ENTOROPY)
|
||||||
#define LOSS_FUNCTION "WINNING_PERCENTAGE"
|
|
||||||
#elif defined(LOSS_FUNCTION_IS_CROSS_ENTOROPY)
|
|
||||||
#define LOSS_FUNCTION "CROSS_ENTOROPY"
|
#define LOSS_FUNCTION "CROSS_ENTOROPY"
|
||||||
#elif defined(LOSS_FUNCTION_IS_CROSS_ENTOROPY_FOR_VALUE)
|
#elif defined(LOSS_FUNCTION_IS_CROSS_ENTOROPY_FOR_VALUE)
|
||||||
#define LOSS_FUNCTION "CROSS_ENTOROPY_FOR_VALUE"
|
#define LOSS_FUNCTION "CROSS_ENTOROPY_FOR_VALUE"
|
||||||
|
|||||||
@@ -163,42 +163,6 @@ namespace Learner
|
|||||||
return ((y2 - y1) / epsilon) / winning_probability_coefficient;
|
return ((y2 - y1) / epsilon) / winning_probability_coefficient;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the objective function is the sum of squares of the difference in winning percentage
|
|
||||||
#if defined (LOSS_FUNCTION_IS_WINNING_PERCENTAGE)
|
|
||||||
// function to calculate the gradient
|
|
||||||
double calc_grad(Value deep, Value shallow, PackedSfenValue& psv)
|
|
||||||
{
|
|
||||||
// The square of the win rate difference minimizes it in the objective function.
|
|
||||||
// Objective function J = 1/2m Σ (win_rate(shallow)-win_rate(deep) )^2
|
|
||||||
// However, σ is a sigmoid function that converts the
|
|
||||||
// evaluation value into the difference in the winning percentage.
|
|
||||||
// m is the number of samples. shallow is the evaluation value
|
|
||||||
// for a shallow search (qsearch()). deep is the evaluation value for deep search.
|
|
||||||
// If W is the feature vector (parameter of the evaluation function)
|
|
||||||
// and Xi and Yi are teachers
|
|
||||||
// shallow = W*Xi // * is the Hadamard product, transposing W and meaning X
|
|
||||||
// f(Xi) = win_rate(W*Xi)
|
|
||||||
// If σ(i th deep) = Yi,
|
|
||||||
// J = m/2 Σ (f(Xi)-Yi )^2
|
|
||||||
// becomes a common expression.
|
|
||||||
// W is a vector, and if we write the jth element as Wj, from the chain rule
|
|
||||||
// ∂J/∂Wj = ∂J/∂f ・∂f/∂W ・∂W/∂Wj
|
|
||||||
// = 1/m Σ (f(Xi)-y) ・f'(Xi) ・ 1
|
|
||||||
|
|
||||||
// 1/m will be multiplied later, but the contents of Σ can
|
|
||||||
// be retained in the array as the value of the gradient.
|
|
||||||
// f'(Xi) = win_rate'(shallow) = sigmoid'(shallow/600) = dsigmoid(shallow / 600) / 600
|
|
||||||
// This /600 at the end is adjusted by the learning rate, so do not write it..
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
const double p = winning_percentage(deep, psv.gamePly);
|
|
||||||
const double q = winning_percentage(shallow, psv.gamePly);
|
|
||||||
return (q - p) * Math::dsigmoid(double(shallow) / 600.0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined (LOSS_FUNCTION_IS_CROSS_ENTOROPY)
|
#if defined (LOSS_FUNCTION_IS_CROSS_ENTOROPY)
|
||||||
double calc_grad(Value deep, Value shallow, const PackedSfenValue& psv)
|
double calc_grad(Value deep, Value shallow, const PackedSfenValue& psv)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user