Time based contempt

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
Michel
Posts: 2001
Joined: Sun Sep 28, 2008 11:50 pm

Time based contempt

Post by Michel » Sun Apr 20, 2014 4:15 pm

A very interesting idea has appeared on fishtest!

It is common wisdom that standard contempt (altering the draw score) weakens an engine against an engine of equal strength since occasionally an inferior move will be selected, just to avoid a draw.

However contempt is supposed to help against weaker engines.

This patch

http://tests.stockfishchess.org/tests/v ... 04a4ce6a2b

implements the following variation on this idea: if we have more time than our opponent, use contempt, otherwise not. The idea is of course that if we have more time then we are virtually stronger (our opponent is time handicapped), so contempt might help.

The above patch tested positive in self testing so it might actually work!

One criticism I have is that I believe that the implementation should be symmetrical. If we have less time we should use negative contempt (in other words: go for the draw).

This modification would remove the asymmetry of contempt which is one of its main ugly features.

syzygy
Posts: 4376
Joined: Tue Feb 28, 2012 10:56 pm

Re: Time based contempt

Post by syzygy » Sun Apr 20, 2014 4:51 pm

Making it dependent on remaining time is a nice idea, but maybe the transition between contempt and no contempt could be smoother? There can be a big difference between having more time left on the clock and having more time left on the clock. But the idea seems healthy: if you can think longer than your opponent, you will play stronger.

Ideally you would also want to know how much stronger than the opponent you are (given equal time) and take that into account as well, but I guess this information is not provided by UCI.

I wonder a bit about using DrawValue for contempt. A dead draw is a dead draw and no amount of contempt will help to win it. At most a too large contempt value can help to lose it.

Would it not be a better idea to keep DrawValue at 0.00 and implement contempt as an additional bonus dependent on estimated difference in strength (which could take into account remaining time) and the amount of play left in the position being evaluated? The amount of play could be a function of pawn structure, material balance, maybe king safety (maybe just of material to keep it fast). If you know you are stronger than your opponent, you have reason to be positive about a position that is objectively balanced but has room for complications.

jpqy
Posts: 513
Joined: Thu Apr 24, 2008 7:31 am
Location: Belgium

Re: Time based contempt

Post by jpqy » Sun Apr 20, 2014 7:13 pm

contempt diff

LLR: 2.96 (-2.94,2.94) [-1.50,4.50]
Total: 16305 W: 3001 L: 2855 D: 10449

sprt @ 15+0.05 th 1 Raise contempt if having advantage

I'm playing with this patch..i like it more then having more time left.
It doesn't mean you have more time that your position is better.
So when Stockfish get a higher score from the side he plays..and it goes higher and higher..Raise contempt.
Much more tests we need..but i like this idea..and like already said when SF is behind, lower the contempt. Maybe back to default=0

syzygy
Posts: 4376
Joined: Tue Feb 28, 2012 10:56 pm

Re: Time based contempt

Post by syzygy » Sun Apr 20, 2014 7:49 pm

jpqy wrote:It doesn't mean you have more time that your position is better.
If your position is better (eval > 0), there is no need for contempt.

The point of contempt is to avoid letting the search settle for a draw if the position is evaluated <= 0.0 and there are reasons for believing that winning the game is still possible.

One such reason is having more time available. Having more time to think is essentially equivalent to running on faster hardware. In other words: the quality of moves can be expected to be higher.
So when Stockfish get a higher score from the side he plays..and it goes higher and higher..Raise contempt.
Contempt willl achieve absolutely nothing in this case.

syzygy
Posts: 4376
Joined: Tue Feb 28, 2012 10:56 pm

Re: Time based contempt

Post by syzygy » Sun Apr 20, 2014 8:17 pm

On second thoughts, I very much dislike the idea of changing evaluation parameters as a function of time. Once you do this, hash scores from previous searches become unreliable as they are based on the old evaluation parameters.

Still (very much) worse are the other patches that make contempt dependent on best_value, which means it changes between iterations. I have no idea why this seems to work on Fishtest, but it is very ugly, very unsound, and I very much doubt that it will translate into "real" improved play.

