This is my first post here, I'm developing an engine you can find here: https://github.com/vladciocoiu/ciorap-bot
I am currently working on tuning the evaluation parameters and that's how I found Texel's Tuning method.
This is the code that I use for tuning (please ask me if anything is unclear):
Code: Select all
const int nParams = initialGuess.size();
// E(params) = sum((sigmoid(eval(params)) - game_result)^2) for all positions
// where sigmoid(x) = 1 / (1 + exp(-x / 400))
double bestE = E(initialGuess);
vector<int> bestParValues = initialGuess;
bool improved = true;
int iteration = 0;
while ( improved ) {
cout << "Iteration " << iteration << " started.\n";
improved = false;
for (int pi = 0; pi < nParams; pi++) {
bool improvedParam;
do {
improvedParam = false;
vector<int> newParValues = bestParValues;
newParValues[pi] += 1;
double newE = E(newParValues);
if (newE < bestE) {
improvedParam = true;
cout << "Found better value at parameter " << pi << ": " << bestParValues[pi] << " -> " << newParValues[pi] << ", mse=" << newE << '\n';
bestE = newE;
bestParValues = newParValues;
improved = true;
} else {
newParValues[pi] -= 2;
newE = E(newParValues);
if (newE < bestE) {
improvedParam = true;
cout << "Found better value at parameter " << pi << ": " << bestParValues[pi] << " -> " << newParValues[pi] << ", mse=" << newE << '\n';
bestE = newE;
bestParValues = newParValues;
improved = true;
}
}
} while(improvedParam);
}
iteration++;
}
return bestParValues;
I have to mention that the parameters I'm trying to tune are the piece-square tables, king safety table, passed pawn bonuses, mobility bonuses, and other smaller features such as trapped minor piece penalties, tempo bonus, rook on open file bonus etc.
The problem is that every time I try and train these parameters, some of them get inexplicably big / small.
For example the value for the queen on g3 in the piece-square table becomes -555 centipawns, or the tempo bonus becomes -107.
Has someone else ever experienced this or knows what could cause it?
I would appreciate your help a lot. Thanks!