Computer Chess Club Archives


Search

Terms

Messages

Subject: Small refinement to Hastings' approximation (OT)

Author: Eelco de Groot

Date: 07:15:47 01/22/06

Go up one level in this thread


On January 21, 2006 at 22:26:17, Eelco de Groot wrote:

>On January 20, 2006 at 23:03:07, Jeff Lischer wrote:
>
>>How is the last column in the cross table at
>>http://www.chesscenter.com/twic/event/wijk06/results.html calculated? I tried
>>the TPR equation I know about -- average elo of opponents + (# wins - #
>>losses)/# games -- but that didn't give same numbers. For Anand I go 2843, but
>>the value in the cross table is 2834.
>>
>>Is the last column a performance rating of some sort? If it is, guess who has
>>the highest performance so far at Wijk aan Zee?
>
>Hi Jeff,
>
>Here is an example with Hasting's approximation to integrate the Gaussian normal
>distribution, in Pascal code and Gunnar's code for a VBA Excel macro.
>
>In C it is probably easier to look for an erf (error function), see posts by
>Dieter in that thread; I'm curious if the Elo.gif link still works!
>
>
> Eelco
>-------------------------------------------------------------------------------
>Posted by Odd Gunnar Malin (Profile) on April 21, 2005 at 10:46:15:
>
>In Reply to: Re: Wow! Re: Slide rules at the ready! posted by Eelco de Groot on
>April 21, 2005 at 09:57:34:
>
>
>On April 21, 2005 at 09:57:34, Eelco de Groot wrote:
>
>>I changed the Rtdiff routine so that it should now converge faster, using not a
>>slope of fixed 700 everytime but making use of the fact that I can calculate the
>>slope in Performance vs. Ratingdifference when assuming the normal distribution.
>>I believe this is similar to Newton's method, for finding the roots of a graph
>>or function numerically? But here I actually now the precise slope.
>>
>>But if Hastings approximation is just not good enough or I have forgotten
>>another minus sign....it will of course not work... So I'll try to put this into
>>an actual program. I have never made macro's for Excel yet, I will certainly try
>>that now that you showed me how, Odd Gunnar! That is probably the easiest thing
>>to do.
>>
>>These are the new routines, until further notice...:
>>
>>FUNCTION phi(x:REAL):REAL;
>>CONST 	p=0.2316419;
>>	c1=0.31938153;
>>	c2=-0.356563782;
>>	c3=1.78147937;
>>	c4=-1.821255978;
>>	c5=1.330274429;
>>VAR t,sndf:REAL;
>>BEGIN
>>  sndf:=EXP(-SQR(x)/2)/SQRT(2*PI);
>>  t:=1/(p*x+1);
>>  phi:=-(((((c5*t+c4)*t+c3)*t+c2)*t+c1)*t*sndf)+1;
>>END;
>>
>>
>>
>>FUNCTION Rtdiff(Performance:REAL):REAL;
>>CONST	tol=0.0001;
>>	sdev=200*SQRT(2);
>>VAR delta,slope:REAL;
>>BEGIN
>>  slope:=708;
>>  Rtdiff:=(Performance-0.50)*slope;
>>  delta:=1
>>  WHILE delta >= tol DO BEGIN
>>     Iteration:=phi(Rtdiff/sdev);
>>     delta:=Performance-Iteration;
>>     slope:=400*SQRT(PI)*EXP(SQR(Rtdiff/sdev)/2);
>>     Rtdiff:=Rtdiff+(delta*slope);
>>  END;
>>END;
>>
>>
>>Regards, Eelco
>>
>
>Now you have it!
>http://home.online.no/~malin/sjakk/elo.gif
>Your number are equal with Excels Norm.dist function.
>
>  Score      FIDE     Log10   Norm.dist. Schmitt     W-L      Groot
>   0,50       0         0         0         0         0         0
>   0,51       7         7         7         7         8         7
>   0,52       14        14        14        14        16        14
>   0,53       21        21        21        21        24        21
>   0,54       29        28        28        28        32        28
>   0,55       36        35        36        36        40        36
>   0,56       43        42        43        43        48        43
>   0,57       50        49        50        50        56        50
>   0,58       57        56        57        57        64        57
>   0,59       65        63        64        65        72        64
>   0,60       72        70        72        72        80        72
>   0,61       80        78        79        79        88        79
>   0,62       87        85        86        87        96        86
>   0,63       95        92        94        94       104        94
>   0,64      102       100       101       102       112       101
>   0,65      110       108       109       110       120       109
>   0,66      117       115       117       118       128       117
>   0,67      125       123       124       125       136       124
>   0,68      133       131       132       133       144       132
>   0,69      141       139       140       142       152       140
>   0,70      149       147       148       150       160       148
>   0,71      158       156       157       158       168       157
>   0,72      166       164       165       167       176       165
>   0,73      175       173       173       175       184       173
>   0,74      184       182       182       184       192       182
>   0,75      193       191       191       193       200       191
>   0,76      202       200       200       202       208       200
>   0,77      211       210       209       211       216       209
>   0,78      220       220       218       221       224       218
>   0,79      230       230       228       231       232       228
>   0,80      240       241       238       241       240       238
>   0,81      251       252       248       251       248       248
>   0,82      262       263       259       262       256       259
>   0,83      273       275       270       273       264       270
>   0,84      284       288       281       285       272       281
>   0,85      296       301       293       297       280       293
>   0,86      309       315       306       309       288       306
>   0,87      322       330       319       322       296       319
>   0,88      336       346       332       336       304       332
>   0,89      351       363       347       350       312       347
>   0,90      366       382       362       366       320       362
>   0,91      383       402       379       382       328       379
>   0,92      401       424       397       400       336       397
>   0,93      422       449       417       420       344       417
>   0,94      444       478       440       443       352       440
>   0,95      470       512       465       468       360       465
>   0,96      501       552       495       499       368       495
>   0,97      538       604       532       539       376       532
>   0,98      589       676       581       597       384       581
>   0,99      677       798       658       685       392       658
>   1,00
>
>Excel format (basic) of your code:
>
>Function phi(x)
>  p = 0.2316419
>  c1 = 0.31938153
>  c2 = -0.356563782
>  c3 = 1.78147937
>  c4 = -1.821255978
>  c5 = 1.330274429
>  Pi = 3.14159265358979
>  sndf = Exp(-(x * x) / 2) / Sqr(2 * Pi)
>  t = 1 / (p * x + 1)
>  phi = -((((c5 * t + c4) * t + c3) * t + c2) * t + c1) * t * sndf + 1
>End Function
>
>Function Rtdiff(Performance)
>  Pi = 3.14159265358979
>  tol = 0.0001
>  sdev = 200 * Sqr(2)
>  Slope = 708
>  Rtdiff2 = (Performance - 0.5) * Slope
>  delta = 1
>  Do While delta >= tol
>    Iteration = phi(Rtdiff / sdev)
>    delta = Performance - Iteration
>    Slope = 400 * Sqr(Pi) * Exp((Rtdiff * Rtdiff) / (sdev * sdev * 2))
>    Rtdiff = Rtdiff + (delta * Slope)
>  Loop
>End Function
>
>Odd Gunnar

