Contents Top Previous Next

B.4 Compiling and Running TinyGP

It is very common, nowadays, for people to write and execute code within some development environment. Each has its own way of doing these operations, but the process is typically very straightforward.

If one wants to compile TinyGP from the operating system's shell, this can be done by issuing the command javac -O tiny_gp.java. This applies to both Unix and Windows users. Windows users will have to click on Start®Run and then issue the command cmd to launch a shell. Of course, if the javac Java compiler and/or the tiny_gp.java source file are not in the current directory/folder, then full path names must be provided when issuing the compilation command.

If the dataset is stored in a file problem.dat, the program can then simply be launched with the command java tiny_gp. Otherwise, the user can specify a different datafile on the command line, by giving the command java tiny_gp FILE, where FILE is the dataset file name (which can include the full path to the file). Finally, the user can specify both the datafile and a seed for the random number generator on the command line, by giving the command java tiny_gp SEED FILE, where SEED is an integer.

As an example, we ran TinyGP on the sin(x) dataset described in Section  B.2 (which is available at http://cswww.essex.ac.uk/staff/rpoli/TinyGP/sin-data.txt). The output produced by the program was something like the following

-- TINY GP (Java version) --SEED=-1MAX_LEN=10000POPSIZE=100000DEPTH=5CROSSOVER_PROB=0.9PMUT_PER_NODE=0.05MIN_RANDOM=-5.0MAX_RANDOM=5.0GENERATIONS=100TSIZE=2----------------------------------Generation=0 Avg Fitness=42.53760218120066 Best Fitness=39.997953686554816 Avg Size=10.9804Best Individual: (1.589816334458055 / -2.128280559500907)Generation=1 Avg Fitness=1226.404415960088 Best Fitness=24.441994244449372 Avg Size=10.97024Best Individual: ((( -0.3839867944222206 / -2.2796127162428403) + ( -1.8386812853617673 / -1.06553859601892)) - 
                   (((4.984026635222818 * (0.17196413319878445 - 0.1294044215655923)) + (X1  - -1.8956001614031734)) * 0.3627020733460027)). . .
The flip-o-rama animation in the footer of the bibliography and index include plots of the best and mean fitness, the mean program size and the behaviour of the best-so-far individual at each generation. The animation should be viewed by rapidly flipping the pages of the book from the beginning of the bibliography onward. For convenience, the plots corresponding to the final generation are also reported in Figure  B.1 .


Figure B.1: Final generation of a TinyGP sample run: best and mean fitness (top), mean program size (middle) and behaviour of the best-so-far individual (bottom).

As one can see, GP progressively evolves better and better approximations to the sine function. The best individual at the end of the run had an error of 1.88. Its unsimplified version as produced by the system is

(X1  / (( -2.766097899954383 * (X1  / (((X1  / ( ( ( (X1  / (X1  * -3.2001163763204445)) * X1 ) - -3.2001163763204445) * -3.2001163763204445)) + X1 )
 + (X1  * (X1  - 3.9532436938954376))))) - (((X1  * X1 ) / (((X1  / (3.9532436938954376 * -3.2001163763204445)) * X1 ) - -3.2001163763204445)) / (((X1  + X1 ) / (X1  * X1 ))
 + X1 ))))
which can be simplified to
-------------x------------- -x---a×x------ -----x2(---)- x-b+x+x×(x- c)   (2x+x)× d- x2e-


a = 2.76609789995
b = 10.240744822
c = 3.9532436939
d = 3.20011637632
e = 12.6508398844
Hardly an obvious approximation for the sine function, but still a very accurate one, at least over the test range.

Contents Top Previous Next