diff --git a/.idea/COSC-4P80-Assignment-3.iml b/.idea/COSC-4P80-Assignment-3.iml index f08604b..19cf2da 100644 --- a/.idea/COSC-4P80-Assignment-3.iml +++ b/.idea/COSC-4P80-Assignment-3.iml @@ -1,2 +1,8 @@ - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml index fde0314..5fff85e 100644 --- a/.idea/editor.xml +++ b/.idea/editor.xml @@ -1,580 +1,244 @@ - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 0b76fe5..51ead9c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e6f9ea..0d49a2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(COSC-4P80-Assignment-3 VERSION 0.0.24) +project(COSC-4P80-Assignment-3 VERSION 0.0.25) include(FetchContent) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) diff --git a/plot_heatmap.py b/plot_heatmap.py index 79db893..127d45c 100644 --- a/plot_heatmap.py +++ b/plot_heatmap.py @@ -7,6 +7,10 @@ import sys filename = sys.argv[1] size = sys.argv[2] +if len(sys.argv) > 3: + subtitle = sys.argv[3] +else: + subtitle = "" df = pd.read_csv(filename, header=None) @@ -22,6 +26,7 @@ plt.yticks(np.arange(height), np.arange(height)) plt.xlabel('X Pos') plt.ylabel('Y Pos') plt.title('Heatmap of Motor Data (Bins: {})'.format(size)) +plt.suptitle(subtitle) plt.gca().invert_yaxis() diff --git a/plot_line_graph.py b/plot_line_graph.py index 4495580..a628c32 100644 --- a/plot_line_graph.py +++ b/plot_line_graph.py @@ -3,10 +3,16 @@ import matplotlib.pyplot as plt import numpy as np import sys +from plot_heatmap import subtitle + file1 = sys.argv[1] file2 = sys.argv[2] bins = sys.argv[3] split = sys.argv[4] +if len(sys.argv) > 4: + subtitle = sys.argv[5] +else: + subtitle = "" df1 = pd.read_csv(file1) df2 = pd.read_csv(file2) @@ -35,6 +41,7 @@ if split.lower() == "false": ax2.set_ylim(y_min, y_max) ax1.set_title('Topological and Quantization Error (Bins: {})'.format(bins)) + fig.suptitle(subtitle) plt.savefig("errors{}.png".format(bins)) else: @@ -45,7 +52,8 @@ else: plt.ylim(0, 1) plt.title("Topological Error (Bins: {})".format(bins)) - + plt.suptitle(subtitle) + plt.savefig("errors-topological{}.png".format(bins)) plt.plot(data2, color='b', label='Quantization Error') @@ -55,7 +63,8 @@ else: plt.ylim(y_min, y_max) plt.title("Quantization Error (Bins: {})".format(bins)) - + plt.suptitle(subtitle) + plt.savefig("errors-quantization{}.png".format(bins)) diff --git a/src/main.cpp b/src/main.cpp index d1fbc93..cc503a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,32 @@ #include #include #include +#include + +void plot_heatmap(const std::string& path, const std::string& activations_csv, blt::size_t bin_size, const std::string& subtitle) +{ +#ifdef __linux__ + auto pwd = std::filesystem::current_path(); + if (!blt::string::ends_with(pwd.string(), '/')) + pwd += '/'; + std::string command = "cd '" + path + "' && python3 " + pwd.string() + "plot_heatmap.py '" + activations_csv + "' " + std::to_string(bin_size) + " '" + + subtitle + "'"; + std::system(("sh -c \"" + command + "\"").c_str()); +#endif +} + +void plot_line_graph(const std::string& path, const std::string& topological_csv, const std::string& quantization_csv, blt::size_t bin_size, + const std::string& subtitle) +{ +#ifdef __linux__ + auto pwd = std::filesystem::current_path(); + if (!blt::string::ends_with(pwd.string(), '/')) + pwd += '/'; + std::string command = "cd '" + path + "' && python3 " + pwd.string() + "plot_line_graph.py '" + topological_csv + "' '" + quantization_csv + "' " + + std::to_string(bin_size) + " false '" + subtitle + "'"; + std::system(("sh -c \"" + command + "\"").c_str()); +#endif +} using namespace assign3; @@ -197,7 +223,7 @@ void action_test(const std::vector& argv_vector) for (auto [i, v] : blt::enumerate(average_activations)) { activations << v / static_cast(runs); - if (i % task.width == task.width-1) + if (i % task.width == task.width - 1) activations << '\n'; else activations << ','; @@ -248,6 +274,11 @@ int main(int argc, const char** argv) } // argv_vector.erase(argv_vector.begin() + 1); + +#ifdef __EMSCRIPTEN__ + action_start_graphics(argv_vector); + return 0; +#endif auto action = blt::string::toLowerCase(args.get("action")); if (action == "graphics")