TalkChess.com
Hosted by Your Move Chess & Games

 Stockfish - material balance/imbalance evaluation Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Author Message
Ralph Stoesser

Joined: 06 Mar 2010
Posts: 294

Posted: Wed May 05, 2010 4:39 pm    Post subject: Stockfish - material balance/imbalance evaluation

Could somebody explain the below code pls.?

but I wonder what exactly Tord Romstad's polynomial function does.

Where do the coefficients come from?
Is this a formula which translates Kaufman's findings or is it something independent?

material.cpp, starting line 324, SF 1.7.1
 Code: // Redundancy of major pieces, formula based on Kaufman's paper     // "The Evaluation of Material Imbalances in Chess"     // http://mywebpages.comcast.net/danheisman/Articles /evaluation_of_material_imbalance.htm     if (pieceCount[c][ROOK] >= 1)         matValue -= sign * ((pieceCount[c][ROOK] - 1) * RedundantRookPenalty + pieceCount[c][QUEEN] * RedundantQueenPenalty);     them = opposite_color(c);     v = 0;     // Second-degree polynomial material imbalance by Tord Romstad     //     // We use NO_PIECE_TYPE as a place holder for the bishop pair "extended piece",     // this allow us to be more flexible in defining bishop pair bonuses.     for (pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; pt1++)     {         pc = pieceCount[c][pt1];         if (!pc)             continue;         vv = LinearCoefficients[pt1];         for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)             vv +=  pieceCount[c][pt2] * QuadraticCoefficientsSameColor[pt1][pt2]                  + pieceCount[them][pt2] * QuadraticCoefficientsOppositeColor[pt1][pt2];         v += pc * vv;     }     matValue += sign * v;
Marco Costalba

Joined: 14 Jun 2008
Posts: 2097

 Posted: Wed May 05, 2010 4:48 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation Only "Redundancy of major pieces" is from Kaufman's paper, "Second-degree polynomial material imbalance" is fully from Tord....well idea is from Tord, implementation and coefficents tuning from me and Joona (and it took more then one month!)
Ralph Stoesser

Joined: 06 Mar 2010
Posts: 294

 Posted: Wed May 05, 2010 5:37 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation Hi Marco, Wow, one month of work! Kudos! I never thought that "piece counting" could be that hard. How did you find the coefficients?
Marco Costalba

Joined: 14 Jun 2008
Posts: 2097

Posted: Wed May 05, 2010 5:47 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation

 Ralph Stoesser wrote: Hi Marco, Wow, one month of work! Kudos! I never thought that "piece counting" could be that hard. How did you find the coefficients?

Well implemantation of course took just few minutes, the problem is the tuning of the corfficents that took a lot.

