i have no idea just some tests
parent
23587bb2f0
commit
4729e94d4f
|
@ -16,3 +16,6 @@
|
|||
[submodule "lib/lockfree"]
|
||||
path = lib/lockfree
|
||||
url = https://github.com/bhhbazinga/LockFreeLinkedList.git
|
||||
[submodule "lib/implot"]
|
||||
path = lib/implot
|
||||
url = https://github.com/epezent/implot.git
|
||||
|
|
|
@ -18,9 +18,11 @@ include_directories( ${OpenCV_INCLUDE_DIRS} )
|
|||
include_directories(lib/stb)
|
||||
|
||||
include_directories(include/)
|
||||
include_directories(lib/implot)
|
||||
file(GLOB_RECURSE PROJECT_BUILD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
|
||||
file(GLOB IMPLOT_BUILD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/lib/implot/*.cpp")
|
||||
|
||||
add_executable(image-gp-2 ${PROJECT_BUILD_FILES})
|
||||
add_executable(image-gp-2 ${PROJECT_BUILD_FILES} ${IMPLOT_BUILD_FILES})
|
||||
|
||||
target_compile_options(image-gp-2 PRIVATE -Wall -Wextra -Wpedantic -Wno-comment)
|
||||
target_link_options(image-gp-2 PRIVATE -Wall -Wextra -Wpedantic -Wno-comment)
|
||||
|
|
|
@ -43,4 +43,6 @@ std::array<image_storage_t, 3>& get_reference_image();
|
|||
|
||||
std::array<image_pixel_t, IMAGE_DIMENSIONS * IMAGE_DIMENSIONS * 3> to_gl_image(const std::array<image_storage_t, 3>& image);
|
||||
|
||||
std::tuple<const std::vector<float>&, const std::vector<float>&, const std::vector<float>&, const std::vector<float>&> get_fitness_history();
|
||||
|
||||
#endif //GP_SYSTEM_H
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 3da8bd34299965d3b0ab124df743fe3e076fa222
|
|
@ -25,10 +25,15 @@
|
|||
|
||||
using namespace blt::gp;
|
||||
|
||||
float filter_nan(const float f)
|
||||
bool is_nan(const float f)
|
||||
{
|
||||
if (std::isnan(f) || std::isinf(f) || std::isinf(-f))
|
||||
return 0.0f;
|
||||
return std::isnan(f) || std::isinf(f) || std::isinf(-f);
|
||||
}
|
||||
|
||||
float filter_nan(const float f, const float failure = 0.0f)
|
||||
{
|
||||
if (is_nan(f))
|
||||
return failure;
|
||||
return f;
|
||||
}
|
||||
|
||||
|
@ -38,6 +43,11 @@ prog_config_t config{};
|
|||
std::vector<std::array<image_pixel_t, IMAGE_DIMENSIONS * IMAGE_DIMENSIONS * 3>> images;
|
||||
auto reference_image = image_storage_t::from_file("../silly.png");
|
||||
|
||||
std::vector<float> average_fitness;
|
||||
std::vector<float> best_fitness;
|
||||
std::vector<float> worst_fitness;
|
||||
std::vector<float> overall_fitness;
|
||||
|
||||
template <size_t Channel>
|
||||
void fitness_func(const tree_t& tree, fitness_t& fitness, const blt::size_t index)
|
||||
{
|
||||
|
@ -54,13 +64,18 @@ void fitness_func(const tree_t& tree, fitness_t& fitness, const blt::size_t inde
|
|||
|
||||
auto multiplier = (1 - std::abs((static_cast<float>(x) / (static_cast<float>(IMAGE_DIMENSIONS) / 2)) - 1)) + (1 - std::abs(
|
||||
(static_cast<float>(y) / (static_cast<float>(IMAGE_DIMENSIONS) / 2)) - 1));
|
||||
const auto diff = filter_nan(data.get(x, y)) - reference_image[Channel].get(x, y);
|
||||
fitness.raw_fitness += diff * diff * multiplier;
|
||||
auto our = data.get(x, y);
|
||||
auto our2 = blt::mem::type_cast<blt::u32>(our);
|
||||
auto our3 = static_cast<double>(our2) / static_cast<double>(std::numeric_limits<blt::u32>::max());
|
||||
auto theirs = reference_image[Channel].get(x, y);
|
||||
const auto diff = std::pow(our3, 1.0f/2.2f) - std::pow(theirs, 1.0f/2.2f);
|
||||
fitness.raw_fitness += static_cast<float>(diff * multiplier);
|
||||
}
|
||||
}
|
||||
fitness.raw_fitness /= static_cast<float>(IMAGE_SIZE_CHANNELS);
|
||||
// fitness.raw_fitness /= static_cast<float>(IMAGE_SIZE_CHANNELS);
|
||||
fitness.raw_fitness = static_cast<float>(std::sqrt(fitness.raw_fitness));
|
||||
fitness.standardized_fitness = fitness.raw_fitness;
|
||||
fitness.adjusted_fitness = -fitness.standardized_fitness;
|
||||
fitness.adjusted_fitness = 1 - 1 / (1 + fitness.standardized_fitness);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -271,6 +286,16 @@ void run_step()
|
|||
BLT_TRACE("Channel Green");
|
||||
else
|
||||
BLT_TRACE("Channel Blue");
|
||||
const auto avg = stats.average_fitness.load(std::memory_order_relaxed);
|
||||
const auto best = stats.best_fitness.load(std::memory_order_relaxed);
|
||||
const auto worst = stats.worst_fitness.load(std::memory_order_relaxed);
|
||||
const auto overall = stats.overall_fitness.load(std::memory_order_relaxed);
|
||||
|
||||
average_fitness.push_back(static_cast<float>(avg));
|
||||
best_fitness.push_back(static_cast<float>(best));
|
||||
worst_fitness.push_back(static_cast<float>(worst));
|
||||
overall_fitness.push_back(static_cast<float>(overall));
|
||||
|
||||
BLT_TRACE("\tAvg Fit: {:0.6f}, Best Fit: {:0.6f}, Worst Fit: {:0.6f}, Overall Fit: {:0.6f}",
|
||||
stats.average_fitness.load(std::memory_order_relaxed), stats.best_fitness.load(std::memory_order_relaxed),
|
||||
stats.worst_fitness.load(std::memory_order_relaxed), stats.overall_fitness.load(std::memory_order_relaxed));
|
||||
|
@ -340,3 +365,8 @@ void regenerate_image(blt::size_t index, float& image_storage, blt::i32 width, b
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
std::tuple<const std::vector<float>&, const std::vector<float>&, const std::vector<float>&, const std::vector<float>&> get_fitness_history()
|
||||
{
|
||||
return {average_fitness, best_fitness, worst_fitness, overall_fitness};
|
||||
}
|
||||
|
|
33
src/main.cpp
33
src/main.cpp
|
@ -6,8 +6,7 @@
|
|||
#include "blt/gfx/renderer/camera.h"
|
||||
#include <imgui.h>
|
||||
#include <thread>
|
||||
|
||||
#include "../cmake-build-release-examples/_deps/imgui-src/imgui_internal.h"
|
||||
#include <implot.h>
|
||||
|
||||
blt::gfx::matrix_state_manager global_matrices;
|
||||
blt::gfx::resource_manager resources;
|
||||
|
@ -58,6 +57,7 @@ std::thread run_gp()
|
|||
|
||||
void init(const blt::gfx::window_data&)
|
||||
{
|
||||
ImPlot::CreateContext();
|
||||
using namespace blt::gfx;
|
||||
|
||||
for (blt::size_t i = 0; i < population_size; i++)
|
||||
|
@ -193,7 +193,7 @@ void update(const blt::gfx::window_data& data)
|
|||
{
|
||||
auto w = data.width;
|
||||
auto h = data.height - top_bar_height - 10;
|
||||
renderer_2d.drawRectangle({w / 2, h / 2, w, h}, "reference");
|
||||
renderer_2d.drawRectangle({static_cast<blt::f32>(w / 2), h / 2, w, h}, "reference");
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
|
@ -202,6 +202,33 @@ void update(const blt::gfx::window_data& data)
|
|||
|
||||
ImGui::End(); // MainWindow
|
||||
|
||||
// if (ImGui::Begin("Fitness"))
|
||||
// {
|
||||
// const auto& [average, best, worst, overall] = get_fitness_history();
|
||||
//
|
||||
// if (ImPlot::BeginPlot("Average Fitness", ImVec2{-1, 0}, ImPlotFlags_NoInputs))
|
||||
// {
|
||||
// ImPlot::PlotLine("Average Fitness", average.data(), static_cast<blt::i32>(average.size()));
|
||||
// ImPlot::EndPlot();
|
||||
// }
|
||||
// if (ImPlot::BeginPlot("Best Fitness", ImVec2{-1, 0}, ImPlotFlags_NoInputs))
|
||||
// {
|
||||
// ImPlot::PlotLine("Best Fitness", best.data(), static_cast<blt::i32>(best.size()));
|
||||
// ImPlot::EndPlot();
|
||||
// }
|
||||
// if (ImPlot::BeginPlot("Worst Fitness", ImVec2{-1, 0}, ImPlotFlags_NoInputs))
|
||||
// {
|
||||
// ImPlot::PlotLine("Worst Fitness", worst.data(), static_cast<blt::i32>(worst.size()));
|
||||
// ImPlot::EndPlot();
|
||||
// }
|
||||
// if (ImPlot::BeginPlot("Overall Fitness", ImVec2{-1, 0}, ImPlotFlags_NoInputs))
|
||||
// {
|
||||
// ImPlot::PlotLine("Overall Fitness", overall.data(), static_cast<blt::i32>(overall.size()));
|
||||
// ImPlot::EndPlot();
|
||||
// }
|
||||
// }
|
||||
// ImGui::End();
|
||||
|
||||
if (ImGui::Begin("Debug"))
|
||||
{
|
||||
const auto allocated_blocks = g_allocated_blocks.load(std::memory_order_relaxed);
|
||||
|
|
Loading…
Reference in New Issue