An idea of how to make your engine play more rational chess

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: An idea of how to make your engine play more rational ch

Post by Don »

AlvaroBegue wrote:I thought about a similar method in the past, but I never did anything about it. My plan was to make an evaluation function that computes both the expected value of the evaluation of a depth-8 search (say) and its standard deviation. You can then use the logistic function to map scores to expected number of points earned in this game.

If you scale your scores appropriately, you can get the expected number of points earned in this game (0 for losing, 1/2 for drawing, 1 for winning) as approximately 1/(1+exp(-score)).

If you model your score as a normal distribution with mean m and standard deviation s, the expected number of points earned is

Integral(normal_distribution_density(x,m,s) / (1+exp(-x))), where the integral is to be evaluated from -infinity to infinity. I will check with Mathematica to see if it can be done analytically, but I can always compute it numerically for a grid of values of m and s and then interpolate.

A large standard variation will naturally result in a bonus if you are behind and a penalty if you are ahead.
I have often thought of similar ideas. Not all equal score are really "equal" in this sense. If you can estimate the error of various evaluation features your score falls within a range of possible values.
Capital punishment would be more effective as a preventive measure if it were administered prior to the crime.
Pio
Posts: 334
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: An idea of how to make your engine play more rational ch

Post by Pio »

Hi Don!

You can prove on fixed node-games that the idea will not be a regression in any case since you could always set all the features' optimistic values to zero :)

It is just a matter if it is worth the additional computing cost. And I am pretty sure that it is worth it.

One way of getting a first guess of the optimistic values might for instance be to evaluate some random positions occuring in your games, but probably not more than one position from each game since you will get biased then, and compare the results with a deep search of that position. I think the deep search will correspond more to the optimistic value of the position and the evaluation of the original position will correspond more to the pessimistic value of the position. When you have many more positions than parameters to tune you do least square fitting of the parameters for the deeper searches.

As an example lets say that you have made your evaluation function as a sum over the set of features {f1, f2 ,f3, ..., fn}. First evaluate your postions p1 to pm with m>>n without any search so that you get
(f1sideToMove(p1) - f1sideToRest(p1)) + (f2sideToMove(p1) - f2sideToRest(p1)) + ... + (fnsideToMove(p1) - fnsideToRest(p1)) = value(p1static). Then do the same with the deeper search but assume that each feature is multiplied by a constant (fi * ci) where ci is constant number i, that is sum((fiSideToMove(p1) - fisideToRest(p1)) * ci(p1)) = value(p1deepSearch). Take the left hand side of the second equation and subtract the first equation and do the same for the right hand side. Then make the equation on the form SUM(ci*vi) = v where each vi is constant and v is a constant. Do that for all the postions p1 to pm and put up a matrix. Then do least square fitting with respect to ci. Finally when you have the ci values the optimistic feature multiplier will equal to ci - 1, which will be both positive and negative.

It is just a rough idea of how you might do it. I am to tired now and have to sleep. I hope I have not written to much nonsens.

Good luck!!!
Pio
Posts: 334
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: An idea of how to make your engine play more rational ch

Post by Pio »

Hi all of you!

If you make any progress please let me know, and if you have some problems I would be happy to help out if I can.

What is interesting is to see what kind of impact this type of change has on the draw ratio. I guess the draw ratio will be slightly less after implementation of the idea but I am often wrong :)
zamar
Posts: 613
Joined: Sun Jan 18, 2009 7:03 am

Re: An idea of how to make your engine play more rational ch

Post by zamar »

AlvaroBegue wrote:
A large standard variation will naturally result in a bonus if you are behind and a penalty if you are ahead.
And even more importantly, you could use this for pruning decisions. If you are 2 pawn ahead and evaluation standard deviation is small, you can quite safely prune early. If you are 2 pawns ahead, but evaluation standard deviation is huge (passed pawns, king safety) you shouldn't prune.

I never had time to put this into practice, but there definitely is a lot of potential.
Joona Kiiski
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: An idea of how to make your engine play more rational ch

Post by AlvaroBegue »

zamar wrote:
AlvaroBegue wrote:
A large standard variation will naturally result in a bonus if you are behind and a penalty if you are ahead.
And even more importantly, you could use this for pruning decisions. If you are 2 pawn ahead and evaluation standard deviation is small, you can quite safely prune early. If you are 2 pawns ahead, but evaluation standard deviation is huge (passed pawns, king safety) you shouldn't prune.

I never had time to put this into practice, but there definitely is a lot of potential.
Oh, that sounds promising. I didn't think of trying to use this for a pruning scheme.
jd1
Posts: 269
Joined: Wed Oct 24, 2012 2:07 am

Re: An idea of how to make your engine play more rational ch

Post by jd1 »

Pio wrote:Hi all of you!

If you make any progress please let me know, and if you have some problems I would be happy to help out if I can.

What is interesting is to see what kind of impact this type of change has on the draw ratio. I guess the draw ratio will be slightly less after implementation of the idea but I am often wrong :)
Hi Pio!

Have been busy but I've got a version which uses your idea for a very small improvement as I have not tuned it much.

I do it slightly differently however -
I compute eval and uncertainty. Uncertainty is applied to passed pawns, king safety, trapped pieces. If the score is winning > 1.50 pawns, I add an adjustment based on the uncertainty. For example:

score: 4.00
uncertainty 1.50
Statistically determined average uncertainty: 1.00
Adjustment: -0.50

For lower evaluations, e.g. 2 pawns, the adjustment is scaled to be smaller.
The formula I use is
factor = abs(score) - win threshold.
adjustment = (uncertainty-average uncertainty)*factor/scaling.

Jerry