Why computing K that minimizes the sigmoid func. value?...

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Why computing K that minimizes the sigmoid func. value?.

Post by cdani »

I just implemented the function to try to minimize k for Andscacs, but I found that the best k is 1. Is possible that can be 1?
Thanks!

abstract:

Code: Select all

void minimize_k() {
	double e, k;
	for &#40;k = 1; k < 2; k += 0.05&#41; &#123;
		e = calc_e&#40;k&#41;;
		printf&#40;"with k = %f, e = %f\n", k, e&#41;;
	&#125;
&#125;

double calc_e&#40;double k&#41; &#123;
	addition = 0;
	n = 0;
	for each position &#123;
		s = quiesce&#40;position&#41;;
		Sigmoid = 1.0 / &#40;1.0 + pow&#40;10.0, (-k&#41; * &#40;double&#41;s / 400.0&#41;);
		addition += &#40;game_result - Sigmoid&#41; * &#40;game_result - Sigmoid&#41;;
		n++;
	&#125;
	return 1.0 / n * addition;
&#125;
Result:

Code: Select all

with k = 1.000000, e = 0.146207
with k = 1.050000, e = 0.146228
with k = 1.100000, e = 0.146249
with k = 1.150000, e = 0.146270
with k = 1.200000, e = 0.146291
with k = 1.250000, e = 0.146311
with k = 1.300000, e = 0.146332
with k = 1.350000, e = 0.146351
with k = 1.400000, e = 0.146371
with k = 1.450000, e = 0.146390
with k = 1.500000, e = 0.146409
with k = 1.550000, e = 0.146428
with k = 1.600000, e = 0.146446
with k = 1.650000, e = 0.146464
with k = 1.700000, e = 0.146482
with k = 1.750000, e = 0.146500
with k = 1.800000, e = 0.146517
with k = 1.850000, e = 0.146534
with k = 1.900000, e = 0.146551
with k = 1.950000, e = 0.146568
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: Why computing K that minimizes the sigmoid func. value?.

Post by brtzsnr »

You didn't try with K<1. Mine is 0.5.
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Why computing K that minimizes the sigmoid func. value?.

Post by AlvaroBegue »

If you make a plot of your numbers, you'll see that they are pretty much on a straight line. That means that the optimal K is much less than 1 (nothing wrong with that).
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Why computing K that minimizes the sigmoid func. value?.

Post by cdani »

Thanks! Somehow I thought that must be over 1 :-)

Anyway I started from -1 to 1, and the best is "0", and the results form an absolute straight line. Maybe I'm doing something bad...

Code: Select all

with k = -1.000000, e = 0.146227
with k = -0.950000, e = 0.146204
with k = -0.900000, e = 0.146180
with k = -0.850000, e = 0.146156
with k = -0.800000, e = 0.146132
with k = -0.750000, e = 0.146108
with k = -0.700000, e = 0.146084
with k = -0.650000, e = 0.146059
with k = -0.600000, e = 0.146034
with k = -0.550000, e = 0.146010
with k = -0.500000, e = 0.145985
with k = -0.450000, e = 0.145961
with k = -0.400000, e = 0.145937
with k = -0.350000, e = 0.145915
with k = -0.300000, e = 0.145894
with k = -0.250000, e = 0.145874
with k = -0.200000, e = 0.145857
with k = -0.150000, e = 0.145843
with k = -0.100000, e = 0.145831
with k = -0.050000, e = 0.145814
with k = 0.000000, e = 0.145790
with k = 0.050000, e = 0.145816
with k = 0.100000, e = 0.145835
with k = 0.150000, e = 0.145849
with k = 0.200000, e = 0.145863
with k = 0.250000, e = 0.145880
with k = 0.300000, e = 0.145899
with k = 0.350000, e = 0.145919
with k = 0.400000, e = 0.145940
with k = 0.450000, e = 0.145962
with k = 0.500000, e = 0.145984
with k = 0.550000, e = 0.146006
with k = 0.600000, e = 0.146029
with k = 0.650000, e = 0.146051
with k = 0.700000, e = 0.146074
with k = 0.750000, e = 0.146096
with k = 0.800000, e = 0.146119
with k = 0.850000, e = 0.146141
with k = 0.900000, e = 0.146163
with k = 0.950000, e = 0.146185
with k = 1.000000, e = 0.146207
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Why computing K that minimizes the sigmoid func. value?.

Post by cdani »

Refining it also is 0:

Code: Select all

with k = -0.010000, e = 0.145792
with k = -0.009000, e = 0.145791
with k = -0.008000, e = 0.145791
with k = -0.007000, e = 0.145791
with k = -0.006000, e = 0.145791
with k = -0.005000, e = 0.145790
with k = -0.004000, e = 0.145790
with k = -0.003000, e = 0.145790
with k = -0.002000, e = 0.145790
with k = -0.001000, e = 0.145790
with k = 0.000000, e = 0.145790
with k = 0.001000, e = 0.145790
with k = 0.002000, e = 0.145790
with k = 0.003000, e = 0.145790
with k = 0.004000, e = 0.145791
with k = 0.005000, e = 0.145791
with k = 0.006000, e = 0.145791
with k = 0.007000, e = 0.145791
with k = 0.008000, e = 0.145792
with k = 0.009000, e = 0.145792
with k = 0.010000, e = 0.145792
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Why computing K that minimizes the sigmoid func. value?.

Post by cdani »

I think I've found the problem. I should return the value of quiesce function relative to white, not to the one that moves :-)

