Skip to main content
GameDev.net gamedev.net
🔒 Locked

fit to data

Started by flounder Jul 18, 2007 at 9:24 PM 9 replies 2.2k views
Original Post
flounder
flounder
I've written a brute force equation generator that accepts possible integer inputs, integer constants, and operators and uses them to generate an equation that outputs the given answers. This is very slow though, and i figured that there had to be some other method that could generate equations quicker or try to reason a way to a possible equation. The information i found on generating equations for already known data was on how to fit an equation to a graph using polynomials, or was on "learning algorithms" that were meant to mimic a brain (seems daunting for just an equation generator). Does anyone know of a fast (non brute force) equation generation algorithm for integer data, or maybe even a method where the program can reason it's way to an equation?
Geoff the Medio
Geoff the Medio
Can you clairify what you mean by "integer data" and "equation generator"?

Curve fitting typically involves a set of known or measured data points (x, y) and the desire to find a relationship of the form y = f(x) or y = g(t), x = h(t) where t is some other variable.

Usually one has some initial knowledge about the shape of the curve to be fit. For example, right now I'm working on extracting rate contants that appear in a set of differential equations from a series of measured data points.

Or are you trying to randomly generate the relationships themselves, rather than fit to a set of known data points? A simple example of this would be to start with a general equation, and generate some constants to determine its exact form, and then generate y values for a set of fixed or known x values.

For example, I could assume the relationship is y = Ax^2 + Bx + C, then randomly generate A, B and C, and then generate values of y for x = 1, 2, 3, 4, 5.

What exactly are you trying to do?
flounder
flounder
The equation generator takes a list of possible inputs and outputs and finds an equation that satisfies those outputs with those inputs and/or additional constants. What i meant by integers is that i'm using 32 bit integers and the operators AND, OR, XOR, +, -, left shift, and right shift. No floating point math or multiplication/division is used.

I realize that "fit to data" usually refers to fitting a curve to a list of points, but it was the closest term i could use to describe what i'm trying to do. The data i'm using may or may not fit a curve.
Geoff the Medio
Geoff the Medio
You're probably going to have to give an example problem and solution. The description is still too vague or incomplete to understand what you're trying to describe without a lot of guessing to fill in the blanks...

However, you might be describing a more general case of the Subset Sum Problem.
flounder
flounder
edit: Yes, the subset sum problem does look to be related, i'll look into it to see if i can relate it to my problem.

An example:

"input" is a 2 dimensional array of variables that the resulting equation will receive as arguments. "output" is an array of the desired outputs for the equation, given the inputs.

The array index for input corresponds with the array index for output, so if the equation was given arguments input[5][0] and input[5][1], it should ouput output[5]. The input array can have any number of sub elements, in this case it has 2. The ouput array only has 1 sub element, since there should only be 1 answer for given inputs.

int input[10][2];//the resulting equation will take these as argumentsint output[10];//and output these//these are values that when added together will equal fibonacci numbersinput[0][0]=1;input[0][1]=1;//1+1=2input[1][0]=1;input[1][1]=2;//1+2=3input[2][0]=2;input[2][1]=3;//2+3=5input[3][0]=3;input[3][1]=5;//3+5=8...etc//these are fibonacci numbers +1output[0]=3;//1+1+1=3output[1]=4;//1+2+1=4output[2]=6;//2+3+1=6output[3]=9;//3+5+1=9...etc//run these inputs and outputs through the equation generation function//and output an equation that, when presented with input, will produce//outputgenerate_equation(input,output);


The "generate_equation()" function should output the equation, "input[0]+input[1]+1=output", in some form or another. Using fibonacci numbers was just an example in this case, any numbers may be used. The input array could have any number of sub elements, and the resulting equation may have any number of operands, constants, and uses of the input array, though bounds can be placed on any them if need be.

Basically, i have inputs and outputs, but no equation that can relate the inputs to the outputs. The job of the equation generator is to find the equation that relates them.
Rockoon1
Rockoon1
Genetic Programming all the way.
Steadtler
Steadtler
Funny pattern recognition problem.
There might be an infinite number of solutions, too.

If you limit yourself to a certain model, like a polynome, you can use different regression methods. Like using the a linear model:

ax+by+c = z;

you can use regression to find a, b, and c that solve the equation for all your (x,y,z) triplets.

If you dont want to limit you to a certain model, some kind of search is your best chance, but I dont see any good heuristic for that.
Raghar
Raghar
I remember I did something similar, thought yours looks simpler.

I had fa(a,b,c,d,e,f) -> some module -> (a?, b?, c?)
and group (a?,b?,c?) could be validated only through one way hash function.

Of course simple solution with breath first actually worked because I was interested by computationally least intensive solution. (Actually it worked after infusion of dot product, forcing your weak AI to reinvent dot product because you were lazy is bad idea.)

Your problem would be probably simplier, if you know the order of numbers beforehand. Try to test subchains for validity, it might save some computing power.

5 & 5 & 5 = 5
5 - 5 + 5 = 5

So be prepared for multiple correct solutions, that would break in real live situation. BTW if you plan to get some "real" world data, be prepared for soft tests, because quite a lot of real world data is malformed.

And one more thing, do you mean SAR by bitshift to the right? All CPUs are able to do SHR as well. ((int)-1 SAR 1 = -1, (int)-1 SHR 1 = INT32.MAX_NUMBER)
flounder
flounder
Rockoon1, genetic programming seems like the best option so far, though it's going to be more involving than "just" an equation generator.

Steadtler, there would be constraints placed on the number of possible operators, constants, etc so there wouldn't be infinite possibilities.

Raghar, my current brute force methods precomputes sections of the equation being tested, though it's still very slow. I meant SHR (unsigned shift).
Steadtler
Steadtler
Quote:
Original post by flounder
Steadtler, there would be constraints placed on the number of possible operators, constants, etc so there wouldn't be infinite possibilities.


Thats no guaranty of a single solution, tho.
Rockoon1
Rockoon1
Quote:
Original post by flounder
Rockoon1, genetic programming seems like the best option so far, though it's going to be more involving than "just" an equation generator.


Well thats the nice thing about genetic programming, its more than just an equation generator. It is probably not the "best" way to attack this sort of problem, but its right up there in good company.

Quote:
Original post by flounder
Raghar, my current brute force methods precomputes sections of the equation being tested, though it's still very slow. I meant SHR (unsigned shift).


I can imagine that. brute force searching the space of even short equation lengths can be computationally irretractable.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.