Description of all the CGP-Library functions and structures.
API | Description of all the CGP-Library functions and structures. |
Structures | Description of all the structures used by CGP-Library. |
Variables | |
parameters | Stores general evolutionary and chromosome parameters used by the CGP-Library. |
chromosome | Stores a CGP chromosome instances used by the CGP-Library. |
dataSet | Stores a data set which can be used by fitness functions when calculating a chromosomes fitness. |
results | Stores the best chromosome found on each run when using repeatCGP |
Parameters Functions | Description of all the functions related to CGP-Library parameters |
Functions | |
initialiseParameters | Initialises a parameters structure used throughout the CGP-Library. |
freeParameters | Frees parameters structure instance. |
printParameters | Prints the given parameters to the screen in a human readable format. |
addNodeFunction | Adds pre-defined node function(s) to the set of functions stored by a parameters structure. |
addCustomNodeFunction | Adds custom node function to the set of functions stored by a parameters structure. |
clearFunctionSet | Resets the function set stored by a parameters structure to contain no functions. |
setNumInputs | Sets the number of chromosome inputs in the given parameters. |
setNumNodes | Sets the number of chromosome nodes in the given parameters. |
setNumOutputs | Sets the number of chromosome outputs in the given parameters. |
setArity | Sets the arity of the chromosome nodes in the given parameters. |
setMu | Sets the mu value in the given parameters. |
setLambda | Sets the lambda value in the given parameters. |
setEvolutionaryStrategy | Sets the evolutionary strategy in the given parameters. |
setMutationRate | Sets the mutation rate in the given parameters. |
setRecurrentConnectionProbability | Sets the recurrent connection probability in the given parameters. |
setShortcutConnections | Sets whether shortcut connections are used in the given parameters. |
setConnectionWeightRange | Sets the connection weight range in the given parameters. |
setCustomFitnessFunction | Set custom fitness function. |
setCustomSelectionScheme | Sets custom selection scheme. |
setCustomReproductionScheme | Sets custom reproduction scheme. |
setTargetFitness | Sets the target fitness used when running CGP. |
setMutationType | Sets the mutation method used when mutating chromosomes. |
setUpdateFrequency | Sets the frequency of the updates to the user when using runCGP. |
setNumThreads | Sets the number of threads in the given parameters. |
Chromosome Functions | Description of all functions and structures relating to chromosomes |
Functions | |
initialiseChromosome | Initialises a chromosome based on the given parameters. |
initialiseChromosomeFromFile | Initialises a chromosome from a given previously saved chromosome. |
initialiseChromosomeFromChromosome | Initialises a chromosome from a given chromosome. |
freeChromosome | Frees chromosome instance. |
printChromosome | Displays the given chromosome to the terminal / command prompt in a human readable format. |
executeChromosome | Executes the given chromosome. |
getChromosomeOutput | Gets the outputs of the given chromosome after it has been executed using executeChromosome. |
getChromosomeNodeValue | Gets the node value of the given chromosome and node after it has been executed using executeChromosome. |
isNodeActive | Returns whether the given node in the given chromosome is active. |
saveChromosome | Saves the given chromosome to a file which can used to initialise new chromosomes. |
saveChromosomeDot | Saves the given chromosome to a graphviz .dot file. |
saveChromosomeLatex | Saves the given chromosome to a latex .tex file for visulisation and inclusion in written workes. |
mutateChromosome | Mutate the given chromosome using the mutation method described in the given parameters. |
removeInactiveNodes | Removes all of the inactive nodes from the given chromosome. |
setChromosomeFitness | Sets the fitness of the chromosome using the fitness function given in the parameters |
resetChromosome | Resets all of the chromosome nodes to output zero. |
copyChromosome | Copies the contents of one chromoosme into the other. |
getNumChromosomeInputs | Gets the number of chromosome inputs |
getNumChromosomeNodes | Gets the number of chromosome nodes |
getNumChromosomeActiveNodes | Gets the number of chromosome active nodes |
getNumChromosomeOutputs | Gets the number of chromosome outputs |
getChromosomeNodeArity | Gets the arity of the chromosome nodes |
getChromosomeFitness | Gets the fitness of the given chromosome |
getNumChromosomeActiveConnections | Gets the number of active connections in the given chromosome |
getChromosomeGenerations | Gets the number of generations for which the given chromosome has been trained. |
DataSet Functions | Description of all functions and structures relating to data sets |
Functions | |
initialiseDataSetFromArrays | Initialises a dataSet structures using the given input output pairs. |
initialiseDataSetFromFile | Initialises a dataSet structures using the given file. |
freeDataSet | Frees dataSet instance. |
printDataSet | Prints the input output pairs held by a dataSet structure to the terminal. |
saveDataSet | Saves the given dataSet to a file which can be read using initialiseDataSetFromFile. |
getNumDataSetInputs | Gets the number of dataSet inputs. |
getNumDataSetOutputs | Gets the number of dataSet outputs. |
getNumDataSetSamples | Gets the number of samples in the given dataSet. |
getDataSetSampleInputs | Gets the dataSet inputs for the given sample index. |
getDataSetSampleInput | Gets the dataSet input for the given sample index and input index. |
getDataSetSampleOutputs | Gets the dataSet outputs for the given sample index. |
getDataSetSampleOutput | Gets the dataSet output for the given sample index and output index. |
Results Functions | |
Functions | |
freeResults | Frees results instance. |
saveResults | Saves the given results to a csv file. |
getChromosome | Gets a copy of the best chromosome found on the given run in an initialised results structure. |
getNumChromosomes | Gets number of chromosomes stored in the given results structure. |
getAverageFitness | Gets the average fitness of the best chromosome found for each run in results. |
getMedianFitness | Gets the median fitness of the best chromosome found for each run in results. |
getAverageActiveNodes | Gets the average number of active nodes of the best chromosome found for each run in results. |
getMedianActiveNodes | Gets the median number of active nodes of the best chromosome found for each run in results. |
getAverageGenerations | Gets the average number generations required to find the best best chromosome for each run in results. |
getMedianGenerations | Gets the median number generations required to find the best best chromosome for each run in results. |
CGP Functions | |
Functions | |
runCGP | Applies CGP to the given task. |
repeatCGP | Repeatedly applies CGP to the given task. |
Other | |
Functions | |
setRandomNumberSeed | Sets the seed used by the random number generator in CGP-Library. |
Description of all the structures used by CGP-Library.
Variables | |
parameters | Stores general evolutionary and chromosome parameters used by the CGP-Library. |
chromosome | Stores a CGP chromosome instances used by the CGP-Library. |
dataSet | Stores a data set which can be used by fitness functions when calculating a chromosomes fitness. |
results | Stores the best chromosome found on each run when using repeatCGP |
struct parameters
Stores general evolutionary and chromosome parameters used by the CGP-Library.
The parameters structure is used extensively by the CGP-Library and controls every aspect of the evolutionary algorithm and solution structure.
The values stored in parameters are set to default values when initialised using initialiseParameters. These default values can then be altered using provided setter functions.
Default parameter values.
mu: 1 lambda: 4 evolutionary strategy: + mutation rate: 0.05 Recurrent Connection Probability 0.00 Shortcut Connections 1 connection weight range: 1 update frequency: 1 mutation type: probabilistic fitness function: supervisedLearning selection scheme: selectFittest reproduction scheme: mutateRandomParent number of threads 1
struct chromosome
Stores a CGP chromosome instances used by the CGP-Library.
initialiseChromosome, initialiseChromosomeFromFile freeChromosome, printChromosome, executeChromosome, mutateChromosome
struct dataSet
Stores a data set which can be used by fitness functions when calculating a chromosomes fitness.
Typically contains input output pairs of data used when applying CGP to supervised learning tasks.
initialiseDataSetFromFile, initialiseDataSetFromArrays, freeDataSet, printDataSet
struct results
Stores the best chromosome found on each run when using repeatCGP
repeatCGP, freeResults, getChromosome, getAverageFitness, getAverageActiveNodes, getAverageGenerations
Description of all the functions related to CGP-Library parameters
Functions | |
initialiseParameters | Initialises a parameters structure used throughout the CGP-Library. |
freeParameters | Frees parameters structure instance. |
printParameters | Prints the given parameters to the screen in a human readable format. |
addNodeFunction | Adds pre-defined node function(s) to the set of functions stored by a parameters structure. |
addCustomNodeFunction | Adds custom node function to the set of functions stored by a parameters structure. |
clearFunctionSet | Resets the function set stored by a parameters structure to contain no functions. |
setNumInputs | Sets the number of chromosome inputs in the given parameters. |
setNumNodes | Sets the number of chromosome nodes in the given parameters. |
setNumOutputs | Sets the number of chromosome outputs in the given parameters. |
setArity | Sets the arity of the chromosome nodes in the given parameters. |
setMu | Sets the mu value in the given parameters. |
setLambda | Sets the lambda value in the given parameters. |
setEvolutionaryStrategy | Sets the evolutionary strategy in the given parameters. |
setMutationRate | Sets the mutation rate in the given parameters. |
setRecurrentConnectionProbability | Sets the recurrent connection probability in the given parameters. |
setShortcutConnections | Sets whether shortcut connections are used in the given parameters. |
setConnectionWeightRange | Sets the connection weight range in the given parameters. |
setCustomFitnessFunction | Set custom fitness function. |
setCustomSelectionScheme | Sets custom selection scheme. |
setCustomReproductionScheme | Sets custom reproduction scheme. |
setTargetFitness | Sets the target fitness used when running CGP. |
setMutationType | Sets the mutation method used when mutating chromosomes. |
setUpdateFrequency | Sets the frequency of the updates to the user when using runCGP. |
setNumThreads | Sets the number of threads in the given parameters. |
DLL_EXPORT struct parameters *initialiseParameters( const int numInputs, const int numNodes, const int numOutputs, const int arity )
Initialises a parameters structure used throughout the CGP-Library. The arguments describe the structure of the chromosomes created when using initialiseChromosome, runCGP or repeatCGP.
numInputs | the number of chromosome inputs required. |
numNodes | the number of chromosome nodes required. |
numOutputs | the number of chromosome outputs required. |
arity | the arity of each chromosome node required. |
A pointer to an initialised parameters structure.
Initialising parameters
struct parameters *params; int numInputs = 3; int numNodes = 10; int numOutputs = 2; int nodeArity = 2; params = initialiseParameters(numInputs, numNodes, numOutputs, nodeArity);
DLL_EXPORT void freeParameters( struct parameters * params )
Frees parameters structure instance.
params | pointer to initialised parameters structure. |
DLL_EXPORT void printParameters( struct parameters * params )
Prints the given parameters to the screen in a human readable format.
params | pointer to parameters structure. |
Typical parameters structure printed using printParameters.
--------------------------------------------------- Parameters --------------------------------------------------- Evolutionary Strategy: (1+4)-ES Inputs: 1 Nodes: 15 Outputs: 1 Node Arity: 2 Connection weights range: +/- 1.000000 Mutation Type: probabilistic Mutation rate: 0.050000 Fitness Function: supervisedLearning Target Fitness: 0.100000 Selection scheme: selectFittest Reproduction scheme: mutateRandomParent Update frequency: 500 Function Set: add sub mul div sin (5) ---------------------------------------------------
DLL_EXPORT void addNodeFunction( struct parameters * params, char const * functionNames )
Adds pre-defined node function(s) to the set of functions stored by a parameters structure. These are the node functions available when using runCGP, repeatCGP and mutateChromosome.
If one function name is given that function is added to the function set. If multiple node function names are given then each must be separated by a ‘,’.
If a node function name is given which is not recognised, a warning is given and that function is not added to the function set.
params | pointer to parameters structure |
functionNames | the name(s) of the function(s) to be added to the function set |
mathematical operations
logic gates
neuron transfer/activation functions
Other
Add the node functions logical AND OR NAND NOR and XOR to the function set.
addNodeFunction(params, "and,or,nand,nor,xor");
DLL_EXPORT void addCustomNodeFunction( struct parameters * params, double (*function)(const int numInputs, const double *inputs, const double *weights), char const * functionName, int maxNumInputs )
Adds custom node function to the set of functions stored by a parameters structure. See addNodeFunction.
The custom fitness function prototype must take the form
double nodeFunctionName(const int numInputs, const double *inputs, const double *weights);
where the user replaces ‘nodeFunctionName’ with their own function name.
params | pointer to an initialised parameters structure |
function | the custom node function |
functionName | the name of the added function |
maxNumInputs | maximum number of inputs to function (-1 is unlimited) |
Creating a custom node function ‘add’
double add(const int numInputs, const double *inputs, const double *connectionWeights){ int i; double sum = 0; for(i=0; i<numInputs; i++){ sum += inputs[i]; } return sum; }
Adding the new custom node function to the function set
addCustomNodeFunction(params, add, "add", -1);
The connections weights are used for when creating custom node functions for Artificial Neural Networks. If required they are accessed in the same way as the inputs.
DLL_EXPORT void clearFunctionSet( struct parameters * params )
Resets the function set stored by a parameters structure to contain no functions.
params | pointer to an initialised parameters structure |
DLL_EXPORT void setNumInputs( struct parameters * params, int numInputs )
Sets the number of chromosome inputs in the given parameters.
The given number of chromosome inputs is also parsed to ensure a valid number of chromosome inputs. A number of chromosome inputs <0 is invalid. If an invalid number of chromosome inputs is give an error is displayed and CGP-Library terminates.
params | pointer to parameters structure. |
numInputs | The number of chromosome inputs to be set. |
DLL_EXPORT void setNumNodes( struct parameters * params, int numNodes )
Sets the number of chromosome nodes in the given parameters.
The given number of chromosome nodes is also parsed to ensure a valid number of chromosome nodes. A number of chromosome nodes <0 is invalid. If an invalid number of chromosome nodes is give an error is displayed and CGP-Library terminates.
params | pointer to parameters structure. |
nodes | The number of chromosome nodes to be set. |
DLL_EXPORT void setNumOutputs( struct parameters * params, int numOutputs )
Sets the number of chromosome outputs in the given parameters.
The given number of chromosome outputs is also parsed to ensure a valid number of chromosome outputs. A number of chromosome outputs <1 is invalid. If an invalid number of chromosome outputs is give an error is displayed and CGP-Library terminates.
params | pointer to parameters structure. |
numOutputs | The number of chromosome outputs to be set. |
DLL_EXPORT void setArity( struct parameters * params, int arity )
Sets the arity of the chromosome nodes in the given parameters.
The given arity for each chromosome node is also parsed to ensure a valid chromosome node arity. A chromosome node arity <1 is invalid. If an invalid chromosome node arity is give an error is displayed and CGP-Library terminates.
params | pointer to parameters structure. |
arity | The chromosome node arity to be set. |
DLL_EXPORT void setMu( struct parameters * params, int mu )
Sets the mu value in the given parameters.
The given mu value is also parsed to ensure a valid mu value. mu values <1 are invalid. If an invalid mu value is give a warning is displayed and the mu value is left unchanged.
params | pointer to parameters structure. |
mu | The value of mu to be set. |
DLL_EXPORT void setLambda( struct parameters * params, int lambda )
Sets the lambda value in the given parameters.
The given lambda value is also parsed to ensure a valid lambda value. lambda values <1 are invalid. If an invalid lambda value is give a warning is displayed and the lambda value is left unchanged.
params | pointer to parameters structure. |
lambda | The value of lambda to be set. |
DLL_EXPORT void setEvolutionaryStrategy( struct parameters * params, char evolutionaryStrategy )
Sets the evolutionary strategy in the given parameters.
The given evolutionary strategy is also parsed to ensure a valid evolutionary strategy. Evolutionary strategies other than ‘+’ and ‘,’ are invalid. If an invalid evolutionary strategy is give a warning is displayed and the evolutionary strategy is left unchanged.
params | pointer to parameters structure. |
evolutionaryStrategy | The evolutionary strategy to be set. |
DLL_EXPORT void setMutationRate( struct parameters * params, double mutationRate )
Sets the mutation rate in the given parameters.
The given mutation rate is also parsed to ensure a valid mutation rate. Mutation rate <0 or >1 are invalid. If an invalid mutation rate is give a warning is displayed and the mutation rate is left unchanged.
params | pointer to parameters structure. |
mutationRate | The value of the mutation rate to be set. |
DLL_EXPORT void setRecurrentConnectionProbability( struct parameters * params, double recurrentConnectionProbability )
Sets the recurrent connection probability in the given parameters.
The recurrent connection probability specifies the probability that a mutation to a connection gene will create a recurrent connection; otherwise a standard feed forward connection is made. The given recurrent connection probability is also parsed to ensure a valid recurrent connection probability. Recurrent connection probability <0 or >1 are invalid. If an invalid recurrent connection probability is give a warning is displayed and the recurrent connection probability is left unchanged.
params | pointer to parameters structure. |
recurrentConnectionProbability | The value of the recurrent connection probability to be set. |
DLL_EXPORT void setShortcutConnections( struct parameters * params, int shortcutConnections )
Sets whether shortcut connections are used in the given parameters.
Shortcut Connections specifies whether an output can connect directly to an input. Only Shortcut Connections of values 0 (no) and 1 (yes) are valid. If an invalid value is given, a warning is displayed and the shortcut connections value is left unchanged.
params | pointer to parameters structure. |
shortcutConnections | whether shortcut connections are used |
DLL_EXPORT void setConnectionWeightRange( struct parameters * params, double weightRange )
Sets the connection weight range in the given parameters. (only used by NeuroEvolution)
params | pointer to parameters structure. |
weightRange | The connection weight range to be set. (the range is +/- weightRange) |
DLL_EXPORT void setCustomFitnessFunction( struct parameters * params, double (*fitnessFunction)(struct parameters *params, struct chromosome *chromo, struct dataSet *data), char const * fitnessFunctionName )
Set custom fitness function.
By default the CGP-Library used a generic supervised learning fitness function where the fitness assigned to each chromosome is the sum of the absolute differences between the actual and target outputs defined in the given dataSet. setCustomFitnessFunction is used to redefine the fitness function to be one of the users design.
All custom fitness function prototype must take the following form. Where params is a parameters structure, chromo is the chromosome to be assigned a fitness and data is a dataSet which may be used by the custom fitness function.
double functionName(struct parameters *params, struct chromosome *chromo, struct dataSet *data);
params | pointer to parameters structure. |
fitnessFunction | the custom fitness function |
fitnessFunctionName | name of custom fitness function |
If the fitnessFunction parameter is set as NULL, the fitness function will be reset to the default supervised learning fitness function.
Defining a custom fitness function, full adder. Note that the dataSet does not have to be used.
double fullAdder(struct parameters *params, struct chromosome *chromo, struct data *dat){ int i; double error = 0; // full adder truth table double inputs[8][3] = {{0,0,0},{0,0,1},{0,1,0},{0,1,1},{1,0,0},{1,0,1},{1,1,0},{1,1,1}}; double outputs[8][2] = {{0,0},{1,0},{1,0},{0,1},{1,0},{0,1},{0,1},{1,1}}; //for each line in the truth table for(i=0; i<8; i++){ // calculate the chromosome outputs for each set of inputs executeChromosome(chromo, inputs[i]); // If the first chromosome outputs differ from the correct outputs increment the error if(outputs[i][0] != getChromosomeOutput(chromo, 0) ){ error++; } // If the second chromosome outputs differ from the correct outputs increment the error if(outputs[i][1] != getChromosomeOutput(chromo, 1) ){ error++; } } return error; }
Setting the new custom fitness function as the fitness function to be used
setCustomFitnessFunction(params, fullAdder, "fullAdder");
DLL_EXPORT void setCustomSelectionScheme( struct parameters * params, void (*selectionScheme)(struct parameters *params, struct chromosome **parents, struct chromosome **candidateChromos, int numParents, int numCandidateChromos), char const * selectionSchemeName )
Sets custom selection scheme.
By default the selection scheme used by CGP-Library is select fittest, where the fittest members of the candidate chromosomes are always selected as the parents. This type of selection scheme is commonly used by CGP. setCustomSelectionScheme is used to redefine the selection scheme to be one of the users design.
The custom selection scheme prototype must take the following form. Where params is a parameters structure, parents is an array of chromosomes used to store the selected parents, candidateChromos is an array of chromosomes containing the pool of chromosomes to select the parent from, numParents is the number of parents to be selected and numCandidateChromos is the number of candidate chromosomes.
void selectionSchemeNmes(struct parameters *params, struct chromosome **parents, struct chromosome **candidateChromos, int numParents, int numCandidateChromos);
The ordering of the candidateChromos is children followed by parents.
params | pointer to parameters structure |
selectionScheme | the custom selection scheme |
selectionSchemeName | name of custom selection scheme |
If the selectionScheme parameter is set as NULL, the selection scheme will be reset to the default select fittest selection scheme.
Defining a custom selection scheme, tournament selection.
void tournament(struct parameters *params, struct chromosome **parents, struct chromosome **candidateChromos, int numParents, int numCandidateChromos){ int i; // two chromosome pointers to point to the chromosomes in the torment struct chromosome *candidateA; struct chromosome *candidateB; // for the number of required parents for(i=0; i<numParents; i++){ // randomly select chromosomes for tournament candidateA = candidateChromos[rand() % numCandidateChromos]; candidateB = candidateChromos[rand() % numCandidateChromos]; // choose the fittest chromosome to become a parent if(getChromosomeFitness(candidateA) <= getChromosomeFitness(candidateB)){ copyChromosome(parents[i], candidateA); } else{ copyChromosome(parents[i], candidateB); } } }
Setting the new custom selection scheme as the selection scheme to be used
setCustomSelectionScheme(params, tournament, "tournament");
DLL_EXPORT void setCustomReproductionScheme( struct parameters * params, void (*reproductionScheme)(struct parameters *params, struct chromosome **parents, struct chromosome **children, int numParents, int numChildren), char const * reproductionSchemeName )
Sets custom reproduction scheme.
By default the reproduction scheme used by CGP-Library is to create each child as a mutated version of a randomly selected parent. This type of reproduction scheme is commonly used by CGP. setCustomReproductionScheme is used to redefine the reproduction scheme to be one of the users design.
The custom reproduction scheme prototype must take the following form. Where params is a parameters structure, parents is an array of chromosomes which store the parents to select from, children is an array of chromosomes which will contain the children after reproduction, numParents is the number of parents available for reproduction and numChildren is the number of children to be created.
void reproductionScheme(struct parameters *params, struct chromosome **parents, struct chromosome **children, int numParents, int numChildren);
If the reproductionScheme parameter is set as NULL, the reproduction scheme will be reset to the default mutate random parent reproduction scheme.
Defining a custom reproduction scheme, ...
Setting the new custom reproduction scheme as the reproduction scheme to be used
setCustomReproductionScheme(params, ..., "...");
DLL_EXPORT void setTargetFitness( struct parameters * params, double targetFitness )
Sets the target fitness used when running CGP.
In all cases lower fitness values are used to represent fitter chromosomes.
params | pointer to parameters structure. |
targetFitness | The target fitness to be set. |
DLL_EXPORT void setMutationType( struct parameters * params, char const * mutationType )
Sets the mutation method used when mutating chromosomes.
Used to set the mutation method used when running runCGP and repeatCGP or when mutating an individual chromosome using mutateChromosome. The type of mutation used is set the parameters structure.
If an invalid mutation type is given a warning is displayed and the mutation type is left unchanged.
These are the mutation methods which can be selected from.
params | pointer to parameters structure. |
mutationType | char array specifying the mutation type. |
struct parameters *params = NULL; params = initialiseParameters(1,10,1,2); setMutationType(params, "point"); setMutationType()
DLL_EXPORT void setUpdateFrequency( struct parameters * params, int updateFrequency )
Sets the frequency of the updates to the user when using runCGP.
The update frequency represents the number of generations which elapse between showing the user the current best fitness.
A value of ‘0’ is a special case which causes not updates to be shown.
params | pointer to parameters structure. |
updateFrequency | update frequency in generations. |
DLL_EXPORT void setNumThreads( struct parameters * params, int numThreads )
Sets the number of threads in the given parameters.
The given number of threads is also parsed to ensure a valid value. Values <1 are invalid. If an invalid value is give a warning is displayed and the value is left unchanged.
In order for the CGP-Library to use multiple threads it must be compiled with openMP flag set (-fopenmp for gcc/mingw).
The CGP-Library ignores the OMP_NUM_THREADS environment variable. The only method for setting the number of threads is using setNumThreads.
params | pointer to parameters structure. |
numThreads | The number of threads to be set. |
Description of all functions and structures relating to chromosomes
Functions | |
initialiseChromosome | Initialises a chromosome based on the given parameters. |
initialiseChromosomeFromFile | Initialises a chromosome from a given previously saved chromosome. |
initialiseChromosomeFromChromosome | Initialises a chromosome from a given chromosome. |
freeChromosome | Frees chromosome instance. |
printChromosome | Displays the given chromosome to the terminal / command prompt in a human readable format. |
executeChromosome | Executes the given chromosome. |
getChromosomeOutput | Gets the outputs of the given chromosome after it has been executed using executeChromosome. |
getChromosomeNodeValue | Gets the node value of the given chromosome and node after it has been executed using executeChromosome. |
isNodeActive | Returns whether the given node in the given chromosome is active. |
saveChromosome | Saves the given chromosome to a file which can used to initialise new chromosomes. |
saveChromosomeDot | Saves the given chromosome to a graphviz .dot file. |
saveChromosomeLatex | Saves the given chromosome to a latex .tex file for visulisation and inclusion in written workes. |
mutateChromosome | Mutate the given chromosome using the mutation method described in the given parameters. |
removeInactiveNodes | Removes all of the inactive nodes from the given chromosome. |
setChromosomeFitness | Sets the fitness of the chromosome using the fitness function given in the parameters |
resetChromosome | Resets all of the chromosome nodes to output zero. |
copyChromosome | Copies the contents of one chromoosme into the other. |
getNumChromosomeInputs | Gets the number of chromosome inputs |
getNumChromosomeNodes | Gets the number of chromosome nodes |
getNumChromosomeActiveNodes | Gets the number of chromosome active nodes |
getNumChromosomeOutputs | Gets the number of chromosome outputs |
getChromosomeNodeArity | Gets the arity of the chromosome nodes |
getChromosomeFitness | Gets the fitness of the given chromosome |
getNumChromosomeActiveConnections | Gets the number of active connections in the given chromosome |
getChromosomeGenerations | Gets the number of generations for which the given chromosome has been trained. |
DLL_EXPORT struct chromosome *initialiseChromosome( struct parameters * params )
Initialises a chromosome based on the given parameters.
params | pointer to parameters structure |
A pointer to an initialised chromosome structure.
freeChromosome, initialiseChromosomeFromFile, initialiseChromosomeFromChromosome
DLL_EXPORT struct chromosome* initialiseChromosomeFromFile( char const * file )
Initialises a chromosome from a given previously saved chromosome.
Only chromosomes which use node functions defined by the CGP-library can be loaded. Chromosomes which use custom node functions cannot be loaded.
file | char array giving the location of the chromosome to be loaded. |
A pointer to an initialised chromosome structure.
struct Chromosome *chromo; char *chromoFile = "location of Chromosome"; chromo = loadChromosome(chromoFile);
freeChromosome, initialiseChromosome, initialiseChromosomeFromChromosome,
DLL_EXPORT struct chromosome *initialiseChromosomeFromChromosome( struct chromosome * chromo )
Initialises a chromosome from a given chromosome.
This functions can be used to create a copy of a chromosome.
chromo | pointer to an initialised chromosome structure. |
A pointer to an initialised chromosome structure.
freeChromosome, initialiseChromosome, initialiseChromosomeFromFile
DLL_EXPORT void printChromosome( struct chromosome * chromo, int weights )
Displays the given chromosome to the terminal / command prompt in a human readable format.
chromo | pointer to chromosome structure. |
weights | if set as 1 display connections weights |
Typical output from printChromosome.
Each input and functioning node is labelled with its index in the chromosome. There is a textual description of the node e.g. input for input nodes or the operation for the function nodes. Function node operations are followed by space separated values describing each nodes inputs. Active nodes are also labelled with an *. Finally the last line gives the nodes used as chromosome outputs.
(0): input (1): mul 0 0 * (2): add 0 1 * (3): sub 2 0 * (4): mul 0 1 * (5): add 4 3 * (6): sub 4 2 * (7): mul 6 5 * (8): add 5 7 * (9): mul 1 6 (10): mul 5 3 (11): add 4 1 (12): add 10 3 (13): add 5 11 (14): sub 3 6 (15): div 5 13 outputs: 8
DLL_EXPORT void executeChromosome( struct chromosome * chromo, const double * inputs )
Executes the given chromosome.
Executes the given chromosome with the given inputs. The dimensions of the inputs arrays must match the dimensions of the chromosome inputs. The chromosome outputs are then accessed using getChromosomeOutput.
chromo | pointer to an initialised chromosome structure. |
inputs | array of doubles used as inputs to the chromosome |
for a chromosome with three inputs and one outputs.
struct parameters *params = NULL; struct chromosome *chromo = NULL; double chromoInputs[] = {1, 2}; double chromoOutput; params = initialiseParameters(2, 10, 1, 2); addNodeFunction(params, "add,sub,mul,sq,cube,sin"); chromo = initialiseChromosome(params); executeChromosome(chromo, chromoInputs); chromoOutput = getChromosomeOutput(chromo, 0); freeParameters(params); freeChromosome(chromo);
(end)
DLL_EXPORT double getChromosomeOutput( struct chromosome * chromo, int output )
Gets the outputs of the given chromosome after it has been executed using executeChromosome.
After a given chromosome has been executed using executeChromosome the chromosome outputs are made available using getChromosomeOutput.
chromo | pointer to an initialised chromosome structure. |
output | The index of the output to be retrieved |
DLL_EXPORT double getChromosomeNodeValue( struct chromosome * chromo, int node )
Gets the node value of the given chromosome and node after it has been executed using executeChromosome.
After a given chromosome has been executed using executeChromosome the chromosome node values are made available using getChromosomeNodeValue.
chromo | pointer to an initialised chromosome structure. |
output | The index of the node value to be retrieved |
DLL_EXPORT int isNodeActive( struct chromosome * chromo, int node )
Returns whether the given node in the given chromosome is active. 1-active, 0-inactive
If the given node index is less than zero or greater then the number of nodes in the given chromosome and error message is displayed and the program will terminate.
chromo | pointer to an initialised chromosome structure. |
node | The index of the node |
DLL_EXPORT void saveChromosome( struct chromosome * chromo, char const * fileName )
Saves the given chromosome to a file which can used to initialise new chromosomes.
New chromosomes can be initialised using the saved chromosomes by calling initialiseChromosomeFromFile.
Only chromosome which use node functions defined by the CGP-library can be loaded. Chromosomes which use custom node functions cannot be loaded.
chromo | pointer to chromosome structure. |
fileName | char array giving the location of the chromosome to be saved. |
initialiseChromosomeFromFile, saveChromosomeDot saveChromosomeLatex
DLL_EXPORT void saveChromosomeDot( struct chromosome * chromo, int weights, char const * fileName )
Saves the given chromosome to a graphviz .dot file.
graphviz (www.graphviz.org) is a free open source graph drawing tool. Once installed graphviz can be used to draw the chromosomes saved using saveChromosomeDot with the following command.
dot -Tsvg chromosome.dot -o chromosome.svg
chromo | pointer to chromosome structure. |
weights | whether or not to include connection weights, 0 - without weights, 1 - with weights. |
fileName | char array giving the location of the chromosome dot file to be saved. |
DLL_EXPORT void saveChromosomeLatex( struct chromosome * chromo, int weights, char const * fileName )
Saves the given chromosome to a latex .tex file for visulisation and inclusion in written workes.
LaTeX (www.http://latex-project.org/intro.html) is a free open source document preparation system. Once installed LaTeX can be used to draw the chromosomes saved using saveChromosomeLatex with the following command.
latex chromosome.tex
or
pdflatex chromosome.tex
chromo | pointer to chromosome structure. |
weights | whether or not to include connection weights, 0 - without weights, 1 - with weights. |
fileName | char array giving the location of the chromosome dot file to be saved. |
DLL_EXPORT void mutateChromosome( struct parameters * params, struct chromosome * chromo )
Mutate the given chromosome using the mutation method described in the given parameters.
params | pointer to parameters structure |
chromo | pointer to chromosome structure. |
struct parameters *params; struct chromosome *chromo; params = initialiseParameters(3,10,2,2); chromo = initialiseChromosome(params); mutateChromosome(params, chromo);
DLL_EXPORT void setChromosomeFitness( struct parameters * params, struct chromosome * chromo, struct dataSet * data )
Sets the fitness of the chromosome using the fitness function given in the parameters
params | pointer to parameters structure |
chromo | pointer to chromosome structure. |
data | pointer to the data used by the fitness function (NULL if not used) |
DLL_EXPORT void copyChromosome( struct chromosome * chromoDest, struct chromosome * chromoSrc )
Copies the contents of one chromoosme into the other.
In order for copy chromosome to opperate correctly the dimensions of the chromosomes must match i.e. the number of inputs, nodes, outputs and node arity must be the same.
chromoDest | pointer to an initialised chromosome to be copied too |
chromoSrc | pointer to an initialised chromosome to be copied from |
DLL_EXPORT double getChromosomeFitness( struct chromosome * chromo )
Gets the fitness of the given chromosome
chromo | pointer to initialised chromosome structure. |
The fitness of the given chromosome
setChromosomeFitness getChromosomeGenerations getNumChromosomeActiveNodes
DLL_EXPORT int getChromosomeGenerations( struct chromosome * chromo )
Gets the number of generations for which the given chromosome has been trained.
If the chromosome has not been trained then -1 is returned.
chromo | pointer to initialised chromosome structure. |
Number of generations for which the given chromosome has been trained
Description of all functions and structures relating to data sets
Functions | |
initialiseDataSetFromArrays | Initialises a dataSet structures using the given input output pairs. |
initialiseDataSetFromFile | Initialises a dataSet structures using the given file. |
freeDataSet | Frees dataSet instance. |
printDataSet | Prints the input output pairs held by a dataSet structure to the terminal. |
saveDataSet | Saves the given dataSet to a file which can be read using initialiseDataSetFromFile. |
getNumDataSetInputs | Gets the number of dataSet inputs. |
getNumDataSetOutputs | Gets the number of dataSet outputs. |
getNumDataSetSamples | Gets the number of samples in the given dataSet. |
getDataSetSampleInputs | Gets the dataSet inputs for the given sample index. |
getDataSetSampleInput | Gets the dataSet input for the given sample index and input index. |
getDataSetSampleOutputs | Gets the dataSet outputs for the given sample index. |
getDataSetSampleOutput | Gets the dataSet output for the given sample index and output index. |
DLL_EXPORT struct dataSet *initialiseDataSetFromArrays( int numInputs, int numOutputs, int numSamples, double * inputs, double * outputs )
Initialises a dataSet structures using the given input output pairs.
The given arrays containing the input output pairs must take the form
double inputs[numSamples][numInputs] double outputs[numSamples][numOutputs]
Where the numInputs and numOutputs are the number of inputs and outputs per sample.
numInputs | number of inputs per data sample |
numOutputs | number of outputs per data sample |
numSamples | number of data samples |
inputs | pointer to the first element in the inputs to be stored to the data structure |
outputs | pointer to the first element in outputs to be stored to the data structure |
A pointer to an initialised dataSet structure.
Initialising a dataSet to contain the input output pairs for a full adder truth table.
struct data *trainingData; int numInputs = 3; int numOutputs = 2; int numSamples = 8; // full adder input output pairs double inputs[8][3] = {{0,0,0},{0,0,1},{0,1,0},{0,1,1},{1,0,0},{1,0,1},{1,1,0},{1,1,1}}; double outputs[8][2] = {{0,0},{1,0},{1,0},{0,1},{1,0},{0,1},{0,1},{1,1}}; trainingData = initialiseDataFromArrays(numInputs, numOutputs, numSamples, inputs[0], outputs[0]);
DLL_EXPORT struct dataSet *initialiseDataSetFromFile( char const * file )
Initialises a dataSet structures using the given file.
file | the location of the file to be loaded into the dataSet structure |
A pointer to an initialised dataSet structure.
The file containing the dataSet must take the form
2,3,4 1,2,3,4,5 6,7,8,9,10 11,12,13,14,15 16,17,18,19,20
Where the header describes the number of inputs, number of outputs and the number of samples. The rest of the file gives the inputs and then the outputs of each sample on a new line. All values are comma separated.
The file can then be used to initialise a dataSet structure.
struct dataSet *trainingData; trainingData = initialiseDataFromFile("file");
DLL_EXPORT void freeDataSet( struct dataSet * data )
Frees dataSet instance.
data | pointer to dataSet structure. |
DLL_EXPORT void printDataSet( struct dataSet * data )
Prints the input output pairs held by a dataSet structure to the terminal.
data | pointer to dataSet structure. |
initialiseDataSetFromArrays, initialiseDataSetFromFile, freeDataSet
DLL_EXPORT void saveDataSet( struct dataSet * data, char const * fileName )
Saves the given dataSet to a file which can be read using initialiseDataSetFromFile.
data | pointer to dataSet structure. |
fileName | char array giving the location of the dataSet to be saved. |
DLL_EXPORT double *getDataSetSampleInputs( struct dataSet * data, int sample )
Gets the dataSet inputs for the given sample index.
data | pointer to an initialised dataSet structure. |
sample | index of the sample inputs |
Pointer to an array containing the sample inputs.
getDataSetSampleInput, getDataSetSampleOutputs, getDataSetSampleOutput
DLL_EXPORT double getDataSetSampleInput( struct dataSet * data, int sample, int input )
Gets the dataSet input for the given sample index and input index.
data | pointer to an initialised dataSet structure |
sample | index of the sample inputs |
input | index of the input for the given sample |
The input value for the given input of the given sample.
getDataSetSampleInputs, getDataSetSampleOutput, getDataSetSampleOutputs
DLL_EXPORT double *getDataSetSampleOutputs( struct dataSet * data, int sample )
Gets the dataSet outputs for the given sample index.
data | pointer to an initialised dataSet structure |
sample | index of the sample outputs |
Pointer to an array containing the sample outputs.
getDataSetSampleOutput, getDataSetSampleInputs, getDataSetSampleInput
DLL_EXPORT double getDataSetSampleOutput( struct dataSet * data, int sample, int output )
Gets the dataSet output for the given sample index and output index.
data | pointer to an initialised dataSet structure. |
sample | index of the sample inputs |
output | index of the output for the given sample |
The output value for the given output for the given sample.
getDataSetSampleOutputs, getDataSetSampleInput, getDataSetSampleInputs
Functions | |
freeResults | Frees results instance. |
saveResults | Saves the given results to a csv file. |
getChromosome | Gets a copy of the best chromosome found on the given run in an initialised results structure. |
getNumChromosomes | Gets number of chromosomes stored in the given results structure. |
getAverageFitness | Gets the average fitness of the best chromosome found for each run in results. |
getMedianFitness | Gets the median fitness of the best chromosome found for each run in results. |
getAverageActiveNodes | Gets the average number of active nodes of the best chromosome found for each run in results. |
getMedianActiveNodes | Gets the median number of active nodes of the best chromosome found for each run in results. |
getAverageGenerations | Gets the average number generations required to find the best best chromosome for each run in results. |
getMedianGenerations | Gets the median number generations required to find the best best chromosome for each run in results. |
DLL_EXPORT struct chromosome* getChromosome( struct results * rels, int run )
Gets a copy of the best chromosome found on the given run in an initialised results structure.
rels | pointer to an initialised results structure. |
run | the run for which the chromosome is got |
Pointer to an initialised chromosome structure.
repeatCGP, getAverageFitness, getAverageActiveNodes, getAverageGenerations
DLL_EXPORT int getNumChromosomes( struct results * rels )
Gets number of chromosomes stored in the given results structure.
rels | pointer to an initialised results structure. |
The number of chromosomes stored in the given results structure
repeatCGP, getAverageFitness, getAverageActiveNodes, getAverageGenerations
DLL_EXPORT double getAverageActiveNodes( struct results * rels )
Gets the average number of active nodes of the best chromosome found for each run in results.
rels | pointer to an initialised results structure. |
The average number of active nodes of the best chromosome found for each run in results.
DLL_EXPORT double getMedianActiveNodes( struct results * rels )
Gets the median number of active nodes of the best chromosome found for each run in results.
rels | pointer to an initialised results structure. |
The median number of active nodes of the best chromosome found for each run in results.
DLL_EXPORT double getAverageGenerations( struct results * rels )
Gets the average number generations required to find the best best chromosome for each run in results.
rels | pointer to an initialised results structure. |
The average number generations required to find the best chromosome found for each run in results.
DLL_EXPORT double getMedianGenerations( struct results * rels )
Gets the median number generations required to find the best best chromosome for each run in results.
rels | pointer to an initialised results structure. |
The median number generations required to find the best chromosome found for each run in results.
DLL_EXPORT struct chromosome* runCGP( struct parameters * params, struct dataSet * data, int numGens )
Applies CGP to the given task.
Returns the best chromosome found after applying CGP to a given task using the specified parameters. Depending upon the update frequency given in parameters (setUpdateFrequency) the progress made by CGP will be displayed in the terminal.
As runCGP returns an initialised chromosome this should later be free’d using freeChromosome.
params | pointer to parameters structure. |
data | pointer to dataSet structure. |
gens | the number of allowed generations before terminating the search. |
A pointer to an initialised chromosome.
struct parameters *params; struct dataSet *data; struct chromosome *chromo; params = initialiseParameters(a,b,c,d); addNodeFunction(params, "aaa,bbb,ccc"); data = initialiseDataSetFromFile("file"); chromo = runCGP(params, data, 100); freeParameters(params); freeDataSet(data); freeChromosome(chromo);
repeatCGP, initialiseParameters, initialiseDataSetFromFile, freeChromosome
DLL_EXPORT struct results* repeatCGP( struct parameters * params, struct dataSet * data, int numGens, int numRuns )
Repeatedly applies CGP to the given task.
Returns a results structure containing the results of applying CGP to the given task multiple times.
As repeatCGP returns an initialised results structure this should later be free’d using freeResults.
params | pointer to parameters structure. |
data | pointer to dataSet structure. |
numGens | the number of allowed generations before terminating the search. |
numRuns | the number of times CGP will be applied to the given task |
A pointer to an initialised results structure.
struct parameters *params; struct dataSet *data; struct results *rels; params = initialiseParameters(a,b,c,d); addNodeFunction(params, "aaa,bbb,ccc"); data = initialiseDataSetFromFile("file"); rels = repeatCGP(params, data, 100, 50); freeParameters(params); freeDataSet(data); freeResults(rels);
runCGP, initialiseParameters, initialiseDataSetFromFile, freeResults
Functions | |
setRandomNumberSeed | Sets the seed used by the random number generator in CGP-Library. |
DLL_EXPORT void setRandomNumberSeed( unsigned int seed )
Sets the seed used by the random number generator in CGP-Library.
By default the current time is used as the random number seed. When a random number seed is specified the CGP-Library will produce the same results if used in the same way.
setRandomNumberSeed must be called after initialiseParameters otherwise the time will be used as the random number seed.
seed | the random number seed to be used |
Stores general evolutionary and chromosome parameters used by the CGP-Library.
struct parameters
Stores a CGP chromosome instances used by the CGP-Library.
struct chromosome
Stores a data set which can be used by fitness functions when calculating a chromosomes fitness.
struct dataSet
Stores the best chromosome found on each run when using repeatCGP
struct results
Repeatedly applies CGP to the given task.
DLL_EXPORT struct results* repeatCGP( struct parameters * params, struct dataSet * data, int numGens, int numRuns )
Initialises a parameters structure used throughout the CGP-Library.
DLL_EXPORT struct parameters *initialiseParameters( const int numInputs, const int numNodes, const int numOutputs, const int arity )
Frees parameters structure instance.
DLL_EXPORT void freeParameters( struct parameters * params )
Prints the given parameters to the screen in a human readable format.
DLL_EXPORT void printParameters( struct parameters * params )
Adds pre-defined node function(s) to the set of functions stored by a parameters structure.
DLL_EXPORT void addNodeFunction( struct parameters * params, char const * functionNames )
Adds custom node function to the set of functions stored by a parameters structure.
DLL_EXPORT void addCustomNodeFunction( struct parameters * params, double (*function)(const int numInputs, const double *inputs, const double *weights), char const * functionName, int maxNumInputs )
Resets the function set stored by a parameters structure to contain no functions.
DLL_EXPORT void clearFunctionSet( struct parameters * params )
Sets the number of chromosome inputs in the given parameters.
DLL_EXPORT void setNumInputs( struct parameters * params, int numInputs )
Sets the number of chromosome nodes in the given parameters.
DLL_EXPORT void setNumNodes( struct parameters * params, int numNodes )
Sets the number of chromosome outputs in the given parameters.
DLL_EXPORT void setNumOutputs( struct parameters * params, int numOutputs )
Sets the arity of the chromosome nodes in the given parameters.
DLL_EXPORT void setArity( struct parameters * params, int arity )
Sets the mu value in the given parameters.
DLL_EXPORT void setMu( struct parameters * params, int mu )
Sets the lambda value in the given parameters.
DLL_EXPORT void setLambda( struct parameters * params, int lambda )
Sets the evolutionary strategy in the given parameters.
DLL_EXPORT void setEvolutionaryStrategy( struct parameters * params, char evolutionaryStrategy )
Sets the mutation rate in the given parameters.
DLL_EXPORT void setMutationRate( struct parameters * params, double mutationRate )
Sets the recurrent connection probability in the given parameters.
DLL_EXPORT void setRecurrentConnectionProbability( struct parameters * params, double recurrentConnectionProbability )
Sets whether shortcut connections are used in the given parameters.
DLL_EXPORT void setShortcutConnections( struct parameters * params, int shortcutConnections )
Sets the connection weight range in the given parameters.
DLL_EXPORT void setConnectionWeightRange( struct parameters * params, double weightRange )
Set custom fitness function.
DLL_EXPORT void setCustomFitnessFunction( struct parameters * params, double (*fitnessFunction)(struct parameters *params, struct chromosome *chromo, struct dataSet *data), char const * fitnessFunctionName )
Sets custom selection scheme.
DLL_EXPORT void setCustomSelectionScheme( struct parameters * params, void (*selectionScheme)(struct parameters *params, struct chromosome **parents, struct chromosome **candidateChromos, int numParents, int numCandidateChromos), char const * selectionSchemeName )
Sets custom reproduction scheme.
DLL_EXPORT void setCustomReproductionScheme( struct parameters * params, void (*reproductionScheme)(struct parameters *params, struct chromosome **parents, struct chromosome **children, int numParents, int numChildren), char const * reproductionSchemeName )
Sets the target fitness used when running CGP.
DLL_EXPORT void setTargetFitness( struct parameters * params, double targetFitness )
Sets the mutation method used when mutating chromosomes.
DLL_EXPORT void setMutationType( struct parameters * params, char const * mutationType )
Sets the frequency of the updates to the user when using runCGP.
DLL_EXPORT void setUpdateFrequency( struct parameters * params, int updateFrequency )
Applies CGP to the given task.
DLL_EXPORT struct chromosome* runCGP( struct parameters * params, struct dataSet * data, int numGens )
Sets the number of threads in the given parameters.
DLL_EXPORT void setNumThreads( struct parameters * params, int numThreads )
Initialises a chromosome based on the given parameters.
DLL_EXPORT struct chromosome *initialiseChromosome( struct parameters * params )
Initialises a chromosome from a given previously saved chromosome.
DLL_EXPORT struct chromosome* initialiseChromosomeFromFile( char const * file )
Initialises a chromosome from a given chromosome.
DLL_EXPORT struct chromosome *initialiseChromosomeFromChromosome( struct chromosome * chromo )
Frees chromosome instance.
DLL_EXPORT void freeChromosome( struct chromosome * chromo )
Displays the given chromosome to the terminal / command prompt in a human readable format.
DLL_EXPORT void printChromosome( struct chromosome * chromo, int weights )
Executes the given chromosome.
DLL_EXPORT void executeChromosome( struct chromosome * chromo, const double * inputs )
Gets the outputs of the given chromosome after it has been executed using executeChromosome.
DLL_EXPORT double getChromosomeOutput( struct chromosome * chromo, int output )
Gets the node value of the given chromosome and node after it has been executed using executeChromosome.
DLL_EXPORT double getChromosomeNodeValue( struct chromosome * chromo, int node )
Returns whether the given node in the given chromosome is active.
DLL_EXPORT int isNodeActive( struct chromosome * chromo, int node )
Saves the given chromosome to a file which can used to initialise new chromosomes.
DLL_EXPORT void saveChromosome( struct chromosome * chromo, char const * fileName )
Saves the given chromosome to a graphviz .dot file.
DLL_EXPORT void saveChromosomeDot( struct chromosome * chromo, int weights, char const * fileName )
Saves the given chromosome to a latex .tex file for visulisation and inclusion in written workes.
DLL_EXPORT void saveChromosomeLatex( struct chromosome * chromo, int weights, char const * fileName )
Mutate the given chromosome using the mutation method described in the given parameters.
DLL_EXPORT void mutateChromosome( struct parameters * params, struct chromosome * chromo )
Removes all of the inactive nodes from the given chromosome.
DLL_EXPORT void removeInactiveNodes( struct chromosome * chromo )
Sets the fitness of the chromosome using the fitness function given in the parameters
DLL_EXPORT void setChromosomeFitness( struct parameters * params, struct chromosome * chromo, struct dataSet * data )
Resets all of the chromosome nodes to output zero.
DLL_EXPORT void resetChromosome( struct chromosome * chromo )
Copies the contents of one chromoosme into the other.
DLL_EXPORT void copyChromosome( struct chromosome * chromoDest, struct chromosome * chromoSrc )
Gets the number of chromosome inputs
DLL_EXPORT int getNumChromosomeInputs( struct chromosome * chromo )
Gets the number of chromosome nodes
DLL_EXPORT int getNumChromosomeNodes( struct chromosome * chromo )
Gets the number of chromosome active nodes
DLL_EXPORT int getNumChromosomeActiveNodes( struct chromosome * chromo )
Gets the number of chromosome outputs
DLL_EXPORT int getNumChromosomeOutputs( struct chromosome * chromo )
Gets the arity of the chromosome nodes
DLL_EXPORT int getChromosomeNodeArity( struct chromosome * chromo, int index )
Gets the fitness of the given chromosome
DLL_EXPORT double getChromosomeFitness( struct chromosome * chromo )
Gets the number of active connections in the given chromosome
DLL_EXPORT int getNumChromosomeActiveConnections( struct chromosome * chromo )
Gets the number of generations for which the given chromosome has been trained.
DLL_EXPORT int getChromosomeGenerations( struct chromosome * chromo )
Initialises a dataSet structures using the given input output pairs.
DLL_EXPORT struct dataSet *initialiseDataSetFromArrays( int numInputs, int numOutputs, int numSamples, double * inputs, double * outputs )
Initialises a dataSet structures using the given file.
DLL_EXPORT struct dataSet *initialiseDataSetFromFile( char const * file )
Frees dataSet instance.
DLL_EXPORT void freeDataSet( struct dataSet * data )
Prints the input output pairs held by a dataSet structure to the terminal.
DLL_EXPORT void printDataSet( struct dataSet * data )
Saves the given dataSet to a file which can be read using initialiseDataSetFromFile.
DLL_EXPORT void saveDataSet( struct dataSet * data, char const * fileName )
Gets the number of dataSet inputs.
DLL_EXPORT int getNumDataSetInputs( struct dataSet * data )
Gets the number of dataSet outputs.
DLL_EXPORT int getNumDataSetOutputs( struct dataSet * data )
Gets the number of samples in the given dataSet.
DLL_EXPORT int getNumDataSetSamples( struct dataSet * data )
Gets the dataSet inputs for the given sample index.
DLL_EXPORT double *getDataSetSampleInputs( struct dataSet * data, int sample )
Gets the dataSet input for the given sample index and input index.
DLL_EXPORT double getDataSetSampleInput( struct dataSet * data, int sample, int input )
Gets the dataSet outputs for the given sample index.
DLL_EXPORT double *getDataSetSampleOutputs( struct dataSet * data, int sample )
Gets the dataSet output for the given sample index and output index.
DLL_EXPORT double getDataSetSampleOutput( struct dataSet * data, int sample, int output )
Frees results instance.
DLL_EXPORT void freeResults( struct results * rels )
Saves the given results to a csv file.
DLL_EXPORT void saveResults( struct results * rels, char const * fileName )
Gets a copy of the best chromosome found on the given run in an initialised results structure.
DLL_EXPORT struct chromosome* getChromosome( struct results * rels, int run )
Gets number of chromosomes stored in the given results structure.
DLL_EXPORT int getNumChromosomes( struct results * rels )
Gets the average fitness of the best chromosome found for each run in results.
DLL_EXPORT double getAverageFitness( struct results * rels )
Gets the median fitness of the best chromosome found for each run in results.
DLL_EXPORT double getMedianFitness( struct results * rels )
Gets the average number of active nodes of the best chromosome found for each run in results.
DLL_EXPORT double getAverageActiveNodes( struct results * rels )
Gets the median number of active nodes of the best chromosome found for each run in results.
DLL_EXPORT double getMedianActiveNodes( struct results * rels )
Gets the average number generations required to find the best best chromosome for each run in results.
DLL_EXPORT double getAverageGenerations( struct results * rels )
Gets the median number generations required to find the best best chromosome for each run in results.
DLL_EXPORT double getMedianGenerations( struct results * rels )
Sets the seed used by the random number generator in CGP-Library.
DLL_EXPORT void setRandomNumberSeed( unsigned int seed )