Help with Texel's tuning

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
maksimKorzh
Posts: 525
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Help with Texel's tuning

Post by maksimKorzh » Tue Jan 05, 2021 8:42 pm

Hi guys, I have got this pseudo code from Ronal Friederich, author of rofChade and PeSTO:

Code: Select all

repeat while sum of errors still lowers
	for each tunable parameter
		increase parameter by one
		for each testposition
			calc eval
			calc error
			sum error			
		fe
		if sum error is lowered then next parameter
		else
			decrease parameter by one
			for each testposition
				calc eval
				calc error
				sum error			
			fe
		end else	
	fe
end repeat
I have a question about "for each position" meaning:
CPW's page on Texel's tuning requires to use 64 000 games which result 8+ millions of position.
Does the loop over each test position mean to loop over 8 million positions every time adjusting a single param???
This would take several lives to complete...

What am I missing?
Maybe this means test positions per game?
Please clarify.
JavaScript chess engine with UCI support, own GUI and public API:
https://github.com/maksimKorzh/wukongJS

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

Sesse
Posts: 262
Joined: Mon Apr 30, 2018 9:51 pm
Contact:

Re: Help with Texel's tuning

Post by Sesse » Tue Jan 05, 2021 8:59 pm

Computers are fast, and can do 8 million positions in a second or less. No need for lifetimes.

Pio
Posts: 252
Joined: Sat Feb 25, 2012 9:42 pm
Location: Stockholm
Contact:

Re: Help with Texel's tuning

Post by Pio » Tue Jan 05, 2021 11:25 pm

maksimKorzh wrote:
Tue Jan 05, 2021 8:42 pm
Hi guys, I have got this pseudo code from Ronal Friederich, author of rofChade and PeSTO:

Code: Select all

repeat while sum of errors still lowers
	for each tunable parameter
		increase parameter by one
		for each testposition
			calc eval
			calc error
			sum error			
		fe
		if sum error is lowered then next parameter
		else
			decrease parameter by one
			for each testposition
				calc eval
				calc error
				sum error			
			fe
		end else	
	fe
end repeat
I have a question about "for each position" meaning:
CPW's page on Texel's tuning requires to use 64 000 games which result 8+ millions of position.
Does the loop over each test position mean to loop over 8 million positions every time adjusting a single param???
This would take several lives to complete...

What am I missing?
Maybe this means test positions per game?
Please clarify.
You can speed up the process from linear to logarithmic time w.r.t. your evaluations granularity and how far from optimum values you are. You can do this by having a variable delta for each feature (save the deltas together with if they were halved or doubled in an array of tuples (delta, halvedOrDoubled) of size nrOfFeatures) that is doubled every time The eval was improved and halved when not improved. If you have a very fine grained eval the speed up can be significant. Let’s say your feature is off by 1000 units. Then it will pass 1000 times in the original code but only 20 times with the optimised code. That is a speed up by 50 😀

User avatar
maksimKorzh
Posts: 525
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: Help with Texel's tuning

Post by maksimKorzh » Tue Jan 05, 2021 11:29 pm

Thank you guys.
I just got detailed PM from Ronald, so now it's clear and I'm almost at the stage where the first version of Texel's tuning would be implemented for my eval.
JavaScript chess engine with UCI support, own GUI and public API:
https://github.com/maksimKorzh/wukongJS

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

jdart
Posts: 4070
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: Help with Texel's tuning

Post by jdart » Wed Jan 06, 2021 2:20 am

Gradient descent can be run on parallel threads if you are using an algorithm like ADAM. Does not readily work with "mini-batches," though.

--Jon

Ferdy
Posts: 4443
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Help with Texel's tuning

Post by Ferdy » Wed Jan 06, 2021 7:00 am

maksimKorzh wrote:
Tue Jan 05, 2021 8:42 pm
Hi guys, I have got this pseudo code from Ronal Friederich, author of rofChade and PeSTO:

Code: Select all

repeat while sum of errors still lowers
	for each tunable parameter
		increase parameter by one
		for each testposition
			calc eval
			calc error
			sum error			
		fe
		if sum error is lowered then next parameter
		else
			decrease parameter by one
			for each testposition
				calc eval
				calc error
				sum error			
			fe
		end else	
	fe