We used automatic tuning, but we needed different attempts before to find a way to actually get out something good from background noise. This material balance gives some gain, but is not a big gain (at least we didn't find a big gain) so changing the coefficents resulted in _almost_ no change, that's the reason that automatic tuning took a very long time and many attempts before to converge to something measurable.
Jan Brouwer

Joined: 22 Mar 2007
Posts: 198
Location: Netherlands

 Posted: Wed May 05, 2010 5:49 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation It seems to add for each of my pieces a value which is a linear function of the number of my and your pieces of each piece type not more valuable than the piece under consideration. It is probably a "2nd order" correction to a base piece value. I don't quite understand the need for LinearCoefficients[].
Eelco de Groot

Joined: 12 Mar 2006
Posts: 2596
Location: Groningen

Posted: Wed May 05, 2010 7:25 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation

 Jan Brouwer wrote: It seems to add for each of my pieces a value which is a linear function of the number of my and your pieces of each piece type not more valuable than the piece under consideration. It is probably a "2nd order" correction to a base piece value. I don't quite understand the need for LinearCoefficients[].

Just like two bishops of opposite color can be more than the sum of the two pieces alone, that idea is generalized to all the possible piece pairs, including the relations with pieces of the other side. The relation is put into the form of a + bx + cxy, a second order approximation of the real relation but the a falls out of the relation because the sum of the equations for White and Black goes through the origin, otherwise this introduces color asymmetry. vv is if I rememer correctly then the b coefficient for the piece type x, vv is multiplied with the piececount of the corresponding piecetype, x in our description, and after adding the second order relations this is added to the term v.

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
Joona Kiiski

Joined: 18 Jan 2009
Posts: 548

 Posted: Wed May 05, 2010 7:54 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation In short, the idea is that pieces affect the value of each other. Here we give bonus and penalties for different duos (like bishop and knight, pawn and pawn, queen and rook, etc.). "Bishop pair" is a special piece in this implementation. But as Marco already mentioned, this is not a big deal, maybe around +15 elo or sth like that. We expected more, but fine tuning was extremely difficult._________________Joona Kiiski
Ralph Stoesser

Joined: 06 Mar 2010
Posts: 294

 Posted: Wed May 05, 2010 8:02 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation Thanks Eelco. Now it's clearer what this code does. But I still wonder a little why there is no distinction between white colored bishop and black colored bishop, because our white colored bishop would relate in another way to their white colored bishop than to their black colored bishop. Besides I wonder whether it is a good idea to relate our piece type to their piece type. I must think a while about it, hopefully not a full month. Btw: Thanks also @Joona.
Ralph Stoesser

Joined: 06 Mar 2010
Posts: 294

Posted: Wed May 05, 2010 8:28 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation

 zamar wrote: "Bishop pair" is a special piece in this implementation.

Yeah, this is well documented, but not the idea behind the imbalance calculation itself.
Also I cannot see an advantage in using a special bishop pair type, because, at least to me, it seems very hard to play around with this code anyway.
Eelco de Groot

Joined: 12 Mar 2006
Posts: 2596
Location: Groningen

Posted: Wed May 05, 2010 10:10 pm    Post subject: Re: Stockfish - material balance/imbalance evaluation

 Ralph Stoesser wrote: Thanks Eelco. Now it's clearer what this code does. But I still wonder a little why there is no distinction between white colored bishop and black colored bishop, because our white colored bishop would relate in another way to their white colored bishop than to their black colored bishop. Besides I wonder whether it is a good idea to relate our piece type to their piece type. I must think a while about it, hopefully not a full month. Btw: Thanks also @Joona.

Hello Ralph,

Yes, I think you are right that that is something of a weakness. I had not noticed this myself yet, good that you say it! Also from the top of my head elsewhere in the code when we have two bishops it is assumed these are opposite coloured bishops. It is commented that it would be better to do an explicit check because one or more of these bishops might be underpromoted, so they could be of the same colour.

The our piece to their type piece relationships are I think fairly necessary because this is all about imbalanced positions, well otherwise the whole calculation would always result in zero of course. So for every combination of our pieces, there are still countless ways of how the opponents pieces are assembled. Each of these combinations can be thought of as a subgame in the game of chess, and every transition from one combination to another -especially if an imbalance is created- breaks some "symmetries" to use an analogy from cosmology, it changes the rules of the game slightly, in an n-dimensional landscape I imagine it is a bit like a crossing, like climbing or descending a mountain range to a different valley, a little higher or a little lower in average altitude, where there live different people, in a matter of speaking, using different mores, a different language or playing different games.

Every transition can improve or worsen your position, and to each new landscape you have to adapt the program. It could maybe be said that mastery of these transitions distinguishes the true masters of the game, it forces the flow of the game from opening to endgame.

Regards, 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMTGoto page 1, 2, 3, 4, 5, 6, 7, 8, 9  Next Page 1 of 9

 Jump to: Select a forum Computer Chess Club Forums----------------Computer Chess Club: General TopicsComputer Chess Club: Tournaments and MatchesComputer Chess Club: Programming and Technical DiscussionsComputer Chess Club: Engine Origins Other Forums----------------Chess Thinkers ForumForum Help and Suggestions
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum