[Cs254f11] evolving programs that use functions of different arities

Lee Spector LSPECTOR at HAMPSHIRE.EDU
Sun Nov 13 14:32:29 EST 2011


I've updated my "evolvefn" GP system to handle functions with different arities. E.g. one of the suggested exercises is to add the "inc" function -- which has arity 1, which is just another way of saying that it takes just 1 argument -- to the function set.

This involved a couple of changes, e.g. to the code generator and to mutation/crossover, and I changed the utility functions in order to make the changes easier. 

You'll note that the utility functions now use the "zipper" data structure, which is why there's a "require" in the ns declaration to use the zipper library. If you're curious about how zippers work you could look at the code for "at-index" and "insert-at-index", but if you're not then that's fine; just use this code instead of the old code and you'll be able to evolve programs that use functions of different arities.

The functions and their arities are now specified as follows:

(def function-table (zipmap '(+ - * pd)
                            '(2 2 2 2 )))

If you want to add inc, for example, you could change this to:

(def function-table (zipmap '(+ - * pd inc)
                            '(2 2 2 2 1)))

The updated code is at: https://gist.github.com/1297325

 -Lee

--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438



More information about the Cs254f11 mailing list