Symbolic regression searches for a formula's structure and constants together, and sees only the sample points. A conventional genetic programming (GP) system (population 500, tournaments of 7, at most 50 generations, seeds 0 to 29) solved the course's quadratic $x^2 + x + 1$ on 21 points in 14 of 30 runs and Koza's quartic on 20 points in 10, at a computational effort of 63,000 and 168,000 evaluations. Linear scaling sets the best slope $b = \mathrm{Cov}(y, p)/\mathrm{Var}(p)$ and offset of a program's output $p$ in one pass. Hits are not equality: only five of the ten successful quartic programs were exact on $[-2, 2]$. With Gaussian noise of standard deviation 0.1, selection replaced the true law in 10 of the 14 runs that had found it.
Twenty-one measurements of an unknown quantity $y$, at inputs $x = -1.0, -0.9, \dots, 1.0$, lie on a smooth curve. Ordinary regression begins by choosing a form for that curve, say a line $y = a + bx$ or a parabola $y = a + bx + cx^2$, and then finds the best coefficients. If the form is wrong, the fit is poor, and the analyst tries another form by hand. A search can find the form itself from the 21 points alone. In 30 attempts, the system run in this article returns exactly $x^2 + x + 1$ nine times, and five more times a program within 0.01 of it at every point. A formula found this way has been checked only at its sample points. Later sections show evolved programs that fit every sample point of their problem and are far from the target outside the sampled interval.
Symbolic regression removes the first step of ordinary regression. It searches for the formula itself, its structure and its constants together, among all expressions that can be built from a given set of operations (Poli, Langdon and McPhee, 2008, §12.2). For the 21 points above the answer might be $x^2 + x + 1$, and a symbolic regression system should be able to say so in those terms. It was one of the earliest applications of genetic programming (GP) (Koza, 1992), and it is still widely studied (Poli, Langdon and McPhee, 2008, §12.2). Expressions are program trees, such as (+ (* x x) (+ x 1)), evolved with the operators of initialization and variation in genetic programming.
This article covers what is particular to the regression setting. First we set up the course's quadratic and Koza's quartic, and measure fitness on sample points, with linear scaling as a cheap improvement. Then we see where constants come from. Next we run a conventional GP system 30 times on each problem and read what it evolves. Finally we ask what the evolved formulas do away from the sample points and on noisy data, and what modern benchmarks show.
Two classic problems
One of Koza's (1992) introductory examples is a quartic polynomial, $x^4 + x^3 + x^2 + x$, sampled at 20 points in $[-1, 1]$. The function set was $\{+, -, \times, \%, \sin, \cos, \exp, \mathrm{rlog}\}$, where $\%$ is protected division and rlog a protected logarithm. The only terminal was $x$. The transcendental functions are not needed. They make the point that GP is given a vocabulary, not a form, and must find out which words to use. Each sample point is a fitness case. Raw fitness was the sum over the 20 cases of the absolute error, and a case counted as a hit when the error was below 0.01.
The course's example, taken from Poli, Langdon and McPhee (2008, ch. 4), is the quadratic $x^2 + x + 1$ on $[-1, 1]$:
| Preparatory step | Choice |
|---|---|
| Terminal set | $x$ and ephemeral random constants in $[-5, 5]$ |
| Function set | $+$, $-$, $\times$, $\%$ (protected division) |
| Fitness | sum of absolute errors at $x = -1.0, -0.9, \dots, 1.0$ (21 cases) |
| Termination | a program with error below 0.1 |
The target can be written with these primitives, so the set is sufficient in the sense of program trees in genetic programming. Poli, Langdon and McPhee walk through one generation of a population of four to show the mechanics.
Example (the error of $x + 1$). The best program in their initial population is $x + 1$, and its error on the 21 cases is 7.7. The difference from the target is $x^2$, and $\sum x^2$ over the 21 points is $2(0.01 + 0.04 + \dots + 1) = 7.7$. Crossover then combines the $x^2$ of a second parent, $x^2 + 1$, with the $x + 1$ of the first, and produces the target in one step. A run of realistic size takes longer, as the experiment below shows.
Fitness on sample points
Fitness in symbolic regression is a distance between the program's outputs and the data, computed at the fitness cases. With $n$ cases $(x_i, y_i)$ and a program $p$, the two common measures are the sum of absolute errors and the mean squared error:
$$E_{\mathrm{abs}}(p) = \sum_{i=1}^{n} \lvert p(x_i) - y_i \rvert, \qquad E_{\mathrm{MSE}}(p) = \frac{1}{n} \sum_{i=1}^{n} \bigl(p(x_i) - y_i\bigr)^2.$$
For evenly spaced points, $E_{\mathrm{abs}}$ divided by $n$ approximates the average gap between the two curves over the interval. That is why Poli, Langdon and McPhee (2008, §4.1) describe it as roughly proportional to the area between them. Lower is better, and zero means the program passes through every point.
The hits criterion is a second, coarser measure. A program scores a hit on a case when its error there is below a tolerance, 0.01 in Koza's problem. A run is usually called successful when one program hits every case. Hits are useful for reporting, because "solved in 14 of 30 runs" is easier to read than a distribution of error sums. But a program that hits all 20 cases has been checked at 20 points and nowhere else.
That is the central limitation of sample-based fitness: it says nothing about the program's behavior between the cases or outside their range. A protected division whose divisor crosses zero between two cases creates a pole that the cases never see, as program trees shows with (% 1 (- x 0.3)).
Keijzer (2003) addressed this with two devices, and reported greatly improved predictive performance and reliability on 15 symbolic regression problems.
- Interval arithmetic checks that an expression is defined over the whole range spanned by the data, so that ordinary division can replace the protected one.
- Linear scaling rescales each program's output to $a + b\,p(x)$, with the slope and intercept that minimize the squared error, computed in closed form.
Linear scaling worked through
Here is the idea: judge a program on its shape, and compute the best offset and scale for that shape instead of evolving them. The closed form comes from ordinary least squares. For a program $p$ with outputs $p_i = p(x_i)$, choose $a$ and $b$ to minimize
$$S(a, b) = \sum_{i=1}^{n} \bigl(y_i - a - b\,p_i\bigr)^2.$$
Setting $\partial S / \partial a = -2 \sum_i (y_i - a - b\,p_i) = 0$ gives $a = \bar{y} - b\,\bar{p}$, where bars denote means over the fitness cases. So the scaled program must pass through the point of means. Substituting this $a$ turns each residual $y_i - a - b\,p_i$ into $(y_i - \bar{y}) - b\,(p_i - \bar{p})$, so
$$S(b) = \sum_{i=1}^{n} \bigl((y_i - \bar{y}) - b\,(p_i - \bar{p})\bigr)^2, \qquad \frac{dS}{db} = -2 \sum_{i=1}^{n} (p_i - \bar{p})\bigl((y_i - \bar{y}) - b\,(p_i - \bar{p})\bigr).$$
Setting the derivative to zero gives $\sum_i (p_i - \bar{p})(y_i - \bar{y}) = b \sum_i (p_i - \bar{p})^2$, that is,
$$b = \frac{\sum_i (y_i - \bar{y})(p_i - \bar{p})}{\sum_i (p_i - \bar{p})^2},$$
the covariance of target and output divided by the variance of the output. This is the least-squares slope of simple linear regression, with the program's output in the role of the predictor. (If the program is constant, $b$ is undefined, and $a = \bar{y}$ is the best that can be done.) Both are computed in one pass over the cases, so scaling adds almost nothing to the cost of evaluation.
Example (which shapes scaling can complete). Of the three programs $x(x+1)$, $x^2$ and $x + 1$, linear scaling turns only $x(x+1)$ into the quadratic exactly. That program is the target minus 1. The script tools/experiments/evolution/sr_worked.py computes the scaling for all three on the 21 cases, where $\bar{y} = 1.3667$ (rounded to four decimals):
| Program $p$ | $\bar{p}$ | $b$ | $a$ | Error before scaling | Error after |
|---|---|---|---|---|---|
| $x(x+1)$ | 0.3667 | 1.0000 | 1.0000 | 21.0000 | 0.0000 |
| $x^2$ | 0.3667 | 1.0000 | 1.0000 | 21.0000 | 11.0000 |
| $x + 1$ | 1.0000 | 1.0000 | 0.3667 | 7.7000 | 5.8933 |
- The first program has the right shape and is off by a constant. Scaling supplies the missing $+1$ and makes it exact, where unscaled fitness ranked it far behind $x + 1$.
- The second gains the same intercept and becomes $x^2 + 1$. No rescaling can create the missing linear term, so its error stays at $\sum \lvert x_i \rvert = 11$.
- The third is shifted to the point of means. That lowers its squared error, and here also its absolute error.
With scaling, GP's job reduces to finding the right shape. The offset and the scale, which are expensive to build from random constants, come free.
Constants and ephemeral random constants
Linear scaling supplies two constants. Most formulas fitted to real data contain others that are not small integers: 9.81, 0.5, 3.1416. A program tree can only contain values that enter through its terminals. Koza's (1992) answer is the ephemeral random constant $\mathcal{R}$ of program trees in genetic programming. Each time it is chosen, it is replaced by a fresh random value from a given range, fixed thereafter (Poli, Langdon and McPhee, 2008, §3.1). Crossover moves these constants between programs, and arithmetic combines them into new ones: (* 2.5 (- 1.2 0.4)) evaluates to 2.0.
The approach has well-known weaknesses.
- The range has to be guessed. Poli, Langdon and McPhee (2008, §4.1) note that supplying constants of roughly the right magnitude can improve performance considerably.
- A constant can be refined only by building arithmetic around it, which costs nodes.
- GP often prefers to build a constant from the variables. With protected division,
(% x x)equals 1 for every $x$, including $x = 0$.
In the runs below, every one of the nine programs that reproduced $x^2 + x + 1$ exactly built its 1 this way, although random constants were available. A constant drawn uniformly from $[-5, 5]$ equals 1 with probability zero (in floating-point arithmetic, about one chance in $10^{16}$), so an exact 1 has to be built. Modern systems usually treat constants as parameters and fit them numerically inside the evolutionary loop. Operon, for example, optimizes them with the Levenberg–Marquardt algorithm (La Cava et al., 2021).
A worked run
With fitness and constants settled, this section runs the system at a realistic size and reports what it produces. The script tools/experiments/evolution/symbolic_regression.py in the site repository runs both classic problems with a conventional GP system built on the shared tree library gp.py:
- a population of 500 created by ramped half-and-half (depths 2 to 6);
- tournament selection with tournaments of 7;
- 90% subtree crossover with Koza's 90/10 rule for choosing crossover points, 10% reproduction, and no mutation;
- a depth limit of 17 (a child that exceeds it is replaced by a copy of its parent);
- at most 50 generations.
Fitness is the sum of absolute errors, and a run succeeds, and stops, when a program scores a hit on every case. The quadratic uses the primitives and fitness cases in the table above, with $\mathcal{R}$ uniform on $[-5, 5)$, but the hits criterion replaces the table's termination rule. The quartic uses Koza's function set, no constants, and 20 points drawn uniformly from $[-1, 1]$ once and shared by all runs. Each problem is run with seeds 0 to 29.
| Problem | Successful runs | Generation of success, median [Q1, Q3] | Computational effort |
|---|---|---|---|
| $x^2 + x + 1$ | 14 of 30 | 8 [4.5, 17.2] | 63,000 |
| $x^4 + x^3 + x^2 + x$ | 10 of 30 | 15 [13.2, 24] | 168,000 |
Computational effort
The last column gives the number of program evaluations it takes to solve the problem with 99% probability, when GP may be run as often as we like. It is Koza's (1992) computational effort. Suppose a fraction $P(M, i)$ of runs with population $M$ have succeeded by generation $i$, and let $z = 0.99$. Then
$$R = \left\lceil \frac{\ln(1 - z)}{\ln(1 - P(M, i))} \right\rceil$$
independent runs of $i + 1$ generations succeed at least once with probability $z$. The effort is the minimum over $i$ of $M (i + 1) R$ program evaluations.
The formula for $R$ comes from asking how many independent runs are needed. If one run of $i + 1$ generations succeeds with probability $P$, then $R$ independent runs all fail with probability $(1 - P)^R$. We require this to be at most $1 - z$. Taking logarithms (both sides negative, so the inequality turns over) gives $R \geq \ln(1 - z) / \ln(1 - P)$, and $R$ is the smallest whole number that satisfies it.
Example (the effort at generation 6). By generation 6, 7 of the 30 quadratic runs had succeeded, and 18 runs of 7 generations are needed. Here $P = 7/30 = 0.233$, and $\ln 0.01 / \ln(1 - 7/30) = 17.33$, so the smallest whole number at least that large is $R = 18$. The effort is $500 \times 7 \times 18 = 63{,}000$ evaluations, the minimum for this problem.
The effort trades two things against each other. Stopping runs early makes each run cheap but rarely successful, so many runs are needed. Letting them run long makes success likelier but every run expensive. The script tools/experiments/evolution/sr_worked.py lists the computation generation by generation for the quadratic. The generations of success of the 14 successful runs were 2, 3, 3, 4, 6, 6, 6, 10, 15, 15, 18, 24, 25 and 45.
| $i$ | Runs solved by $i$ | $P(M, i)$ | $R$ | $M (i + 1) R$ |
|---|---|---|---|---|
| 2 | 1 | 0.033 | 136 | 204,000 |
| 3 | 3 | 0.100 | 44 | 88,000 |
| 4 | 4 | 0.133 | 33 | 82,500 |
| 5 | 4 | 0.133 | 33 | 99,000 |
| 6 | 7 | 0.233 | 18 | 63,000 |
| 10 | 8 | 0.267 | 15 | 82,500 |
| 20 | 11 | 0.367 | 11 | 115,500 |
| 50 | 14 | 0.467 | 8 | 204,000 |
Between successes $P$ is flat while $i + 1$ grows, so the effort rises. Each new success lowers $R$ and makes it drop. The minimum sits just after the early cluster of successes at generation 6. The estimate is itself uncertain with 30 runs. Koza's runs also differed from these in their selection method and other details, so the numbers describe this system only.
The failed runs
Half or more of the runs failed. Most failures are not near misses of the kind the hits criterion would forgive. In the quadratic runs:
- seed 3 ended with $x + 1.38$;
- seed 4 ended with $x^2 + x + 0.9666$, of error 0.70: the constant is 0.033 too small, more than the 0.01 tolerance;
- seed 0 ended with an 85-node rational function of error 1.38.
The script does not measure diversity, but a likely cause is the premature convergence familiar from genetic algorithms. With tournaments of 7 and no mutation, a population that has converged on a wrong structure has few ways to leave it.
Watching one run
One successful run, followed generation by generation, shows how a solution is assembled. The script tools/experiments/evolution/gp_curves.py repeats the runs of the table above and records the best program of every generation. For the quartic run with seed 11:
| Generation | Best program | Size | Error |
|---|---|---|---|
| 0 | (+ (* x x) (sin x)) |
6 | 5.9652 |
| 1 | (* x (exp x)) |
4 | 3.4659 |
| 5 | (+ (sin x) (* x (+ (sin x) (* x (* (sin x) (exp x)))))) |
15 | 0.7429 |
| 16 | (+ (+ (sin (sin x)) (* x x)) (* x (* (sin x) (* x (exp x))))) |
17 | 0.4526 |
| 45 | (+ x (* x (+ x (* x (+ x (* x x)))))) |
13 | 0.0000 |
The early programs show how GP uses its vocabulary. None of them is a polynomial, but all of them behave like one near 0, which is where most of the fitness cases lie. Expanding each in a Taylor series about 0 shows what each generation has learned. (The script fits the coefficients numerically, rounded to three decimals.)
| Generation | Coefficients of $x$, $x^2$, $x^3$, $x^4$ near 0 |
|---|---|
| target | 1, 1, 1, 1 |
| 0 | 1, 1, −0.167, 0 |
| 1 | 1, 1, 0.5, 0.167 |
| 5 | 1, 1, 0.833, 0.833 |
| 16 | 1, 1, 0.667, 1 |
| 45 | 1, 1, 1, 1 |
The first rows can be confirmed by hand from the series $\sin x = x - x^3/6 + \cdots$ and $e^x = 1 + x + x^2/2 + x^3/6 + \cdots$. Generation 0 is $x^2 + \sin x = x + x^2 - x^3/6 + \cdots$, and generation 1 is $x e^x = x + x^2 + x^3/2 + x^4/6 + \cdots$. Generation 5 is $\sin x + x \sin x + x^2 \sin x\, e^x$. Its three terms contribute $x - x^3/6$, then $x^2 - x^4/6$, then $x^3 + x^4$, up to the fourth power, and the sum is $x + x^2 + \tfrac{5}{6}x^3 + \tfrac{5}{6}x^4$. Generation 16 is $\sin(\sin x) + x^2 + x^2 \sin x\, e^x$. Since $\sin(\sin x) = x - x^3/3 + \cdots$ and $x^2 \sin x\, e^x = x^3 + x^4 + \cdots$, the sum is $x + x^2 + \tfrac{2}{3}x^3 + x^4$.
From the first generation the best program gets the two lowest-order terms right, since $\sin x \approx x$ and $x e^x \approx x + x^2$. Later generations approach the higher coefficients, which matter only for larger $\lvert x \rvert$. The products of $\sin$ and $\exp$ are standing in for powers of $x$.
For 29 generations the population could not improve on the generation-16 program, an approximation within about 0.02 of the target at a typical fitness case. Then one crossover assembled the exact nested form. Plateaus followed by a sudden jump recur in these runs. The quartic run with seed 9 had a best error of 2.2332 from generation 3 to generation 13, and found an exact program at generation 14. A run that has stalled is not necessarily finished.
What the successful programs compute
The evolved trees are rarely the shortest form. To read them, the script evaluates each program at 61 points of $[-2, 2]$ and fits polynomials of increasing degree. It reports the polynomial whenever it reproduces the program to within $10^{-6}$ at 401 other points. Some successful quadratic programs:
| Seed | Evolved program | Size | Simplified |
|---|---|---|---|
| 2 | (+ (% x x) (+ x (* x x))) |
9 | $x^2 + x + 1$ |
| 1 | (+ (% x x) (* (+ (% x x) x) x)) |
11 | $x^2 + x + 1$ |
| 22 | (+ (+ (% x x) (- (* x x) (% x -1.236))) (* (% x x) (+ x (% x -1.236)))) |
21 | $x^2 + x + 1$ |
| 11 | (+ (* x x) (- x -0.9929)) |
7 | $x^2 + x + 0.992874$ |
| 9 | 31 nodes with constants $-3.698$, 4.734, 4.012, 1.114 | 31 | $x^2 + x + 1.00795$ |
Nine of the 14 successful programs are exactly $x^2 + x + 1$. Seed 22's contains two terms that cancel. Reading it by hand, with $c = -1.236$ (the constant is $-1.2364563\ldots$, and its value does not matter):
(% x x)is 1 wherever it appears, so the program is(+ (+ 1 (- (* x x) (% x c))) (* 1 (+ x (% x c)))).- The left branch is $1 + (x^2 - x/c)$, and the right branch is $1 \cdot (x + x/c)$.
- Their sum is $1 + x^2 - x/c + x + x/c$, and the two terms in $x/c$ cancel, leaving $x^2 + x + 1$.
The cancellation is exact for every $c \neq 0$, so the evolved constant does no work at all. It is a small piece of code that computes nothing, of the kind the bloat article calls an intron.
Seeds 11 and 9 found the right structure with a constant that is slightly off, but close enough that every case is a hit. Seed 11's error of 0.0071 per case passes the 0.01 tolerance. The remaining three successes, of 45, 65 and 91 nodes, are rational functions that stay within 0.01 of the target at all 21 cases without being equal to it. The median size of the successful programs is 10 nodes [Q1 9, Q3 28.5], against a minimum of 7. That is a first sign of the growth studied in bloat in genetic programming.
The quartic runs show the same range. Seeds 2, 11, 17 and 27 found 13-node trees that simplify exactly to $x^4 + x^3 + x^2 + x$. Seed 11's nested form (+ x (* x (+ x (* x (+ x (* x x)))))) is Horner's rule, $x(1 + x(1 + x(1 + x)))$. Seed 9's 27-node program is also exact, but it contains three pieces that compute nothing new:
(rlog (exp x)), which is just $x$;(exp (rlog (- x x))), which is $e^{0} = 1$, because the protected logarithm returns 0 at 0, and which multiplies another term;(- x x), which is 0, added to the rest.
Such code is a simple instance of the introns discussed in the bloat article.
Hits are not equality
Every successful program in the last section hits all of its fitness cases. That does not make it the target. Seed 28's successful quartic program is
(+ (* x (+ x (exp (rlog (* (+ (* x x) x) x))))) x)
Since $\exp(\mathrm{rlog}(u)) = \lvert u \rvert$ for $u \ne 0$, it computes $x \cdot (x + \lvert x^3 + x^2 \rvert) + x$.
Example (where seed 28's program is the quartic). This program equals the quartic for $x > -1$ and differs from it for $x \le -1$. For $x > -1$, $x^3 + x^2 = x^2(x + 1)$ is non-negative, so the absolute value does nothing. The program is then $x\,(x + x^3 + x^2) + x = x^4 + x^3 + x^2 + x$, and the script finds its error below $10^{-15}$ at every fitness case. (At $x = 0$ the argument $u$ is 0 and the protected logarithm makes $\exp(\mathrm{rlog}(u))$ equal to 1 instead of 0, but the factor $x$ in front is 0 there, so the program still returns 0, as the quartic does.) For $x < -1$ the absolute value changes the sign: at $x = -2$, $x^3 + x^2 = -4$, and the program returns $-2\,(-2 + 4) - 2 = -6$ where the quartic gives $16 - 8 + 4 - 2 = 10$. At $x = -1$ exactly, the protected logarithm of 0 makes the program return $-1$ instead of 0. The smallest fitness case is $-0.991$, so nothing in the data could reveal the difference.
Seed 5's program, $e^{x^2} (x + x^2) \cos(x \sin(\sin x))$, is a different kind of near miss. It approximates the quartic within 0.0052 at every case, but at $x = 2$ it returns $-2.41$ instead of 30.
The two programs fail in different ways. Seed 28's program is the quartic over a region that happens to include the data, and differs from it by a sign flip in an absolute value. It is exactly right or very wrong depending on the side of $-1$. Seed 5's is an approximation everywhere: good where the data are and poor where they are not. That is what any flexible model fitted to data on $[-1, 1]$ tends to be.
Generalization and overfitting
A model found by fitting data has to be judged on data it was not fitted to. For the quartic, the script measures each best-of-run program's mean absolute error (MAE) against the true function. It uses 401 evenly spaced points, both inside the sampled interval and on the wider interval $[-2, 2]$:
| Best-of-run programs | Exact on $[-2, 2]$ | MAE on $[-1, 1]$, median [Q1, Q3] | MAE on $[-2, 2]$, median [Q1, Q3] |
|---|---|---|---|
| 10 successful runs | 5 | 0.0001 [0.0000, 0.0017] | 0.62 [0.00, 1.31] |
| 20 unsuccessful runs | 0 | 0.025 [0.010, 0.041] | 2.50 [1.95, 3.12] |
Inside the sampled interval the successful programs interpolate well. Outside it, only the five exact ones are reliable, and the median error of the successful runs is 0.62 because half of them are approximations. Extrapolation is where an approximation and the true law part company. It is also where a formula is most useful, since data inside the interval could be interpolated without one.
Noisy data
Overfitting appears when the data contain noise. The script's fourth part draws one dataset of 20 points, with $x$ uniform on $[-1, 1]$ and $y = x^2 + x + 1$ plus Gaussian noise of standard deviation 0.1. GP runs as before, without the hits criterion, for all 50 generations. Each generation, the program with the lowest training error is scored on 401 noise-free points of the target.
Example (training error below the true function's). The true function itself has a training MAE of 0.0723 on this sample, because the noise is in the data. A program whose training error falls below 0.0723 is fitting the noise. It matches the particular random errors in the 20 training points more closely than the law that generated them does. The runs show how often that happens:
| Generation | Training MAE | Test MAE | Program size |
|---|---|---|---|
| 0 | 0.2859 [0.2611, 0.3649] | 0.2909 [0.2609, 0.3737] | 7 [5, 14] |
| 5 | 0.0877 [0.0723, 0.1558] | 0.0755 [0.0000, 0.1710] | 11 [9, 15] |
| 10 | 0.0723 [0.0714, 0.0976] | 0.0609 [0.0000, 0.0985] | 16 [9, 21] |
| 20 | 0.0668 [0.0577, 0.0764] | 0.0707 [0.0361, 0.0894] | 54 [14, 70] |
| 30 | 0.0639 [0.0537, 0.0723] | 0.0700 [0.0436, 0.0894] | 74 [30, 104] |
| 40 | 0.0574 [0.0522, 0.0723] | 0.0689 [0.0445, 0.0896] | 95 [24, 120] |
| 50 | 0.0562 [0.0499, 0.0722] | 0.0714 [0.0445, 0.0891] | 100 [38, 129] |
(Medians over 30 runs, with the first and third quartiles in brackets.) In 14 of the 30 runs, the best program of some generation was exactly $x^2 + x + 1$, with test error zero. These runs are the zeros in the first quartile at generations 5 and 10. Only 4 of the 14 still had it at generation 50. In the others, selection replaced the true law with larger programs that matched the noisy training points more closely.
By generation 50, 22 of the 30 final programs had a training error below the true function's 0.0723. In 22 runs the final test error was more than 10% above the best test error reached earlier in the run. Training error kept falling after generation 10 while test error did not, and program size grew more than sixfold over the same period.
The dotted line is the useful reference. Everything gained below it in the left panel was paid for with the extra nodes in the right panel, and tells nothing about the function.
The remedies are those of any learning method.
- Separate data. A training set is used for fitness, and a separate set is used to choose among programs and to report results. A third set is held back when the second has been used for selection. When data are scarce, cross-validation rotates which part is held out, so that every point serves for both fitting and checking.
- Simpler programs. In GP this means some form of parsimony pressure on size, one motivation for the size-control methods in bloat in genetic programming. Such methods trade some training accuracy for simpler models and are tuned on held-out data.
Modern symbolic regression
The method reaches well beyond the quartic. Schmidt and Lipson (2009) applied symbolic regression to motion-tracking data from physical systems, from simple harmonic oscillators to chaotic double pendula. A formula that fits the data is not enough to be interesting, so they proposed a criterion for what makes a discovered relation nontrivial. Without prior knowledge of physics, kinematics or geometry, their algorithm found Hamiltonians, Lagrangians and other laws of geometric and momentum conservation. Its demonstrations used systems whose laws were already known, which is what allowed the results to be checked.
Comparisons across methods became more systematic with SRBench (La Cava et al., 2021). It is an open benchmark of 14 symbolic regression methods and 7 machine learning methods on 252 regression problems. Each method was given a fixed budget, for the real-world problems 500,000 evaluations or 48 hours per training run. The findings include:
- On real-world datasets with no known model, four of the five most accurate methods were GP-based. The most accurate was Operon, a GP system with nonlinear least-squares optimization of constants. Operon, FEAT and SBP-GP were significantly more accurate than LightGBM, and Operon and SBP-GP more accurate than XGBoost. The models of the top methods other than SBP-GP were one to three orders of magnitude smaller than those of the tree ensembles.
- On synthetic problems with known equations from physics and dynamical systems, AI Feynman, a physics-inspired method that is not GP-based, recovered the exact equation in 53% of noise-free cases. That is about twice as often as the next method. At noise levels above 0.01, four other methods recovered exact solutions more often.
- Operon, the most accurate on real-world data, rarely recovered the exact equations of the synthetic problems, despite finding many models with near-perfect test scores.
The last finding repeats, on a larger scale, the distinction between fitting and identifying that seeds 5 and 28 show above. The benchmark's authors also note that the field has relied on small, easy problems and on comparisons with basic GP systems of the kind Koza described. The quartic and the quadratic are such problems: useful for teaching the mechanics, and not evidence of how a method performs on real data.
What we have learned
Symbolic regression searches for a formula's structure and constants together, and the sample points are all it sees. A conventional GP system solved the quadratic in 14 of 30 runs and the quartic in 10. Nine of the quadratic's successes are exactly $x^2 + x + 1$. But hits are not equality: only five of the ten successful quartic programs are reliable outside $[-1, 1]$. On noisy data, selection replaced the true law in 10 of the 14 runs that had found it.
Throughout, the programs grew. Successful quadratic programs had a median of 10 nodes where 7 suffice, and on noisy data the median best program grew from 16 nodes to 100. The next article, bloat in genetic programming, sets out why GP programs grow without getting better and compares the methods that control the growth.
References
- Keijzer, M. (2003). Improving symbolic regression with interval arithmetic and linear scaling. In C. Ryan et al. (eds.), Genetic Programming: EuroGP 2003, Lecture Notes in Computer Science 2610, 70–82. Springer. record
- Koza, J. R. (1992). Genetic Programming: On the Programming of Computers by Means of Natural Selection. MIT Press. record · 6 pages
- La Cava, W., Orzechowski, P., Burlacu, B., de França, F. O., Virgolin, M., Jin, Y., Kommenda, M., and Moore, J. H. (2021). Contemporary symbolic regression methods and their relative performance. In Proceedings of the Neural Information Processing Systems Track on Datasets and Benchmarks, vol. 1. arXiv:2107.14351. record
- Poli, R., Langdon, W. B., and McPhee, N. F. (2008). A Field Guide to Genetic Programming, chapters 3, 4 and 12. Lulu.com. record · 5 pages
- Schmidt, M., and Lipson, H. (2009). Distilling free-form natural laws from experimental data. Science, 324(5923), 81–85. record
Reviewed: verified, 16 Nov 2026 · checked against sources, 23 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 7 revisions