Help with Texel's tuning

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Help with Texel's tuning

Post by maksimKorzh »

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.
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: Help with Texel's tuning

Post by Sesse »

Computers are fast, and can do 8 million positions in a second or less. No need for lifetimes.
Pio
Posts: 334
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: Help with Texel's tuning

Post by Pio »

maksimKorzh wrote: Tue Jan 05, 2021 9: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: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Help with Texel's tuning

Post by maksimKorzh »

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.
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Help with Texel's tuning

Post by jdart »

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: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Help with Texel's tuning

Post by Ferdy »

maksimKorzh wrote: Tue Jan 05, 2021 9: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: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Help with Texel's tuning

Post by maksimKorzh »

Ferdy wrote: Wed Jan 06, 2021 8:00 am
maksimKorzh wrote: Tue Jan 05, 2021 9: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.
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Help with Texel's tuning

Post by maksimKorzh »

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
      ]
    ]
  ]
}
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Help with Texel's tuning

Post by Ferdy »

maksimKorzh wrote: Wed Jan 06, 2021 8: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: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Help with Texel's tuning

Post by maksimKorzh »

Ferdy wrote: Wed Jan 06, 2021 9:03 am
maksimKorzh wrote: Wed Jan 06, 2021 8: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!