main

This module is intended to duplicate the ‘main()’ function found in other languages such as C++ and Java. In order to run an experiment, this module should be passes to your interpreter. In the interest of speed and consistency we suggest that PyPy 1.9.0 be used to run this code, although Python 2.7 should be able to handle it correctly.

To see a full description of this modules command line arguments, run ``pypy main.py -h``.

Provided with this code should be the cfg folder which contains some configuration files useful for running experiments. These files can be passed to main along with other configuration information in order to recreate the experiments performed in the Reducing Wasted Evaluations in Cartesian Genetic Programming publication. For example, the following command runs a the Accumulate mutation method on the Parity problem using seed number 13 with 3000 nodes in the graph and a mutation rate of 0.01 with verbose output turned on, outputting the results to output/test_run.dat.

pypy main.py cfg/once.cfg cfg/parity.cfg -g 3000 -m 0.01 -seed 13 -s accumulate -v -o output/test_run.dat

For any support questions email brianwgoldman@acm.org.

main.all_runs(config)[source]

Perform all of the requested runs on a given problem. Returns a list of the dictionaries returned by one_run. Will give results for all completed runs if a keyboard interrupt is received.

Parameters:

  • config: Dictionary containing all configuration information required to perform all of the necessary runs of the experiment. Should contain values for:
    • All configuration information needed by one_run
    • problem: The name of which problem from the problem module to run experiments on.
    • runs: How many runs to perform
main.combine_results(results)[source]

Given a list of result dictionaries, return analysis information such as the median values of each statistic as well as the median absolute deviation.

Parameters:

  • results: A list of dictionaries containing similar key values.
main.one_run(evaluator, config)[source]

Performs a single run of the given configuration. Returns a dictionary containing results.

Parameters:

  • evaluator: An object with the function get_fitness that takes an individual and returns its fitness value
  • config: A dictionary containing all of the configuration information required to perform a experimental run, including:
    • All information required to initialize an individual.
    • All information required to run evolution.generate.
    • verbose: Boolean value for if extra runtime information should be displayed.
    • max_evals: The maximum number of evaluations allowed before termination.
    • max_fitness: The fitness required to cause a “successful” termination.

evolution

Handles how to perform all of the actual evolution.

class evolution.Individual(graph_length, input_length, output_length, max_arity, function_list, **_)[source]

Bases: object

An individual object used to combine gene fitness with genomes, as well methods for manipulating those genomes.

asym_phenotypic_difference(other)[source]

Determine how many genes would have to be mutated in order to make the other individual phenotypically identical to self.

Parameters:

  • other: The individual to compare with.
connections(node_index)[source]

Return the list of connections that a specified node has.

Parameters

  • node_index: The index of the node information is being requested for. Note this is different from gene index.
copy()[source]

Return a copy of the individual. Note that individuals are shallow copied except for their list of genes.

determine_active_nodes()[source]

Determines which nodes are currently active and sets self.active to the sorted list of active genes. Automatically called by gene manipulating member functions.

evaluate(inputs)[source]

Given a list of inputs, return a list of outputs from executing this individual.

Parameters:

  • inputs: The list of input values for the individual to process.
mutate(mutation_rate)[source]

Return a mutated version of this individual using the specified mutation rate.

Parameters:

  • mutation_rate: The probability that a specific gene will mutate.
one_active_mutation(_)[source]

Return a mutated version of this individual using the Single mutation method.

random_gene(index, invalid=None)[source]

Determines a random gene value given a gene index. If optional invalid option is used, the returned value will only be invalid if the gene has no other valid values.

Parameters:

  • index: The gene index who’s value is being set.
  • invalid: Value to avoid returning if possible
show_active()[source]

Prints the active portions of the individual in a somewhat readable way.

evolution.generate(config, output)[source]

An Individual generator that will yield a never ending supply of Individual objects that need to have their fitness set before the next Individual can be yielded.