So my k is -0.028. I suppose there is nothing bad in having a negative number...

Code: Select all

with k = -0.040000, e = 0.6671677316
with k = -0.039000, e = 0.6671676291
with k = -0.038000, e = 0.6671675316
with k = -0.037000, e = 0.6671674399
with k = -0.036000, e = 0.6671673546
with k = -0.035000, e = 0.6671672766
with k = -0.034000, e = 0.6671672067
with k = -0.033000, e = 0.6671671457
with k = -0.032000, e = 0.6671670946
with k = -0.031000, e = 0.6671670543
with k = -0.030000, e = 0.6671670258
with k = -0.029000, e = 0.6671670101
with k = -0.028000, e = 0.6671670083
with k = -0.027000, e = 0.6671670216
with k = -0.026000, e = 0.6671670510
with k = -0.025000, e = 0.6671670976
with k = -0.024000, e = 0.6671671628
with k = -0.023000, e = 0.6671672476
with k = -0.022000, e = 0.6671673534
with k = -0.021000, e = 0.6671674812
with k = -0.020000, e = 0.6671676324
with k = -0.019000, e = 0.6671678081
with k = -0.018000, e = 0.6671680097
with k = -0.017000, e = 0.6671682382
with k = -0.016000, e = 0.6671684948
with k = -0.015000, e = 0.6671687806
with k = -0.014000, e = 0.6671690968
with k = -0.013000, e = 0.6671694444
with k = -0.012000, e = 0.6671698242
with k = -0.011000, e = 0.6671702373
with k = -0.010000, e = 0.6671706844
petero2
Posts: 687
Joined: Mon Apr 19, 2010 7:07 pm
Location: Sweden
Full name: Peter Osterlund

Re: Why computing K that minimizes the sigmoid func. value?.

Post by petero2 »

cdani wrote:I think I've found the problem. I should return the value of quiesce function relative to white, not to the one that moves :-)

So my k is -0.028. I suppose there is nothing bad in having a negative number...

Code: Select all

with k = -0.028000, e = 0.6671670083
Yes, the quiesce function value should be relative to white. I forgot to mention this in the algorithm description.

I would expect K to be between roughly 0.5 and 2.0 if your base pawn value is roughly 100. A negative K would mean that a higher score corresponds to an increased probability of losing, which does not make sense.

Also your E value seems strange. With such a small K, I would expect the sigmoid function to evaluate to approximately 0.5 for most training positions, which would make the error for a position at most 0.5^2 = 0.25, so the average should not be 0.667.

I suspect something is wrong in your implementation.
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Why computing K that minimizes the sigmoid func. value?.

Post by cdani »

petero2 wrote:
cdani wrote:I think I've found the problem. I should return the value of quiesce function relative to white, not to the one that moves :-)

So my k is -0.028. I suppose there is nothing bad in having a negative number...

Code: Select all

with k = -0.028000, e = 0.6671670083
Yes, the quiesce function value should be relative to white. I forgot to mention this in the algorithm description.

I would expect K to be between roughly 0.5 and 2.0 if your base pawn value is roughly 100. A negative K would mean that a higher score corresponds to an increased probability of losing, which does not make sense.

Also your E value seems strange. With such a small K, I would expect the sigmoid function to evaluate to approximately 0.5 for most training positions, which would make the error for a position at most 0.5^2 = 0.25, so the average should not be 0.667.

I suspect something is wrong in your implementation.
Yes! Was wrong! I found it. Now a first estimation is
k = 1.286000, e = 0.1451990338

Thanks for all!! I will explain all the results obtained. I expect (I hope) a considerable improvement of Andscacs, because it was never automatically tuned from when I compared to Stockfish evaluation and with this arrived to something like 2400. So until now it has been done all by hand.
mvk
Posts: 589
Joined: Tue Jun 04, 2013 10:15 pm

Re: Why computing K that minimizes the sigmoid func. value?.

Post by mvk »

cdani wrote:Yes! Was wrong! I found it. Now a first estimation is
k = 1.286000, e = 0.1451990338
Those look like normal numbers for a qsearch.

One thing: It is easier to report the residual as sqrt of the average squared error, because then it is the same unit as sigmoid(s) and game outcome. In this case sqrt(0.1451..) = 38%. This is slightly high, but definitely not abnormal for an untuned function.

With only a little bit of tuning effort you should be able to get it near or below 30%, depending on the completeness of your eval. Sub-30% should be possible when you have both passer evaluation and king safety. Floyd is currently around 32%, Rookie is around 27%.
[Account deleted]
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Why computing K that minimizes the sigmoid func. value?.

Post by cdani »

mvk wrote:
cdani wrote:Yes! Was wrong! I found it. Now a first estimation is
k = 1.286000, e = 0.1451990338
Those look like normal numbers for a qsearch.

One thing: It is easier to report the residual as sqrt of the average squared error, because then it is the same unit as sigmoid(s) and game outcome. In this case sqrt(0.1451..) = 38%. This is slightly high, but definitely not abnormal for an untuned function.

With only a little bit of tuning effort you should be able to get it near or below 30%, depending on the completeness of your eval. Sub-30% should be possible when you have both passer evaluation and king safety. Floyd is currently around 32%, Rookie is around 27%.
Thanks!

Well, Andscacs is like 3100 elo at CCRL 4CPU, and I have passer evaluation and king safety in it, you can believe me :-)

So maybe when it's dawn to 30% it will be 3200 elo :-) :-) :-)