The idea of gaining more confidence as the time on the clock increases is nice, but properly integrating this into the search seems difficult. The hacks that are now being tested most likely will come back to haunt SF development.

Michel
Posts: 2001
Joined: Sun Sep 28, 2008 11:50 pm

Re: Time based contempt

Post by Michel » Sun Apr 20, 2014 9:21 pm

The idea of gaining more confidence as the time on the clock increases is nice, but properly integrating this into the search seems difficult. The hacks that are now being tested most likely will come back to haunt SF development.
I already indicated the problem with the hash table in my fishtest post.

It is not totally impossible to solve this in a theoretically correct way by storing the value of contempt that was in force when the entry was computed. If there is not enough room then one might approximate things with some flags. I am not sure if it is worth it.

I was strongly against contempt myself also, but the time based one at least seems as if it has a chance of actually working. Furthermore it can be made symmetric. Given that a version of contempt will end up in SF anyway (people are just too enamored with black magic devices), this might be the best option.

syzygy
Posts: 4376
Joined: Tue Feb 28, 2012 10:56 pm

Re: Time based contempt

Post by syzygy » Sun Apr 20, 2014 10:11 pm

Michel wrote:I already indicated the problem with the hash table in my fishtest post.
Yes, I don't claim to be the first to have this insight ;-)
It is not totally impossible to solve this in a theoretically correct way by storing the value of contempt that was in force when the entry was computed. If there is not enough room then one might approximate things with some flags. I am not sure if it is worth it.
The solution would be practically equivalent to clearing the hash table with an age counter (and not using old scores). I guess if contempt ping pongs between two values you could let the age ping pong as well. Not nice.
I was strongly against contempt myself also, but the time based one at least seems as if it has a chance of actually working. Furthermore it can be made symmetric. Given that a version of contempt will end up in SF anyway (people are just too enamored with black magic devices), this might be the best option.
I'd like to see it tested against one that always has positive contempt. Chances are it just somehow makes the trees a bit smaller and what is being tested is really just a pruning adjustment.

Anyway, a single evaluation adjustment per complete search is somewhat less painful to think about than one per search iteration (or probably several per iteration, I didn't study the code too well).

Michel
Posts: 2001
Joined: Sun Sep 28, 2008 11:50 pm

Re: Time based contempt

Post by Michel » Mon Apr 21, 2014 5:50 am

The solution would be practically equivalent to clearing the hash table with an age counter (and not using old scores). I guess if contempt ping pongs between two values you could let the age ping pong as well. Not nice.
Well, I have not thought it through but I think that an entry with incorrect contempt can still be used to compute a bound on the score, and of course it can also still be used for move ordering.

But I agree it would be ugly.

Anyway testing agains Critter seems to show that none of the contempt patches actually works in foreign testing. So I assume contempt will be off the table for now, until the next round...

Masta
Posts: 26
Joined: Fri Jul 26, 2013 4:24 am

Re: Time based contempt

Post by Masta » Tue Apr 22, 2014 12:58 pm

There is nothing ugly with asymmetry. BTW...I really think that a dynamic approach is better than a static one. It takes in consideration that things change...positions change, and you have to adapt to them. Adaptation, harmonic asymmetry are beautiful (like fibonacci sequence). That´s how nature works.

syzygy
Posts: 4376
Joined: Tue Feb 28, 2012 10:56 pm

Re: Time based contempt

Post by syzygy » Tue Apr 22, 2014 7:11 pm

Masta wrote:There is nothing ugly with asymmetry. BTW...I really think that a dynamic approach is better than a static one. It takes in consideration that things change...positions change, and you have to adapt to them. Adaptation, harmonic asymmetry are beautiful (like fibonacci sequence). That´s how nature works.
Ehm, lol?

This is just a case of spaghetti that somehow happened to stick to the self-test wall. All attempts at a rational explanation (which yours certainly is not) that I have seen are flawed.

Post Reply