Parameters:

  • config: A dictionary containing all configuration information required to generate initial individuals. Should include values for:
    • All configuration information required to initialize an Individual.
    • mutation_rate: The probably to use for mutation.
    • off_size: The number of offspring to produce per generation.
    • output_length: The number of output variables.
    • max_arity: The maximum arity used by any function.
    • speed: String specifying the way to handle duplicate individual creation, either normal'', ``skip'', ``accumulate, or single.
  • output: Dictionary used to return information about evolution, will send out:
    • skipped: The number of individuals skipped by Skip.
    • estimated: The estimated number of individuals that are skippable.

problems

Defines each of the benchmark problems used as well as the function sets for those problems.

class problems.Problem(problem_function, config)[source]

Bases: object

Object used to store training input values and expected output values which are used in evaluating individuals.

get_fitness(individual)[source]

Return the fitness of an individual as applied to this problem.

Parameters:

  • individual: The individual to be evaluated.
problems.binary_decode(inputs)[source]

Returns a 1 on the output line specified by the binary input index

problems.binary_encode(inputs)[source]

Returns the binary encoding of which input line contains a one.

problems.binary_multiply(inputs)[source]

Return the result of performing a binary multiplication of the first half of the inputs with the second half. Will always have the same number of output bits as input bits.

problems.binary_range(config)[source]

Given a dictionary specifying the input_length, returns all binary values of that length.

problems.even_parity(inputs)[source]

Return the even parity of a list of boolean values.

problems.nand(x, y)[source]

Simple Nand function for inclusion in function sets.

problems.nor(x, y)[source]

Simple Nor function for inclusion in function sets.

problems.problem_attributes(range_method, operators, max_arity)[source]

Decorator that adds attributes to problem functions.

Parameters

  • range_method: The function used to generate training input values.
  • operators: The list of valid operators on this problem.
  • max_arity: The maximum arity of all operators.
problems.single_bit_set(config)[source]

Creates the list of all possible binary strings of specified length with exactly one set bit. config should specify the input_length.

plotter

Takes file names from the output/ folder and parses the information into readable values and produces a graph. Use this module as an executable to process all information for a single problem, such as:

python plotter.py output/multiply*

Do not mix problems in a single run. The graph will be saved to a .eps file named after the problem used.

NOTE: You CANNOT use pypy for this as pylab is current unsupported. Use python 2.7 instead.

wasteplot

Creates the plot of the predicted amount of waste for different mutation rates and different numbers of active genes. To make the plot use:

python wasteplot.py

The graph will be saved to Probability.eps

NOTE: You CANNOT use pypy for this as pylab is current unsupported. Use python 2.7 instead.

util

Collection of utility functions with no other obvious home.

util.diff_count(data1, data2)[source]

Count the number of differences is two sets of data

util.find_median(data)[source]

Returns the median of the data.

util.load_configurations(filenames, file_method=<built-in function open>)[source]

Given a list of files containing json encoded dictionaries, combined the data into a single dictionary.

Parameters:

  • filenames: The list of files paths.
  • file_method: The method to open the file with. Defaults to open. Can be used to read compressed configurations.
util.median_deviation(data, median=None)[source]

Returns the median and the median absolute deviation of the data.

Parameters:

  • data: The data to find the medians of.
  • median: If the median is already known you can pass it in to save time.
util.save_configuration(filename, data, file_method=<built-in function open>)[source]

Write a dictionary to the specified file in json format.

Parameters

  • filename: The path to write to.
  • data: The data to be written.
  • file_method: The method to open the file with. Defaults to open. Can be used to write compressed configurations.
util.save_list(filename, data, file_method=<built-in function open>)[source]

Write a list of dictionaries to the file in a more human readable way.

Parameters

  • filename: The path to write to.
  • data: The list of dictionaries to be written.
  • file_method: The method to open the file with. Defaults to open. Can be used to write compressed configurations.
util.wilcoxon_signed_rank(d1, d2)[source]

Perform a statistical test paired data given in two data sets. Returns W, the number of non-identical pairs, the standard deviation of the rankings, and finally the z value (which is only correct if the data contains more than 10 non identical pairs).

Table Of Contents

Previous topic

Reducing Wasted Evaluations in Cartesian Genetic Programming

This Page