int main(void){ int i; struct dataSet *data = NULL; double inputs[NUMSAMPLES][NUMINPUTS]; double outputs[NUMSAMPLES][NUMOUTPUTS]; double inputTemp; double outputTemp; for(i=0; i<NUMSAMPLES; i++){ inputTemp = (i * (INPUTRANGE/(NUMSAMPLES-1))) - INPUTRANGE/2; outputTemp = symbolicEq1(inputTemp); inputs[i][0] = inputTemp; outputs[i][0] = outputTemp; } data = initialiseDataSetFromArrays(NUMINPUTS, NUMOUTPUTS, NUMSAMPLES, inputs[0], outputs[0]); saveDataSet(data, "symbolic.data"); freeDataSet(data); return 0; }
int main(void){ struct parameters *params = NULL; struct chromosome *chromoA = NULL; struct chromosome *chromoB = NULL; struct chromosome *chromoC = NULL; struct dataSet *trainingData = NULL; double testInputs[NUMINPUTS]; params = initialiseParameters(NUMINPUTS, NUMNODES, NUMOUTPUTS, ARITY); addNodeFunction(params, "add,sub,mul,sq,cube,sin"); trainingData = initialiseDataSetFromFile("./dataSets/symbolic.data"); chromoA = initialiseChromosome(params); chromoB = initialiseChromosome(params); setChromosomeFitness(params, chromoA, trainingData); mutateChromosome(params,chromoA); copyChromosome(chromoB, chromoA); removeInactiveNodes(chromoB); printf("chromoA with inactive nodes.\n"); printChromosome(chromoA, 0); printf("chromoB without inactive nodes.\n"); printChromosome(chromoB, 1); saveChromosome(chromoB, "chromoB.chromo"); chromoC = initialiseChromosomeFromFile("chromoB.chromo"); testInputs[0] = 3; executeChromosome(chromoC, testInputs); printf("Applied input: %f\n", testInputs[0]); printf("Generated output: %f\n", getChromosomeOutput(chromoC, 0)); freeChromosome(chromoA); freeChromosome(chromoB); freeChromosome(chromoC); freeDataSet(trainingData); freeParameters(params); return 0; }
int main(void){ int i, gen; struct parameters *params = NULL; struct chromosome *population[POPULATIONSIZE]; struct chromosome *fittestChromosome = NULL; struct dataSet *trainingData = NULL; double targetFitness = 0; int maxGens = 10000; params = initialiseParameters(NUMINPUTS, NUMNODES, NUMOUTPUTS, ARITY); addNodeFunction(params, "or,nor,and,nand"); /*setTargetFitness(params, targetFitness);*/ setMutationType(params, "probabilistic"); setMutationRate(params, 0.08); trainingData = initialiseDataSetFromFile("./examples/parity3bit.data"); for(i=0; i<POPULATIONSIZE; i++){ population[i] = initialiseChromosome(params); } fittestChromosome = initialiseChromosome(params); /* for the number of allowed generations*/ for(gen=0; gen<maxGens; gen++){ /* set the fitnesses of the population of chromosomes*/ for(i=0; i<POPULATIONSIZE; i++){ setChromosomeFitness(params, population[i], trainingData); } /* copy over the last chromosome to fittestChromosome*/ copyChromosome(fittestChromosome, population[POPULATIONSIZE - 1]); /* for all chromosomes except the last*/ for(i=0; i<POPULATIONSIZE-1; i++){ /* copy ith chromosome to fittestChromosome if fitter*/ if(getChromosomeFitness(population[i]) < getChromosomeFitness(fittestChromosome)){ copyChromosome(fittestChromosome, population[i]); } } /* termination condition*/ if(getChromosomeFitness(fittestChromosome) <= targetFitness){ break; } /* set the first member of the population to be the fittest chromosome*/ copyChromosome(population[0], fittestChromosome); /* set remaining member of the population to be mutations of the fittest chromosome*/ for(i=1; i<POPULATIONSIZE; i++){ copyChromosome(population[i], fittestChromosome); mutateChromosome(params, population[i]); } } printf("gen\tfitness\n"); printf("%d\t%f\n", gen, getChromosomeFitness(fittestChromosome)); for(i=0; i<POPULATIONSIZE; i++){ freeChromosome(population[i]); } freeChromosome(fittestChromosome); freeDataSet(trainingData); freeParameters(params); return 0; }
MySqlDataSet::~MySqlDataSet() { freeDataSet(); }