2024-11-14 23:55:48 -05:00
|
|
|
#pragma once
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2024 Brett Terpstra
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COSC_4P80_ASSIGNMENT_3_UI_H
|
|
|
|
#define COSC_4P80_ASSIGNMENT_3_UI_H
|
|
|
|
|
|
|
|
#include <blt/meta/codegen.h>
|
|
|
|
#include "blt/gfx/renderer/batch_2d_renderer.h"
|
|
|
|
#include "blt/gfx/renderer/font_renderer.h"
|
|
|
|
#include <assign3/file.h>
|
|
|
|
#include <assign3/som.h>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace assign3
|
|
|
|
{
|
|
|
|
class renderer_t;
|
|
|
|
|
2024-11-15 17:08:54 -05:00
|
|
|
struct neuron_render_info_t
|
2024-11-14 23:55:48 -05:00
|
|
|
{
|
|
|
|
blt::vec2 base_pos;
|
|
|
|
blt::vec2 neuron_padding;
|
|
|
|
float neuron_scale = 0;
|
|
|
|
|
2024-11-15 17:08:54 -05:00
|
|
|
static neuron_render_info_t fill_screen(renderer_t& renderer, float neuron_scale = 35, float x_padding = 250, float y_padding = 50,
|
|
|
|
float w_padding = 50, float h_padding = 50);
|
2024-11-14 23:55:48 -05:00
|
|
|
|
|
|
|
BLT_LVALUE_SETTER(blt::vec2, base_pos);
|
2024-11-15 17:08:54 -05:00
|
|
|
|
2024-11-14 23:55:48 -05:00
|
|
|
BLT_LVALUE_SETTER(blt::vec2, neuron_padding);
|
2024-11-15 17:08:54 -05:00
|
|
|
|
2024-11-14 23:55:48 -05:00
|
|
|
BLT_PRVALUE_SETTER(float, neuron_scale);
|
|
|
|
};
|
|
|
|
|
|
|
|
class motor_data_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<data_file_t> files;
|
|
|
|
std::vector<std::string> map_files_names;
|
|
|
|
|
|
|
|
void update();
|
|
|
|
};
|
|
|
|
|
2024-11-15 17:08:54 -05:00
|
|
|
struct render_data_t
|
|
|
|
{
|
|
|
|
blt::size_t index;
|
|
|
|
const neuron_t& neuron;
|
|
|
|
blt::vec2 neuron_scaled;
|
|
|
|
blt::vec2 neuron_offset;
|
|
|
|
blt::vec2 neuron_padded;
|
|
|
|
|
|
|
|
render_data_t(size_t index, const neuron_t& neuron, const blt::vec2& neuronScaled, const blt::vec2& neuronOffset,
|
|
|
|
const blt::vec2& neuronPadded):
|
|
|
|
index(index), neuron(neuron), neuron_scaled(neuronScaled), neuron_offset(neuronOffset), neuron_padded(neuronPadded)
|
|
|
|
{}
|
|
|
|
};
|
2024-11-14 23:55:48 -05:00
|
|
|
|
|
|
|
class renderer_t
|
|
|
|
{
|
|
|
|
friend motor_data_t;
|
2024-11-15 17:08:54 -05:00
|
|
|
friend neuron_render_info_t;
|
2024-11-14 23:55:48 -05:00
|
|
|
public:
|
|
|
|
explicit renderer_t(motor_data_t& data, blt::gfx::resource_manager& resources, blt::gfx::matrix_state_manager& state):
|
|
|
|
motor_data(data), br2d{resources, state}
|
|
|
|
{}
|
|
|
|
|
|
|
|
void create();
|
|
|
|
|
|
|
|
void cleanup();
|
|
|
|
|
2024-11-15 17:08:54 -05:00
|
|
|
void draw_som(neuron_render_info_t info, const std::function<blt::vec4(render_data_t)>& color_func);
|
|
|
|
|
|
|
|
void draw_debug(const data_file_t& file);
|
2024-11-14 23:55:48 -05:00
|
|
|
|
|
|
|
void render();
|
|
|
|
|
2024-11-15 19:06:12 -05:00
|
|
|
void regenerate_network()
|
2024-11-14 23:55:48 -05:00
|
|
|
{
|
2024-11-19 15:48:33 -05:00
|
|
|
distance_function = distance_function_t::from_shape(static_cast<shape_t>(selected_som_mode), som_width, som_height);
|
2024-11-18 00:53:32 -05:00
|
|
|
som = std::make_unique<som_t>(motor_data.files[currently_selected_network], som_width, som_height, max_epochs,
|
2024-11-18 19:50:46 -05:00
|
|
|
distance_function.get(), topology_function.get(), static_cast<shape_t>(selected_som_mode),
|
2024-11-18 16:49:56 -05:00
|
|
|
static_cast<init_t>(selected_init_type), normalize_init);
|
2024-11-18 19:50:46 -05:00
|
|
|
som->compute_neuron_activations();
|
2024-11-14 23:55:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
motor_data_t& motor_data;
|
|
|
|
std::unique_ptr<som_t> som;
|
|
|
|
std::unique_ptr<topology_function_t> topology_function;
|
2024-11-18 00:53:32 -05:00
|
|
|
std::unique_ptr<distance_function_t> distance_function;
|
|
|
|
|
2024-11-14 23:55:48 -05:00
|
|
|
blt::gfx::font_renderer_t fr2d{};
|
|
|
|
blt::gfx::batch_renderer_2d br2d;
|
|
|
|
|
2024-11-15 19:06:12 -05:00
|
|
|
blt::i32 som_width = 5;
|
|
|
|
blt::i32 som_height = 5;
|
2024-11-18 00:53:32 -05:00
|
|
|
blt::i32 max_epochs = 2000;
|
|
|
|
Scalar initial_learn_rate = 1;
|
2024-11-14 23:55:48 -05:00
|
|
|
|
|
|
|
int currently_selected_network = 0;
|
2024-11-18 00:53:32 -05:00
|
|
|
int selected_som_mode = 0;
|
2024-11-18 16:49:56 -05:00
|
|
|
int selected_init_type = 0;
|
|
|
|
bool normalize_init = false;
|
2024-11-15 17:08:54 -05:00
|
|
|
bool debug_mode = false;
|
2024-11-16 18:13:17 -05:00
|
|
|
bool draw_colors = true;
|
|
|
|
bool draw_data_lines = false;
|
2024-11-15 17:08:54 -05:00
|
|
|
bool running = false;
|
|
|
|
int debug_state = 0;
|
|
|
|
int selected_data_point = 0;
|
2024-11-18 16:49:56 -05:00
|
|
|
int selected_neuron = 0;
|
2024-11-16 18:13:17 -05:00
|
|
|
|
|
|
|
float requested_activation = 0.5;
|
|
|
|
float at_distance_measurement = 2;
|
2024-11-14 23:55:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //COSC_4P80_ASSIGNMENT_3_UI_H
|