void FireflyOptimizator::init() { generationRanked = false; optmized=false; groundTruth.getRegions(); normalizeDis = sqrt( groundTruth.getMask().rows*groundTruth.getMask().rows + groundTruth.getMask().cols*groundTruth.getMask().cols); createPopulation(); }
void ExperimentRun::setupExperimentInProgressUseDat(string _datFile, string populationFileName,string _outputFileName) { outputFileName = _outputFileName; //datFile = _datFile; PRINT(populationFileName); { TiXmlDocument doc(populationFileName); bool loadStatus; if (iends_with(populationFileName,".gz")) { loadStatus = doc.LoadFileGZ(); } else { loadStatus = doc.LoadFile(); } if (!loadStatus) { cerr << "Error trying to load the XML file!" << endl; throw CREATE_LOCATEDEXCEPTION_INFO("Error trying to load the XML file!"); } TiXmlElement *element = doc.FirstChildElement(); NEAT::Globals* globals = NEAT::Globals::init(element); (void) globals; //to get rid of unused variable warning NEAT::Globals::getSingleton()->overrideParametersFromFile(_datFile); NEAT::Globals::getSingleton()->setOutputFilePrefix(outputFileName); //set the name of the outputPrefixFile //Destroy the document } int experimentType = int(NEAT::Globals::getSingleton()->getParameterValue("ExperimentType")+0.001); cout << "Loading Experiment: " << experimentType << endl; setupExperiment(experimentType,_outputFileName); cout << "Experiment set up. Creating population...\n"; createPopulation(populationFileName); cout << "Population Created\n"; }
int main() { srand(time(NULL)); cfg_t cfg = {0}; configureGA(&cfg); printf("Initial population: %d\nUniform rate: %f\nMutation rate: %f\nTarget genome: %s\n" , cfg.initialPopulation , cfg.uniformRate , cfg.mutationRate , cfg.targetGenome); population p = createPopulation(cfg.initialPopulation, true); for (uint8_t i = 0; i < cfg.initialPopulation; i++) { calcFitness(p[i], cfg.targetGenome); printf("%s (fit: %d)\n", p[i]->genes, p[i]->fitnessValue); } individual * ind = createIndividual(false); uint16_t counter = 0; evolve(p, &cfg, ind, counter); return 0; }
void ExperimentRun::setupExperimentInProgress( string populationFileName, string _outputFileName ) { outputFileName = _outputFileName; { TiXmlDocument *doc = new TiXmlDocument(populationFileName); cout << "Loading population\n"; bool loadStatus; if (iends_with(populationFileName,".gz")) { loadStatus = doc->LoadFileGZ(); } else { loadStatus = doc->LoadFile(); } if (!loadStatus) { throw CREATE_LOCATEDEXCEPTION_INFO("Error trying to load the XML file!"); } TiXmlElement *element = doc->FirstChildElement(); NEAT::Globals* globals = NEAT::Globals::init(element); //Destroy the document delete doc; cout << "Population loaded\n"; } int experimentType = int(NEAT::Globals::getSingleton()->getParameterValue("ExperimentType")+0.001); NEAT::Globals::getSingleton()->seedRandom((unsigned int)(NEAT::Globals::getSingleton()->getParameterValue("ActualRandomSeed")+0.001)); cout << "Loading Experiment: " << experimentType << endl; setupExperiment(experimentType,_outputFileName); cout << "Experiment set up. Creating population...\n"; createPopulation(populationFileName); cout << "Population Created\n"; /*cout << "Cleaning up old generations\n"; population->cleanupOld(population->getGenerationCount()-1); cout << "Done cleaning\n";*/ }
SEXP evolutionRun(SEXP numberOfRuns_ext, SEXP popSize_ext, SEXP sampleSize_ext, SEXP actualParameters, SEXP targetValues, SEXP funcSet, SEXP inSet, SEXP maxDepth_ext, SEXP maxLeafs_ext, SEXP maxNodes_ext, SEXP constProb_ext, SEXP constScaling_ext, SEXP subtreeProb_ext, SEXP RMSElimit_ext, SEXP returnRMSE_ext, SEXP silent_ext, SEXP timeLimit_ext) { SEXP population; PROTECT(population= createPopulation(popSize_ext, funcSet, inSet, maxDepth_ext, constProb_ext, subtreeProb_ext, constScaling_ext)); PROTECT(numberOfRuns_ext= coerceVector(numberOfRuns_ext, INTSXP)); int numberOfRuns= INTEGER(numberOfRuns_ext)[0]; PROTECT(RMSElimit_ext= coerceVector(RMSElimit_ext, REALSXP)); double RMSElimit= REAL(RMSElimit_ext)[0]; PROTECT(silent_ext= coerceVector(silent_ext, INTSXP)); int silent= INTEGER(silent_ext)[0]; PROTECT(timeLimit_ext= coerceVector(timeLimit_ext, INTSXP)); int timeLimit= INTEGER(timeLimit_ext)[0]; PROTECT(returnRMSE_ext= coerceVector(returnRMSE_ext, INTSXP)); int rRMSE= INTEGER(returnRMSE_ext)[0]; clock_t prgstart, prgende; prgstart=clock(); double bestRMSE= 1000000; for(int i=0; i < numberOfRuns; i++) { PROTECT(population= selection(population, sampleSize_ext, actualParameters, targetValues, funcSet, inSet, maxDepth_ext, constProb_ext, subtreeProb_ext, maxLeafs_ext, maxNodes_ext, constScaling_ext, &bestRMSE)); if(silent == 0) { Rprintf(" \n StepNumber: %d", i+1); Rprintf(" best RMSE: %f", bestRMSE); } if(RMSElimit > 0) { if (RMSElimit >= bestRMSE) { UNPROTECT(7); if(rRMSE == 0) { if(silent != 1) { summary(population, actualParameters, targetValues, &bestRMSE); } return population; } else { SEXP returnRMSE; PROTECT(returnRMSE = allocVector(REALSXP, 1)); REAL(returnRMSE)[0] = bestRMSE; UNPROTECT(1); return returnRMSE; } } } prgende=clock(); float runtime= (float)(prgende-prgstart) / CLOCKS_PER_SEC; if(silent != 1) { Rprintf(" runtime: %.2f sec", runtime); } if(timeLimit > 0) { if ((int)runtime >= timeLimit) { UNPROTECT(7); if(rRMSE == 0) { if(silent != 1) { summary(population, actualParameters, targetValues, &bestRMSE); } return population; } else { SEXP returnRMSE; PROTECT(returnRMSE = allocVector(REALSXP, 1)); REAL(returnRMSE)[0] = bestRMSE; UNPROTECT(1); return returnRMSE; } } } UNPROTECT(1); } if(silent != 1) { summary(population, actualParameters, targetValues, &bestRMSE); } UNPROTECT(6); if(rRMSE == 0) { return population; } else { SEXP returnRMSE; PROTECT(returnRMSE = allocVector(REALSXP, 1)); REAL(returnRMSE)[0] = bestRMSE; UNPROTECT(1); return returnRMSE; } }