Initialization and Variation in Genetic Programming

How genetic programming creates its first trees and changes them. The full, grow and ramped half-and-half methods and the tree shapes they actually produce, probabilistic tree creation, subtree crossover and Koza's 90/10 node-selection rule, subtree, point, hoist and shrink mutation, and the evidence on crossover versus mutation in GP.

Tree-based genetic programming (GP) builds its first trees with the full, grow or ramped half-and-half method and changes them by crossover and mutation. A grow tree with depth limit $D$ has expected size $\sum_{i=0}^{D} g^i$, where $g = b\,|F|/(|F| + |T|)$ is the mean number of children per node: 19.47 nodes for four binary functions, two terminals and $D = 6$, against 19.33 measured. Grow trees pile up at a single node and at the depth limit. Koza's 90/10 rule cuts leaf-for-leaf crossover swaps from about 38% to about 1%. Of the mutations, only subtree mutation grows trees on average. In published comparisons, crossover usually beats subtree mutation, often by less than a change of tournament size makes, depending on the problem.

Take two parents, in the prefix notation of program trees in genetic programming:

P1 = (+ (* x x) (- x 1))        P2 = (* (+ x 0.5) (% x 2))

Choose the subtree (- x 1) in P1 and the subtree (+ x 0.5) in P2, and put a copy of the second in place of the first. The child is (+ (* x x) (+ x 0.5)), a near relative of the unit's running example $x^2 + x + 1$. Choose instead the leaf x at the start of (* x x) and the leaf 2 in P2, and the child is (+ (* 2 x) (- x 1)): the same operator, a much smaller change. Which points get chosen, how large the exchanged pieces are, and which trees the population starts from decide much of how a GP run behaves.

This article measures what the standard methods actually produce. First we build initial populations with the full, grow and ramped half-and-half methods, measure the shapes and sizes of 10,000 trees from each, and derive a formula that predicts their mean size. Then we turn to subtree crossover and the rule Koza used to choose its points. Next come the mutation operators and what one application of each does to tree size. Finally we review the evidence on whether crossover beats mutation in GP, and repeat the comparison on a small scale. The article assumes the representation of program trees in genetic programming.

The sources are those of the previous article. Poli, Langdon and McPhee (2008) describe the basic methods in chapter 2 of their Field Guide and the alternatives in chapter 5, and Eiben and Smith (2015, §4.6 and §6.4) give the textbook treatment. The measurements come from tools/experiments/evolution/gp_init.py and the crossover-versus-mutation runs from tools/experiments/evolution/gp_xo_vs_mut.py. Both are in the site repository and both are built on the library tools/experiments/evolution/gp.py.

Creating the initial population

The initial population is usually random. The aim is not to start near a solution but to start with programs of many sizes and shapes, so that the search has varied material to recombine.

Full and grow

Both methods build a tree from the root down, recursively, and both stop at a maximum depth $D$, with the root at depth 0 (Poli, Langdon and McPhee, 2008, §2.2, Algorithm 2.1).

  • Full chooses a function at every node above depth $D$ and a terminal at depth $D$, so every leaf lies at depth $D$. When all functions have the same arity, every full tree of depth $D$ has the same size. With mixed arities sizes vary, although the range of sizes and shapes can still be rather limited (Poli, Langdon and McPhee, 2008, §2.2).
  • Grow chooses each node from the whole primitive set until depth $D$, where it must choose a terminal. In the Field Guide's formulation, a node above the limit is a terminal with probability $|T|/(|T| + |F|)$, where $|T|$ and $|F|$ are the numbers of terminals and functions. Every primitive is therefore equally likely. Branches can end early, and trees vary in shape.

Ramped half-and-half

Neither method alone gives a wide spread of shapes. Koza (1992) therefore combined them in ramped half-and-half: half the population is built with full and half with grow, over a range of depth limits, the "ramp" (Poli, Langdon and McPhee, 2008, §2.2). A depth range of 2 to 6 is common (Poli, Langdon and McPhee, 2008, §3.4). In the implementation used here, individual $i$ gets depth limit $2 + (i \bmod 5)$ and alternates between full and grow in blocks of five. Each depth thus gets 2,000 of the 10,000 trees, half from each method.

