From f94a3305943d4cf00e4531857279b8032d0e9489 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sun, 31 May 2020 06:41:26 -0400 Subject: [PATCH] use STL's inner_product --- machine_learning/adaline_learning.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/machine_learning/adaline_learning.cpp b/machine_learning/adaline_learning.cpp index a58b59cca..f271289e3 100644 --- a/machine_learning/adaline_learning.cpp +++ b/machine_learning/adaline_learning.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #define MAX_ITER 500 // INT_MAX ///< Maximum number of iterations to learn @@ -81,7 +82,8 @@ class adaline { double y = weights.back(); // assign bias value - for (int i = 0; i < x.size(); i++) y += x[i] * weights[i]; + // for (int i = 0; i < x.size(); i++) y += x[i] * weights[i]; + y = std::inner_product(x.begin(), x.end(), weights.begin(), y); return y >= 0 ? 1 : -1; // quantizer: apply ADALINE threshold function } @@ -229,7 +231,7 @@ void test2(double eta = 0.01) { Y[i] = (x0 + x1) > -1 ? 1 : -1; } - std::cout << "------- Test 1 -------" << std::endl; + std::cout << "------- Test 2 -------" << std::endl; std::cout << "Model before fit: " << ada << std::endl; ada.fit(X, Y);