Formulas for tables

Discussion of chess software programming and technical issues.

Moderator: Ras

benstoker
Posts: 342
Joined: Tue Jan 19, 2010 2:05 am

Formulas for tables

Post by benstoker »

Given nothing but the table of values like so:

Code: Select all

5 10 -20 -40 -40 -20 10 5 
15 20 -10 -30 -30 -10 20 15 
25 30 0 -20 -20 0 30 25 
30 35 5 -15 -15 5 35 30 
35 40 10 -10 -10 10 40 35 
38 43 13 -7 -7 13 43 38 
41 46 16 -4 -4 16 46 41 
44 49 19 -1 -1 19 49 44
How do you determine the formula values to plug into a function that will compute table values in the form of:

Code: Select all

static int 
openings_king_static (int square) 
{ 
  int G[8] = { 
    [b][u]4, 1, -2, -5, -10, -15, -25, -35 [/u][/b]
  }; 
  int V[8] = { 
    [b][u]40, 45, 15, -5, -5, 15, 45, 40 [/u][/b]
  }; 
  int horizontal = ((square) >> 3), vertical = ((square) & 7); 
  return G[horizontal] + V[vertical]; 
} 
Educate me please. What is the point of having a formula calculate the values? If it's a fixed set of values for the initial table, why not simply hard plug the numbers? Is there some kind of processing efficiency gained?
mathmoi
Posts: 290
Joined: Mon Mar 13, 2006 5:23 pm
Location: Québec
Full name: Mathieu Pagé

Re: Formulas for tables

Post by mathmoi »

It makes less parameters to tune?
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Formulas for tables

Post by michiguel »

mathmoi wrote:It makes less parameters to tune?
Exactly.

Having less parameters, also helps because they are more robust and reliable. Besides, when you hardwire numbers, there is always a risk to have some that do not change smoothly. In other words, having an equation is less prone to bugs. Last year I was able to tune score for passed pawns thanks to an equation I got that included square, material, and curvature. Only three (IIRC). Before it was a complete mess.

I am going to further and say that having hardwired tables is really insane. There is no reason why they cannot be initialized at start up. I still have some hardwired crap somewhere but those will have to go.

Miguel
metax
Posts: 344
Joined: Wed Sep 23, 2009 5:56 pm
Location: Germany

Re: Formulas for tables

Post by metax »

What is the best way to find formulas if you have a table already?
jwes
Posts: 778
Joined: Sat Jul 01, 2006 7:11 am

Re: Formulas for tables

Post by jwes »

metax wrote:What is the best way to find formulas if you have a table already?
Do a search on "Regression analysis" and you may learn more than you ever wanted to know about this.
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Formulas for tables

Post by michiguel »

metax wrote:What is the best way to find formulas if you have a table already?
You have to have a mathematical intuition because it is basically trial and error. Having worked in the sciences helps, because when I see a certain plot I can say, oh, this looks like this type of equation. Polynomials are a quick and dirty solution (and division of polynomials). Exponentials, logs etc, are many that could be tried. If it is a simple case, y = a * x^n + b helps often (if n == 1 it is a straight line, if n > 1 or < 1 it will bend the curve upwards or downwards). IIRC I use that one for mobility score of different pieces. Each piece has their own equation determined by a, b and n.

With a table, it should be an equation in 2D i.e z = f(x,y) or value function or row and column. Someone posted here a website that helped to find equations to fit certain type of data like a year ago. Maybe we can find that post. I replied to it, so maybe searching my name will help. I do not think I book marked it (darn it!).

Miguel
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: Formulas for tables

Post by Edmund »

metax wrote:What is the best way to find formulas if you have a table already?
For simple issues I use Microsoft Excel, once you have a diagram you can add a "trendline" with certain features. It then also tells you the equation and sd. For more complex problems statistic programs are better.

regards,
Edmund