Trees with depth limit 3 over plus, minus, times and protected division, with terminals x and a random constant. Top: two full trees; every leaf is at depth 3, and with only binary functions both have 15 nodes. Bottom: three grow trees from the same generator. Notice how different they are: one is a single constant, because grow chose a terminal at the root; one stops at depth 2 with 5 nodes; one reaches the limit on some branches and not on others.
Trees with depth limit 3 over plus, minus, times and protected division, with terminals x and a random constant. Top: two full trees; every leaf is at depth 3, and with only binary functions both have 15 nodes. Bottom: three grow trees from the same generator. Notice how different they are: one is a single constant, because grow chose a terminal at the root; one stops at depth 2 with 5 nodes; one reaches the limit on some branches and not on others.

What the methods produce

The script builds 10,000 trees with each method over the primitive set {+, −, ×, %}, with terminals $x$ and an ephemeral random constant on $[-1, 1)$. So $|F| = 4$ and $|T| = 2$, and grow chooses a terminal with probability 1/3.

Example (two predictions from the primitive set). Two features of the table below follow from the primitive set alone. With depth limits 2 to 6, full trees can have only five sizes, 7, 15, 31, 63 and 127. With only binary functions, a full tree of depth $d$ has $2^i$ nodes at each depth $i \le d$, and so exactly $2^{d+1} - 1$ nodes. A grow tree is a single node whenever its root is a terminal, which happens with probability 1/3. The script measures 33.7%:

Method Depth 0 1 2 3 4 5 6 Median size Mean size Single node
Full, limits 2 to 6 0 0 2,000 2,000 2,000 2,000 2,000 31 48.60 0%
Grow, limit 6 3,367 725 362 214 134 91 5,107 15 19.33 33.7%
Ramped half-and-half, 2 to 6 1,637 368 1,735 1,647 1,551 1,526 1,536 15 29.69 16.4%
Ramped, grow root always a function 0 550 2,116 1,920 1,836 1,801 1,777 15 32.15 0%
Depth (top) and size (bottom) of 10,000 trees from each method. Full trees (solid bars) are spread evenly over depths 2 to 6 and come in exactly five sizes. Notice that grow trees (hatched) pile up at the two extremes: a third are single nodes at depth 0 and half reach the depth limit of 6. Ramped half-and-half (dotted) mixes the two and covers every size bin, but inherits a sixth of its trees as single nodes from grow.
Depth (top) and size (bottom) of 10,000 trees from each method. Full trees (solid bars) are spread evenly over depths 2 to 6 and come in exactly five sizes. Notice that grow trees (hatched) pile up at the two extremes: a third are single nodes at depth 0 and half reach the depth limit of 6. Ramped half-and-half (dotted) mixes the two and covers every size bin, but inherits a sixth of its trees as single nodes from grow.

Three things stand out.

Full trees come in five sizes. The full half of the population has sizes 7, 15, 31, 63 and 127 and nothing in between, as the example computed.

Grow is bimodal. A third of the grow trees are a single node, and just over half reach the depth limit. Few lie in between. Why should a random process favor the extremes? Luke (2000, Lemma 1 and Theorem 1) explains it. If each new node has on average $g$ children, the expected number of nodes at depth $i$ is $g^i$. Without a depth limit the expected tree size is then the geometric series $1 + g + g^2 + \cdots$, which is $1/(1 - g)$ when $g < 1$, and infinite otherwise. Here $g = (4/6) \times 2 = 4/3$. An unlimited grow tree that survives its first few nodes therefore tends to keep growing, and the depth limit cuts it off.

How often does that happen? Without a limit, grow is a branching process: each node has no children with probability 1/3 and two with probability 2/3, independently of the others. Write $q_n$ for the probability that a tree ends within depth $n - 1$, so $q_1 = 1/3$, the chance that the root is a terminal. A tree ends within depth $n$ exactly when the root is a terminal, or the root is a function and both of its subtrees end within depth $n - 1$, so $$q_{n+1} = \tfrac13 + \tfrac23\, q_n^2, \qquad q_0 = 0.$$ The probability that a tree reaches depth 6 is $1 - q_6 = 0.515$. That is the share of grow trees the depth limit should cut off, against 51.1% measured (5,107 of 10,000). As $n$ grows, $q_n$ rises to the smaller root of $q = \tfrac13 + \tfrac23 q^2$, which is $q = \tfrac12$. Half of all unlimited grow trees over this primitive set are finite and half grow forever. The depth limit turns the infinite half, together with the 1.5% of trees that are finite but reach depth 6, into the peak at the limit.

