5 minute read

In genetic programming, the learning problem is not the only important choice. The way a candidate solution is represented can change what the search can reach, how genetic operators affect it, and how much it costs to evaluate.

I compared two representations on the same computer-vision task: detecting roads in satellite imagery.

  • Tree-based genetic programming (TGP): a candidate is a syntax tree evaluated directly.
  • Grammatical Evolution (GE): a linear integer chromosome is mapped through a formal grammar into an executable expression.

The question was whether the representation changed the result when both approaches used the same image features, similar evolutionary settings, and the same classification problem.

A shared problem

Both systems were trained on a balanced sample of pixels from the same QEW/Highway 406 image used in my earlier road-detection experiment:

Satellite image of the QEW and Highway 406 training scene

For every sampled pixel, the implementation precomputed 3 × 3, 7 × 7, and 11 × 11 neighbourhood features:

  • average intensity;
  • standard deviation;
  • minimum intensity;
  • maximum intensity.

Each run used 20 repetitions, a population of 1,024, 200 generations, tournament selection, and the same family of arithmetic and logarithmic functions. The test image contained 29,800 pixels.

This matters because it separates the two hypotheses from the image-processing pipeline. The systems consumed the same information; the experiment varied how that information was assembled into a program.

Two ways to represent a program

The tree implementation used ECJ. A complete individual was a parse tree whose terminal nodes supplied precomputed image values and whose internal nodes combined them with functions such as addition, multiplication, minimum, logarithm, inversion, or protected division.

GE represented individuals differently. A fixed linear chromosome contained codons—integer values used to select productions from a Backus-Naur Form grammar. The grammar mapped that chromosome to a valid expression:

<expression> ::= <value>
               | <function>(<expression>)
               | <function>(<expression>, <expression>)

<value>      ::= Avg3x3 | Avg7x7 | Min3x3 | Min7x7
               | Max3x3 | Max7x7 | Std3x3 | Std7x7
               | Std11x11 | <constant>

<function>   ::= add | subtract | multiply | divide
               | max | min | log10 | ln | inverse

This distinction is important. In TGP, crossover and mutation operate directly on tree nodes. In GE, they operate on codons first; a grammar then maps the changed genotype into a new executable phenotype. One codon-level change can therefore alter a branch of the derived expression.

The GEVA command-line configuration reflected that split between representation and evaluation:

java -jar GEVA.jar \
  -main_class Main.Run \
  -fitness_function FitnessEvaluation.ComputerVision.CoscCompVisionImgAnalysis \
  -grammar_file ../param/Grammar/sr5p71a4.bnf \
  -properties_file ../param/Parameters/Tutorials/CVision5p71a4.properties \
  -generations 200 \
  -population_size 512

One limitation of this comparison is that the representations ran in different software systems: ECJ for TGP and GEVA for GE. The study controlled the problem and major settings, but implementation-level differences remained a possible source of variation.

Fitness could not be compared directly

Each system used a fitness scale suited to its framework. TGP minimized the number of misclassified pixels using Koza-style standardized fitness. GE rewarded correct classifications and penalized incorrect ones through a reciprocal score.

To compare them fairly, I used classification outcomes rather than the raw fitness values:

  • true positive (road correctly identified);
  • true negative (non-road correctly identified);
  • false positive;
  • false negative.

For the final comparison, the main measure was total correctness: true positives plus true negatives.

Training behaviour

TGP showed the smoother and more continuous improvement on the training set. It kept improving through 200 generations, with convergence slowing after roughly generation 100.

GE reached a strong level earlier, then improved more slowly. That could indicate useful early discovery, but it could also mean the population converged into a local region too quickly.

The convergence curves show the contrast:

Convergence of GE and panmictic tree-based GP over 200 generations

Training accuracy favoured TGP: the report records 96.1% correct classification for TGP versus 88.85% for GE. But training accuracy alone did not predict the final test result.

Test-set performance

Over the average of 20 runs, GE correctly classified 82.7% of the test image, compared with 74.6% for TGP. The detailed pattern was revealing:

Representation TP TN FP FN Correct
TGP 79.2% 73.9% 26.1% 20.8% 74.6%
GE 43.0% 88.7% 11.9% 52.5% 82.7%

Because non-road pixels dominated the image, GE’s stronger non-road classification lifted its overall score. TGP found more road pixels, but at the cost of more false positives.

The best individuals showed the same direction:

Representation Best-run correct TP TN
TGP 85.9% 70.4% 88.2%
GE 87.9% 66.4% 91.1%

The output images make the trade-off visible:

Tree-based GP Grammatical Evolution
Best TGP classification image Best GE classification image

Green represents true positives, black true negatives, red false positives, and yellow false negatives. Both models struggled with edge regions and with non-road textures that resembled roads.

The statistical check

Since the best scores did not follow normal distributions and the systems used different fitness definitions, I used a Mann-Whitney U test on the 20 best test scores from each representation.

  • GE mean rank: 26.92
  • TGP mean rank: 14.08
  • Mann-Whitney U: 71.5
  • two-tailed significance: 0.001

At a 95% significance level, the difference was statistically significant. A supplemental t-test reached the same direction. The result supports the observed advantage of GE in this experiment; it is not a general proof that GE is always superior to TGP.

Complexity and evaluation time

The strongest difference outside accuracy was program complexity.

The best GE individual used 11 nodes: 6 functions and 5 terminals. The best TGP individual used 43 nodes: 33 functions and 10 terminals.

TGP’s average program size grew substantially through the run:

Average tree size for GE and TGP over 200 generations

GE’s smaller expressions also cost less to evaluate:

Average evaluation time for GE and TGP

The average figures were:

Representation Per individual Per generation Per run
GE 0.12 s 2.03 min 6.79 h
TGP 0.31 s 5.29 min 17.63 h

GE used about 38.37% of the evaluation time required by TGP.

The evolved programs

The best TGP expression was a deep composition dominated by nested logarithmic operations:

(ln
  (* (ln Avg3x3)
     (log10
       (+ (log10 (log10 (log10 (log10 (Inv (log10 Min3x3))))))
          (log10
            (+ (+ Avg3x3
                  (Inv (log10 (ln (+ (log10 (log10 (- Avg3x3 StD7x7)))
                                    (- Avg3x3 StD7x7)))))))
               ...)))))

The best GE-derived expression was much smaller:

(log10
  (- (% (max Max3x3 Min11x11)
        (- Max3x3 Std3x3))
     (log10 Avg3x3)))

The second expression is easier to inspect, test, and reason about. It still combines scale, extremes, and contrast, but does so without the deep nesting seen in the best TGP result.

What the comparison taught me

Representation affected more than search syntax:

  • GE produced more compact solutions. The grammar and chromosome mapping helped limit program size.
  • TGP showed steadier training convergence. It continued improving throughout the run.
  • GE generalized better on this test. Its smaller overall error was statistically significant in the study.
  • Runtime followed complexity. Smaller GE expressions required substantially less evaluation time.
  • Neither model solved edge ambiguity. Similar-looking road and non-road textures remained difficult.

The result is specific to this image, grammar, fitness setup, and implementation environment. It does not establish a universal ranking of GE and TGP. It does show why representation deserves to be treated as a first-class design decision in evolutionary machine learning—not merely an implementation detail.