Utilities

Module containing a host of useful functions that do not fall into more explicit categories.

Util.binaryCounter(bits)[source]

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:

  • bits The number of bits in the binary counter.
Util.classMethods(classType)[source]

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:

  • classType: Specifies what class to retrieve methods for.
Util.loadConfiguration(filename, fileMethod=<built-in function open>)[source]

Loads a json from the given file name. Optional file method allows for compressed files.

Parameters:

  • filename: The relative path to the file to be loaded.
  • fileMethod: Handler to use to open the file. Defaults to regular open.
Util.loadConfigurations(filenames, fileMethod=<built-in function open>)[source]

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:

  • filenames: A list of relative paths to the files to be loaded.
  • fileMethod: Handler to use to open the file. Defaults to regular open.
Util.meanstd(data)[source]

Returns the mean and standard deviation of the given data.

Parameters:

  • data: The data to find the mean and standard deviation of.
Util.median(data, default=0)[source]

Given a data set, return the median value.

Parameters:

  • data: The data to find the median of.
  • default: If data contains no information, what value should be returned. Defaults to 0.
Util.moduleClasses(module)[source]

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:

  • module: Specifies what module to retrieve classes for.
Util.randomBitString(length)[source]

Generate and return a random list of 0s and 1s.

Parameters:

  • length: The length of the list to be generated.
Util.saveConfiguration(filename, data, fileMethod=<built-in function open>)[source]

Writes a block of json-able data to the specifed file path.

Parameters:

  • filename: The relative path to the file to be written to.
  • data: Data that can be converted to a json. IE dictionaries and lists.
  • fileMethod: Handler to use to open the file. Defaults to regular open.
Util.saveList(filename, data)[source]

Write out a list of jsons in a more human readable way than saveConfiguration.

Parameters:

  • filename: The relative path to the file to be written to.
  • data: A list of json-able data to be written

Previous topic

Solution Fitness Function

Next topic

Settings

This Page