With many terminals the balance tips the other way. With the same functions and nine terminals ($x_1, \dots, x_8$ and a constant), $g = (4/13) \times 2 = 8/13$, and the expected unlimited size is 2.6. The script measures a mean of 2.50 under the depth limit of 6, with 68.8% of trees a single node and a median size of 1. Poli, Langdon and McPhee (2008, §2.2) give the same warning in words. With many more terminals than functions, grow almost always produces very short trees, and with many more functions it behaves much like full. Small changes to the primitive set can thus change the initial population a great deal.

Predicting the mean size

Luke's argument predicts more than the shape. It predicts the mean sizes in the table, depth limit included. Here is the plan: count the expected nodes level by level, stop the count at the limit, and add.

The formal version. Above the limit, each node that grow creates is a function with probability $p = |F|/(|F| + |T|)$, and a function has $b$ children (here $b = 2$). Each node at depth $i$ therefore has on average $g = p\,b$ children at depth $i + 1$. Write $n_i$ for the number of nodes at depth $i$. There is one root, so $n_0 = 1$. Given $n_i$ nodes at a depth $i < D$, the expected number of their children is $g\,n_i$, so $E[n_{i+1}] = g\,E[n_i]$. The number of nodes at depth $i + 1$ is a random sum, the children of a random number $n_i$ of nodes, and the last step is the mean of a random sum, $E[S] = \mu\,E[N]$, which conditional expectation proves from the law of total expectation. By induction the expected number of nodes at depth $i$ is $g^i$, for every $i \le D$. At the limit $D$ every node is a terminal, so nothing lies deeper, and the expected size is the partial geometric sum

$$E[\text{size}] = \sum_{i=0}^{D} g^i = \frac{g^{D+1} - 1}{g - 1} \quad (g \neq 1).$$

Now the check against the measurements.

  • For the primitive set above, $g = 4/3$ and $D = 6$ give $3\bigl((4/3)^7 - 1\bigr) = 19.47$, against the measured mean of 19.33.
  • For the nine-terminal set, $g = 8/13$ gives 2.51, against 2.50.
  • The full half of the ramped population has the exact mean $(7 + 15 + 31 + 63 + 127)/5 = 48.6$. The grow half has expected sizes 4.11, 6.48, 9.64, 13.86 and 19.47 at limits 2 to 6, a mean of 10.71. So the ramped population should average $(48.6 + 10.71)/2 = 29.66$ nodes; the measured mean is 29.69.

These predictions are printed by Part 5 of gp_init.py, which also checks each limit against 10,000 fresh grow trees. The formula shows where the bimodal shape comes from. When $g > 1$ the expected size is dominated by its last terms, so the mean is carried by the trees that reach the limit. Meanwhile the probability $|T|/(|T| + |F|)$ that the root is a terminal fixes the share of single nodes, whatever $g$ is.

Ramped half-and-half inherits grow's small trees

In the Field Guide formulation used here, where grow may choose a terminal for the root, 16.4% of the ramped population consists of single nodes. Also, 27.8% of the trees duplicate the shape of another tree (ignoring constant values). Forcing grow to place a function at the root (last row of the table) removes the single-node trees and raises the mean size from 29.69 to 32.15. Luke (2000, §III) reports that Koza's classic code "rejects all trees of depth 1, and eliminates duplicate trees, which increases average tree size". Luke does not say how depth is counted there. Some GP systems count the root as depth 1, in which case the rejected trees are the single nodes; under this article's convention, with the root at depth 0, the phrase would mean trees of three nodes. Either way, the initial population of Koza's code differed from the one measured here. These details are rarely reported, but they change the starting population.

The size histogram of the standard ramped population is broad:

Size 1 3 5–7 9–15 17–31 33–63 65–127
Trees 1,637 368 1,929 1,907 1,768 1,364 1,027

Beyond ramped half-and-half

Any way of generating random programs has a bias, because there are infinitely many programs and they cannot be sampled uniformly. Ramped half-and-half favors bushy, roughly symmetric trees (Poli, Langdon and McPhee, 2008, §5.1.1). Several alternatives give more control.

