A different way of summing evaluation features

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: A different way of summing evaluation features

Post by zullil »

syzygy wrote:
zullil wrote:But maybe I'm missing something ...
Some kind of Euclidean distance between "white's position" and "black's position" would only measure the dissimilarity between the two. That is of no use whatsoever as a measure of how good the position is for white or for black. (Well, if white and black's positions are identical, the evaluation should indeed be close to zero, but that's really it.)
I'm not sure I understand the OP. But maybe a simple example would help (or reveal that he means something different). Suppose we wish to evaluate a position with respect to the side-to-move. For simplicity, suppose we only consider "mobility" and "king safety". Say each is assigned an (int) value between 0 and 15 inclusive. Suppose we decide that mobility is twice as important as king safety, so we weight the former with coefficient 2 and the latter with coefficient 1. Suppose we have a position where the (base) mobility eval is 10 and the (base) king safety eval is 5.

Then one way to compute the total eval is 2 * 10 + 1 * 5 = 25. This amounts to calculating the taxi distance from (20, 5) to the origin. I think the OP's suggestion is to calculate the total as something like sqrt(20^2 + 5^2) instead, which would be the euclidean distance.

I still don't see any advantage to the OP's approach ...
User avatar
hgm
Posts: 27795
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: A different way of summing evaluation features

Post by hgm »

Although the OP's proposal is rather vague, there still could be something in it. The point is that in a root-mean-square combination the most extreme feature tends to dominate. This might actually correspond to what you need in Chess. E.g. when you have the choice between weakening your opponent's King safety or his Pawn structure by an amount that in itself would give about an equal advantage (in terms of win probability), it is probably better to go for further weakening his King safety when that was already compromised and his Pawn structure was average, and vice versa. So some non-linearity in combiningthe eval terms, like squaring them before addition, is not completely crazy.

The idea as given seems non-sensical though, as negative values for a certain term would give a total evaluation that is indistinguishable from when it had an equal positive value. Adding all terms corresponding to a certain aspect of the position, and applying a non-linear correction to that, does make sense, though. And to determine King safety from the number of individual attacks on the King neighborhood, this is actually somewhat standard.

Focus on the most imbalanced aspect, because that is most likely to decide the game. Aspects could be white and black King safety, Pawn structure, material advantage. When the opponent King safety is low, you want to lower it further at the expense of material. While when it was good, but you were ahead in material, you would probably be happy to gain that same amount of material for allowing him to increase his King safety by the same amount.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: A different way of summing evaluation features

Post by bob »

hgm wrote:Although the OP's proposal is rather vague, there still could be something in it. The point is that in a root-mean-square combination the most extreme feature tends to dominate. This might actually correspond to what you need in Chess. E.g. when you have the choice between weakening your opponent's King safety or his Pawn structure by an amount that in itself would give about an equal advantage (in terms of win probability), it is probably better to go for further weakening his King safety when that was already compromised and his Pawn structure was average, and vice versa. So some non-linearity in combiningthe eval terms, like squaring them before addition, is not completely crazy.

The idea as given seems non-sensical though, as negative values for a certain term would give a total evaluation that is indistinguishable from when it had an equal positive value. Adding all terms corresponding to a certain aspect of the position, and applying a non-linear correction to that, does make sense, though. And to determine King safety from the number of individual attacks on the King neighborhood, this is actually somewhat standard.

Focus on the most imbalanced aspect, because that is most likely to decide the game. Aspects could be white and black King safety, Pawn structure, material advantage. When the opponent King safety is low, you want to lower it further at the expense of material. While when it was good, but you were ahead in material, you would probably be happy to gain that same amount of material for allowing him to increase his King safety by the same amount.
I would imagine that most have some sort of second-order evaluation for some things anyway. Not everything, but at least king safety comes to mind, where there is king shelter, closeness of attacking pieces, closeness of defending pieces, where combining those non-linearly makes a lot of sense.

There are other harder cases that I have not seen anyone report much success with. For example, why worry about pawn structure when your king is being attacked. Unless you have two ways to drive home the attack and one leaves you in a better position if your attack fizzles out.

Humans have a pretty innate ability to do just that, figure out what is important and what is irrelevant. Computers depend on a huge search space to discover this tactically rather than positionally.
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: A different way of summing evaluation features

Post by syzygy »

