Compare commits
No commits in common. "593e02b6ffd36cfabda85e9dcfd88ec60b8a8741" and "19f94b14dc0922a4f3394f2c198b7b93d38d9f82" have entirely different histories.
593e02b6ff
...
19f94b14dc
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
project(blt-gp VERSION 0.0.120)
|
project(blt-gp VERSION 0.0.118)
|
||||||
|
|
||||||
include(CTest)
|
include(CTest)
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ constexpr auto fitness_function = [](blt::gp::tree_t& current_tree, blt::gp::fit
|
||||||
}
|
}
|
||||||
fitness.standardized_fitness = fitness.raw_fitness;
|
fitness.standardized_fitness = fitness.raw_fitness;
|
||||||
fitness.adjusted_fitness = (1.0 / (1.0 + fitness.standardized_fitness));
|
fitness.adjusted_fitness = (1.0 / (1.0 + fitness.standardized_fitness));
|
||||||
return fitness.hits == fitness_cases.size();
|
//BLT_TRACE("fitness: %lf raw: %lf", fitness.adjusted_fitness, fitness.raw_fitness);
|
||||||
};
|
};
|
||||||
|
|
||||||
float example_function(float x)
|
float example_function(float x)
|
||||||
|
|
|
@ -141,12 +141,10 @@ namespace blt::gp
|
||||||
|
|
||||||
storage.operators.push_back(info);
|
storage.operators.push_back(info);
|
||||||
storage.print_funcs.push_back([&op](std::ostream& out, stack_allocator& stack) {
|
storage.print_funcs.push_back([&op](std::ostream& out, stack_allocator& stack) {
|
||||||
if constexpr (blt::meta::is_streamable_v<Return>)
|
if constexpr (blt::meta::is_streamable_v<Return>) {
|
||||||
{
|
|
||||||
out << stack.pop<Return>();
|
out << stack.pop<Return>();
|
||||||
(void) (op); // remove warning
|
(void)(op); // remove warning
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
out << "[Printing Value on '" << (op.get_name() ? *op.get_name() : "") << "' Not Supported!]";
|
out << "[Printing Value on '" << (op.get_name() ? *op.get_name() : "") << "' Not Supported!]";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -285,7 +283,6 @@ namespace blt::gp
|
||||||
template<typename FitnessFunc>
|
template<typename FitnessFunc>
|
||||||
void generate_population(type_id root_type, FitnessFunc& fitness_function, bool eval_fitness_now = true)
|
void generate_population(type_id root_type, FitnessFunc& fitness_function, bool eval_fitness_now = true)
|
||||||
{
|
{
|
||||||
using LambdaReturn = typename decltype(blt::meta::lambda_helper(fitness_function))::Return;
|
|
||||||
current_pop = config.pop_initializer.get().generate(
|
current_pop = config.pop_initializer.get().generate(
|
||||||
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
||||||
if (config.threads == 1)
|
if (config.threads == 1)
|
||||||
|
@ -293,17 +290,8 @@ namespace blt::gp
|
||||||
BLT_INFO("Starting with single thread variant!");
|
BLT_INFO("Starting with single thread variant!");
|
||||||
thread_execution_service = new std::function([this, &fitness_function](blt::size_t) {
|
thread_execution_service = new std::function([this, &fitness_function](blt::size_t) {
|
||||||
for (const auto& ind : blt::enumerate(current_pop.get_individuals()))
|
for (const auto& ind : blt::enumerate(current_pop.get_individuals()))
|
||||||
{
|
|
||||||
if constexpr (std::is_same_v<LambdaReturn, bool> || std::is_convertible_v<LambdaReturn, bool>)
|
|
||||||
{
|
|
||||||
auto result = fitness_function(ind.second.tree, ind.second.fitness, ind.first);
|
|
||||||
if (result)
|
|
||||||
fitness_should_exit = true;
|
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
fitness_function(ind.second.tree, ind.second.fitness, ind.first);
|
fitness_function(ind.second.tree, ind.second.fitness, ind.first);
|
||||||
}
|
|
||||||
|
|
||||||
if (ind.second.fitness.adjusted_fitness > current_stats.best_fitness)
|
if (ind.second.fitness.adjusted_fitness > current_stats.best_fitness)
|
||||||
current_stats.best_fitness = ind.second.fitness.adjusted_fitness;
|
current_stats.best_fitness = ind.second.fitness.adjusted_fitness;
|
||||||
|
|
||||||
|
@ -337,16 +325,7 @@ namespace blt::gp
|
||||||
{
|
{
|
||||||
auto& ind = current_pop.get_individuals()[i];
|
auto& ind = current_pop.get_individuals()[i];
|
||||||
|
|
||||||
|
|
||||||
if constexpr (std::is_same_v<LambdaReturn, bool> || std::is_convertible_v<LambdaReturn, bool>)
|
|
||||||
{
|
|
||||||
auto result = fitness_function(ind.tree, ind.fitness, i);
|
|
||||||
if (result)
|
|
||||||
fitness_should_exit = true;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
fitness_function(ind.tree, ind.fitness, i);
|
fitness_function(ind.tree, ind.fitness, i);
|
||||||
}
|
|
||||||
|
|
||||||
auto old_best = current_stats.best_fitness.load(std::memory_order_relaxed);
|
auto old_best = current_stats.best_fitness.load(std::memory_order_relaxed);
|
||||||
while (ind.fitness.adjusted_fitness > old_best &&
|
while (ind.fitness.adjusted_fitness > old_best &&
|
||||||
|
@ -428,7 +407,7 @@ namespace blt::gp
|
||||||
|
|
||||||
[[nodiscard]] bool should_terminate() const
|
[[nodiscard]] bool should_terminate() const
|
||||||
{
|
{
|
||||||
return current_generation >= config.max_generations || fitness_should_exit;
|
return current_generation >= config.max_generations;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool should_thread_terminate() const
|
[[nodiscard]] bool should_thread_terminate() const
|
||||||
|
@ -541,7 +520,6 @@ namespace blt::gp
|
||||||
population_stats current_stats{};
|
population_stats current_stats{};
|
||||||
population_t next_pop;
|
population_t next_pop;
|
||||||
std::atomic_uint64_t current_generation = 0;
|
std::atomic_uint64_t current_generation = 0;
|
||||||
std::atomic_bool fitness_should_exit = false;
|
|
||||||
|
|
||||||
blt::u64 seed;
|
blt::u64 seed;
|
||||||
prog_config_t config{};
|
prog_config_t config{};
|
||||||
|
|
2
lib/blt
2
lib/blt
|
@ -1 +1 @@
|
||||||
Subproject commit 3e8b616bf9d0513824d4452e3e77fccac910f0fb
|
Subproject commit f9938691ecb13b7b6acb2402235015bef9d58982
|
Loading…
Reference in New Issue