Probabilistic tree creation (Luke, 2000) addresses grow's lack of control over size. PTC1 is a modified grow in which the user specifies the probability of each function and terminal and a desired expected tree size $E$. The algorithm then chooses a function rather than a terminal with probability

$$p = \frac{1 - 1/E}{\sum_{n \in N} q_n b_n},$$

where $q_n$ is the probability of function $n$ among the functions and $b_n$ is its arity (Luke, 2000, Theorem 3). This makes $g = p \sum_n q_n b_n = 1 - 1/E$, and so, by the unlimited-size formula above, the expected size is $1/(1 - g) = 1/(1/E) = E$ exactly, when no depth limit cuts the tree off (and provided $1 - 1/E \le \sum_n q_n b_n$, so that $p \le 1$). Luke's PTC1 does take a maximum depth, at which it places a terminal as grow does, but he intends it only as a large bound on memory use. For four equally likely binary functions and $E = 20$, $p = 0.95/2 = 0.475$.

PTC2 instead takes a whole distribution of desired sizes. It draws a size from it and builds a tree of that size or slightly larger, giving control over the spread as well as the mean. Luke shows both to be fast, effectively linear in the tree size under reasonable conditions, and gives versions of both for strongly typed GP. Other methods sample trees uniformly at random from all trees of a given size. They produce more asymmetric trees, with some leaves close to the root (Poli, Langdon and McPhee, 2008, §5.1.1).

The initial distribution does not last. Crossover rearranges the sizes and shapes of the initial trees within a few generations. Initializations that produce many short programs may make bloat appear sooner (Poli, Langdon and McPhee, 2008, §5.1.2). The next section describes what crossover does to a tree.

Subtree crossover

Subtree crossover is the standard GP recombination operator. It chooses a crossover point (a node) in each parent, independently. It then replaces the subtree at the point in a copy of the first parent with a copy of the subtree at the point in the second (Poli, Langdon and McPhee, 2008, §2.4). The parents are copied so that a parent selected several times is not changed. The common form produces one child. A version that also returns the complementary child exists but is less used. Swapping the roles of the parents in the opening example gives the complementary child (* (- x 1) (% x 2)).

The opening example. In P1 the crossover point is node 4, the subtree x minus 1 (solid outline); in P2 it is node 1, the subtree x plus 0.5 (hatched). The child is P1 with its marked subtree replaced by P2's, and the complementary child is P2 with its marked subtree replaced by P1's. Notice that both children keep the size and depth of their first parent here, because the two exchanged subtrees have the same shape.
The opening example. In P1 the crossover point is node 4, the subtree x minus 1 (solid outline); in P2 it is node 1, the subtree x plus 0.5 (hatched). The child is P1 with its marked subtree replaced by P2's, and the complementary child is P2 with its marked subtree replaced by P1's. Notice that both children keep the size and depth of their first parent here, because the two exchanged subtrees have the same shape.

Unlike GA crossover, which exchanges values at matching positions, subtree crossover can move code to a different position, depth and context. It also changes the size of the child:

$$\text{child size} = \text{size of first parent} - \text{removed subtree} + \text{inserted subtree}.$$

In the opening example both exchanged subtrees have three nodes, so the sizes do not change.

Example (a leaf replaced by a whole tree). Take as the point in P1 the leaf x at node 2, and insert the whole of P2, its root. The child has $7 - 1 + 7 = 13$ nodes and depth 4: (+ (* (* (+ x 0.5) (% x 2)) x) (- x 1)). The leaf sat at depth 2, and P2, of depth 2, now hangs from that spot.

Click a node in each parent to choose the two crossover points; the subtree below each chosen node is outlined. The lower half shows the child, P1 with its chosen subtree replaced by a copy of P2's, and the complementary child, with the size arithmetic in the readout. Random points uses Koza's 90/10 rule, and New random parents draws two grow trees of depth limit 3.

The demo makes three properties easy to check.

  • Choosing a leaf in P1 and the root of P2 grows the child by the whole of P2, minus one node.
  • Choosing the root of P1 returns a copy of P2's chosen subtree, so the child can be as small as a single node.
  • Choosing two identical subtrees, such as an x in each parent, returns P1 unchanged. That is how crossover between the article's two parents can produce a child identical to its first parent.

The 90/10 rule

Choosing crossover points uniformly over all nodes has a problem: most nodes are leaves. A tree built only from binary functions with $n$ function nodes has $n + 1$ leaves, more than half its nodes, and a tree of size 1 is all leaf.

