From 923c27f7235f698e0508abc1ffc2bd27406b5fff Mon Sep 17 00:00:00 2001 From: andrewldesousa Date: Wed, 3 Jul 2024 16:58:27 -0700 Subject: [PATCH] fix unit tests --- .github/workflows/unit_tests.yaml | 17 +++++++---------- .vscode/settings.json | 6 +++++- apps/and.cpp | 18 ++++++++---------- scalar.h | 3 ++- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml index e74e27a..18918e7 100644 --- a/.github/workflows/unit_tests.yaml +++ b/.github/workflows/unit_tests.yaml @@ -12,13 +12,11 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - - name: Install compiler id: install_cc uses: rlalik/setup-cpp-compiler@master with: compiler: latest - - name: Install dependencies run: | sudo apt-get update @@ -26,11 +24,10 @@ jobs: sudo apt-get install -y cmake # Install Google Test sudo apt-get install -y libgtest-dev - - # - name: Build and run tests - # run: | - # mkdir build - # cd build - # cmake .. - # make - # ./tests/test_main \ No newline at end of file + - name: Build and run tests + run: | + mkdir build + cd build + cmake .. + make + ./tests/test_main \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index d77e2aa..665d136 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -90,6 +90,10 @@ "future": "cpp", "regex": "cpp", "typeindex": "cpp", - "valarray": "cpp" + "valarray": "cpp", + "numeric": "cpp", + "stop_token": "cpp", + "thread": "cpp", + "__nullptr": "cpp" } } \ No newline at end of file diff --git a/apps/and.cpp b/apps/and.cpp index 5c770d2..93abdac 100644 --- a/apps/and.cpp +++ b/apps/and.cpp @@ -6,12 +6,15 @@ // move operator #include +// include exp +#include + int main(int argc, char** argv) { if (argc > 1 && std::string(argv[1]) == "debug") Logger::get_instance().set_debug_mode(true); else if (argc > 1) throw std::runtime_error("Invalid argument in main function. Use 'debug' to enable debug mode."); - int num_epochs = 50000, num_samples = 4; + int num_epochs = 5000000, num_samples = 4; float learning_rate = 0.001; // weights shared pointer @@ -41,18 +44,13 @@ int main(int argc, char** argv) { for (int i = 0; i < num_epochs; i++) { std::shared_ptr> loss = Scalar::make(0); for (int j = 0; j < num_samples; j++) { - auto z = Scalar::make(0); - - for (int k = 0; k < weights.size(); k++) { - if (k == weights.size() - 1) z = z + weights[k]; - else z = z + weights[k] * X[j][k]; - } + auto z = weights[0] * X[j][0] + weights[1] * X[j][1] + weights[2]; auto a = sigmoid(z); - loss = cross_entropy(Y[j], a) + loss; + // loss = cross_entropy(Y[j], a) + loss; } - loss = loss / Scalar::make(num_samples); - loss->backward(); + // loss = loss / Scalar::make(num_samples); + // loss->backward(); // update weights for (int j = 0; j < weights.size(); j++) { diff --git a/scalar.h b/scalar.h index 0f89976..b1bf070 100644 --- a/scalar.h +++ b/scalar.h @@ -7,6 +7,7 @@ #include #include #include "utils.h" +#include static int id_counter; @@ -146,7 +147,7 @@ class Scalar: public std::enable_shared_from_this> { // log friend std::shared_ptr> log(std::shared_ptr> rhs) { - auto result = Scalar::make(std::log(rhs->value)); + auto result = Scalar::make(log(rhs->value)); result->children.insert(rhs); rhs->in_degrees++;