mcostalba wrote:
This post made came to my mind old memories
Hehe, I would never have guessed so.
mcostalba wrote:Actually the tweak of interpolation was the first patch I tried just after I forked Glaurung (!)
https://github.com/mcostalba/Stockfish/ ... 6471f28e1b
I had also committed it (see the date, 5 years ago!!!) but then reverted, at the time my standard test was of few hundreds games on my old and slow PC.
I was using a kind of transition where instead of climbing linearly the line started almost flat or with lower steep than linear and about at half way it climbed in super linear way to end the run at the other point in the same symmetrical flat way.
The description of the function you used makes me think of the "error function".
With second thoughts, I don't think that a decaying exponential would be appropriate. Given 2 points (x0,y0) and (x1,y1) such that y1>y0, I don't think that it's always possible to find a function f such that f(x)=a*exp(-b*x) where a and b are constants be to be found and such that f satisifies the boundary conditions f(x0)=y0 and f(x1)=y1. There are arbitrary cases where it is not possible. But what matters is the case of Stockfish with x0=3998, y0=0 (or 1 because 0 would either give a=0 or b worth infinity), x1=15581 and y1=128 and I don't think it's possible: I reach a non linear system of 2 equations with 2 unknows but it doesn't seem to have solution (it doesn't even make sense). I may be wrong and could have done some error though.
So I tried to use a quadratic to interpolate the game phase. Since I am interpolating only 2 points with a 2nd degree polynomial, I will be left with a free parameter. I have in mind using the SPSA tuner to tune it.
The polynomial is approximately worth p(x)=5.64x10^(-7) * x^2 -9+b (-3182-x^2 *5.11x10^(-5)+x) where b could be in principle any value. In other words, for any value of b, this polynomial will interpolate through the game phase and will be worth 128 for when x=15581 and worth 0 for when x=3998. Here x stands for the "npm" value in Stockfish's code, namely the non pawn material value.
b could be either positive or negative. When b is approximately worth 0.01 you get the original Stockfish linear interpolation. So I already know what is the value to start with, for the SPSA tuner.
I've plotted the polynomial for a range of values for b, and I think that a reasonable range for these values could be around [-0.011, 0.030]. Else the parabola gets really too pronounced. This gives you the order of magnitude for b.
If I understand more or less correctly Stockfish's code (without knowing how to write a hello world program in c++), I'd have to change the line 264 of material.cpp, which currently reads
Code: Select all
: Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
to
Code: Select all
: Phase( 5.64*pow(10,-7)*pow(npm,2) -9 + b *(-3182-pow(npm,2)*5.11*pow(10,-5) +npm) );
where b would be the well tuned value I find with the SPSA.
I am still skeptical on how much elo there's to gain using a 2nd order polynomial instead of a 1st order in order to calculate the game phase. But if I succeed using the SPSA tuner to tune b, I will probably give 1 shot in the fishtest. Unless you tell me not to, or point out errors I am/could be making.