The reason is a count of edges, made two ways. Every node except the root hangs from exactly one edge, so a tree with $n$ function nodes and $L$ leaves has $n + L - 1$ edges. Every function node has exactly two edges below it, so there are also $2n$ edges. Equating the two gives $L = n + 1$.

In the ramped population above, leaves make up 61.5% of the nodes of the average tree. Pooled over all nodes the share is 51.7%, because large trees have proportionally fewer leaves.

Example (leaf-for-leaf swaps). If both crossover points are chosen uniformly, and 61.5% of each tree's nodes are leaves, crossover merely swaps one leaf for another about $0.615^2 \approx 38\%$ of the time, often exchanging a terminal for an identical terminal. To make crossover exchange larger pieces of code, Koza (1992) suggested choosing function nodes 90% of the time and leaves 10% of the time. The rule is still widely used (Poli, Langdon and McPhee, 2008, §2.4). Averaged over the ramped population, the expected size of the selected subtree is 3.39 nodes under uniform selection and 5.55 under the 90/10 rule.

The rule is a parameter like any other. Angeline (1996) varied the leaf selection frequency in subtree crossover, in a non-standard GP system. He reported that performance was sensitive to it, and could often be improved by setting the frequency by a random process rather than a constant.

Depth limits

Subtree crossover can produce children much deeper than either parent, as the example of a leaf replaced by a whole tree showed, so GP systems impose a maximum depth or size. A common implementation, used by Koza (1992), applies the operator and, if the child exceeds the limit, returns a parent instead (Poli, Langdon and McPhee, 2008, §11.3.2). Luke and Spector (1997), keeping close to Koza's traditional settings, used a depth limit of 17. Returning parents has side effects, such as filling the population with trees that sit just under the limit. Bloat in genetic programming discusses these and the alternatives.

Mutation operators

Crossover recombines material that is already in the population. Mutation brings in new material, or removes some. GP uses many mutation operators, often several at once (Poli, Langdon and McPhee, 2008, §5.2.2). Applied to P1 = (+ (* x x) (- x 1)):

Operator What it does Example result
Subtree mutation Replaces a randomly chosen subtree with a new random tree (* x x) replaced by (% x (+ x x)): (+ (% x (+ x x)) (- x 1))
Point mutation Replaces a node with a different primitive of the same arity, keeping its children * replaced by %: (+ (% x x) (- x 1))
Hoist mutation Returns a copy of a randomly chosen subtree of the parent (- x 1)
Shrink mutation Replaces a randomly chosen subtree with a random terminal (* x x) replaced by x: (+ x (- x 1))
The parent P1 and the four example mutants of the table. Hatched nodes are new material. Notice that only subtree mutation makes the tree larger, replacing the subtree x times x (outlined in P1) with a new random subtree of five nodes. Point mutation changes only the label of one node, from times to protected division; hoist mutation keeps only the subtree x minus 1 of P1, now the whole program; shrink mutation collapses x times x into a single new leaf.
The parent P1 and the four example mutants of the table. Hatched nodes are new material. Notice that only subtree mutation makes the tree larger, replacing the subtree x times x (outlined in P1) with a new random subtree of five nodes. Point mutation changes only the label of one node, from times to protected division; hoist mutation keeps only the subtree x minus 1 of P1, now the whole program; shrink mutation collapses x times x into a single new leaf.

Subtree mutation is Koza's mutation (Koza, 1992, p. 106, as cited by Poli, Langdon and McPhee, 2008, §5.2.2). The new subtree is usually generated with grow or full and a small depth limit. It can be implemented as crossover with a freshly generated random tree, sometimes called "headless chicken" crossover (Poli, Langdon and McPhee, 2008, §2.4).

Point mutation, or node replacement mutation, is the nearest GP analogue of the bit-flip mutation of genetic algorithms. It is usually applied per node. Each node, with some probability, is replaced by a different primitive with the same number of arguments; if no such primitive exists, the node is left alone (Poli, Langdon and McPhee, 2008, §2.4). It never changes a tree's size or shape.

Hoist mutation and shrink mutation both make trees smaller. Poli, Langdon and McPhee (2008, §5.2.2) attribute hoist to Kinnear (1994) and shrink to Angeline (1996). Both are motivated by the wish to reduce program size. Other operators in the same catalog permute a function's arguments, perturb numerical constants with Gaussian noise, or optimize the constants by local search.

