stats
parent
3ba20ba4da
commit
91ec4b0a5c
|
@ -19,6 +19,7 @@
|
||||||
#ifndef GP_SYSTEM_H
|
#ifndef GP_SYSTEM_H
|
||||||
#define GP_SYSTEM_H
|
#define GP_SYSTEM_H
|
||||||
#include <image_storage.h>
|
#include <image_storage.h>
|
||||||
|
#include <blt/gp/tree.h>
|
||||||
#include <blt/std/types.h>
|
#include <blt/std/types.h>
|
||||||
|
|
||||||
void setup_gp_system(blt::size_t population_size);
|
void setup_gp_system(blt::size_t population_size);
|
||||||
|
@ -47,4 +48,6 @@ std::array<image_pixel_t, IMAGE_DIMENSIONS * IMAGE_DIMENSIONS * 3> to_gl_image(c
|
||||||
|
|
||||||
std::tuple<const std::vector<float>&, const std::vector<float>&, const std::vector<float>&, const std::vector<float>&> get_fitness_history();
|
std::tuple<const std::vector<float>&, const std::vector<float>&, const std::vector<float>&, const std::vector<float>&> get_fitness_history();
|
||||||
|
|
||||||
|
std::array<blt::gp::population_t*, 3> get_populations();
|
||||||
|
|
||||||
#endif //GP_SYSTEM_H
|
#endif //GP_SYSTEM_H
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.3 MiB |
|
@ -214,44 +214,14 @@ void setup_operations(gp_program* program)
|
||||||
return ret;
|
return ret;
|
||||||
}, "lt_image");
|
}, "lt_image");
|
||||||
static operation_t op_image_grad([](const image_t a, const image_t b) {
|
static operation_t op_image_grad([](const image_t a, const image_t b) {
|
||||||
image_t out{}; // storage for the result
|
image_t out{};
|
||||||
const auto& inA = a.get_data().data;
|
|
||||||
const auto& inB = b.get_data().data;
|
|
||||||
auto& dst = out.get_data().data;
|
|
||||||
|
|
||||||
constexpr std::size_t W = IMAGE_DIMENSIONS;
|
for (const auto& [i, av, bv] : blt::in_pairs(std::as_const(a.get_data().data), std::as_const(b.get_data().data)).enumerate().flatten())
|
||||||
constexpr std::size_t H = IMAGE_DIMENSIONS;
|
|
||||||
|
|
||||||
if (true)
|
|
||||||
{
|
{
|
||||||
for (std::size_t y = 0; y < H; ++y)
|
const auto p = static_cast<double>(i) / static_cast<double>(IMAGE_SIZE);
|
||||||
{
|
const auto pi = 1 - p;
|
||||||
for (std::size_t x = 0; x < W; ++x)
|
|
||||||
{
|
|
||||||
const double t = static_cast<double>(x) / static_cast<double>(W - 1);
|
|
||||||
const std::size_t idx = y * W + x;
|
|
||||||
|
|
||||||
const double a = static_cast<double>(inA[idx]);
|
out.get_data().data[i] = static_cast<blt::u32>(av * p + bv * pi);
|
||||||
const double b = static_cast<double>(inB[idx]);
|
|
||||||
|
|
||||||
dst[idx] = static_cast<blt::u32>((1.0 - t) * a + t * b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else // vertical gradient
|
|
||||||
{
|
|
||||||
for (std::size_t y = 0; y < H; ++y)
|
|
||||||
{
|
|
||||||
const double t = static_cast<double>(y) / static_cast<double>(H - 1);
|
|
||||||
for (std::size_t x = 0; x < W; ++x)
|
|
||||||
{
|
|
||||||
const std::size_t idx = y * W + x;
|
|
||||||
|
|
||||||
const double a = static_cast<double>(inA[idx]);
|
|
||||||
const double b = static_cast<double>(inB[idx]);
|
|
||||||
|
|
||||||
dst[idx] = static_cast<blt::u32>((1.0 - t) * a + t * b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}, "grad_image");
|
}, "grad_image");
|
||||||
|
@ -341,10 +311,11 @@ void setup_operations(gp_program* program)
|
||||||
// }, "erode_image");
|
// }, "erode_image");
|
||||||
|
|
||||||
operator_builder builder{};
|
operator_builder builder{};
|
||||||
// builder.build(op_image_ephemeral, make_add<image_t>(), make_sub<image_t>(), make_mul<image_t>(), make_div<image_t>(), op_image_x, op_image_y,
|
builder.build(op_image_ephemeral, make_add<image_t>(), make_sub<image_t>(), make_mul<image_t>(), make_div<image_t>(), op_image_x, op_image_y,
|
||||||
// op_image_sin, op_image_gt, op_image_lt, op_image_cos, op_image_log, op_image_exp, op_image_or, op_image_and, op_image_xor, op_image_cos_off, op_image_sin_off op_image_perlinm
|
op_image_sin, op_image_gt, op_image_lt, op_image_cos, op_image_log, op_image_exp, op_image_or, op_image_and, op_image_xor,
|
||||||
// op_image_2d_ifs_eph, op_image_noise, op_image_random, op_image_2d_perlin_eph, op_image_not, op_image_2d_perlin_oct);
|
op_image_cos_off, op_image_sin_off, op_image_perlin, op_image_noise, op_image_random, op_image_2d_perlin_eph, op_image_not, op_image_grad,
|
||||||
builder.build(op_image_grad, op_image_x, op_image_y);
|
op_image_2d_perlin_oct);
|
||||||
|
// builder.build(op_image_grad, op_image_x, op_image_y);
|
||||||
program->set_operations(builder.grab());
|
program->set_operations(builder.grab());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,3 +462,8 @@ std::tuple<const std::vector<float>&, const std::vector<float>&, const std::vect
|
||||||
{
|
{
|
||||||
return {average_fitness, best_fitness, worst_fitness, overall_fitness};
|
return {average_fitness, best_fitness, worst_fitness, overall_fitness};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::array<population_t*, 3> get_populations()
|
||||||
|
{
|
||||||
|
return {&programs[0]->get_current_pop(), &programs[1]->get_current_pop(), &programs[2]->get_current_pop()};
|
||||||
|
}
|
||||||
|
|
22
src/main.cpp
22
src/main.cpp
|
@ -190,6 +190,28 @@ void update(const blt::gfx::window_data& data)
|
||||||
if (ImGui::BeginTabItem("Statistics"))
|
if (ImGui::BeginTabItem("Statistics"))
|
||||||
{
|
{
|
||||||
ImGui::Text("Here you can view statistics.");
|
ImGui::Text("Here you can view statistics.");
|
||||||
|
|
||||||
|
auto pops = get_populations();
|
||||||
|
|
||||||
|
const std::array<std::string, 3> labels = {"Red", "Green", "Blue"};
|
||||||
|
|
||||||
|
for (const auto& [i, label, pop] : blt::in_pairs(labels, pops).enumerate().flatten())
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::BeginGroup();
|
||||||
|
ImGui::Text("Population (%s)", label.c_str());
|
||||||
|
if (ImGui::BeginChild(label.c_str(), ImVec2(250, 0), true))
|
||||||
|
{
|
||||||
|
for (const auto& [i, ind] : blt::enumerate(*pop))
|
||||||
|
{
|
||||||
|
ImGui::Text("Tree (%ld) -> Fitness: %lf", i, ind.fitness.adjusted_fitness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
ImGui::EndGroup();
|
||||||
|
}
|
||||||
|
|
||||||
// Additional UI for statistical data
|
// Additional UI for statistical data
|
||||||
ImGui::EndTabItem();
|
ImGui::EndTabItem();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue