-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A better contempt implementation for Stockfish #1325
A better contempt implementation for Stockfish #1325
Conversation
The round 2 of TCEC season 10 demonstrated the benefit of having a nice contempt implementation: it gives the strongest programs in the tournament the ability to slow down the game when they feel the position is slightly worse, prefering to stay in a complicated (even if slightly risky) middle game rather than simplifying by force into a drawn endgame. The current contempt implementation of Stockfish is inadequate, and this patch is an attempt to provide a better one. Passed STC non-regression test against master: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 83360 W: 15089 L: 15075 D: 53196 http://tests.stockfishchess.org/tests/view/5a1bf2de0ebc590ccbb8b370 This contempt implementation is showing promising results in certains situations. For instance, it obtained a nice +30 Elo gain when playing with contempt=40 against Stockfish 7, compared to current master: • master against SF 7 (20000 games at LTC): +121.2 Elo • this patch with contempt=40 (20000 games at LTC): +154.11 Elo This was the result of real cooperative work from the Stockfish team, with key ideas coming from Stefan Geschwentner (locutus2) and Chris Cain (ceebo) while most of the community helped with feedback and computer time. In this commit the bench is unchanged by default, but you can test at home with the new contempt in the UCI options. The style of play will change a lot when using contempt different of zero (I repeat: not done in this version by default, however)! The Stockfish team is still deliberating over the best default contempt value in self-play and the best contempt modeling strategy, to help users choosing a contempt value when playing against much weaker programs. These informations will be given in future commits when available :-) Bench: 5051254
The forum thread where all the discussion occurred: |
In particular, the forum thread has results of tests to support the claim in the pull request that "current contempt implementation of Stockfish is inadequate". We got the following tests which showed that "master + contempt=40" doesn't gain Elo against SF7, compared to master against SF7 (all tests against SF7, 40000 games at STC): master : +120.19 Elo master, contempt=40 : +119.11 Elo phased_contempt6, contempt=40 (this version) : +139 Elo |
Thank you @snicolet and others for making this happen! |
I'm impressed by the simplicity of this patch! I wonder about the prefetch in evaluate.cpp at line 831. A single value accessed in every call to evaluate() is practically guaranteed to be in cache, so prefetching it seems unnecessary. |
@snicolet I'd think the prefetch is logically unrelated with the patch semantic and I hardly see it useful in any way. Could you please remove it? I will merge afterward. |
No functional change.
@mcostalba |
If I´m not mistaken the prefetch was used to optimize the code and accelerate the calls for the contempt score. But whatever...I´m not certain of it. |
For all those that were involved in this patch - very nice , a great collaborative effort. 👍👊 |
@mcostalba Thanks for merging. However, could it be possible to rewrite the last lines of the commit message? They are |
@snicolet yeah I see, but I cannot do it without breaking people 'git pull' in their local repo. Better to leave as is and to fix in next commit. |
Set the default contempt value of Stockfish to 20 centipawns. The contempt feature of Stockfish tries to prevent the engine from simplifying the position too quickly when it feels that it is very slightly behind, instead keeping the tension a little bit longer. Various tests in November 2017 have proved that our current imple- mentation works well against SF7 (which is about 130 Elo weaker than current master) and than the Elo gain is an increasing function of contempt, going (against SF7) from +0 Elo when contempt is set at zero centipawns, to +30 Elo when contempt is 40 centipawns. See pull request 1325 for details: official-stockfish/Stockfish#1325 This november discussion left open the decision of which "default" value for contempt we should use for Stockfish, taking into account the various uses ofStockfish (opening preparation for humans, computer online tournaments,analysis tool for web pages, human/computer play, etc). This pull request proposes to set the default contempt value of SF to twenty centipawns, which turns out to be the highest value which is not a regression against current master, as this seemed to be a good compromise between risk and safety. A couple of SPRT[-3..1] tests were done to bisect this value: Contempt 10: http://tests.stockfishchess.org/tests/view/5a5d42d20ebc5902977e2901 (PASSED) Contempt 15: http://tests.stockfishchess.org/tests/view/5a5d41740ebc5902977e28fa (PASSED) Contempt 20: http://tests.stockfishchess.org/tests/view/5a5d42060ebc5902977e28fc (PASSED) Contempt 25: http://tests.stockfishchess.org/tests/view/5a5d433f0ebc5902977e2904 (FAILED) Surprisingly, a test at "very long time control" hinted that using contempt 20 is not only be non-regressive against contempt 0, but may actually exhibit some small Elo gain, giving a likehood of superio- rity of 88.7% after 8500 games: VLTC: ELO: 2.28 +-3.7 (95%) LOS: 88.7% Total: 8521 W: 1096 L: 1040 D: 6385 http://tests.stockfishchess.org/tests/view/5a60b2820ebc590297b9b7e0 Finally, there was some concerns that a contempt value of 20 would be worse than a value of 7, but a test with 20000 games at STC was neutral: STC: ELO: 0.45 +-3.1 (95%) LOS: 61.2% Total: 20000 W: 4222 L: 4196 D: 11582 http://tests.stockfishchess.org/tests/view/5a64d2fd0ebc590297903868 See the comments in pull request 1361 for the long, nice discussion (180 entries :-)) leading to the decision to propose contempt 20 as the default value: official-stockfish/Stockfish#1361 Whether Stockfish should strictly adhere to the Komodo and Houdini semantics and add the UCI commands to force the contempt to be White in the so-called "analysis mode" is still under discussion, and may be or may not be the object of a future commit. Bench: 5571216
Set the default contempt value of Stockfish to 20 centipawns. The contempt feature of Stockfish tries to prevent the engine from simplifying the position too quickly when it feels that it is very slightly behind, instead keeping the tension a little bit longer. Various tests in November 2017 have proved that our current imple- mentation works well against SF7 (which is about 130 Elo weaker than current master) and than the Elo gain is an increasing function of contempt, going (against SF7) from +0 Elo when contempt is set at zero centipawns, to +30 Elo when contempt is 40 centipawns. See pull request 1325 for details: #1325 This november discussion left open the decision of which "default" value for contempt we should use for Stockfish, taking into account the various uses ofStockfish (opening preparation for humans, computer online tournaments,analysis tool for web pages, human/computer play, etc). This pull request proposes to set the default contempt value of SF to twenty centipawns, which turns out to be the highest value which is not a regression against current master, as this seemed to be a good compromise between risk and safety. A couple of SPRT[-3..1] tests were done to bisect this value: Contempt 10: http://tests.stockfishchess.org/tests/view/5a5d42d20ebc5902977e2901 (PASSED) Contempt 15: http://tests.stockfishchess.org/tests/view/5a5d41740ebc5902977e28fa (PASSED) Contempt 20: http://tests.stockfishchess.org/tests/view/5a5d42060ebc5902977e28fc (PASSED) Contempt 25: http://tests.stockfishchess.org/tests/view/5a5d433f0ebc5902977e2904 (FAILED) Surprisingly, a test at "very long time control" hinted that using contempt 20 is not only be non-regressive against contempt 0, but may actually exhibit some small Elo gain, giving a likehood of superio- rity of 88.7% after 8500 games: VLTC: ELO: 2.28 +-3.7 (95%) LOS: 88.7% Total: 8521 W: 1096 L: 1040 D: 6385 http://tests.stockfishchess.org/tests/view/5a60b2820ebc590297b9b7e0 Finally, there was some concerns that a contempt value of 20 would be worse than a value of 7, but a test with 20000 games at STC was neutral: STC: ELO: 0.45 +-3.1 (95%) LOS: 61.2% Total: 20000 W: 4222 L: 4196 D: 11582 http://tests.stockfishchess.org/tests/view/5a64d2fd0ebc590297903868 See the comments in pull request 1361 for the long, nice discussion (180 entries :-)) leading to the decision to propose contempt 20 as the default value: #1361 Whether Stockfish should strictly adhere to the Komodo and Houdini semantics and add the UCI commands to force the contempt to be White in the so-called "analysis mode" is still under discussion, and may be or may not be the object of a future commit. Bench: 5783344
* A better contempt implementation for Stockfish The round 2 of TCEC season 10 demonstrated the benefit of having a nice contempt implementation: it gives the strongest programs in the tournament the ability to slow down the game when they feel the position is slightly worse, prefering to stay in a complicated (even if slightly risky) middle game rather than simplifying by force into a drawn endgame. The current contempt implementation of Stockfish is inadequate, and this patch is an attempt to provide a better one. Passed STC non-regression test against master: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 83360 W: 15089 L: 15075 D: 53196 http://tests.stockfishchess.org/tests/view/5a1bf2de0ebc590ccbb8b370 This contempt implementation is showing promising results in certains situations. For instance, it obtained a nice +30 Elo gain when playing with contempt=40 against Stockfish 7, compared to current master: • master against SF 7 (20000 games at LTC): +121.2 Elo • this patch with contempt=40 (20000 games at LTC): +154.11 Elo This was the result of real cooperative work from the Stockfish team, with key ideas coming from Stefan Geschwentner (locutus2) and Chris Cain (ceebo) while most of the community helped with feedback and computer time. In this commit the bench is unchanged by default, but you can test at home with the new contempt in the UCI options. The style of play will change a lot when using contempt different of zero (I repeat: not done in this version by default, however)! The Stockfish team is still deliberating over the best default contempt value in self-play and the best contempt modeling strategy, to help users choosing a contempt value when playing against much weaker programs. These informations will be given in future commits when available :-) Bench: 5051254 * Remove the prefetch No functional change.
Set the default contempt value of Stockfish to 20 centipawns. The contempt feature of Stockfish tries to prevent the engine from simplifying the position too quickly when it feels that it is very slightly behind, instead keeping the tension a little bit longer. Various tests in November 2017 have proved that our current imple- mentation works well against SF7 (which is about 130 Elo weaker than current master) and than the Elo gain is an increasing function of contempt, going (against SF7) from +0 Elo when contempt is set at zero centipawns, to +30 Elo when contempt is 40 centipawns. See pull request 1325 for details: official-stockfish#1325 This november discussion left open the decision of which "default" value for contempt we should use for Stockfish, taking into account the various uses ofStockfish (opening preparation for humans, computer online tournaments,analysis tool for web pages, human/computer play, etc). This pull request proposes to set the default contempt value of SF to twenty centipawns, which turns out to be the highest value which is not a regression against current master, as this seemed to be a good compromise between risk and safety. A couple of SPRT[-3..1] tests were done to bisect this value: Contempt 10: http://tests.stockfishchess.org/tests/view/5a5d42d20ebc5902977e2901 (PASSED) Contempt 15: http://tests.stockfishchess.org/tests/view/5a5d41740ebc5902977e28fa (PASSED) Contempt 20: http://tests.stockfishchess.org/tests/view/5a5d42060ebc5902977e28fc (PASSED) Contempt 25: http://tests.stockfishchess.org/tests/view/5a5d433f0ebc5902977e2904 (FAILED) Surprisingly, a test at "very long time control" hinted that using contempt 20 is not only be non-regressive against contempt 0, but may actually exhibit some small Elo gain, giving a likehood of superio- rity of 88.7% after 8500 games: VLTC: ELO: 2.28 +-3.7 (95%) LOS: 88.7% Total: 8521 W: 1096 L: 1040 D: 6385 http://tests.stockfishchess.org/tests/view/5a60b2820ebc590297b9b7e0 Finally, there was some concerns that a contempt value of 20 would be worse than a value of 7, but a test with 20000 games at STC was neutral: STC: ELO: 0.45 +-3.1 (95%) LOS: 61.2% Total: 20000 W: 4222 L: 4196 D: 11582 http://tests.stockfishchess.org/tests/view/5a64d2fd0ebc590297903868 See the comments in pull request 1361 for the long, nice discussion (180 entries :-)) leading to the decision to propose contempt 20 as the default value: official-stockfish#1361 Whether Stockfish should strictly adhere to the Komodo and Houdini semantics and add the UCI commands to force the contempt to be White in the so-called "analysis mode" is still under discussion, and may be or may not be the object of a future commit. Bench: 5783344
Set the default contempt value of Stockfish to 20 centipawns. The contempt feature of Stockfish tries to prevent the engine from simplifying the position too quickly when it feels that it is very slightly behind, instead keeping the tension a little bit longer. Various tests in November 2017 have proved that our current imple- mentation works well against SF7 (which is about 130 Elo weaker than current master) and than the Elo gain is an increasing function of contempt, going (against SF7) from +0 Elo when contempt is set at zero centipawns, to +30 Elo when contempt is 40 centipawns. See pull request 1325 for details: official-stockfish/Stockfish#1325 This november discussion left open the decision of which "default" value for contempt we should use for Stockfish, taking into account the various uses ofStockfish (opening preparation for humans, computer online tournaments,analysis tool for web pages, human/computer play, etc). This pull request proposes to set the default contempt value of SF to twenty centipawns, which turns out to be the highest value which is not a regression against current master, as this seemed to be a good compromise between risk and safety. A couple of SPRT[-3..1] tests were done to bisect this value: Contempt 10: http://tests.stockfishchess.org/tests/view/5a5d42d20ebc5902977e2901 (PASSED) Contempt 15: http://tests.stockfishchess.org/tests/view/5a5d41740ebc5902977e28fa (PASSED) Contempt 20: http://tests.stockfishchess.org/tests/view/5a5d42060ebc5902977e28fc (PASSED) Contempt 25: http://tests.stockfishchess.org/tests/view/5a5d433f0ebc5902977e2904 (FAILED) Surprisingly, a test at "very long time control" hinted that using contempt 20 is not only be non-regressive against contempt 0, but may actually exhibit some small Elo gain, giving a likehood of superio- rity of 88.7% after 8500 games: VLTC: ELO: 2.28 +-3.7 (95%) LOS: 88.7% Total: 8521 W: 1096 L: 1040 D: 6385 http://tests.stockfishchess.org/tests/view/5a60b2820ebc590297b9b7e0 Finally, there was some concerns that a contempt value of 20 would be worse than a value of 7, but a test with 20000 games at STC was neutral: STC: ELO: 0.45 +-3.1 (95%) LOS: 61.2% Total: 20000 W: 4222 L: 4196 D: 11582 http://tests.stockfishchess.org/tests/view/5a64d2fd0ebc590297903868 See the comments in pull request 1361 for the long, nice discussion (180 entries :-)) leading to the decision to propose contempt 20 as the default value: official-stockfish/Stockfish#1361 Whether Stockfish should strictly adhere to the Komodo and Houdini semantics and add the UCI commands to force the contempt to be White in the so-called "analysis mode" is still under discussion, and may be or may not be the object of a future commit. Bench: 5783344
* A better contempt implementation for Stockfish The round 2 of TCEC season 10 demonstrated the benefit of having a nice contempt implementation: it gives the strongest programs in the tournament the ability to slow down the game when they feel the position is slightly worse, prefering to stay in a complicated (even if slightly risky) middle game rather than simplifying by force into a drawn endgame. The current contempt implementation of Stockfish is inadequate, and this patch is an attempt to provide a better one. Passed STC non-regression test against master: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 83360 W: 15089 L: 15075 D: 53196 http://tests.stockfishchess.org/tests/view/5a1bf2de0ebc590ccbb8b370 This contempt implementation is showing promising results in certains situations. For instance, it obtained a nice +30 Elo gain when playing with contempt=40 against Stockfish 7, compared to current master: • master against SF 7 (20000 games at LTC): +121.2 Elo • this patch with contempt=40 (20000 games at LTC): +154.11 Elo This was the result of real cooperative work from the Stockfish team, with key ideas coming from Stefan Geschwentner (locutus2) and Chris Cain (ceebo) while most of the community helped with feedback and computer time. In this commit the bench is unchanged by default, but you can test at home with the new contempt in the UCI options. The style of play will change a lot when using contempt different of zero (I repeat: not done in this version by default, however)! The Stockfish team is still deliberating over the best default contempt value in self-play and the best contempt modeling strategy, to help users choosing a contempt value when playing against much weaker programs. These informations will be given in future commits when available :-) Bench: 5051254 * Remove the prefetch No functional change.
Set the default contempt value of Stockfish to 20 centipawns. The contempt feature of Stockfish tries to prevent the engine from simplifying the position too quickly when it feels that it is very slightly behind, instead keeping the tension a little bit longer. Various tests in November 2017 have proved that our current imple- mentation works well against SF7 (which is about 130 Elo weaker than current master) and than the Elo gain is an increasing function of contempt, going (against SF7) from +0 Elo when contempt is set at zero centipawns, to +30 Elo when contempt is 40 centipawns. See pull request 1325 for details: official-stockfish#1325 This november discussion left open the decision of which "default" value for contempt we should use for Stockfish, taking into account the various uses ofStockfish (opening preparation for humans, computer online tournaments,analysis tool for web pages, human/computer play, etc). This pull request proposes to set the default contempt value of SF to twenty centipawns, which turns out to be the highest value which is not a regression against current master, as this seemed to be a good compromise between risk and safety. A couple of SPRT[-3..1] tests were done to bisect this value: Contempt 10: http://tests.stockfishchess.org/tests/view/5a5d42d20ebc5902977e2901 (PASSED) Contempt 15: http://tests.stockfishchess.org/tests/view/5a5d41740ebc5902977e28fa (PASSED) Contempt 20: http://tests.stockfishchess.org/tests/view/5a5d42060ebc5902977e28fc (PASSED) Contempt 25: http://tests.stockfishchess.org/tests/view/5a5d433f0ebc5902977e2904 (FAILED) Surprisingly, a test at "very long time control" hinted that using contempt 20 is not only be non-regressive against contempt 0, but may actually exhibit some small Elo gain, giving a likehood of superio- rity of 88.7% after 8500 games: VLTC: ELO: 2.28 +-3.7 (95%) LOS: 88.7% Total: 8521 W: 1096 L: 1040 D: 6385 http://tests.stockfishchess.org/tests/view/5a60b2820ebc590297b9b7e0 Finally, there was some concerns that a contempt value of 20 would be worse than a value of 7, but a test with 20000 games at STC was neutral: STC: ELO: 0.45 +-3.1 (95%) LOS: 61.2% Total: 20000 W: 4222 L: 4196 D: 11582 http://tests.stockfishchess.org/tests/view/5a64d2fd0ebc590297903868 See the comments in pull request 1361 for the long, nice discussion (180 entries :-)) leading to the decision to propose contempt 20 as the default value: official-stockfish#1361 Whether Stockfish should strictly adhere to the Komodo and Houdini semantics and add the UCI commands to force the contempt to be White in the so-called "analysis mode" is still under discussion, and may be or may not be the object of a future commit. Bench: 5783344
The round 2 of TCEC season 10 demonstrated the benefit of having a nice contempt implementation: it gives the strongest programs in the tournament the ability to slow down the game when they feel the position is slightly worse, preferring to stay in a complicated (even if slightly risky) middle game rather than simplifying by force into a drawn endgame.
The current contempt implementation of Stockfish is inadequate, and this patch is an attempt to provide a better one.
Passed STC non-regression test against master:
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 83360 W: 15089 L: 15075 D: 53196
http://tests.stockfishchess.org/tests/view/5a1bf2de0ebc590ccbb8b370
This contempt implementation is showing promising results in certains situations. For instance, it obtained a nice +30 Elo gain when playing with contempt=40 against Stockfish 7, compared to current master:
• master against SF 7 (20000 games at LTC): +121.2 Elo
• this patch with contempt=40 (20000 games at LTC): +154.11 Elo
This was the result of real cooperative work from the Stockfish team, with key ideas coming from Stefan Geschwentner (locutus2) and Chris Cain (ceebo) while most of the community helped with feedback and computer time.
In this commit the bench is unchanged by default, but you can test at home with the new contempt in the UCI options. The style of play will change a lot when using contempt different of zero (I repeat: not done in this version by default, however)!
The Stockfish team is still deliberating over the best default contempt value in self-play and the best contempt modeling strategy, to help users choosing a contempt value when playing against much weaker programs. These informations will be given in future commits when available :-)
Bench: 5051254