zullil wrote:
syzygy wrote:
zullil wrote:But maybe I'm missing something ...
Some kind of Euclidean distance between "white's position" and "black's position" would only measure the dissimilarity between the two. That is of no use whatsoever as a measure of how good the position is for white or for black. (Well, if white and black's positions are identical, the evaluation should indeed be close to zero, but that's really it.)
I'm not sure I understand the OP. But maybe a simple example would help (or reveal that he means something different). Suppose we wish to evaluate a position with respect to the side-to-move. For simplicity, suppose we only consider "mobility" and "king safety". Say each is assigned an (int) value between 0 and 15 inclusive. Suppose we decide that mobility is twice as important as king safety, so we weight the former with coefficient 2 and the latter with coefficient 1. Suppose we have a position where the (base) mobility eval is 10 and the (base) king safety eval is 5.

Then one way to compute the total eval is 2 * 10 + 1 * 5 = 25. This amounts to calculating the taxi distance from (20, 5) to the origin. I think the OP's suggestion is to calculate the total as something like sqrt(20^2 + 5^2) instead, which would be the euclidean distance.

I still don't see any advantage to the OP's approach ...
In more interesting positions the base mobility will be 10 and the base king safety eval will be -5. White has an advantage, but black has another advantage and it is not immediately clear which side is better. Now the Euclidean distance will still be sqrt (20^2 + 5^2), which is clearly useless.
zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: A different way of summing evaluation features

Post by zullil »

syzygy wrote:
zullil wrote:
syzygy wrote:
zullil wrote:But maybe I'm missing something ...
Some kind of Euclidean distance between "white's position" and "black's position" would only measure the dissimilarity between the two. That is of no use whatsoever as a measure of how good the position is for white or for black. (Well, if white and black's positions are identical, the evaluation should indeed be close to zero, but that's really it.)
I'm not sure I understand the OP. But maybe a simple example would help (or reveal that he means something different). Suppose we wish to evaluate a position with respect to the side-to-move. For simplicity, suppose we only consider "mobility" and "king safety". Say each is assigned an (int) value between 0 and 15 inclusive. Suppose we decide that mobility is twice as important as king safety, so we weight the former with coefficient 2 and the latter with coefficient 1. Suppose we have a position where the (base) mobility eval is 10 and the (base) king safety eval is 5.

Then one way to compute the total eval is 2 * 10 + 1 * 5 = 25. This amounts to calculating the taxi distance from (20, 5) to the origin. I think the OP's suggestion is to calculate the total as something like sqrt(20^2 + 5^2) instead, which would be the euclidean distance.

I still don't see any advantage to the OP's approach ...
In more interesting positions the base mobility will be 10 and the base king safety eval will be -5. White has an advantage, but black has another advantage and it is not immediately clear which side is better. Now the Euclidean distance will still be sqrt (20^2 + 5^2), which is clearly useless.
Pure speculation, but I think the OP intended all base values to be non-negative, with separate evals for White and Black (which would then be compared by subtraction). So White might have king safety base score = 2 and Black base score = 7. But no negatives.

Maybe I'll give up here.
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: A different way of summing evaluation features

Post by syzygy »

zullil wrote:Pure speculation, but I think the OP intended all base values to be non-negative, with separate evals for White and Black (which would then be compared by subtraction). So White might have king safety base score = 2 and Black base score = 7. But no negatives.
OK, his second post is a bit clearer and you are right. He calculates a "goodness" for both white and black and subtracts those. The "goodness" of white is the square root of the sum of the squares of certain points awarded to white, and similar for black's "goodness".

The problem that I see is that it becomes arbitrary whether to award two points to white for white's two bishops and one point to black for black's sole bishop, or whether to award one point to white for having one extra bishop. With a linear evaluation identical advantages for white and black cancel out, which, as a first approximation, seems correct.

Hmm, I suppose this can be handled by having a single evaluation term for number of bishops: number of white bishops - number of black bishops. This term goes into white's goodness if positive and into black's goodness if negative. The same must be done for all other white/black evaluation features, probably including king safety. Quite a hassle, but vector instructions might be of help here to make it somewhat efficient.

OK, so it is not all nonsense and I take back what I wrote earlier.
But I still doubt that orthogonality and invariance under rotation have any real meaning here.

I also doubt the original premiss:
I have no problem with that if it would be that the evaluation features would describe the same thing but I guess that is not the case.
The usual model is that the evaluation measures advantage in cp, and that all evaluation features describe the number of cp that something is worth. So they do describe the same thing.

Whether advantages are really additive is another question, but I see no reason why the counterproposal would be any better. To me it doesn't seem natural at all.
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: A different way of summing evaluation features

Post by syzygy »

