Page 36 - 49A Field Guide to Genetic Programming
P. 36
22 3 Getting Ready to Run Genetic Programming
This, however, can easily be worked around by providing a mechanism to
convert a numeric value into a Boolean automatically as discussed above.
Alternatively, one can replace the 3-input if with a function of four (nu-
meric) arguments a, b, c, d. The 4-input if implements “If a < b then return
value c otherwise return value d”.
An alternative to requiring type consistency is to extend the GP sys-
tem. Crossover and mutation might explicitly make use of type information
so that the children they produce do not contain illegal type mismatches.
When mutating a legal program, for example, mutation might be required
to generate a subtree which returns the same type as the subtree it has just
deleted. This is discussed further in Section 6.2.
The other component of closure is evaluation safety. Evaluation safety
is required because many commonly used functions can fail at run time. An
evolved expression might, for example, divide by 0, or call MOVE FORWARD
when facing a wall or precipice. This is typically dealt with by modifying
the normal behaviour of primitives. It is common to use protected versions
of numeric functions that can otherwise throw exceptions, such as division,
logarithm, exponential and square root. The protected version of a function
first tests for potential problems with its input(s) before executing the cor-
responding instruction; if a problem is spotted then some default value is
returned. Protected division (often notated with %) checks to see if its second
argument is 0. If so, % typically returns the value 1 (regardless of the value
of the first argument). 1 Similarly, in a robotic application a MOVE AHEAD
instruction can be modified to do nothing if a forward move is illegal or if
moving the robot might damage it.
An alternative to protected functions is to trap run-time exceptions and
strongly reduce the fitness of programs that generate such errors. However,
if the likelihood of generating invalid expressions is very high, this can lead
to too many individuals in the population having nearly the same (very
poor) fitness. This makes it hard for selection to choose which individuals
might make good parents.
One type of run-time error that is more difficult to check for is numeric
overflow. If the underlying implementation system throws some sort of ex-
ception, then this can be handled either by protection or by penalising as
discussed above. However, it is common for implementation languages to
ignore integer overflow quietly and simply wrap around. If this is unaccept-
able, then the GP implementation must include appropriate checks to catch
and handle such overflows.
1
The decision to return the value 1 provides the GP system with a simple way to
generate the constant 1, via an expression of the form (% x x). This combined with a
similar mechanism for generating 0 via (- x x) ensures that GP can easily construct
these two important constants.