Skip to content

ethanj/CGP.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

227 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CGP.jl

Cartesian Genetic Programming for julia.

This implementation of CGP includes various extensions, including RCGP, MTCGP, genetic crossover, and more.

Development is still ongoing, so be warned that major changes might happen. Stable resources in other languages can be found on the CGP site.

Installation

From the julia REPL call:

Pkg.clone("https://github.com/d9w/CGP.jl")

Tests

CGP.jl comes with exhaustive tests which can offer examples of detailed usage of the different genetic operators and CGP extensions. To run all tests, use

julia run_tests.jl

Examples

Four different examples are found in the experiments folder:

XOR

XOR evolves a function to compute the xor function over nsamples number of randomly generated bits strings of nbits length. This can be run simply with

julia experiments/xor.jl

but various options can be set using command line arguments:

julia experiments/xor.jl --nbits 5 --nsamples 30

Data tasks

Classification and regression can be performed with the data.jl script. Two example datasets have been provided in the data directory: Wisconsin Breast Cancer and Abalone. The first two lines specify the number of inputs and outputs, and the second two lines specify the number of training samples and test samples. Data are read in the order provided in the files, and must be normalized between -1.0 and 1.0 before use in data.jl. To change any of the data preparation steps, modify the read_data function in data.jl.

Classification is the default problem and uses accuracy as the evolutionary fitness. To run classification on the Breast Cancer set, use:

julia experiments/data.jl --data data/cancer.dt --log cancer.log

Regression can be specified as an option on the command line:

julia experiments/data.jl --data data/abalone.dt --log abalone.log --fitness regression

OpenAI gym environments

gym.jl uses PyCall.jl to evolve CGP programs for the OpenAI gym environments. pybullet environments are also included as an alternative to the mujoco environments used by OpenAI. Please see the PyCall.jl documentation for setting up a python environment with the necessary packages (gym and pybullet).

To evolve a program for the MountainCarContinuous-v0 environment, run:

julia experiments/gym.jl --total_evals 200 --seed 1

Atari

atari.jl uses ArcadeLearningEnvironment.jl to evolve programs which play Atari games. This is a more complex example, as it uses Mixed-Type CGP by default (program inputs are RGB Arrays, and outputs are scalar actions.) ROMs are available from Atari-py. Once ROMs have been configured, a CGP agent can be evolved using:

julia experiments/atari.jl --id boxing

This requires a long runtime. Parallelizing evaluations is a currently planned improvement: see this issue.

Configuration

Configuration is handled by src/config.jl. Configurable options are read in through YAML files (an example being cfg/test.yaml) and then are accessed in the CGP.Config module. YAML files are loaded into configuration by running

CGP.Config.init(file)

Redefinition of a configuration value will overwrite the previous value, so be careful about ordering of configuration files. The example files also show usage of the CGP.Config.add_arg_settings! function, which allows for all configuration values to be passed via the command line.

Function set configuration

All node functions are contained in the CGP.Config.functions array and are populated in the configuration files. The syntax for function definitions allows for mixed type CGP by defining a function for both scalar and vector node inputs. The function ordering is:

  • (x, y)
  • (x, y)
  • (x, y)
  • (x, y)

As shorthand, a single function can be specified for all four input types. If two function definitions are provided, the first will apply to the two first two input types where x is a scalar, and the second definition will apply to the second two input types. cfg/atari.yaml demonstrates many different function definitions.

Attribution

A comprehensive review of genetic operators for CGP is underway and is intended to be the reference for this library, but until then a link to this repository would be appreciated in any works which use it.

About

Cartesian Genetic Programming for Julia

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Julia 100.0%