need new crossover

main
Brett 2024-09-05 02:20:03 -04:00
parent 43e5ac46b9
commit 0dfa4fea93
5 changed files with 15 additions and 20 deletions

View File

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

View File

@ -39,12 +39,12 @@ blt::gp::mutation_t mut;
blt::gp::prog_config_t config = blt::gp::prog_config_t()
.set_initial_min_tree_size(2)
.set_initial_max_tree_size(6)
.set_elite_count(200)
.set_elite_count(2)
.set_crossover_chance(0.9)
.set_mutation_chance(0.1)
.set_reproduction_chance(0)
.set_max_generations(50)
.set_pop_size(20000)
.set_pop_size(500)
.set_thread_count(0);
blt::gp::gp_program program{SEED, config};
@ -65,7 +65,7 @@ constexpr auto fitness_function = [](blt::gp::tree_t& current_tree, blt::gp::fit
if (diff < value_cutoff)
{
fitness.raw_fitness += diff;
if (diff < 0.01)
if (diff <= 0.01)
fitness.hits++;
} else
fitness.raw_fitness += value_cutoff;
@ -99,7 +99,7 @@ int main()
program.set_operations(builder.build(add, sub, mul, pro_div, op_sin, op_cos, op_exp, op_log, lit, op_x));
BLT_DEBUG("Generate Initial Population");
auto sel = blt::gp::select_tournament_t{};
auto sel = blt::gp::select_fitness_proportionate_t{};
program.generate_population(program.get_typesystem().get_type<float>().id(), fitness_function, sel, sel, sel);
BLT_DEBUG("Begin Generation Loop");

View File

@ -100,6 +100,8 @@ namespace blt::gp
{
p1 = &crossover_selection.select(program, current_pop);
p2 = &crossover_selection.select(program, current_pop);
c1.copy_fast(*p1);
c2->copy_fast(*p2);
} while (!config.crossover.get().apply(program, *p1, *p2, c1, *c2));
#ifdef BLT_TRACK_ALLOCATIONS
tracker.stop_measurement_thread_local(state);
@ -124,6 +126,7 @@ namespace blt::gp
do
{
p = &mutation_selection.select(program, current_pop);
c1.copy_fast(*p);
} while (!config.mutator.get().apply(program, *p, c1));
#ifdef BLT_TRACK_ALLOCATIONS
tracker.stop_measurement_thread_local(state);
@ -144,7 +147,7 @@ namespace blt::gp
auto state = tracker.start_measurement_thread_local();
#endif
// reproduction
c1 = reproduction_selection.select(program, current_pop);
c1.copy_fast(reproduction_selection.select(program, current_pop));
#ifdef BLT_TRACK_ALLOCATIONS
tracker.stop_measurement_thread_local(state);
reproduction_calls.call();

View File

@ -30,14 +30,14 @@
namespace blt::gp
{
struct operator_id : integer_type<blt::size_t>
struct operator_id : integer_type<blt::u64>
{
using integer_type<blt::size_t>::integer_type;
using integer_type<blt::u64>::integer_type;
};
struct type_id : integer_type<blt::size_t>
struct type_id : integer_type<blt::u64>
{
using integer_type<blt::size_t>::integer_type;
using integer_type<blt::u64>::integer_type;
};
class type

View File

@ -61,9 +61,6 @@ namespace blt::gp
bool crossover_t::apply(gp_program& program, const tree_t& p1, const tree_t& p2, tree_t& c1, tree_t& c2) // NOLINT
{
c1.copy_fast(p1);
c2.copy_fast(p2);
auto& c1_ops = c1.get_operations();
auto& c2_ops = c2.get_operations();
@ -214,12 +211,9 @@ namespace blt::gp
return crossover_point_t{static_cast<blt::ptrdiff_t>(crossover_point), static_cast<blt::ptrdiff_t>(attempted_point)};
}
bool mutation_t::apply(gp_program& program, const tree_t& p, tree_t& c)
bool mutation_t::apply(gp_program& program, const tree_t&, tree_t& c)
{
c.copy_fast(p);
mutate_point(program, c, program.get_random().get_size_t(0ul, c.get_operations().size()));
return true;
}
@ -307,9 +301,7 @@ namespace blt::gp
bool advanced_mutation_t::apply(gp_program& program, const tree_t& p, tree_t& c)
{
// child tree
c.copy_fast(p);
(void) p;
auto& ops = c.get_operations();
auto& vals = c.get_values();