## Stockfish's tuning method

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Eelco de Groot
Posts: 4596
Joined: Sun Mar 12, 2006 2:40 am
Full name:

### Re: Stockfish's tuning method

gaard wrote:FYI, for g/6", and g/60", I have a 4-sigma result in favor of the default. This weekend I am going to set up for testing with modifications to the ...CheckBonus coefficients. Results to follow...
I still think it is probably not good if you leave out count_1s<Max15>(undefended) like in Marco's original version I think he had this left out? The new king_defender terms all work in one direction and may even lead to negative attackUnits. The squares defended may not be the same as squares attacked and the more this is the case, the more noise is coming from the new terms. In other words, if the defenders leave "holes", and remember these squares are always attacked, because undefended is really a misnomer, then the defenders may simply have no effect at all, the new terms are pure noise all in the wrong direction. Also I thought that if I do not miscalculate, attackUnits = 0 is now a special case because it includes all the cases where the defense is stronger than the attack. Experimented in the past with a initialization function that starts below the x-axis to discourage attacks a bit. I think the case for this is now even stronger. So you could have a KingDangerTable[] array that starts with a negative term. You could take that further and also consider cases where there is just one attacker (forbidden now) and many defenders. attackUnits should lead to an KingDangerTable element in that case with a negative value, to discourage attacking and concentrating on another weaker spot in the enemy's camp. But if you want just the first term negative, I now have

Code: Select all

// init_safety&#40;) initizes the king safety evaluation, based on UCI
// parameters. It is called from read_weights&#40;).

void init_safety&#40;) &#123;

const Value MaxSlope = Value&#40;35&#41;;
const Value Peak = Value&#40;1280&#41;;
Value t&#91;100&#93;;

// First setup the base table
for &#40;int i = 0; i < 100; i++)
&#123;
t&#91;i&#93; = Value&#40;int&#40;&#40;0.5 * i * i&#41; + &#40;4 * i&#41; - 4&#41;);

if &#40;i > 0&#41;
t&#91;i&#93; = Min&#40;t&#91;i&#93;, t&#91;i - 1&#93; + MaxSlope&#41;;

t&#91;i&#93; = Min&#40;t&#91;i&#93;, Peak&#41;;
&#125;

// Then apply the weights and get the final KingDangerTable&#91;&#93; array
for &#40;Color c = WHITE; c <= BLACK; c++)
for &#40;int i = 0; i < 100; i++)
KingDangerTable&#91;c&#93;&#91;i&#93; = apply_weight&#40;make_score&#40;t&#91;i&#93;, 0&#41;, Weights&#91;KingDangerUs + c&#93;);
&#125;
that is supposed to do this. I had not really intended it for this, but thinking about it more I came up with this extra reasoning that KingDangerTable[0] should be negative.

Of course it is still possible that the old king safety calculation from Tord is almost entirely speculative in nature and in that case it may be best to ignore the defenders altogether From the evidence it seems this is worth about twenty elo then. So much for introducing "more knowledge" Anyone else got a bright idea...

Eelco
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as possible, you
are, by definition, not smart enough to debug it.
-- Brian W. Kernighan
BeyondCritics
Posts: 406
Joined: Sat May 05, 2012 2:48 pm
Full name: Oliver Roese

### Re: Stockfish's tuning method

Rémi Coulom wrote:Thanks for posting your algorithm.

...

In order to guarantee convergence of SPSA, it is necessary to decay the deltas and learning rate in time.
Mr. Coulom pointed towards the problem. As presented here, the "stockfish method" is a theoretically flawed method, that should fail to converge except for very simple cases.
Put it with a simple metaphor:
Assume you are playing golf, but unfortunately you are a very bad player, making random mistakes all the times. What is your strategy, to reach the goal in time?
If you think you are far from the goal, you can get away, hitting the ball boldly. The closer you are to the goal, the less bolder you hit your ball. If you make smaller and smaller steps, you have a decent chance to approach the goal arbritary close. Otherwise, if your hits have the same length all the time, your are expected to reach a vicintiy of your solution and then circle around for a very long time, i believe.
Of course, this is all known...
jdart
Posts: 4368
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

### Re: Stockfish's tuning method

There is also a variant of SPSA that uses RPROP (https://www.ualberta.ca/~szepesva/papers/rspsa_acg.pdf). This is often faster to converge.

However, if you are trying to minimize the number of runs you have to do, and each run is expensive, there are still other methods that may do that better. See for example http://link.springer.com/article/10.100 ... 015-9281-2.

--Jon
Rémi Coulom
Posts: 438
Joined: Mon Apr 24, 2006 8:06 pm

### Re: Stockfish's tuning method

All my experiments with RSPSA gave terrible results (you can see the plots in my CLOP paper). I believe that plain SPSA is much better.