diff --git a/CMakeLists.txt b/CMakeLists.txt index c61274b..ae2e6b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(COSC-4P80-Assignment-2 VERSION 0.1.0) +project(COSC-4P80-Assignment-2 VERSION 0.1.1) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/assign2/file.h b/include/assign2/file.h index 1e6d3cb..bf7d6d5 100644 --- a/include/assign2/file.h +++ b/include/assign2/file.h @@ -21,10 +21,8 @@ #include - namespace assign2 { - struct data_t { bool is_bad = false; @@ -38,6 +36,12 @@ namespace assign2 { public: std::vector data_points; + + [[nodiscard]] data_file_t normalize() const; + [[nodiscard]] data_file_t with_padding(blt::size_t desired_size, Scalar padding_value = 0) const; + + data_file_t& operator+=(const data_file_t& o); + data_file_t friend operator+(const data_file_t& a, const data_file_t& b); static std::vector load_data_files_from_path(std::string_view path); diff --git a/src/file.cpp b/src/file.cpp index b72de28..e5e3d7e 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -107,6 +107,39 @@ namespace assign2 return data; } + data_file_t data_file_t::normalize() const + { + auto copy = *this; + + for (auto& v : copy.data_points) + v = v.normalize(); + + return copy; + } + + data_file_t data_file_t::with_padding(blt::size_t desired_size, Scalar padding_value) const + { + auto copy = *this; + + for (auto& v : copy.data_points) + v = v.with_padding(desired_size, padding_value); + + return copy; + } + + data_file_t& data_file_t::operator+=(const data_file_t& o) + { + data_points.insert(data_points.end(), o.data_points.begin(), o.data_points.end()); + return *this; + } + + data_file_t operator+(const data_file_t& a, const data_file_t& b) + { + data_file_t file = a; + file.data_points.insert(file.data_points.end(), b.data_points.begin(), b.data_points.end()); + return file; + } + void save_as_csv(const std::string& file, const std::vector>>& data) { std::ofstream stream{file}; diff --git a/src/main.cpp b/src/main.cpp index 9f364dc..2cb6a41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,16 +2,13 @@ #include #include #include -#include #include "blt/iterator/enumerate.h" #include #include #include #include -#include #include #include -#include using namespace assign2; @@ -35,20 +32,17 @@ network_t create_network(blt::i32 input, blt::i32 hidden) const auto inner_mul = 0.25; auto layer1 = std::make_unique(input, hidden * mul, &sig, randomizer, empty); auto layer2 = std::make_unique(hidden * mul, hidden * inner_mul, &sig, randomizer, empty); -// auto layer3 = std::make_unique(hidden * inner_mul, hidden * inner_mul, &sig, randomizer, empty); -// auto layer4 = std::make_unique(hidden * inner_mul, hidden * inner_mul, &sig, randomizer, empty); - auto layer_output = std::make_unique(hidden * inner_mul, 2, &sig, randomizer, empty); + auto layer_output = std::make_unique(hidden * inner_mul, 2, &relu, randomizer, empty); std::vector> vec; vec.push_back(std::move(layer1)); vec.push_back(std::move(layer2)); -// vec.push_back(std::move(layer3)); -// vec.push_back(std::move(layer4)); vec.push_back(std::move(layer_output)); network_t network{std::move(vec)}; if (with_momentum) network.with_momentum(&omega); + return network; } @@ -606,7 +600,7 @@ int main(int argc, const char** argv) int input = static_cast(f.data_points.begin()->bins.size()); int hidden = input; - if (input != 64) + if (input != 16) continue; BLT_INFO("-----------------"); @@ -616,9 +610,12 @@ int main(int argc, const char** argv) network_t network = create_network(input, hidden); - float o = 0.00001; -// network.with_momentum(&o); - for (blt::size_t i = 0; i < 10000; i++) + auto output = network.execute(f.data_points.front().bins); + print_vec(output) << std::endl; + + float o = 0.0001; + network.with_momentum(&o); + for (blt::size_t i = 0; i < 300; i++) network.train_epoch(f, 1); BLT_INFO("Test Cases:");