Show similarity in app
This commit is contained in:
parent
60a053b929
commit
65faf0230b
@ -31,6 +31,7 @@ add_executable(app
|
||||
shared/src/values/Dna.cpp
|
||||
shared/src/values/DnaManager.cpp
|
||||
shared/src/values/mrand.cpp
|
||||
shared/src/values/Similarity.cpp
|
||||
shared/src/TcpSocket.cpp
|
||||
)
|
||||
# Add include directories
|
||||
|
@ -40,4 +40,6 @@ private:
|
||||
|
||||
Rectangle likedTextBox;
|
||||
Rectangle genTextBox;
|
||||
Rectangle simTextBox;
|
||||
float simil = 100.0f;
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "values/DnaManager.hpp"
|
||||
#include "values/Similarity.hpp"
|
||||
|
||||
namespace DnaStore
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define TOP (1 - pos)
|
||||
#define BOTTOM pos
|
||||
|
||||
Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom)
|
||||
Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom, bool leftOrRigth)
|
||||
{
|
||||
float br = box.width / box.height;
|
||||
float tr = textW / textH;
|
||||
@ -42,8 +42,14 @@ Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, boo
|
||||
ret.y = box.y + box.height - hm - ret.height;
|
||||
}
|
||||
|
||||
if (leftOrRigth)
|
||||
{
|
||||
ret.x = box.x + wm;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ret.x = box.x + box.width - wm - ret.width;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -68,6 +74,7 @@ void App::init(int screenWidth, int screenHeight)
|
||||
}
|
||||
|
||||
DnaStore::load(&manager);
|
||||
simil = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||
upTex(Liked::tbd);
|
||||
while (!canvas.tick(canvasTexure[TOP]))
|
||||
{
|
||||
@ -87,13 +94,19 @@ void App::init(int screenWidth, int screenHeight)
|
||||
0,
|
||||
(float)screenWidth / 2.0f,
|
||||
posY},
|
||||
20.0f, 83.0f, textMargin, false);
|
||||
20.0f, 83.0f, textMargin, false, true);
|
||||
|
||||
genTextBox = TextInSpace({0,
|
||||
posY + screenWidth,
|
||||
(float)screenWidth,
|
||||
posY},
|
||||
20.0f, 200.0f, textMargin, true);
|
||||
20.0f, 200.0f, textMargin, true, true);
|
||||
|
||||
simTextBox = TextInSpace({(float)screenWidth / 2.0f,
|
||||
likedTextBox.y,
|
||||
(float)screenWidth / 2.0f,
|
||||
likedTextBox.height},
|
||||
20.0f, 60.0f, textMargin, false, false);
|
||||
|
||||
destB = {0, posY, (float)screenWidth, (float)screenWidth};
|
||||
destA = destB;
|
||||
@ -115,6 +128,7 @@ void App::upTex(Liked liked)
|
||||
DnaStore::saveGen(&manager);
|
||||
DnaManager::newGen(&manager);
|
||||
DnaStore::saveVec(&manager);
|
||||
simil = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||
}
|
||||
DnaStore::saveData(&manager);
|
||||
}
|
||||
@ -197,9 +211,10 @@ void App::draw()
|
||||
|
||||
DrawTexturePro(canvasTexure[TOP].texture, source, destA, origin, 360 - rotation, WHITE);
|
||||
|
||||
const char *text = TextFormat("GEN %d: %d / %d", manager.generation, unit[TOP].index + 1, NUM_PER_GEN);
|
||||
DrawText(text, genTextBox.x, genTextBox.y, genTextBox.height, BLACK);
|
||||
|
||||
const char *textGen = TextFormat("GEN %d: %d / %d", manager.generation, unit[TOP].index + 1, NUM_PER_GEN);
|
||||
DrawText(textGen, genTextBox.x, genTextBox.y, genTextBox.height, BLACK);
|
||||
const char *textProc = TextFormat("%.1f%%", simil);
|
||||
DrawText(textProc, simTextBox.x, simTextBox.y, simTextBox.height, BLACK);
|
||||
switch (topLiked)
|
||||
{
|
||||
case Liked::yes:
|
||||
|
@ -84,6 +84,6 @@ namespace Similarity
|
||||
}
|
||||
}
|
||||
float average_similarity = total_similarity / num_pairs;
|
||||
return average_similarity;
|
||||
return average_similarity * 100.0f;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include "values/Similarity.hpp"
|
||||
#include "canvas/Canvas.hpp"
|
||||
|
||||
enum DrawingStage{
|
||||
enum DrawingStage
|
||||
{
|
||||
setup,
|
||||
drawTree,
|
||||
drawBig,
|
||||
@ -46,4 +47,7 @@ private:
|
||||
void setUpManager();
|
||||
|
||||
std::array<float, 3> simil;
|
||||
std::vector<std::array<float, 3>> similTable;
|
||||
|
||||
void setUpTable();
|
||||
};
|
@ -129,6 +129,10 @@ void Vapp::draw()
|
||||
enableAll = false;
|
||||
stageOfDrawing = DrawingStage::setup;
|
||||
}
|
||||
if (ImGui::MenuItem("CalcTable", nullptr, false, enableAll))
|
||||
{
|
||||
setUpTable();
|
||||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
@ -173,6 +177,28 @@ void Vapp::draw()
|
||||
ImGui::LabelText("##sim1", "cosine_similarity: %f", simil[0]);
|
||||
ImGui::LabelText("##sim2", "hamming_distance: %f", simil[1]);
|
||||
ImGui::LabelText("##sim3", "cosine_similarity_int: %f", simil[2]);
|
||||
|
||||
const ImGuiTableFlags flags = ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody;
|
||||
const int columns = 4;
|
||||
if (ImGui::BeginTable("table1", columns, flags))
|
||||
{
|
||||
for (int row = 0; row < similTable.size(); row++)
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
for (int column = 0; column < columns; column++)
|
||||
{
|
||||
ImGui::TableSetColumnIndex(column);
|
||||
if (column == 0)
|
||||
{
|
||||
ImGui::Text("%d", row);
|
||||
continue;
|
||||
}
|
||||
ImGui::Text("%f", similTable[row][column - 1]);
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@ -232,3 +258,53 @@ void Vapp::setUpManager()
|
||||
|
||||
sql::finalize(get_gen_stmt);
|
||||
}
|
||||
|
||||
void Vapp::setUpTable()
|
||||
{
|
||||
sqlite3_stmt *get_gen_stmt;
|
||||
sql::prepare_v2(db, get_gen, -1, &get_gen_stmt, NULL);
|
||||
|
||||
DnaManager::cleanUp(&manager, ids[selected_id_index]);
|
||||
similTable.clear();
|
||||
while (true)
|
||||
{
|
||||
sql::bind_int64(get_gen_stmt, 1, manager.id);
|
||||
sql::bind_int64(get_gen_stmt, 2, manager.generation);
|
||||
|
||||
bool new_gen = false;
|
||||
while (sql::step(get_gen_stmt) != SQL_DONE)
|
||||
{
|
||||
int64_t pos = sql::column_int64(get_gen_stmt, 1);
|
||||
int64_t liked = sql::column_int64(get_gen_stmt, 2);
|
||||
UiUnit unit = DnaManager::next(&manager);
|
||||
if ((unit.index != pos))
|
||||
{
|
||||
// DOTO: SET ERROR
|
||||
TraceLog(LOG_ERROR, "LOADING DNA");
|
||||
sql::finalize(get_gen_stmt);
|
||||
return;
|
||||
}
|
||||
unit.liked = (Liked)liked;
|
||||
new_gen = DnaManager::like(unit, &manager);
|
||||
}
|
||||
|
||||
if (new_gen)
|
||||
{
|
||||
similTable.emplace_back();
|
||||
int s = similTable.size() - 1;
|
||||
similTable[s][0] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity);
|
||||
similTable[s][1] = Similarity::calc_similarity(manager.vector, Similarity::hamming_distance);
|
||||
similTable[s][2] = Similarity::calc_similarity(manager.vector, Similarity::cosine_similarity_int);
|
||||
|
||||
DnaManager::newGen(&manager);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
sql::reset(get_gen_stmt);
|
||||
}
|
||||
|
||||
sql::finalize(get_gen_stmt);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user