What each operator does to size

Example (what the definitions already settle). Apply each operator once to a random parent. Point mutation can never change the size, since it only relabels nodes. Hoist and shrink can only shrink the tree or leave it alone: hoist returns a part of the parent, and shrink replaces a subtree with a single node. Subtree mutation should grow trees on average, because a uniformly chosen point is usually a leaf and the replacement is usually larger. Crossover should leave the mean unchanged, for a reason given with the table.

The script measures this. It applies each operator to the same 10,000 parents (pairs, for crossover) drawn at random from the ramped half-and-half population; the drawn parents have mean size 29.62. The new subtree in subtree mutation is a grow tree of depth at most 4, at a uniformly chosen point. Shrink chooses uniformly among the function nodes, so it always shrinks a parent that has one; hoist chooses uniformly among the non-root nodes.

Operator Mean child size Change Larger Smaller Identical to parent
Subtree crossover, 90/10 29.65 +0.03 37.1% 37.2% 1.7%
Subtree crossover, uniform points 29.74 +0.11 28.2% 28.3% 9.7%
Subtree mutation 35.96 +6.33 61.1% 16.5% 5.0%
Point mutation, rate 0.1 per node 29.62 0.00 0% 0% 39.1%
Hoist mutation 2.67 −26.96 0% 83.6% 16.4%
Shrink mutation 24.52 −5.10 0% 83.6% 16.4%

Reading the rows in turn:

  • Crossover leaves the mean size unchanged, as it must when both parents come from the same population. The child's size is the first parent's size, minus the removed subtree, plus the inserted one. The two parents are drawn the same way, and the point in each is chosen by the same rule, which looks only at that parent. So the inserted subtree has the same expected size as the removed one, the two terms cancel, and the expected child size is the expected parent size. The measured changes, +0.03 and +0.11 nodes, are consistent with that zero: their standard errors over the 10,000 pairs are 0.12 and 0.09 nodes.
  • Uniform point selection makes 9.7% of crossovers return an exact copy of the first parent, mostly by swapping a terminal for an identical one. The 90/10 rule cuts that to 1.7%.
  • Subtree mutation grows trees on average, by 6.33 nodes, as the example expected. The size of the change can be predicted from numbers already derived. The child's size is the parent's, minus the removed subtree, plus the new one. The new subtree is a grow tree with depth limit 4, of expected size $\sum_{i=0}^{4} (4/3)^i = 9.64$. The removed subtree, at a uniformly chosen point, has expected size 3.39 in this population (the 90/10 rule section). The predicted change is $9.64 - 3.39 = 6.25$ nodes, against 6.33 measured.
  • Hoist and shrink can only shrink trees. Their 16.4% of identical children are the single-node parents, which they leave unchanged.

Hoist's effect is drastic, from 29.62 nodes to 2.67 on average. The reason is the same one that makes uniform crossover points tend to be leaves. In this implementation the hoisted subtree is chosen uniformly among the non-root nodes, and most nodes of a tree are leaves or sit just above them.

These are measurements of one application of each operator to a random population, not of a run. Under selection, sizes change in ways these averages do not predict, which is the subject of bloat.

Operator rates

In GP the operators are usually mutually exclusive: each child is produced by exactly one of them, chosen at random with given probabilities. Traditionally crossover is applied at a rate of 90% or more and mutation at around 1%. Reproduction, copying a selected individual unchanged, fills the remainder (Poli, Langdon and McPhee, 2008, §2.4). A 50–50 mixture of crossover and several mutations also appears to work well (Poli, Langdon and McPhee, 2008, §3.4).

The tradition of giving crossover 90% and mutation 1% has a history, and it has been tested. The next section covers both.

Crossover versus mutation in GP

Koza (1992) used no mutation in most of his experiments. Poli, Langdon and McPhee (2008, §5.2.1) report that he wanted to show that mutation was not necessary and that GP was not a simple random search, and that this choice strongly influenced the field. Luke and Spector (1997) summarize his argument as resting on two points: the position independence of GP subtrees, and the large number of positions in a typical population (Koza, 1992, pp. 105–107). Its support was data from one problem, the Boolean 6-multiplexer (pp. 599–600).

