Compare commits

..

No commits in common. "06078fddc4c7328f95654437a29c2c7582a6ebed" and "32c5c6abf6b65fff728ad514f92e04a04a3fd438" have entirely different histories.

4 changed files with 12 additions and 20 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25) cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.0.97) project(blt-gp VERSION 0.0.95)
include(CTest) include(CTest)
@ -87,7 +87,7 @@ endmacro()
if (${BUILD_EXAMPLES}) if (${BUILD_EXAMPLES})
blt_add_project(blt-symbolic-regression examples/symbolic_regression.cpp example) blt_add_project(blt-SR-playground examples/symbolic_regression.cpp example)
endif () endif ()

View File

@ -117,8 +117,6 @@ namespace blt::gp
reinterpret_cast<NO_REF_T*>(head->metadata.offset - TYPE_SIZE)->~NO_REF_T(); reinterpret_cast<NO_REF_T*>(head->metadata.offset - TYPE_SIZE)->~NO_REF_T();
// move offset back // move offset back
head->metadata.offset -= TYPE_SIZE; head->metadata.offset -= TYPE_SIZE;
// moving back allows us to allocate with other data, if there is room.
while (head->used_bytes_in_block() == 0 && move_back());
return t; return t;
} }
@ -191,7 +189,6 @@ namespace blt::gp
break; break;
} }
} }
while (head->used_bytes_in_block() == 0 && move_back());
} }
/** /**
@ -215,7 +212,6 @@ namespace blt::gp
to.head->metadata.offset = static_cast<blt::u8*>(ptr) + type_size; to.head->metadata.offset = static_cast<blt::u8*>(ptr) + type_size;
std::memcpy(ptr, head->metadata.offset - type_size, type_size); std::memcpy(ptr, head->metadata.offset - type_size, type_size);
head->metadata.offset -= type_size; head->metadata.offset -= type_size;
while (head->used_bytes_in_block() == 0 && move_back());
} }
template<typename... Args> template<typename... Args>

View File

@ -80,17 +80,12 @@ namespace blt::gp
tree_t& select_fitness_proportionate_t::select(gp_program& program, population_t& pop, population_stats& stats) tree_t& select_fitness_proportionate_t::select(gp_program& program, population_t& pop, population_stats& stats)
{ {
auto choice = program.get_random().get_double(); auto choice = program.get_random().get_double();
for (const auto& [index, ref] : blt::enumerate(pop)) for (const auto& ind : blt::enumerate(pop))
{ {
if (index == 0) if (ind.first == 0 && choice <= stats.normalized_fitness[ind.first])
{ return ind.second.tree;
if (choice <= stats.normalized_fitness[index]) if (choice > stats.normalized_fitness[ind.first - 1] && choice <= stats.normalized_fitness[ind.first])
return ref.tree; return ind.second.tree;
} else
{
if (choice > stats.normalized_fitness[index - 1] && choice <= stats.normalized_fitness[index])
return ref.tree;
}
} }
BLT_WARN("Unable to find individual with fitness proportionate. This should not be a possible code path! (%lf)", choice); BLT_WARN("Unable to find individual with fitness proportionate. This should not be a possible code path! (%lf)", choice);
return pop.get_individuals()[0].tree; return pop.get_individuals()[0].tree;

View File

@ -52,9 +52,9 @@ large_##SIZE tertiary_##SIZE = make_data(large_##SIZE{}, [](auto index) {
return static_cast<blt::u8>(blt::random::murmur_random64c<blt::size_t>(SEED + index, 0, 256)); \ return static_cast<blt::u8>(blt::random::murmur_random64c<blt::size_t>(SEED + index, 0, 256)); \
}) })
#define RUN_TEST(FAILURE_COND, STACK, PASS, ...) do { if (FAILURE_COND) { BLT_ERROR(__VA_ARGS__); } else { BLT_DEBUG_STREAM << PASS << " | " << STACK.size() << "\n"; } } while(false) #define RUN_TEST(FAILURE_COND, PASS, ...) do { if (FAILURE_COND) { BLT_ERROR(__VA_ARGS__); } else { BLT_DEBUG(PASS); } } while(false)
#define RUN_TEST_SIZE(VALUE, SIZE, STACK) RUN_TEST(auto index = compare(VALUE, STACK.pop<SIZE>()); index >= 0, STACK, #SIZE " test PASSED.", "Failed to pop large value (" #SIZE "), failed at index %ld", index) #define RUN_TEST_SIZE(VALUE, SIZE, STACK) RUN_TEST(auto index = compare(VALUE, STACK.pop<SIZE>()); index >= 0, #SIZE " Test PASSED.", "Failed to pop large value (" #SIZE "), failed at index %ld", index)
#define RUN_TEST_TYPE(TYPE, EXPECTED, STACK) RUN_TEST(auto val = STACK.pop<TYPE>(); val != EXPECTED, STACK, #TYPE " test PASSED", "Failed to pop correct " #TYPE " (" #EXPECTED ") found %lf", val); #define RUN_TEST_TYPE(TYPE, EXPECTED, STACK) RUN_TEST(auto val = STACK.pop<TYPE>(); val != EXPECTED, #TYPE " test PASSED", "Failed to pop correct " #TYPE " (" #EXPECTED ") found %lf", val);
const blt::u64 SEED = std::random_device()(); const blt::u64 SEED = std::random_device()();
@ -189,13 +189,14 @@ void test_basic_types()
BLT_TRACE_STREAM << stack.size() << "\n"; BLT_TRACE_STREAM << stack.size() << "\n";
std::cout << std::endl; std::cout << std::endl;
BLT_INFO("Some fishy numbers in the last reported size. Let's try modifying the stack."); // fixed by moving back in pop BLT_INFO("Some fishy numbers in the last reported size. Let's try modifying the stack.");
stack.push(88.9f); stack.push(88.9f);
BLT_TRACE_STREAM << "Pushed float: " << stack.size() << "\n"; BLT_TRACE_STREAM << "Pushed float: " << stack.size() << "\n";
{ {
BLT_INFO("Popping a few values."); BLT_INFO("Popping a few values.");
RUN_TEST_TYPE(float, 88.9f, stack); RUN_TEST_TYPE(float, 88.9f, stack);
BLT_TRACE_STREAM << "popped float: " << stack.size() << "\n";
RUN_TEST_SIZE(secondary_256, large_256, stack); RUN_TEST_SIZE(secondary_256, large_256, stack);
} }
BLT_TRACE_STREAM << stack.size() << "\n"; BLT_TRACE_STREAM << stack.size() << "\n";