I think I can make a small refinement to the constants derived by Hastings for
an Excel formula that fits a little bit better to the Gaussian normal
distribution but it is possible that this only works because of limited accuracy
in Excel '97 of the Excel-funtions used and the way above Functions are
declared. With the following new constants c1;c2;c3;c4 and c5 put in a Visual
Basic macro for Excel

Function phi(x)
  Dim sndf, t
  p = 0.2316419
  c1 = 0.31938128
  c2 = -0.3565641
  c3 = 1.7814791
  c4 = -1.821256282
  c5 = 1.33027414
  Pi = 3.14159265358979
  sndf = Exp(-(x * x) / 2) / Sqr(2 * Pi)
  t = 1 / (p * x + 1)
  phi = 1 - ((((c5 * t + c4) * t + c3) * t + c2) * t + c1) * t * sndf
End Function

Excel gives a slight improvement in accuracy compared to Hastings'
approximation. Of course I can try to find longer constants but I wanted to use
about the same number of digits for the approximation. I umade use of the fact
that the sum of constants can be calculated when x=0:
-(c1+c2+c3+c4+c5)(1/Sqr(2*Pi))+1 = 0.5

This gives the following table:

x       Hastings       		Stand.Norm.Distr.() 	Literature     		De Groot

1	0,841344555035685	0,841344740241004	0,841344746068543	0,841344746295654
0	0,499999429558617	0,499999999781721	0,500000000000000	0,499999999726924
0,1	0,539827365793949	0,539827895533667	0,539827836277202	0,539827895193751
0,2	0,579259199184307	0,579259687166727				0,579259687073719
1,333..	0,908788607944409	0,908788712559023				0,908788718694483
2	0,977249913313505	0,977249937963813	0,977249868051820	0,977249941093487
2,5	0,993790313772571	0,993790320141254				0,993790321352687
3	0,998650031474427	0,998650032776765	0,998650101968369	0,998650033118302
3,5	0,999767326415994	0,999767326626331				0,999767326698293
4	0,999968313938607	0,999968313965391				0,999968313976886
0,5	0,691462105046245	0,691462467364291	0,691462461274013	0,691462469728087
4,5	0,999996599194253	0,999996599196938				0,999996599198342
5	0,999999712894789	0,999999712895000				0,999999712895132
5,5	0,999999980963588	0,999999980963601				0,999999980963611
6	0,999999999009877	0,999999999009878				0,999999999009879


STAND.NORM.VERD is Excel's own approximation function, I tranlated the Dutch
functionname to English. As can be seen the Excel function gives very similar
values to my last approximation and to the literature values. The approximation
can only be used for positive values. It is easy to convert a negative x to a
positive; phi(-x) = 1 - phi(x).

 Eelco




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.