Luke and Spector's comparison

Luke and Spector (1997) tested the claim systematically. They compared 90% crossover against 90% subtree mutation, each with 10% reproduction, on four problems:

  • the 6-multiplexer;
  • the lawnmower;
  • symbolic regression of $x^4 + x^3 + x^2 + x$;
  • the artificial ant on the Santa Fe trail.

They ran each over a grid of population sizes and run lengths, with tournament sizes 2 and 7, a depth ramp of 2 to 6 and a depth limit of 17. Their subtree mutation, which they called "point" mutation, picked internal nodes 90% of the time. Their findings:

  • crossover was more successful in the majority of tests;
  • mutation tended to do better with smaller populations and more generations;
  • there were few large differences between the two;
  • in most situations, changing the tournament size, and with it the selection pressure, had a larger effect than choosing crossover over mutation.

A second set of runs found no blend of the two that was consistently and significantly better than either alone.

The study had two statistical flaws, which the authors corrected the following year (Luke and Spector, 1998). The results for different run lengths had been read from the same runs as they continued, so they were not independent. And 25 runs per setting were too few. The revision repeated the crossover-versus-mutation comparison (not the blends) with 50 independent runs per setting and three times as much computation, about 1.67 billion evaluations. Its conclusions were similar:

  • crossover was more successful overall;
  • even where the difference was statistically significant, it was often surprisingly small, except in symbolic regression;
  • changing the tournament size often mattered more;
  • the trend that mutation did better in small populations and crossover in large ones was obvious only in symbolic regression and the 6-multiplexer.

The authors concluded that crossover does something useful beyond acting as an unusual mutation, but that its extra benefit is usually modest. Which operator is preferable depends strongly on the problem and the parameters. Poli, Langdon and McPhee (2008, §5.2.1) summarize the wider literature the same way. Mutation-based search, alone or combined with hill climbing or simulated annealing, has matched or beaten crossover-based GP on some problems. The relative performance depends on the problem and the details of the system. Mutation is now widely used.

A small check

The script gp_xo_vs_mut.py repeats the comparison on a small scale, as a check rather than a replication. Its settings:

  • the same quartic symbolic regression target, at 20 evenly spaced points in $[-1, 1]$;
  • {+, −, ×, %} with terminal $x$ and no constants;
  • tournament size 7, and 90% of one operator plus 10% reproduction;
  • 90/10 node selection for both operators, a depth limit of 17, and 50 generations;
  • 30 seeded runs per setting.

A run "hits" if its best program is within 0.01 of the target at all 20 points.

Example (which operator ends with larger trees). The table also records the mean tree size at the end of each run. Given the size measurements above, subtree mutation should end with larger trees, if the one-step averages carry over to a run: one application of it adds 6.33 nodes on average, while crossover adds none. Under selection they need not carry over, but here the runs bear the guess out, by a wide margin:

Population Operator Best-of-run error (sum of absolute errors over the 20 cases), median [Q1, Q3] Runs that hit all 20 cases Final mean tree size (median)
50 90% crossover 0.0000 [0.0000, 4.7237] 19 of 30 15.6
50 90% subtree mutation 0.0000 [0.0000, 1.1108] 17 of 30 210.7
500 90% crossover 0.0000 [0.0000, 0.0000] 30 of 30 116.7
500 90% subtree mutation 0.0000 [0.0000, 0.0000] 28 of 30 259.0

On this easy problem both operators usually find the target exactly. The differences in hits, two runs of 30 at each population size, are too small to separate with 30 runs: a two-sided Fisher exact test gives $p = 0.79$ at population 50 and $p = 0.49$ at population 500. At population 50 the runs that failed did worse with crossover (upper quartile 4.72) than with mutation (1.11).

The clearest difference in our runs is not in fitness but in size. The mutation runs ended with much larger trees, 210.7 and 259.0 nodes against 15.6 and 116.7, and so took much longer to evaluate. Luke and Spector (1998) remarked, anecdotally, that tree growth seemed to waste more time in their crossover runs. In this smaller setup, with its particular mutation settings, the reverse happened. One problem and two population sizes cannot settle the question, which is the point of the larger studies. The answer depends on the problem, the population size and details such as how new subtrees are generated.

In practice

