Compare commits

..

No commits in common. "5f1a80c06228b89d527f0fb64a7233d588fc8d60" and "bc903e0251240ca55811e5319854981094c989c7" have entirely different histories.

2 changed files with 45 additions and 79 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.1.33) project(blt-gp VERSION 0.1.31)
include(CTest) include(CTest)

View File

@ -59,7 +59,7 @@ blt::gp::prog_config_t config = blt::gp::prog_config_t()
.set_mutation_chance(0.1) .set_mutation_chance(0.1)
.set_reproduction_chance(0) .set_reproduction_chance(0)
.set_max_generations(50) .set_max_generations(50)
.set_pop_size(5000) .set_pop_size(500)
.set_thread_count(0); .set_thread_count(0);
blt::gp::type_provider type_system; blt::gp::type_provider type_system;
@ -168,35 +168,6 @@ struct test_results_t
blt::size_t hits = 0; blt::size_t hits = 0;
blt::size_t size = 0; blt::size_t size = 0;
double percent_hit = 0; double percent_hit = 0;
test_results_t& operator+=(const test_results_t& a)
{
cc += a.cc;
co += a.co;
oo += a.oo;
oc += a.oc;
hits += a.hits;
size += a.size;
percent_hit += a.percent_hit;
return *this;
}
test_results_t& operator/=(blt::size_t s)
{
cc /= s;
co /= s;
oo /= s;
oc /= s;
hits /= s;
size /= s;
percent_hit /= static_cast<double>(s);
return *this;
}
friend bool operator<(const test_results_t& a, const test_results_t& b)
{
return a.hits < b.hits;
}
}; };
test_results_t test_individual(blt::gp::individual& i) test_results_t test_individual(blt::gp::individual& i)
@ -211,13 +182,13 @@ test_results_t test_individual(blt::gp::individual& i)
case rice_type_t::Cammeo: case rice_type_t::Cammeo:
if (result >= 0) if (result >= 0)
results.cc++; // cammeo cammeo results.cc++; // cammeo cammeo
else else if (result < 0)
results.co++; // cammeo osmancik results.co++; // cammeo osmancik
break; break;
case rice_type_t::Osmancik: case rice_type_t::Osmancik:
if (result < 0) if (result < 0)
results.oo++; // osmancik osmancik results.oo++; // osmancik osmancik
else else if (result >= 0)
results.oc++; // osmancik cammeo results.oc++; // osmancik cammeo
break; break;
} }
@ -307,60 +278,55 @@ int main(int argc, const char** argv)
BLT_END_INTERVAL("Rice Classification", "Main"); BLT_END_INTERVAL("Rice Classification", "Main");
std::vector<std::pair<test_results_t, blt::gp::individual*>> results; auto best = program.get_best_individuals<3>();
for (auto& i : program.get_current_pop().get_individuals())
results.emplace_back(test_individual(i), &i);
std::sort(results.begin(), results.end(), [](const auto& a, const auto& b) {
return !(a.first < b.first);
});
BLT_INFO("Best results:"); BLT_INFO("Best approximations:");
for (blt::size_t index = 0; index < 3; index++) for (auto& i_ref : best)
{ {
const auto& record = results[index].first; auto& i = i_ref.get();
const auto& i = *results[index].second; struct match_t
{
blt::size_t cc = 0;
blt::size_t co = 0;
blt::size_t oo = 0;
blt::size_t oc = 0;
};
BLT_INFO("Hits %ld, Total Cases %ld, Percent Hit: %lf", record.hits, record.size, record.percent_hit); match_t match;
BLT_DEBUG("Cammeo Cammeo: %ld", record.cc);
BLT_DEBUG("Cammeo Osmancik: %ld", record.co); for (auto& testing_case : testing_cases)
BLT_DEBUG("Osmancik Osmancik: %ld", record.oo); {
BLT_DEBUG("Osmancik Cammeo: %ld", record.oc); auto result = i.tree.get_evaluation_value<float>(&testing_case);
switch (testing_case.type)
{
case rice_type_t::Cammeo:
if (result >= 0)
match.cc++; // cammeo cammeo
else if (result < 0)
match.co++; // cammeo osmancik
break;
case rice_type_t::Osmancik:
if (result < 0)
match.oo++; // osmancik osmancik
else if (result >= 0)
match.oc++; // osmancik cammeo
break;
}
}
auto hits = match.cc + match.oo;
auto size = testing_cases.size();
BLT_INFO("Hits %ld, Total Cases %ld, Percent Hit: %lf", hits, size, static_cast<double>(hits) / static_cast<double>(size) * 100);
BLT_DEBUG("Cammeo Cammeo: %ld", match.cc);
BLT_DEBUG("Cammeo Osmancik: %ld", match.co);
BLT_DEBUG("Osmancik Osmancik: %ld", match.oo);
BLT_DEBUG("Osmancik Cammeo: %ld", match.oc);
BLT_DEBUG("Fitness: %lf, stand: %lf, raw: %lf", i.fitness.adjusted_fitness, i.fitness.standardized_fitness, i.fitness.raw_fitness); BLT_DEBUG("Fitness: %lf, stand: %lf, raw: %lf", i.fitness.adjusted_fitness, i.fitness.standardized_fitness, i.fitness.raw_fitness);
i.tree.print(program, std::cout); i.tree.print(program, std::cout);
std::cout << "\n"; std::cout << "\n";
} }
BLT_INFO("Worst Results:");
for (blt::size_t index = 0; index < 3; index++)
{
const auto& record = results[results.size() - 1 - index].first;
const auto& i = *results[results.size() - 1 - index].second;
BLT_INFO("Hits %ld, Total Cases %ld, Percent Hit: %lf", record.hits, record.size, record.percent_hit);
BLT_DEBUG("Cammeo Cammeo: %ld", record.cc);
BLT_DEBUG("Cammeo Osmancik: %ld", record.co);
BLT_DEBUG("Osmancik Osmancik: %ld", record.oo);
BLT_DEBUG("Osmancik Cammeo: %ld", record.oc);
BLT_DEBUG("Fitness: %lf, stand: %lf, raw: %lf", i.fitness.adjusted_fitness, i.fitness.standardized_fitness, i.fitness.raw_fitness);
i.tree.print(program, std::cout);
std::cout << "\n";
}
BLT_INFO("Average Results");
test_results_t avg{};
for (const auto& v : results)
avg += v.first;
avg /= results.size();
BLT_INFO("Hits %ld, Total Cases %ld, Percent Hit: %lf", avg.hits, avg.size, avg.percent_hit);
BLT_DEBUG("Cammeo Cammeo: %ld", avg.cc);
BLT_DEBUG("Cammeo Osmancik: %ld", avg.co);
BLT_DEBUG("Osmancik Osmancik: %ld", avg.oo);
BLT_DEBUG("Osmancik Cammeo: %ld", avg.oc);
std::cout << "\n";
auto& stats = program.get_population_stats(); auto& stats = program.get_population_stats();
BLT_INFO("Stats:"); BLT_INFO("Stats:");
BLT_INFO("Average fitness: %lf", stats.average_fitness.load()); BLT_INFO("Average fitness: %lf", stats.average_fitness.load());