This module contains the code used to actually run experiments and to parse the results of those experiments.
Determines the minimum population size for a configuration that acceptably solves the specified problem using bisection. Starts with a minimum population size of 2, this will double the population size until the success criteria are met. It will then perform a binary search of the space between the lowest found successful population size and the highest found unsuccessful population size. Modifies the input configuration dictionary to contain the minimum successful population size found.
Parameters:
Given a list of result dictionaries, determine the mean and standard deviation for all key values. Only combines results where the success key is true and the number of required evaluations is greater than zero (ensures the LTGA variant was actually used and successful). Returns a dictionary containing all keys found in the original result objects, with the success key now set to the success rate
Parameters:
Used to create the initial population for a given run on a specified problem. Uses a HillClimber.steepestAscentHillClimber to optimize all individuals. Will store results to the ‘initialPopFolder’ specified by config for future use, and will automatically load past saved information. Returns the population and a dictionary describing features of that population as well as how it was created.
Parameters:
Performs a full run of the specified configuration using oneRun. Will return a list of result dictionaries describing what happened in each run. If a keyboard interrupt occurs, will return partial information.
Parameters
Performs a single run of LTGA in solving a specific problem. Returns a dictionary of result information
Parameters:
This module provides an interface for how fitness functions should interact with solvers, as well as the definitions for a few benchmark problems
Bases: ltga.FitnessFunction.DeceptiveTrap
Implementation of the deceptive step trap benchmark. Inherits evaluate and subProblemsSolved from DeceptiveTrap.
Bases: ltga.FitnessFunction.FitnessFunction
Implementation of the deceptive trap benchmark.
Given a list of binary genes, return the normalized fitness of those genes.
Parameters:
Normalizes a fitness for a set of genes to be in the range [0-1], such that 1 is considered a successful run. Automatically called by evaluate.
Parameters:
Bases: object
An interface for a fitness function provided to ensure all required functions of a fitness function object are implemented
Empty function handle that throws an exception if not overridden. Given a list of genes, should return the fitness of those genes.
Empty function handle that throws an exception if not overridden. Given a list of genes, returns a list of zeros and ones indicating which sub problems have been solved. If this fitness function cannot be described as having subproblems, should return a list containing a single 1 or 0 indicating if these genes represent the global optimum.
Bases: ltga.FitnessFunction.FitnessFunction
An implementation of the nearest neighbor NK landscape benchmark.
Attempts to load the NK problem specified by the configuration and problem number. If this problem has not been previously generated, this function will construct the fitness matrix and use solve to find the global minimum and maximum.
Parameters:
Given a list of binary genes, return the normalized fitness of those genes.
Parameters:
Given a gene index and the list of gene values in its neighborhood, return the fitness of the subproblem.
Parameters:
Returns the optimal value for this NK instance in polynomial time using dynamic programming. For full explanation for how this algorithm works see:
A. H. Wright, R. K. Thompson, and J. Zhang. The computational complexity of N-K fitness functions. IEEE Trans. on Evolutionary Computation, 4(4):373-379, 2000
Parameters:
This module contains coroutines designed to perform different types of hill climbing as well as a function to perform a complete climb of a single set of genes.
Improves the fitness of a list of binary genes using the given method on the specified evaluation function. Modifies the genes in place and returns how many hill climbing evaluations were required to optimize the genes.
Parameters:
Given a initial list of binary genes, create a generator designed to yield each step in a steepest ascent hill climb. Modifies the genes in place, such that when iteration ends the genes list contains the best found individual.
Parameters:
Simple module containing individual object implementations.
This module contains the implementation of LTGA itself. It includes functionality for each of the variants
Bases: object
Class containing all of the LTGA functionality. Uses the coroutine design structure to interact with problems being optimized. To use, create an LTGA object and then call the generate function. This will send out individuals and expects their fitness to be sent back in.
Used by two parent crossover to create an individual by coping the genetic information from p2 into a clone of p1 for all genes in the given mask. Returns the newly created individual.
Parameters:
Given a method of calculating distance, build the linkage tree for the current population. The tree is built by finding the two clusters with the minimum distance and merging them into a single cluster. The process is initialized with all possible clusters of size 1 and ends when only a single cluster remains. Returns the subtrees in the order they were created.
Parameters:
Calculates the true entropic distance between two clusters of genes.
Parameters:
Calculates the current populations entropy for a given mask.
Parameters:
The individual generator for the LTGA population. Sends out individuals that need to be evaluated and receives fitness information. Will continue sending out individuals until the population contains only one unique individual or a generation passes without the set of unique individuals changing.
Parameters:
Gets the individual’s gene values for the given mask
Parameters:
Creates individual generator using the global crossover variant. Uses coroutines to send out individuals and receive their fitness values. Terminates when a complete evolutionary generation has finished.
Parameters:
Reorders the subtrees such that the cluster pairs with the least linkage appear first in the list. Assumes incoming subtrees are ordered by when they were created by the self.buildTree function.
Parameters:
Calculates the pairwise approximation of the entropic distance between two clusters of genes.
Parameters:
Sets the individual’s gene values for the given mask
Parameters:
Reorders the subtrees such that the cluster pairs with the smallest number of genes appear first in the list. Assumes incoming subtrees are ordered by when they were created by the self.buildTree function.
Parameters:
Creates individual generator using the two parent crossover variant. Uses coroutines to send out individuals and receive their fitness values. Terminates when a complete evolutionary generation has finished.
Parameters:
Module containing a host of useful functions that do not fall into more explicit categories.
Creates a generator that will count through all possible values for a set number of bits. Returned in counting order. For instance, binaryCounter(3) will yield, 000, 001, 010, 011 ... 110, 111.
Parameters:
Given a class type, return a dictionary mapping string names of that class’s methods to the actual method. For instance classMethod(LTGA)['twoParentCrossover'] will return the twoParentCrossover function.
Parameters:
Loads a json from the given file name. Optional file method allows for compressed files.
Parameters:
Given a list of file names, create a single dictionary containing all of their contents. Repeated keywords will override previously encountered values. Optional file method allows for compressed files.
Parameters:
Returns the mean and standard deviation of the given data.
Parameters:
Given a data set, return the median value.
Parameters:
Given a module, return a dictionary mapping string names of that module’s classes to the actual classes. For instance moduleClasses(FitnessFunction)['DeceptiveTrap'] will return the DeceptiveTrap class.
Parameters:
Generate and return a random list of 0s and 1s.
Parameters:
Writes a block of json-able data to the specifed file path.
Parameters:
Write out a list of jsons in a more human readable way than saveConfiguration.
Parameters:
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.8.0 with GCC 4.6.2 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 folders experiments, problems, and variants, which contain configuration information require to recreate the experiments performed in the Linkage Tree Genetic Algorithms: Variants and Analysis publication. For example, the following command uses the general experiment setup on the Deceptive Trap problem with 50 dimensions and a trap size of 5. The LTGA variant original+ is used, and the verbose flag is set to increase the output given. Since no population size is specified, it will automatically call bisection to find the minimum population size.
pypy main.py experiments/general.cfg problems/DeceptiveTrap_50_5.cfg variants/originalplus.cfg -v
For any support questions email brianwgoldman@acm.org or dtauritz@acm.org.