I guess orthogonality of the evaluation features in this context simply means that a "goodness" value is a simple (weighted) sum of squares and does not include combinations such as (# of bishops) * (# of knights).

Let's ignore the problem of having to shift features between white's goodness and black's goodness depending on their sign. We just look at a set of evaluation features for white. Those are the coordinates of a vector v. Now we apparently assume that the "goodness" of white can be calculated as v_t * A * v, v_t being v transposed, and A being a symmetric matrix. We tune and tune and tune until we have optimal values for A. Now orthogonalisation has a meaning: we look for a coordinate transformation w = T*v such that v_t * A * v becomes w_t * B * w with B a diagonal matrix.

So the basic assumption is that the "goodness" of a position for white can be expressed as a quadratic function of several evaluation features and that taking the difference of goodnesses leads to a good evaluation function.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: A different way of summing evaluation features

Post by lucasart »

syzygy wrote:I guess orthogonality of the evaluation features in this context simply means that a "goodness" value is a simple (weighted) sum of squares and does not include combinations such as (# of bishops) * (# of knights).

Let's ignore the problem of having to shift features between white's goodness and black's goodness depending on their sign. We just look at a set of evaluation features for white. Those are the coordinates of a vector v. Now we apparently assume that the "goodness" of white can be calculated as v_t * A * v, v_t being v transposed, and A being a symmetric matrix. We tune and tune and tune until we have optimal values for A. Now orthogonalisation has a meaning: we look for a coordinate transformation w = T*v such that v_t * A * v becomes w_t * B * w with B a diagonal matrix.

So the basic assumption is that the "goodness" of a position for white can be expressed as a quadratic function of several evaluation features and that taking the difference of goodnesses leads to a good evaluation function.
Ronald,

Take a break. You're overthinking this.

Isn't it obvious that the OP is just pretenting to have something intelligent to say? If you scratch beneath the superficial bullshit, it's just hot air…
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: A different way of summing evaluation features

Post by syzygy »

I agree this isn't going to be of help, but I thought it would be interesting to point out what the orthogonality would come down to:

- you have to start with a quadratic evaluation;
- the orthogonalisation rewrites it, but does not change its values in any way (exactly the point of orthogonalisation).

So it's not a useful exercise.

The invariance under rotation still does not seem to have any meaning. Chess has only a couple of symmetries (of the board) and they have little to do with linear transformations of evaluation features.

Some quadratic or other non-linear terms might of course be useful, as was already pointed out.
Rein Halbersma
Posts: 741
Joined: Tue May 22, 2007 11:13 am

Re: A different way of summing evaluation features

Post by Rein Halbersma »

syzygy wrote:I agree this isn't going to be of help, but I thought it would be interesting to point out what the orthogonality would come down to:

- you have to start with a quadratic evaluation;
- the orthogonalisation rewrites it, but does not change its values in any way (exactly the point of orthogonalisation).

So it's not a useful exercise.

The invariance under rotation still does not seem to have any meaning. Chess has only a couple of symmetries (of the board) and they have little to do with linear transformations of evaluation features.

Some quadratic or other non-linear terms might of course be useful, as was already pointed out.
I don't think you need a quadratic evaluation function in order to make use of PCA. The quadratic form can also come from the sum of least squares of a linear regression. Suppose you have N (few dozen) evaluation terms, and M (few million) positions with known outcomes. Fitting the linear evaluation weights can be done through linear regression techniques (e.g. logistical regression).

But suppose many of the linear evaluation features are strongly correlated with each other. Just generate a few million chess positions from a search, and collect the vectors of their evaluation components (value times weight). Then you have a NxN correlation matrix. This correlation matrix plays the role of the distance matrix. Then you take the top K eigenvalues and the corresponding K eigenvectors of that correlation matrix, where K is chosen such that together they explain a large part (say >95%) of the variation in the observed position scores.

You can then reduce your evaulation function from N to K terms without much loss in predictive power. Redo the logistical regression to obtain K new weights (or hand-tune or CLOP your way out of it). In order for this to be a net win, you need to be able to simplify the linear combinations of the eigenvectors (otherwise, you still have to compute the original N features).

Michael Buro (of the UAlberta Games group) has written such an evaluation function for Othello using linear combination of boolean predicates over the game board. https://skatgame.net/mburo/ps/improve.pdf For chess, one could do the same, but then all the bitboard expressions such as mobility and xray attacks need to be re-expressed as boolean predicates over individual squares. Maybe the transformation to the top-K eigenvectors leads to a substantial symbolic simplification and a net win in the computational burden of computing the eval score.

In practice, this may or may not work better than current evaluation functions, but in theory it's a viable technique at least.