end repeat
I have a question about "for each position" meaning:
CPW's page on Texel's tuning requires to use 64 000 games which result 8+ millions of position.
Does the loop over each test position mean to loop over 8 million positions every time adjusting a single param???
This would take several lives to complete...

What am I missing?
Maybe this means test positions per game?
Please clarify.
You can apply a mini-batch. If you have 500m positions training data, just take for example 100k or so positions at a time. It is important that you randomly sort your training data. Increase the mini-batch size and see its effect on the resulting optimized values. Measure/plot how it progresses, stop the optimization if it is not improving. For piece value optimizations be sure your training data has more positions with material imbalance.

User avatar
maksimKorzh
Posts: 525
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: Help with Texel's tuning

Post by maksimKorzh » Wed Jan 06, 2021 7:18 am

Ferdy wrote:
Wed Jan 06, 2021 7:00 am
maksimKorzh wrote:
Tue Jan 05, 2021 8:42 pm
Hi guys, I have got this pseudo code from Ronal Friederich, author of rofChade and PeSTO:

Code: Select all

repeat while sum of errors still lowers
	for each tunable parameter
		increase parameter by one
		for each testposition
			calc eval
			calc error
			sum error			
		fe
		if sum error is lowered then next parameter
		else
			decrease parameter by one
			for each testposition
				calc eval
				calc error
				sum error			
			fe
		end else	
	fe
end repeat
I have a question about "for each position" meaning:
CPW's page on Texel's tuning requires to use 64 000 games which result 8+ millions of position.
Does the loop over each test position mean to loop over 8 million positions every time adjusting a single param???
This would take several lives to complete...

What am I missing?
Maybe this means test positions per game?
Please clarify.
You can apply a mini-batch. If you have 500m positions training data, just take for example 100k or so positions at a time. It is important that you randomly sort your training data. Increase the mini-batch size and see its effect on the resulting optimized values. Measure/plot how it progresses, stop the optimization if it is not improving. For piece value optimizations be sure your training data has more positions with material imbalance.
I like this idea, thank you Ferdinand!
I saw this mini-batch in minic's source code but didn't understand what that means.
JavaScript chess engine with UCI support, own GUI and public API:
https://github.com/maksimKorzh/wukongJS

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

User avatar
maksimKorzh
Posts: 525
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: Help with Texel's tuning

Post by maksimKorzh » Wed Jan 06, 2021 7:52 am

One more question:
Can I use empty PST for opening/endgame as input weights?
Or should I handcraft the values from my head/some better source?

At the moment parameters I want to tune look like this:

Code: Select all

{
  "material": [
    [0, 100, 300, 300, 500, 900, 20000, -100, -300, -300, -500, -900, -20000],
    [0, 100, 300, 300, 500, 900, 20000, -100, -300, -300, -500, -900, -20000]
  ],
  
  "pst": [
    [
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ]
    ],
    
    [
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ],
      
      [
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0
      ]
    ]
  ]
}
JavaScript chess engine with UCI support, own GUI and public API:
https://github.com/maksimKorzh/wukongJS

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

Ferdy
Posts: 4443
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Help with Texel's tuning

Post by Ferdy » Wed Jan 06, 2021 8:03 am

maksimKorzh wrote:
Wed Jan 06, 2021 7:52 am
One more question:
Can I use empty PST for opening/endgame as input weights?
Yes you can.

You can even start from a weird values, like e1 square is 100 etc, see if your implementation would reduce that value.

User avatar
maksimKorzh
Posts: 525
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

Re: Help with Texel's tuning

Post by maksimKorzh » Wed Jan 06, 2021 8:59 am

Ferdy wrote:
Wed Jan 06, 2021 8:03 am
maksimKorzh wrote:
Wed Jan 06, 2021 7:52 am
One more question:
Can I use empty PST for opening/endgame as input weights?
Yes you can.

You can even start from a weird values, like e1 square is 100 etc, see if your implementation would reduce that value.
Awesome. Thanks you!
Btw already testing my very first implementation!
Still can't believe that Code Monkey King would finally come up with his own values for PST!
JavaScript chess engine with UCI support, own GUI and public API:
https://github.com/maksimKorzh/wukongJS

Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ

Post Reply