The settings traditionally used for tree-based GP, as described in the sources of this article, are listed below. Each is a starting point, not a recommendation for every problem.

  • Initialization: ramped half-and-half with depth limits 2 to 6 (Poli, Langdon and McPhee, 2008, §3.4). Before a run, compute $g = b\,|F|/(|F| + |T|)$ for the primitive set. With $g$ well below 1, grow gives mostly very small trees (a mean of 2.50 nodes in the nine-terminal example); with $g$ above 1, a large share reach the depth limit (51% in the four-function, two-terminal example). Decide whether to allow single-node trees and duplicates, and report the choice.
  • Crossover points: Koza's 90/10 rule, function nodes 90% of the time (Poli, Langdon and McPhee, 2008, §2.4).
  • Operator rates: crossover at 90% or more, mutation around 1%, reproduction for the rest (§2.4); a 50–50 mix of crossover and several mutations also appears to work well (§3.4).
  • Size control: a depth limit of 17 with a parent returned when the child exceeds it, as in Koza (1992) and in Luke and Spector (1997). Returning parents tends to fill the population with trees just under the limit (Poli, Langdon and McPhee, 2008, §11.3.2); bloat in genetic programming gives the alternatives.
  • Selection: tournament size 7 is common in the GP literature (Luke and Spector, 1997). Their studies found the tournament size often mattered more than the choice of operator.

The library behind every number on this page is tools/experiments/evolution/gp.py: full, grow and ramped_half_and_half for initialization, crossover and subtree_mutation with a p_internal argument for the 90/10 rule, point_mutation, hoist_mutation and shrink_mutation, and a generational loop, evolve.

What we have learned

Initialization is less neutral than it looks. With four binary functions and two terminals, full trees come in exactly five sizes, and grow trees pile up at the extremes: a third are single nodes and half reach the depth limit. The geometric sum $\sum_{i=0}^{D} g^i$ predicts the mean sizes, 19.47 for grow against a measured 19.33. Subtree crossover changes a child's size by the difference between the exchanged subtrees, and Koza's 90/10 rule cuts the share of moves that swap one leaf for another from about 38% to about 1% ($0.1 \times 0.1$), apart from single-node parents. Among the mutations, only subtree mutation grows trees on average; point mutation keeps size, and hoist and shrink cut it. In the literature crossover usually beats mutation, but often by less than a change of tournament size makes.

All of these are measurements of operators on random trees, with no selection driving them toward a target. The next article, symbolic regression, runs a complete GP system on the quadratic and the quartic and reads the programs it evolves.

References

  • Angeline, P. J. (1996). An investigation into the sensitivity of genetic programming to the frequency of leaf selection during subtree crossover. In J. R. Koza, D. E. Goldberg, D. B. Fogel, and R. L. Riolo (eds.), Genetic Programming 1996: Proceedings of the First Annual Conference, 21–29. MIT Press. record
  • Eiben, A. E., and Smith, J. E. (2015). Introduction to Evolutionary Computing, 2nd ed., sections 4.6 and 6.4. Springer. record · 35 pages
  • Kinnear, K. E., Jr. (1994). Fitness landscapes and difficulty in genetic programming. In Proceedings of the First IEEE Conference on Evolutionary Computation (IEEE World Congress on Computational Intelligence), vol. 1, 142–147. IEEE. record
  • Koza, J. R. (1992). Genetic Programming: On the Programming of Computers by Means of Natural Selection. MIT Press. record · 6 pages
  • Luke, S. (2000). Two fast tree-creation algorithms for genetic programming. IEEE Transactions on Evolutionary Computation, 4(3), 274–283. record
  • Luke, S., and Spector, L. (1997). A comparison of crossover and mutation in genetic programming. In J. R. Koza et al. (eds.), Genetic Programming 1997: Proceedings of the Second Annual Conference, 240–248. Morgan Kaufmann. record
  • Luke, S., and Spector, L. (1998). A revised comparison of crossover and mutation in genetic programming. In J. R. Koza et al. (eds.), Genetic Programming 1998: Proceedings of the Third Annual Conference, 208–213. Morgan Kaufmann. record
  • Poli, R., Langdon, W. B., and McPhee, N. F. (2008). A Field Guide to Genetic Programming. Published via lulu.com, freely available at gp-field-guide.org.uk (with contributions by J. R. Koza). record · 5 pages

Reviewed: verified, 16 Nov 2026 · second opinion, 23 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 8 revisions