Skip to content
Snippets Groups Projects
Commit bf22fa5a authored by Franck Dary's avatar Franck Dary
Browse files

GeneticAlgorithm now works with a mean to predict, and only save the best quarter of its population

parent d9f848ff
Branches
No related tags found
No related merge requests found
......@@ -39,7 +39,19 @@ void GeneticAlgorithm::init(int nbInputs, const std::string & topology, int nbOu
std::vector<float> GeneticAlgorithm::predict(FeatureModel::FeatureDescription & fd)
{
return generation[0]->mlp.predict(fd);
std::vector<float> prediction = generation[0]->mlp.predict(fd);
for (unsigned int i = 1; i < generation.size(); i++)
{
auto otherPred = generation[i]->mlp.predict(fd);
for (unsigned int j = 0; j < prediction.size(); j++)
prediction[j] += otherPred[j];
}
for (unsigned int j = 0; j < prediction.size(); j++)
prediction[j] /= generation.size();
return prediction;
}
float GeneticAlgorithm::update(FeatureModel::FeatureDescription & fd, int gold)
......@@ -119,10 +131,12 @@ void GeneticAlgorithm::save(const std::string & filename)
fprintf(file->getDescriptor(), "%d %d %s\n", nbInputs, nbOutputs, topology.c_str());
delete file;
for (auto & individual : generation)
unsigned int quarter = generation.size() / 4;
for (unsigned int i = 0; i < quarter; i++)
{
individual->mlp.saveStruct(filename);
individual->mlp.saveParameters(filename);
generation[i]->mlp.saveStruct(filename);
generation[i]->mlp.saveParameters(filename);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment