Exercise 2. Modifying the fitness landscape, making it smoother, creating a gradient 

Question 1

In this exercise, we will learn about three new genetic representations, and then help evolution escape the plateau of the fitness landscape.

Previously, we became familiar with a simple and very limited genetic representation, f9. Now it's time for f0, f1 and f4.

  • Run the GUI: Framsticks.exe.
  • We will start with f1, which is the default representation, so in the genotypes one does not have to provide the representation format prefix, /*1*/.
  • Click the "New" button to enter a new genotype. By experimenting with different genotypes, learn the meaning of genes: X, parentheses ( and ), comma ,, genes-modifiers: uppercase and lowercase R, uppercase and lowercase Q, uppercase and lowercase C, uppercase and lowercase L.
    When editing, you will sometimes see the background turn pink or red, and the gene that is the beginning of the problematic sequence is underlined. If the background is pink, it means that the repair operators were able to transform an invalid genotype into a valid one – for example, by adding or removing parentheses (and then what you see in the 3D structure preview corresponds to the repaired version of the genotype, which you do not see). If the background is red, it means that the genotype is invalid and the repair operators cannot fix it.
  • In f1, write a genotype that corresponds to this shape.
  • In f1, write a genotype that corresponds to a square (it is expected to look like this, but its ends are not joined).
  • In this class we will not be concerned with the neural network. The specification of f1 is here.
  • Now try editing a few simple f4 genotypes. This representation is to some extent similar to f1 (it also uses the X symbol and the same genes-modifiers: RQCL), but it encodes the process of development of a phenotype. We start with a single undifferentiated cell, the < gene always means a division into two cells, and the > gene denotes the completion of the cell's development, i.e., its specialization into a stick X or into a neuron, for example N:N – cf. Fig. 9 on page 11 and Fig. 3.7 on page 28. Additionally, the # gene enables repeated interpretation of a given genotype fragment (play around by modifying, for example, /*4*/rr#5,<<X><<RRX>X>X>>LLX).
    Experiment by trying to write a few valid f4 genotypes (the specification is here).
  • Finally, it's time for f0. This is the most low-level genetic encoding, where each line describes one element of the phenotype. The lines beginning with p: are "Parts" (and the following three values are the x,y,z coordinates), while the lines beginning with j: are the connections between Parts, i.e., "Joints" (and the following two values are index numbers of the connected Parts). Default values (usually zeros) can be omitted.
  • All genotypes in all genetic representations in Framsticks must be translatable to f0, so that their corresponding phenotypes can be simulated. The tree of translations between different genetic representations is shown here. Having the editing window open with any genotype (e.g., some simple f9 genotype from the previous lab class), click in this window on the "Conversions" item on the left – and there you will find the f0 genotype corresponding (equivalent) to the one being edited. Thus, in order to create a new genetic representation, it is only necessary to provide a translation procedure to any existing representation, this way creating a new node in the representation translation tree.
  • According to Gregory Hornby's tree that classifies different embryogeneses (see the pdf from the last lecture – the one on evolutionary design), where should the following encodings be located in this tree: f0, f1, f4, f9, and also the genotype-phenotype mapping for a permutation when we solve problems like the TSP?


In your response, classify the five genetic representations and mappings (f0, f1, f4, f9, permutation) and paste the f1 genotypes of the square and that spiky structure.

Hornby's classification:

  • f0:
  • f1:
  • f4:
  • f9:
  • permutation in TSP and QAP:

f1 genotypes:

  • square:
  • spiky structure:

Question 2

  • Now perform the same experiments as in the previous lab class (i.e., also the criterion of the height of the center of gravity, "vertpos"), but this time testing four genetic representations, starting with the simplest genotype in each of these representations (usually it is a "Stick" – two Parts connected by a Joint). The loop that implements such an experiment may look like this (note a new file, only-body.sim – copy this file to the appropriate directory, just like the other *.sim files):

    for %%F in (0,1,4,9) do (
        for /L %%N in (1,1,10) do (
            python FramsticksEvolution.py -path %DIR_WITH_FRAMS_LIBRARY%  -sim "eval-allcriteria.sim;deterministic.sim;sample-period-2.sim;only-body.sim"  -opt vertpos -max_numparts 30   -genformat %%F   -popsize sizeatleast50    -generations adequatelength -hof_size 1 -hof_savefile HoF-f%%F-%%N.gen
        ))


  • Generate three kinds of plots just as before (on each plot: four categories corresponding to the four genetic representations). As you can see, evolution at the beginning gets stuck in a certain difficult area (small negative values of the height of the center of gravity of the structure can be regarded as a slight depression of the flat structure into soft ground). Let's try to help evolution get out of this difficult area on its own, i.e., not by immediately providing it with the genotype of a structure that is already tall (this is what we did in the previous lab), but by modifying the objective function as minimally as required to get out of the flat area of the landscape. Check whether the solution landscape for vertpos<0 is perfectly flat (the solutions have exactly the same fitness – that is, the total absence of a gradient), or whether it has bumps.
  • Examine the frams_evaluate() function in the FramsticksEvolution.py file. The default_evaluation_data variable is a dictionary of various genotype evaluation criteria (print it), from which only the criteria actually used in evolution are selected (OPTIMIZATION_CRITERIA). You already know what "numparts" and "numjoints" are for the evaluated structure. In addition to these, the dictionary contains "lifespan" (the number of simulation steps – likely the same for all evaluated structures), "distance", and "velocity" (with velocity=distance/lifespan, but only-body.sim disables the development of a neural network). Using these values, figure out how to adjust the formula for fitness, so that it is modified in the smallest possible area of the fitness landscape in a way that will guide evolution out of the plateau by creating a gradient. Introduce modifications and repeat the entire experiment, thereby producing four more categories on the plots.
  • Think carefully about your modification considering its side effects. Quite often the first idea – despite working satisfactorily – has some drawbacks. Drawbacks – for example, it helps at the beginning of evolution, but it also introduces an unnecessary bias, which we want to avoid, or its impact is uncontrollable/unintended, or it is possible to improve its behavior. We seek a modification of which the author can say: it works better, I know why it works better, I achieved this effect intentionally and I can explain it and prove it with specific examples of evaluation criteria of individuals. Our intervention should be minimal and well-justified: affecting only the plateau area and just enough to guide evolution out of the plateau as quickly as possible with the aid of the gradient – but preferably not affecting the characteristics of the results compared to no intervention.

In your response:

  • attach three types of charts (the same as in the previous lab class) with eight categories each (can be more than eight if you carried out more tests and compared more ideas),
  • explain why (with evolution using the unmodified objective function) the population for some representations left the plateau earlier, and for others it required more generations?
  • provide a precise, unambiguous description and justification for your modification of the fitness function,
  • interpret the results of the experiment,
  • consider and write about other methods that can be used to help evolution escape the plateau. One of them was used in the previous lab class – we simply started evolution far from the plateau, but this is not an attractive method, because it requires inventing a solution and introduces our bias. The second one we practiced now, and this current method is also "manual control". Can there be more natural methods than modifying the objective function – for example, something that also appeared in the previous lab class?

...